Syntax
Parameters
Using location objects
Firebolt recommends using location objects as a secure, centralized way to manage Amazon S3 credentials and URLs. Use location objects for:- Centralized credential management.
- Eliminating the exposure of credentials in queries.
- Enabling role-based access control.
- Simplified maintenance and updates.
my_external_table in that loads data from Parquet files matching the *.parquet pattern in my_data_location:
Common LOCATION errors
-
Providing the location name as a string literal instead of an identifier results in an error, as shown in the following code example:
-
If the specified location doesn’t exist or you lack permission to use it, an error occurs, as shown in the following code example:
PARTITION
In some applications, such as Hive partitioning, files use a folder naming convention to identify which partition their data belongs to. ThePARTITION keyword allows you to specify a regular expression, <regex>, to extract a portion of the file path and store it in the specified column when Firebolt uses the external table to ingest partitioned data.
Using PARTITION in this way is one method of extracting partition data from file paths. Another method is to use
the table metadata column, $source_file_name, during the INSERT operation.
Guidelines for creating the regex
- The regular expression is matched against the object prefix, not including the
s3://<bucket_name>/portion of the prefix. - You can specify as many
PARTITIONcolumns as you need, each extracting a different portion of the object prefix. - For each
PARTITIONcolumn, you must specify a re2 regular expression that contains a capturing group, which determines the column value. - When
<column_type>isDATE, Firebolt requires up to three capturing groups that must be in the order of year, month, and day. - When
<column_type>isTIMESTAMP, Firebolt requires up to six capturing groups that must be in the order of year, month, day, hour, minute, second. - Firebolt tries to convert the captured string to the specified
<column_type>. If the type conversion fails, the ingest will error out.
- Count the number of folders in the path, not including the bucket name.
- Concatenate the string
[^/]+/according to the number of folders. - Prefix the regex with an additional
[^/]+for the file name. - Wrap the
[^/]+in the right folder with a capturing group parenthesis, such as([^/]+).
Example–extract Hive-compatible partitions
The example below demonstrates aCREATE EXTERNAL TABLE statement that creates the table my_ext_table. This table is used to ingest all files with a *.parquet file extension in any sub-folder of the Amazon S3 bucket s3://my_bucket.
Consider an example where folders and files in the bucket have the following consistent pattern, which is common for Hive partitions:
CREATE EXTERNAL TABLE statement below, the PARTITION keyword in the column definition for c_type specifies a regular expression. This expression extracts the portion of the Amazon S3 path name that correspond to the xyz or abc within c_type=xyz or c_type=abc.
c_type column for each row contains the extracted portion of the path. For the files listed above, the extraction results in the following values. c_id and c_name are values stored within the respective Parquet files, while c_type are values extracted from the file path.
CREDENTIALS
Unless reading from a public bucket, credentials are required to access your data on AWS Amazon S3. Both access key and IAM role based permissions are supported.Syntax for Access Key & Secret
Parameters
Syntax for IAM role
Parameters
The following example authenticates with a role and includes a recommended external ID:
For role-based AWS access you can additionally set an external ID. An external ID is a value you choose and control that AWS checks when Firebolt assumes your role, adding a second condition on top of your account’s unique IAM principal. Configuring one is a recommended best practice. See IAM roles.
OBJECT_PATTERN
An external table enables reading some (or all) files from an Amazon S3 bucket that you have read access to. The Amazon S3 bucket that you reference must be in the same AWS Region as the Firebolt database. TheOBJECT_PATTERN parameter identifies which files represent the data for the external table.OBJECT_PATTERN is a glob that selects files within the URL or LOCATION.
Syntax
Parameters
The following wildcards are supported:
'*'matches any sequence of characters'?'matches any single character[SET]matches any single character in the specified set[!SET]matches any character, not in the specified set.
Example
In the following layout of objects in a bucket, the data is partitioned according to client type, year, and month, with multiple Parquet files in each partition. The examples demonstrate how choosing both URL and OBJECT_PATTERN impacts the objects that are retrieved from Amazon S3.TYPE
Specifies the type of the files in Amazon S3. The following types and type options are supported.CSV Types
-
[ALLOW_DOUBLE_QUOTES = {TRUE|FALSE}][ALLOW_SINGLE_QUOTES = {TRUE|FALSE}]WithALLOW_DOUBLE_QUOTES = TRUEorALLOW_SINGLE_QUOTES = TRUEyou define that unescaped double or single quotes in CSV input file will not cause an error to be generated on ingest. By defaultALLOW_DOUBLE_QUOTESandALLOW_SINGLE_QUOTESare set toTRUE. -
[ALLOW_COLUMN_MISMATCH = {TRUE|FALSE}]WithALLOW_COLUMN_MISMATCH = TRUEthe number of delimited columns in a CSV input file can be fewer than the number of columns in the corresponding table. By default,ALLOW_COLUMN_MISMATCHis set toFALSE, and an error is generated if the number of columns is fewer than the number of columns defined in the external table. If set toTRUE, and an input file record contains fewer columns than defined in the external table, the non-matching columns in the table are loaded withNULLvalues. -
[ALLOW_UNKNOWN_FIELDS = {TRUE|FALSE}]WithALLOW_UNKNOWN_FIELDS = TRUEthe number of delimited columns in a CSV input file can be more than the number of columns in the corresponding table. By default,ALLOW_UNKNOWN_FIELDSis set toFALSE, and an error is generated if the number of columns is more than the number of columns defined in the external table. If set toTRUE, and an input file record contains more columns than defined in the external table, the non-matching columns in the table are ignored. -
[ESCAPE_CHARACTER = {‘<character>’|NONE}WithESCAPE_CHARACTER = '<character>'you can define which character is used to escape, to change interpretations from the original. By default, theESCAPE_CHARACTERvalue is set to\. If, for example, you want to use"as a value and not as delimiter for string, you can escape like\", with the default escape character. -
[FIELD_DELIMITER = '<field_delimeter>']WithFIELD_DELIMITER = '<field_delimeter>', you can define a custom field delimiter to separate fields for ingest. By default, theFIELD_DELIMITERis set as,. -
[NEW_LINE_CHARACTER = '<new_line_character>']WithNEW_LINE_CHARACTER = '<new_line_character>', you can define a custom new line delimiter to separate entries for ingest. By default, theNEW_LINE_CHARACTERis set as the end of line character\n, but also supports other end of line conventions, such as\r\n,\n\r, and\r, as well as multi-character delimiters, such as#*~. -
[NULL_STRING = '<null_string>']WithNULL_STRING = '<null_string>'you can define which set of characters is interpreted asNULL. By default, theNULL_STRINGvalue is set to\\N. -
[SKIP_BLANK_LINES {TRUE|FALSE}]WithSKIP_BLANK_LINES = TRUEany blank lines encountered in the CSV input file will be skipped. By default,SKIP_BLANK_LINESis set toFALSE, and an error is generated if blank lines are encountered on ingest. -
[SKIP_HEADER_ROWS = {TRUE|FALSE}]WithSKIP_HEADER_ROWS = TRUE, Firebolt assumes that the first row in each file read from Amazon S3 is a header row and skips it when ingesting data. When set toFALSE, which is the default if not specified, Firebolt ingests the first row as data.
JSON Types
TYPE = (JSON [PARSE_AS_JSON = {TRUE|FALSE}] [PARSE_AS_TEXT = {TRUE|FALSE}])
[ {...}, {...} ]. Files may be compressed (see COMPRESSION). TYPE = (JSON) supports three column mappings. PARSE_AS_JSON and PARSE_AS_TEXT are mutually exclusive and both default to FALSE:
PARSE_AS_JSON = TRUEingests each document whole into a singleJSON-typed column, which you query with JSON functions. The table must declare exactly one data column (partition columns excepted), of typeJSON, and each document is validated as well-formed JSON on read. This is the external-table equivalent ofREAD_JSON(..., PARSE_AS_JSON => TRUE).PARSE_AS_TEXT = TRUEingests each document whole into a singleTEXTcolumn, leaving field extraction to query time. The table must declare exactly one data column (partition columns excepted), of typeTEXTorJSON.- With both
FALSE(the default), Firebolt maps each key in a JSON object to the table column of the same name and inserts the key’s value into that column. Keys with no matching column are ignored; columns with no matching key take their default.
Other Types
TYPE = (ORC)TYPE = (PARQUET)TYPE = (AVRO)TYPE = (TSV)
FIELD_DELIMITER, are also supported for the TSV file type.
Example
Creating an external table that reads Parquet files from Amazon S3 is being done with the following statement:COMPRESSION
Specifies the compression type of the files matching the specifiedOBJECT_PATTERN in Amazon S3.
Syntax
Parameters
Example
The example below creates an external table to ingest CSV files from Amazon S3 that are compressed using gzip. The credentials for an IAM user with access to the bucket are provided.CROSS_REGION_REQUEST_MODE
Use this parameter to read data from an Amazon S3 region different than where your engine is running. Unlike query-level settings, this parameter is specified only during external table creation and is automatically persisted for all subsequent SELECT queries on that table. Note that query-level settings cannot be applied to CREATE TABLE operations, as these settings are not enabled for table creation. The table-level parameter is required for file validation during table creation. If the system setting is specified during SELECT queries, the table-level parameter will override it, so it will have no effect. It has three modes:disabled, auto, and enforced, where disabled is the default mode. For detailed explanations of each mode, see the cross-region data access documentation.