HDFql Reference Manual v2.6.0

3.3Java

HDFql can be used in the Java programming language through a wrapper named “HDFql.java”, which is stored in the directory “java” found under the directory “wrapper”. The following short program illustrates how HDFql can be used in this language.

// import HDFql package (make sure it can be found by the Java compiler/JVM)
import as.hdfql.*;

public class Example
{
    public static void main(String args[])
    {
       // display HDFql version in use 
       System.out.println("HDFql version: " + HDFql.VERSION);

       // create an HDF5 file named "my_file.h5" and use (i.e. open) it 
       HDFql.execute("CREATE AND USE FILE my_file.h5"); 

       // create an HDF5 dataset named "my_dataset" of data type int 
       HDFql.execute("CREATE DATASET my_dataset AS INT VALUES(10)"); 

       // select (i.e. read) data from dataset "my_dataset" and populate cursor in use with it
       HDFql.execute("SELECT FROM my_dataset"); 

       // move cursor in use to the first position within the result set 
       HDFql.cursorFirst(); 

       // display content of cursor in use
       System.out.println("Dataset value: " + HDFql.cursorGetInt());
    }
}

Assuming that the program is stored in a file named “Example.java”, it must first be compiled before it can be launched. The program can be compiled by executing the following command in a terminal:

javac -classpath <hdfql_java_wrapper_directory> Example.java

In case the program does not compile, check whether the Java Development Kit (JDK) is installed. If the JDK is missing, the solution is to download and install it from the website https://www.oracle.com/java/technologies/downloads.

The compiled program may be launched by executing the following command in a terminal:

java Example

In case the compiled program does not launch, it is most likely that the HDFql Java wrapper and/or the MPI shared library were not found (these are needed to launch the program). The solution is:

  • On Windows, add the directory where the file “HDFql.java” (i.e. the wrapper) is located to the environment variables “CLASSPATH” and “PATH” by executing the following command in a terminal:
    set CLASSPATH=<hdfql_java_wrapper_directory>;.;%CLASSPATH%
    set PATH=<hdfql_java_wrapper_directory>\as\hdfql;%PATH%
  • On Linux, add the directories where the files “HDFql.java” and (optionally) “libmpi.so” are located to the environment variables “CLASSPATH” and “LD_LIBRARY_PATH” by executing the following command in a terminal:
    • With an HDFql non MPI-based distribution:
      export CLASSPATH=<hdfql_java_wrapper_directory>:.:$CLASSPATH
      export LD_LIBRARY_PATH=<hdfql_java_wrapper_directory>/as/hdfql:$LD_LIBRARY_PATH
    • With an HDFql MPI-based distribution:
      export CLASSPATH=<hdfql_java_wrapper_directory>:.:$CLASSPATH
      export LD_LIBRARY_PATH=<hdfql_java_wrapper_directory>/as/hdfql:<mpi_lib_directory>:$LD_LIBRARY_PATH
  • On macOS, add the directories where the files “HDFql.java” and (optionally) “libmpi.dylib” are located to the environment variables “CLASSPATH” and “DYLD_LIBRARY_PATH”5 by executing the following command in a terminal:
    • With an HDFql non MPI-based distribution:
      export CLASSPATH=<hdfql_java_wrapper_directory>:.:$CLASSPATH
      export DYLD_LIBRARY_PATH=<hdfql_java_wrapper_directory>/as/hdfql:$DYLD_LIBRARY_PATH
    • With an HDFql MPI-based distribution:
      export CLASSPATH=<hdfql_java_wrapper_directory>:.:$CLASSPATH
      export DYLD_LIBRARY_PATH=<hdfql_java_wrapper_directory>/as/hdfql:<mpi_lib_directory>:$DYLD_LIBRARY_PATH

Notes

  1. Starting with version 10.11 (i.e. El Capitan), Apple introduced a security feature named System Integrity Protection (SIP) that may prevent setting the environment variable “DYLD_LIBRARY_PATH” and, ultimately, launching the program. To overcome this, SIP should be disabled (please refer to https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html for additional information). Alternatively, the Java library path property “java.library.path” should be set to the path where the HDFql shared library “libHDFql.dylib” is located when launching the program (e.g. java -Djava.library.path=<hdfql_java_wrapper_directory>/as/hdfql my_program). ↩