10. IMPORT#
10.1. Synopsis#
IMPORT INTO <table_name> FILES ( <import_option> [, ...] );
import_option ::= uris[=]['<input_path>']
| format[=]{ CSV | TSV | PARQUET | <custom_format_definition> }
| deduplicate[=]{ DISABLED | DROP | UPSERT }
| push_mode[=]{ FAST | ASYNC }
| max_errors[=]<count>
custom_format_definition ::= [ <format_option> [, ...] ]
format_option ::= delimiter[=]<quoted_character>
| quote_character[=]<quoted_character>
| first_row_is_header[={true|false}]
quoted_character ::= '<single_character>'
The uris option is mandatory. The other options are optional. You can put
the options in any order. Specify each option no more than once. The equal
sign (=) is optional.
10.2. Description#
Use IMPORT to load one file into an existing time series table. The client
that runs the query reads the file. The QuasarDB servers do not read the file.
QuasarDB 3.14.3 and later support these features:
Import from an Apache Parquet file.
Match named file columns to table columns. The columns can be in a different order.
For CSV and TSV files, the default format includes a header row. For Parquet
files, IMPORT reads the column names from the Parquet schema.
The file must contain $timestamp and all table columns. The column names
must match the table schema. The file can put named columns in any order.
10.3. Parameters#
table_nameThe name of an existing time series table.
input_pathThe path to the input file on the client computer. The path can be absolute or relative to the client working directory. Enclose the path in single quotation marks (
').Specify exactly one path. One
IMPORTstatement cannot read multiple files.formatThe input format. The default value is
CSV.CSVA comma-delimited text file with a header row.
TSVA tab-delimited text file with a header row.
PARQUETAn Apache Parquet file. This value is available in QuasarDB 3.14.3 and later.
custom_format_definitionA delimited text format. It uses the CSV defaults. Specify one or more of these options:
delimiterThe one-character field delimiter. The default value is
,.quote_characterThe one-character quote mark. The default value is
".first_row_is_headerSpecify
trueif the first row contains column names. The default value istrue. You can omit=true.If you specify
false, put$timestampfirst. Then, put the table columns in table-schema order.
IMPORTremoves leading and trailing spaces and tabs from text fields. You cannot configure this operation.deduplicateThe action to take when the imported data contains a row that is already in the table. QuasarDB compares all columns to identify a duplicate row.
DISABLEDInsert the new row. This action can create duplicate rows. This value is the default.
DROPKeep the existing row. Discard the new row.
UPSERTReplace the existing row with the new row.
push_modeThe method that QuasarDB uses to write the data.
FASTUpdate the time series buckets directly. This value is the default.
ASYNCSend the update to the server for asynchronous processing. The command can return before the server inserts the data.
max_errorsThe maximum number of data errors that
IMPORTaccepts. The default value is0.If the error count does not exceed this value,
IMPORTcontinues. For a value conversion error, it writes a null value in a non-timestamp column. If the error count exceeds this value,IMPORTstops and returns an error.
10.4. File schema requirements#
10.4.1. Files with column names#
CSV and TSV headers and Parquet schemas must meet these requirements:
The file contains one
$timestampcolumn.The file contains each table column.
The file does not contain an unknown column.
The number of file columns equals the number of table columns plus
$timestamp.
The column order does not have to match the table schema.
10.4.2. Files without column names#
For a delimited file without a header, IMPORT uses this column order:
$timestampEach table column, in table-schema order
10.4.3. Parquet type conversions#
QuasarDB 3.14.3 and later support these Parquet-to-QuasarDB conversions:
Parquet data exposed through Arrow |
QuasarDB column type |
|---|---|
String or binary |
|
64-bit integer |
|
Double |
|
Timestamp |
|
64-bit date |
|
IMPORT returns an error for an unsupported conversion. A null Parquet
value becomes a null QuasarDB value. The $timestamp value cannot be null.
10.5. Limitations#
The destination must be an existing time series table.
One statement imports one file into one table.
The file must contain
$timestampand all table columns.$timestampcannot contain a null value.Unsorted timestamps can reduce import performance.
10.6. Examples#
10.6.1. Import a CSV file#
The first row contains the column names:
$timestamp,i,d,s
2024-01-23T16:00:00.016759000,12,12.34,mkopoi
2024-01-23T16:00:00.016760000,23,23.45,snjksa
IMPORT INTO test FILES (
format=CSV,
uris=['import.csv']
);
10.6.2. Import a Parquet file#
This feature requires QuasarDB 3.14.3 or later:
IMPORT INTO test FILES (
format=PARQUET,
uris=['C:/data/import.parquet']
);
10.6.3. Import a custom delimited file#
IMPORT INTO test FILES (
format=[delimiter=';', quote_character='"', first_row_is_header=true],
uris=['import.txt']
);
10.6.4. Import a file without a header#
The file must put $timestamp first. The other fields must follow the
table-schema order.
IMPORT INTO test FILES (
format=[delimiter=';', first_row_is_header=false],
uris=['import-no-header.txt']
);
10.6.5. Control duplicate rows and data errors#
IMPORT INTO test FILES (
format=CSV,
deduplicate=UPSERT,
push_mode=FAST,
max_errors=10,
uris=['import.csv']
);