TSL_PutJson function

The TSL_PutJson function loads JSON documents as time series data.

Syntax

TSL_PutJson(
           handle     LVARCHAR,
           pathname   LVARCHAR)
returns integer
handle
The table and column name combination that is returned by the TSL_Attach or the TSL_Init function.
pathname
The fully qualified path and name of a file, which is preceded by the DISK: keyword, or a pipe, which is preceded by the PIPE: keyword.

The database server does not verify that any file or pipe exists at the specified path, that the specified pipe is open, nor that the user has permission to access that file system.

The contents of the file or input stream must be a set of JSON documents that each represent a time series element. Each document must be on a separate line. Each line must end with a newline character (\n). The entire JSON document is inserted into the BSON column in the TimeSeries data type. The primary key and time stamp values are also extracted from the JSON documents:

primary key
The first JSON document must contain the field value-pairs that comprise the primary key. The field names must match the column names for the primary key in the time series table. If primary key values are not included in subsequent JSON documents, the last primary key value from previous documents is used. The primary key value determines into which time series the JSON document is inserted.
Time stamp
The field name of the time stamp value must match field name of TimeSeries subtype that contains the time stamp. The format of the time stamp is specified by the timestamp_format argument of the TSL_Init function. The default format of the time stamp is: YYYY-mm-dd HH:MM:SS (year-month-day hour:minute:seconds).

Usage

Use the TSL_PutJson function to load time series data that is in JSON documents as part of a loader program. You must run the TSL_PutJson function in the context of a loader session that was initialized by the TSL_Init function. You can run the TSL_PutJson function multiple times in the same session. The data is stored in the database server until you run the TSL_Flush function to write the data to disk.

The primary key value and the time stamp are extracted from the JSON documents and inserted into the corresponding columns in the TimeSeries data type. However, the primary key and time stamp values also remain in the JSON documents that are stored in the BSON column of the TimeSeries data type.

Any rejected records are listed in the reject file, reject_file.log, that is specified by the TSL_Init function, and the reject_file.log.ext file that is in the same directory as the reject log.

Returns

  • An integer that indicates the number of records that were inserted.
  • An exception if no records were inserted.

Examples

These examples run in the context of an initialized loader session.

Example: Load a file

The following statement loads data from the loadfile.unl file in the /mydata/ directory:

EXECUTE FUNCTION TSL_PutJson('tsdata|pkcol', 'DISK:/mydata/loadfile.unl');

Example: Load from a pipe

The following statement loads data from the pipe that is named TAPE in the /usr/local/ directory:

EXECUTE FUNCTION TSL_PutJson('tsdata|pkcol', 'PIPE:/usr/local/TAPE');