Maps a foreign data source table (such as Hive tables or files) into Jethro.
Creates an external table in Jethro schema, mapped to a table on an external data source, or to a file(s) located on a local file system or on HDFS. Typically external tables are used for loading data from external data sources into Jethro table using INSERT INTO command.
When a policy or a formatting rule is set for an external table, it will override the policy/formatting rule of the external data source it is belonging to. Otherwise, it will inherit the settings of its external data source.
When a formatting rule is set for a column, it will override the formatting rule of the external table/data source it is belonging to. Otherwise, it will inherit the settings of its external table/data source.
<location_spec> - Specifies the location within the external data source from which the data will be fetched.
table_name_from_the_external_data_source - The name of the table in Hive.
list_of_files - The name or names of files to fetch the data from. When reading more than one file, it is important to varify that they are all using the same structure, order, and date types as defined during the external table creation. It is possible to use a direct full path for a specific file, or to use a hint which will allow access to multiple files, such as: folder path, or a file path with an hint char ('?' represents any single char, '*' represents any set of chars). Regular expression is not supported for the directories components of the path, only for the files. Anyhow the file location must include the full path.
<values_format_spec> - Specifies how to convert values, according to the following parameters:
[NULL DEFINED AS ('<string>' [,'<string>'...])] - A set of strings which should be converted to a NULL value once fetched.
[DATETIME FORMAT <ISO 8601 date format string>] - The format in which the source data is stored as. The default format in Jethro is 'yyyy/MM/dd HH:mm:ss'.
[TIMEZONE=<timezone>] - Converts a timestamp in UTC to a given timezone.
The default timestamp format in Jethro is 'yyyy-MM-dd HH:mm:ss' (without a sub-second component).
However, an alternative format can be specified. For example:
DATETIME FORMAT 'dd-MM-yyyy HH:mm:ss.SSS'
Timestamp format strings are case sensitive. The valid format elements are:
4-digit year (1970-2038)
1 or 2 digit month (1-12)
2-digit month (01-12)
3-character month (Jan-Dec)
1 or 2 digit day (1-31)
2-digit day (01-31)
1 or 2 digit hour (0-23)
2-digit hour (00-23)
1 or 2 digit minute (0-59)
2-digit minute (00-59)
1 or 2 digit second (0-59)
2-digit second (00-59)
1-6 -digit sub-second element
The number of seconds since 1/1/1970 (microseconds/milliseconds optional after the decimal point). The format cannot be mixed with other format elements.
If the input string of the field is longer than the format defined, the rest of the field content is ignored. For example: for the format 'yyyy/MM/dd', the input field '2014-02-14 15:16:17' will be stored as '2014-02-14 00:00:00'. This allows truncating the input record to a lower precision (as in the example above - from a second-level to a day-level).
The query engine by default does not perform any timezone manipulation – the input is loaded as is. In other words, Jethro stores any TIMESTAMP data in UTC timezone and it assumes all input is already in UTC.
However, in some cases you may want to adjust the timezone of an input field. For example, you may want to load log files from different data centers – each file has timestamps in the local timezone, so each needs its own adjustment.
You can ask for a timezone adjustment by using the TIMEZONE property. In that case, the query engine will compute the current offset of that timezone vs. UTC once (at the beginning of its run) and will apply it to all the values of those fields. Example:
<rejects_handling_spec> - Specifies a policy for handling rejects at row/columns level. The allowed polices are:
FILL_NULL (default) - Replace the rejected value with a NULL.
SKIP_ROW - Skip the entire row when any value is rejected.
FAIL - Fail the entire request on the first time it encountered with a rejected value (Choosing this policy will ignore the rejects threshold defined under <rejects_thresholds_spec>).
Setting <rejects_handling_spec> override spec set at data source level via CREATE EXTERNAL DATA SOURCE command.
<rejects_thresholds_spec> - Specifies a rejects threshold policy for handling of multiple rejects at request level. The total number of rows with rejects are counted, and if that number reaches the defined threshold, the request fails (A row with 2 rejects will be counted as 1). The allowed rejects thresholds are:
REJECT_LIMIT_COUNT (default) - An integer value specifying the maximum number of allowed rows with rejects. If the number of rows with rejects reaches the limit, the request will fail. The default value is: 0.
REJECT_LIMIT_RATIO - A decimal value between 0 and 1, specifying the maximum ratio allowed for rows with rejects, from a sample of fetched rows (see REJECT_SAMPLE). If the actual sampled ratio is greater than the limit specified, the request will fail.
REJECT_SAMPLE - The minimum number of rows to process before making a reject decision (based on REJECT_LIMIT_RATIO). If not specified, the default value is '1000000'.
Reject policy & thresholds apply only within INSERT INTO SELECT operation. Otherwise fetching data from an external table using SELECT will fail, and issue an error whenever a mismatch between external table data type and the actual fetched value from the external data source is encountered.
1) Creation of an external data source and an external table for a single simple csv file, such as:
a. Analysis of the data:
- The delimiter is '|'
- Most of the Null value are represented as 'NULL', but only int2 field is using 'null'.
- The first line consist of header names, and therefore it should be skipped.
- The time format is: 'yyyy-MM-dd HH:mm:ss'.
b. Possible business preferences:
- The timestamp fields should be adjusted to New York timezone.
- The data is sometimes generated with mistakes, but the BI needs for updated data is more important than its need for accuracy. Therefore, the Reject policy should not cause a failur for every reject found. Partial data might be good enough, as long as the loss of possible data is not too big. Up to 10% of data loss is a limit that can be tolerated, but more than that should cause a failur and require a human inspection.
- Since the file is very big, a sample of 100 rows should be enough in order to understand quickly if this process should be stopped or to continue.
- If a line includes one or more values which are rejected, it would be better to skip the whole line, rather than filling NULL values instead of the rejected values.
- There could be more than one file that should be used for that table, and there are no other files under that directory, so every file from that directory should be accessed.
c. According to steps a+b, these are the commands that should be sent to Jethro:
2) Creating an external table for an Hive table called 'customer_address', with REJECT_POLICY=FAIL:
3) Creating an external table for a directory of files, located on HDFS:
4) Creating an external table for files that are located in a directory which is mixed with unrelated data. Therefore, hint signs are used to identify only the relevant files: