To store the access details for your data source, first create a credential
with the CREATE CREDENTIAL command, and
reference it in your CREATE DATA SOURCE statement. This will allow you to
store the authentication details of your connection separately.If connecting to a Kafka topic that allows anonymous access, this step can be
skipped.
To initiate the ingest of data into a Kinetica table, use the
LOAD INTO command with the option
SUBSCRIBE = TRUE. This will start the stream of data from your Kafka topic
into the specified table. You can control the ingest (pause, resume, and cancel)
by using the ALTER TABLE command.
LOAD DATA INTO example.ordersFORMAT JSONWITH OPTIONS (DATA SOURCE = 'kafka_ds', SUBSCRIBE = TRUE)
ALTER TABLE example.ordersPAUSE SUBSCRIPTION kafka_ds
ALTER TABLE example.ordersRESUME SUBSCRIPTION kafka_ds
ALTER TABLE example.ordersCANCEL SUBSCRIPTION kafka_ds
The following are some common options used when loading. For the full list of
options, see LOAD INTO. For copy/paste examples of many of
the options, see Loading Data.
Kinetica has two different
error handling modes for dealing
with erroneous data. To halt ingestion after a bad record is found, use the
ABORT mode. To skip erroneous records and continue the ingest, use the
SKIP mode.To inspect erroneous records, you may use the
BAD RECORD TABLE NAME option.
All bad records encountered will be stored there for review. The bad records
table is limited to 10,000 records by default and may be overridden using the
BAD RECORD TABLE LIMIT option.
LOAD INTO ki_home.error_exampleFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', SUBSCRIBE = true, ON ERROR = ABORT)
LOAD INTO ki_home.error_exampleFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', SUBSCRIBE = true, BAD RECORD TABLE NAME = 'error_example_invalid', ON ERROR = SKIP)
In some cases, you may only want to store certain columns from your source data.
Use the FIELDS MAPPED BY NAME(…)
option, which allows you to specify the desired fields to store in Kinetica.
Load Specific Columns Example
LOAD DATA INTO example.ordersFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', FIELDS MAPPED BY NAME(ID, Name, Product_ID, Quantity))
Use the COLUMN FORMATS option
to format date and time fields into Kinetica Date, Time, and DateTime columns.
Time formats are specified using a JSON formatted string. Non-placeholder characters
must be wrapped in quotes, which must also be escaped (e.g.
'{"dt": {"date": "\"(\"YYYY\")\" Mon, DD"}}'). Alternatively, you can use
the ? character as a wildcard character. Note that
Kinetica does not handle or store timezones and they will be discarded.
See the full list of supported
date and time format codes.
-- Example Data:-- {-- "dt": "2022-01-19T15:50:42Z+05:00"-- }LOAD INTO ki_home.timestamp_exampleFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', SUBSCRIBE = true, COLUMN FORMATS = ' { "dt": {"datetime": "YYYY-MM-DD?HH:MI:SS"} }')
-- Example Data:-- {-- "d": "(2022) Feb, 22"-- }LOAD INTO ki_home.date_exampleFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', SUBSCRIBE = true, COLUMN FORMATS = '{"d": {"date": "\"(\"YYYY\")\" Mon, DD"}}')
-- Example Data:-- {-- "t": "18-27-59.5536"-- }LOAD INTO ki_home.time_exampleFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', SUBSCRIBE = true, COLUMN FORMATS = '{"t": {"time": "HH-MI-SS.MS"}}')
By default, Kinetica will use the native null type in JSON for null values.
However, if your data uses a custom string to specify null (e.g. "null") use
the NULL option.
Null String
-- Example Data:-- {-- "example_null": "null"-- }LOAD INTO ki_home.null_exampleFORMAT JSONWITH OPTIONS ( DATA SOURCE = 'kafka_ds', SUBSCRIBE = true, NULL = 'null')