HDFql Reference Manual v2.6.0

6.3.2INTO

Syntax

INTO {cursor | object | text_file | binary_file | excel_file | memory}

cursor := CURSOR | {SLIDING [sliding_value] CURSOR [ON {FIRST | LAST} DIMENSION]}

object := [TRUNCATE] [DATASET | ATTRIBUTE] [file_name] object_name [[selection]]

selection := hyperslab | point

hyperslab := [start]:[stride]:[count]:[block] [, [start]:[stride]:[count]:[block]]* [, {OR | AND | XOR | NOTA | NOTB} [start]:[stride]:[count]:[block] [, [start]:[stride]:[count]:[block]]*]*

point := coord [, coord]* [; coord [, coord]*]*

text_file := [TRUNCATE] [DOS | UNIX] [TEXT] FILE file_name [HEADER [header_value [, header_value]*]] [NO SEPARATOR | SEPARATOR {separator_value | {[separator_value], [subseparator_value]}}] [SPLIT split_value] [DECIMAL SCALE decimal_scale_value]

binary_file := [TRUNCATE] BINARY FILE file_name

excel_file := [TRUNCATE] EXCEL [XLS | XLSX] FILE file_name [SHEET sheet_name] [HEADER [header_value [, header_value]*]] [SPLIT split_value] [DECIMAL SCALE decimal_scale_value]

memory := MEMORY variable_number [SIZE variable_size] [OFFSET (member_offset | {[member_offset] {, [member_offset]}+})] [MAX max_elements]

Description

Write result sets (i.e. data) returned by DATA QUERY LANGUAGE (DQL) and DATA INTROSPECTION LANGUAGE (DIL) operations into the cursor in use (default behavior when no redirecting option is specified), an HDF5 object (i.e. dataset or attribute), a (text, binary, or Excel) file, or memory (i.e. a user-defined variable). In detail, this procedure (which is known as output redirecting) can be performed into:

When redirecting a result set into an HDF5 object (i.e. dataset or attribute) that already exists, the result set is written in function of the characteristics (i.e. data type and dimensions) of the object in question (meaning that the former may eventually be truncated and/or converted to conform to the latter). To have the HDF5 object characterized in function of the result set, specify the keyword TRUNCATE (all data stored in the object will be permanently lost and the object is recreated in function of the characteristics of the result set to store). When redirecting a result set into a text file, binary file or a sheet of an Excel file that already exists, the result set is appended to it. To overwrite an existing text file, binary file or a sheet of an Excel file, specify the keyword TRUNCATE (all data stored in the file or in the sheet will be permanently lost).

Parameter(s)

sliding_value – optional integer that specifies the number of elements (i.e. slice/portion) that the cursor may store before sliding and reading new elements of the dataset whenever the cursor is positioned outside the slice/portion it currently stores (i.e. before or after the first or last element stored in the cursor, respectively). If sliding_value is specified, it must be greater than zero (otherwise an error is raised). If not specified and in case the keyword SLIDING is specified, its default value is one. In case the keyword SLIDING is specified and the dimension of the dataset to slide on is not specified, the sliding is performed on the first dimension by default. In case the keyword ON FIRST DIMENSION or ON LAST DIMENSION is specified, the sliding is performed on the first or last dimension of the dataset, respectively. If the result set to slide on is not from a dataset, an error is raised.

file_name – optional string that specifies the name of an HDF5, text, binary, or Excel file to redirect (i.e. write) a result set into.

object_name – optional string that specifies the name of an HDF5 object (i.e. dataset or attribute) to redirect (i.e. write) a result set into.

selection – optional option that specifies a slice (i.e. portion) of an existing HDF5 dataset to redirect (i.e. write) a result set into using a hyperslab or point selection.

sheet_name – optional string that specifies the name of an Excel sheet to redirect (i.e. write) a result set into. If not specified, the sheet to redirect (i.e. write) a result set into is the one currently selected for viewing/editing within the Excel file.

header_value – optional string that specifies the header to write in a text or an Excel file before redirecting (i.e. writing) a result set into. If not specified and in case the keyword HEADER is specified, its default value is “DATA” in case the result set is not of data type HDFQL_COMPOUND or the names of members of the compound in case the result set is of data type HDFQL_COMPOUND.

separator_value – optional string that specifies the separator to use between elements (of the result set) when redirecting (i.e. writing) these in a text file. If not specified, its default value is a comma (,). In case the keyword NO SEPARATOR is specified, no separator is used between elements (of the result set) when redirecting (i.e. writing) these into a text file (i.e. the elements will be concatenated without separator).

subseparator_value – optional string that specifies the subseparator to use between elements (of the result subset) when redirecting (i.e. writing) these in a text file. The subseparator is only applicable when the data type of the result set is either HDFQL_VARTINYINT, HDFQL_UNSIGNED_VARTINYINT, HDFQL_VARSMALLINT, HDFQL_UNSIGNED_VARSMALLINT, HDFQL_VARINT, HDFQL_UNSIGNED_VARINT, HDFQL_VARBIGINT, HDFQL_UNSIGNED_VARBIGINT, HDFQL_VARFLOAT, HDFQL_VARDOUBLE, or HDFQL_OPAQUE, and ignored otherwise. If not specified, its default value is a space.

split_value – optional integer that specifies the number of elements (of the result set) to redirect (i.e. write) per line before writing the remaining elements on a new line in a text or an Excel file. If split_value is specified, it must be equal to or greater than zero (otherwise an error is raised). If not specified, no splitting is performed, which means that all elements (of the result set) are redirected (i.e. written) on the same line.

decimal_scale_value – optional integer that specifies the decimal scale (i.e. number of decimal places) to use when writing fractional numbers into a text or Excel file. If decimal_scale_value is specified, it must be equal to or greater than zero (otherwise an error is raised). If not specified, the decimal scale to use is the one that may have been set through the operation SET DECIMAL SCALE.

variable_number – optional integer that specifies the number of the variable that will store the result set (i.e. data) returned by DATA QUERY LANGUAGE (DQL) and DATA INTROSPECTION LANGUAGE (DIL) operations. The number is returned by the function hdfql_variable_register upon registering the variable or, subsequently, returned by the function hdfql_variable_get_number.

variable_size – optional integer that specifies the size (in bytes) of the variable that will store the result set (i.e. data). Of note, the specification of a size only has effect for a result set of data type HDFQL_COMPOUND (for any other data type the specification is ignored – i.e. has no effect).

member_offset – optional integer that specifies the (memory) member offsets that compose the variable that will store the result set (i.e. data). If specified, the variable is assumed to be a C padded struct data type (i.e. its members may not be contiguous in memory due to padding between them) and is used as such by HDFql. If not specified, the variable is assumed to be a C primitive or packed struct data type (i.e. its members are contiguous in memory and have no padding between them) and is used as such by HDFql. Of note, the specification of an offset only has effect for a result set of data type HDFQL_COMPOUND (for any other data type the specification is ignored – i.e. has no effect).

max_elements – optional integer that specifies the maximum number of elements to use from the variable to store the result set (i.e. data). In other words, only the first max_elements of the variable will be used to store the result set. Of note, max_elements may be smaller than the number of elements that the result set may store (in this case, the remainder of the result set is discarded). If max_elements is specified, it must be equal to or greater than zero (otherwise an error is raised). If not specified, the variable must have enough space to store the entire result set (otherwise an error may occur such as a segmentation fault).

Example(s)

# create an HDF5 dataset named "my_dataset0" of data type char of one dimension (size 3) 
CREATE DATASET my_dataset0 AS TINYINT(3)

# insert (i.e. write) values into dataset "my_dataset0" 
INSERT INTO my_dataset0 VALUES(65, 66, 67)

# select (i.e. read) data from dataset "my_dataset0" and populate cursor in use with it (should return 65, 66, 67)
SELECT FROM my_dataset0

# select (i.e. read) data from dataset "my_dataset0" and populate cursor in use with it (should return 65, 66, 67)
SELECT FROM my_dataset0 INTO CURSOR

# select (i.e. read) data from dataset "my_dataset0" and write it into an HDF5 attribute named "my_attribute0" (if the attribute does not exist, it will be created automatically and of data type char of one dimension (size 3))
SELECT FROM my_dataset0 INTO ATTRIBUTE my_attribute0

# select (i.e. read) data from dataset "my_dataset0" and write it into a text file named "my_file0.txt" using default separator "," (should write "65,66,67" in one single line)
SELECT FROM my_dataset0 INTO FILE my_file0.txt

# select (i.e. read) data from dataset "my_dataset0" and write it into a text file named "my_file1.txt" using separator "**" (should write "65**66**67**" in one single line)
SELECT FROM my_dataset0 INTO TEXT FILE my_file1.txt SEPARATOR **

# select (i.e. read) data from dataset "my_dataset0" and write it into a text file named "my_file2.txt" splitting every two values on a new line using a UNIX-based EOL terminator (should write "65,65" in the first line and "67" in the second line)
SELECT FROM my_dataset0 INTO UNIX TEXT FILE my_file2.txt SPLIT 2

# select (i.e. read) data from dataset "my_dataset0" and write it into a binary file named "my_file.bin" (truncate it if it already exists) (should write "ABC")
SELECT FROM my_dataset0 INTO TRUNCATE BINARY FILE my_file.bin

# select (i.e. read) data from dataset "my_dataset0" and write it into an Excel file named "my_file0.xlsx" in the sheet currently selected for viewing/editing within the file (should write 65, 66, 67)
SELECT FROM my_dataset0 INTO EXCEL FILE my_file0.xlsx

# select (i.e. read) data from dataset "my_dataset0" and write it into an Excel file named "my_file1.xlsx" in a sheet named "my_sheet" (truncate it if it already exists) (should write 65, 66, 67)
SELECT FROM my_dataset0 INTO TRUNCATE EXCEL FILE my_file1.xlsx SHEET my_sheet
// create a chunked (size 1) HDF5 dataset named "my_dataset1" of data type int of two dimensions (size 3x2), and with initial values of 4 and 6 for the first position, 5 and 7 for the second position, and 8 and 9 for the third position
hdfql_execute("CREATE CHUNKED(1) DATASET my_dataset1 AS INT(3, 2) VALUES((4, 6), (5, 7), (8, 9))");

// prepare cursor in use to be populated with only one slice/portion of dataset "my_dataset1" at the time by sliding on its first dimension (each slice/portion has two elements)
hdfql_execute("SELECT FROM my_dataset1 INTO SLIDING CURSOR");

// move cursor in use to the next position (a new slice/portion of dataset "my_dataset1" is automatically read by HDFql (using a hyperslab selection under the hood) given that the cursor is positioned outside the slice/portion it currently stores)
hdfql_cursor_next(NULL); 

// display content of cursor in use (should be 4) 
printf("%d\n", *hdfql_cursor_get_int(NULL));

// move cursor in use to the next position (no new slice/portion of dataset "my_dataset1" is read given that the cursor is still positioned inside the slice/portion it currently stores)
hdfql_cursor_next(NULL); 

// display content of cursor in use (should be 6) 
printf("%d\n", *hdfql_cursor_get_int(NULL));

// move cursor in use to the next position (a new slice/portion of dataset "my_dataset1" is automatically read by HDFql (using a hyperslab selection under the hood) given that the cursor is positioned outside the slice/portion it currently stores)
hdfql_cursor_next(NULL); 

// display content of cursor in use (should be 5) 
printf("%d\n", *hdfql_cursor_get_int(NULL));

// move cursor in use to the next position (no new slice/portion of dataset "my_dataset1" is read given that the cursor is still positioned inside the slice/portion it currently stores)
hdfql_cursor_next(NULL); 

// display content of cursor in use (should be 7) 
printf("%d\n", *hdfql_cursor_get_int(NULL)); 

// move cursor in use to the next position (a new slice/portion of dataset "my_dataset1" is automatically read by HDFql (using a hyperslab selection under the hood) given that the cursor is positioned outside the slice/portion it currently stores)
hdfql_cursor_next(NULL); 

// display content of cursor in use (should be 8) 
printf("%d\n", *hdfql_cursor_get_int(NULL));

// move cursor in use to the next position (no new slice/portion of dataset "my_dataset1" is read given that the cursor is still positioned inside the slice/portion it currently stores)
hdfql_cursor_next(NULL); 

// display content of cursor in use (should be 9) 
printf("%d\n", *hdfql_cursor_get_int(NULL));
// declare variables 
char script[1024];
double data[3][2];
int x;
int y;

// create an HDF5 dataset named "my_dataset2" of data type double of two dimensions (size 3x2)
hdfql_execute("CREATE DATASET my_dataset2 AS DOUBLE(3, 2)");

// insert (i.e. write) values into dataset "my_dataset2" 
hdfql_execute("INSERT INTO my_dataset2 VALUES((3.2, 1.3), (0, 0.2), (9.1, 6.5))");

// register variable "data" for subsequent use (by HDFql) 
hdfql_variable_register(data);

// prepare script to select (i.e. read) data from dataset "my_dataset2" and populate variable "data" with it
sprintf(script, "SELECT FROM my_dataset2 INTO MEMORY %d", hdfql_variable_get_number(data));

// execute script 
hdfql_execute(script);

// unregister variable "data" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(data); 

// display content of variable "data" (should be 3.2, 1.3, 0, 0.2, 9.1, 6.5) 
for(x = 0; x < 3; x++)
{
    for(y = 0; y < 2; y++)
    {
       printf("%d\n", data[x][y]);
    }
}
// declare variables 
char script[1024];
HDFQL_VARIABLE_LENGTH data[3];
int x; 
int y;
int count;

// create an HDF5 dataset named "my_dataset3" of data type variable-length double of one dimension (size 3)
hdfql_execute("CREATE DATASET my_dataset3 AS VARDOUBLE(3)");

// insert (i.e. write) values into dataset "my_dataset3" 
hdfql_execute("INSERT INTO my_dataset3 VALUES((3.2, 1.3), (0, 0.2), (9.1, 7.4, 6.5))");

// register variable "data" for subsequent use (by HDFql) 
hdfql_variable_register(data);

// prepare script to select (i.e. read) data from dataset "my_dataset3" and populate variable "data" with it
sprintf(script, "SELECT FROM my_dataset3 INTO MEMORY %d", hdfql_variable_get_number(data));

// execute script 
hdfql_execute(script);

// unregister variable "data" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(data); 

// display content of variable "data" (should be 3.2, 1.3, 0, 0.2, 9.1, 7.4, 6.5) 
for(x = 0; x < 3; x++)
{ 
    count = data[x].count;
    for(y = 0; y < count; y++)
    {
       printf("%f\n", *((double *) data[x].address + y));
    }
}

// release memory allocated (by HDFql) in variable "data" 
for(x = 0; x < 3; x++)
{ 
    free(data[x].address);
}
// declare variables 
char script[1024];
char *data[3];
int x; 

// create an HDF5 dataset named "my_dataset4" of data type variable-length char of one dimension (size 3)
hdfql_execute("CREATE DATASET my_dataset4 AS VARCHAR(3)");

// insert (i.e. write) values into dataset "my_dataset4" 
hdfql_execute("INSERT INTO my_dataset4 VALUES(\"Hierarchical\", \"Data\", \"Format\")");

// register variable "data" for subsequent use (by HDFql) 
hdfql_variable_register(data);

// prepare script to select (i.e. read) data from dataset "my_dataset4" and populate variable "data" with it
sprintf(script, "SELECT FROM my_dataset4 INTO MEMORY %d", hdfql_variable_get_number(data));

// execute script 
hdfql_execute(script);

// unregister variable "data" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(data); 

// display content of variable "data" (should be "Hierarchical", "Data", "Format") 
for(x = 0; x < 3; x++)
{ 
    printf("%s\n", data[x]);
}

// release memory allocated (by HDFql) in variable "data" 
for(x = 0; x < 3; x++)
{ 
    free(data[x]);
}
// declare structure 
struct data
{ 
   char description[7]; 
   int index; 
};

// declare variables 
char script[1024];
struct data cities[3]; 
int number; 
int i;

// create an HDF5 dataset named "my_dataset5" of data type compound of one dimension (size 3) composed of two members named "description" (of data type char) and "index" (of data type int), and with initial values of "Toronto" and 10 for the first position, "Nairobi" and 12 for the second position, and "Caracas" and 11 for the third position
hdfql_execute("CREATE DATASET my_dataset5 AS COMPOUND(description AS CHAR(7), index AS INT)(3) VALUES((Toronto, 10), (Nairobi, 12), (Caracas, 11))");

// register variable "cities" for subsequent use (by HDFql) 
number = hdfql_variable_register(cities);

// prepare script to select (i.e. read) data from dataset "my_dataset5" and populate variable "cities" with it
sprintf(script, "SELECT FROM my_dataset5 INTO MEMORY %d SIZE %d OFFSET(%d, %d)", number, sizeof(struct data), offsetof(struct data, description), offsetof(struct data, index));

// execute script 
hdfql_execute(script); 

// unregister variable "cities" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(cities); 

// display content of variable "cities" (should be "The city of Toronto has index 10", "The city of Nairobi has index 12", "The city of Caracas has index 11")
for(i = 0; i < 3; i++)
{
    printf("The city of %s has index %d\n", cities[i].description, cities[i].index);
}