Load Data from Azure Blob

Copy and paste tutorial for loading data from Azure Blob Storage

Loading data from Azure Blob Storage can be done in three easy steps:

  1. Create a credential - holds Azure account authentication information
  2. Create a data source - holds Azure Blob Storage connection information; uses the credential for authentication
  3. Ingest the data - Load data from Azure; uses the data source to identify the Azure source

Create Credential

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 public Azure container that allows anonymous access to itself and its contained files, this step can be skipped.

Password
1
2
3
4
CREATE CREDENTIAL azure_cred
TYPE = 'azure_storage_key',
IDENTITY = 'sampleacc',
SECRET = 'foobaz123'
SAS Token
1
2
3
4
CREATE CREDENTIAL azure_cred
TYPE = 'azure_sas',
IDENTITY = 'sampleacc',
SECRET = 'sv=2015-07-08&sr=b&sig=39Up0JzHkxhUlhFEjEH9673DJxe7w6...'
Active Directory
1
2
3
4
5
6
7
8
9
CREATE CREDENTIAL azure_cred
TYPE = 'azure_ad',
IDENTITY = 'jdoe',
SECRET = 'foobaz123'
WITH OPTIONS
(
    STORAGE ACCOUNT NAME = 'sampleacc',
    TENANT ID = 'x0xxx10-00x0-0x01-0xxx-x0x0x01xx100'
)

Create Data Source

Next, create a data source using the CREATE DATA SOURCE command in Kinetica. The data source defines how Kinetica connects to Azure Blob Storage.

Credential
1
2
3
4
5
6
7
CREATE DATA SOURCE azure_ds
LOCATION = 'AZURE'
WITH OPTIONS
(
    CREDENTIAL = 'azure_cred',
    CONTAINER NAME = 'samplecontainer'
)
Public (No Auth)
1
2
3
4
5
6
7
CREATE DATA SOURCE azure_ds
LOCATION = 'AZURE'
USER = 'sampleacc'
WITH OPTIONS
(
    CONTAINER NAME = 'samplecontainer'
)

Ingest Data

To initiate the ingest of data into a Kinetica table, use the LOAD INTO command. You can initiate a one-time batch load, or a continuous load using change-data-capture by using the option SUBSCRIBE = TRUE.

Batch Load
1
2
3
4
LOAD DATA INTO example.orders
FROM FILE PATHS 'example_orders.csv'
FORMAT TEXT
WITH OPTIONS (DATA SOURCE = 'blob_ds')
Streaming Load
1
2
3
4
5
6
7
LOAD DATA INTO example.orders
FROM FILE PATHS 'example_orders.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    SUBSCRIBE = TRUE
)

Considerations

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.


Error Handling

Kinetica has several 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. If you wish to ingest erroneous records to the best of Kinetica's ability and continue the ingest, use the PERMISSIVE 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.

Abort
1
2
3
4
5
6
7
LOAD INTO ki_home.error_example
FROM FILE PATHS 'error_example.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    ON ERROR = ABORT
)
Log Bad Records
1
2
3
4
5
6
7
8
LOAD INTO ki_home.error_example
FROM FILE PATHS 'error_example.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    BAD RECORD TABLE NAME = 'error_example_invalid',
    ON ERROR = SKIP
)

Load Specific Columns

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
1
2
3
4
5
6
7
LOAD DATA INTO example.orders
FROM FILE PATHS 'example_orders.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    FIELDS MAPPED BY NAME(ID, Name, Product_ID, Quantity)
)

DateTime Formatting

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 of supported date and time format codes.

ISO 8601 Timestamps
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
-- Example Data:
-- dt
-- 2022-01-19T15:50:42Z+05:00

LOAD INTO ki_home.timestamp_example
FROM FILE PATHS 'timestamp_example.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    COLUMN FORMATS = '
    {
        "dt": {"datetime": "YYYY-MM-DD?HH:MI:SS"}
    }'
)
Custom Date
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
-- Example Data:
-- d
-- (2022) Feb, 22

LOAD INTO ki_home.date_example
FROM FILE PATHS 'date_example.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    COLUMN FORMATS = '{"d": {"date": "\"(\"YYYY\")\" Mon, DD"}}'
)
Custom Time
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
-- Example Data:
-- t
-- 18-27-59.5536

LOAD INTO ki_home.time_example
FROM FILE PATHS 'time_example.csv'
FORMAT TEXT
WITH OPTIONS (
    DATA SOURCE = 'blob_ds',
    COLUMN FORMATS = '{"t": {"time": "HH-MI-SS.MS"}}'
)