Using our C SDK Sample Program
This section describes how to use our sample c
program, available on Nexus, to send the data from the sample.csv file to either:
- kdb Insights RT Microservice
- An
sdk_sample_assembly
assembly inside the kdb Insights Enterprise. You can download this assembly using the instructions here.
Downloading
The C SDK samples-${VERSION}.zip, downloaded from the kdb Insights Nexus registry), contains the following files:
The C SDK kdb-insights-c-sdk-samples-${VERSION}.zip contains the following files:
csvupload.c
- csv upload source codeCMakeLists.txt
- cmake filesample.csv
- a CSV file containing sample data based on thesdk-sample-assembly
schema
Note
Before using the sample program you must download and extract the C SDK.
The source code for the sample program can be taken and edited for use inside your applications.
Building
Build the sample program as follows:
$ unzip kxi-c-sdk-${VERSION}.zip && unzip kxi-c-sdk_samples-${VERSION}.zip
$ mkdir samples/build && cd samples/build
$ cmake .. -DKXI_C_SDK_INCLUDE_DIR:PATH=../kxi_c_sdk/include -DKXI_C_SDK_LINK_DIR:PATH=../kxi_c_sdk && cmake --build .
csvupload
(extensions will vary depending on the platform).
Application parameters
The application parameters are defined as follows:
parameter | required | default | description |
---|---|---|---|
-u str |
Mandatory | none | Authenticated SDK client URL |
-s str |
Mandatory | none | Schema - see note below. |
-t str |
Mandatory | none | Table (for example: "trace") |
-r str |
Optional | /tmp/rt | RT directory |
-f int |
Optional | 5000 | Time in ms to sleep between reads of the configuration details. |
-c int |
Optional | 300000 | Maximum age of configuration details in milliseconds. After this amount of time, if still unable to fetch a new configuration, the connection is considered to be broken and any subsequent attempts to send data to kdb Insights Enterprise will fail with a Not connected error. This is only needed when using the kdb Insights Enterprise Information Service to obtain the configuration details. |
-l int |
Optional | 600000 | Local persistence period (in milliseconds) |
-g str |
Optional | info | Log Level (example: "info") |
-m str |
Optional | err | Console log level (info/warn/err/off) |
-w num |
Optional | 2000 | Milliseconds to wait for the connection to establish |
-i str |
Optional | stdin | Used to set an input file name, rather than stdin, eg. '../sample.csv' |
-o int |
Optional | 1 | Send the file a specific number of many times, -1 for infinite loop |
-z int |
Optional | 0 | Set to 1 to write a single test record |
The schema defined here MUST match what is defined in the assembly
s str
: The schema must match that defined in the pipeline assembly. If the schema in the table matches the one in thesdk_sample_assembly
, described here, the schema definition is as follows: sensorID:int,captureTS:ts,readTS:ts,valFloat:float,qual:int,alarm:int
Publishing data
The example below runs the csvupload program from the command line. It sets the mandatory parameters and uses defaults for the rest:
url="$KXI_CONFIG_URL"
schema="sensorID:int,captureTS:ts,readTS:ts,valFloat:float,qual:byte,alarm:byte"
table="trace"
./csvupload -u $url -s $schema -t $table < ../sample.csv
url
The url
parameter can be set to:
- KXI_CONFIG_URL
to access kdb Insights Enterprise from outside the cluster
- file:///locaton/config_file_name
to use a local file to access kdb Insights Enterprise or a kdb Insights RT Microservice from inside the cluster
Supported data types
The following data types are supported by the sample application:
type | schema notation | example |
---|---|---|
string | string | name |
symbol | symbol | LLOY |
int | int | 1 |
byte | byte | 0 |
long | long | 200000 |
float | float | 1.2345 |
timestamp | ts | 2000.01.01D00:00:00.000000000 |