JSON Egress

Copy-paste examples of retrieving JSON data with the /get/records/json endpoint


The /get/records/json REST endpoint can be called to retrieve data in JSON form directly from the database.

See Overview for call details and Responses for return values.


Simple Egress

cURL
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
KINETICA_URL=http://localhost:9191
USERNAME=auser
PASSWORD=apassword
TABLE_NAME=product

# Quote the URL when passing multiple options, or any & will stop the URL
#   parsing and run the URL parsed up to that point as a background job
curl -sS ${KINETICA_URL}/get/records/json?table_name=${TABLE_NAME} \
--header "Content-Type: application/json" \
--user "${USERNAME}:${PASSWORD}"
Python
1
2
3
4
5
6
7
8
9
kinetica_url = "http://localhost:9191"
username = "auser"
password = "apassword"
kinetica = gpudb.GPUdb([kinetica_url], username = username, password = password)

table_name = "example.product"
order = None

response = kinetica.get_records_json(table_name, orderby_columns = order)
Java
1
2
3
4
5
6
7
8
9
String url = "http://localhost:9191"
GPUdb.Options options = new GPUdb.Options();
options.setUsername(username);
options.setPassword(password);
GPUdb kdb = new GPUdb(url, options);

String tableName = "product";

GetRecordsJsonResponse response = kdb.getRecordsJson(tableName, null, 0, GPUdb.END_OF_SET);
JavaScript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
const kinetica_url = 'http://localhost:9191'
const username = 'auser'
const password = 'apassword'
const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

let tableName = 'product';
let order = [];

db.get_records_json(tableName, [], 0, GPUdb.END_OF_SET, null, order, null, (err,  response) => {
    if (err)
        console.error(err);
    else
        console.info("All records:");
        response.records.forEach(element => {
            console.info(element);
        });
});
Node.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
const kinetica_url = 'http://localhost:9191'
const username = 'auser'
const password = 'apassword'
const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

let tableName = 'product';
let order = [];

db.get_records_json(tableName, [], 0, GPUdb.END_OF_SET, null, order, null, (err,  response) => {
    if (err)
        console.error(err);
    else
        console.info("All records:");
        response.records.forEach(element => {
            console.info(element);
        });
});

Egress with Parameters

cURL
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
KINETICA_URL=http://localhost:9191
USERNAME=auser
PASSWORD=apassword
TABLE_NAME=product

# Using data-urlencode can make params easier to read than appending to URL
#   Use the G option to pass the data-urlencode options as GET query parameters
curl -sSG ${KINETICA_URL}/get/records/json \
--header "Content-Type: application/json" \
--user "${USERNAME}:${PASSWORD}" \
--data-urlencode "table_name=${TABLE_NAME}" \
--data-urlencode "column_names=name,category,description,stock" \
--data-urlencode "expression=stock > 100000" \
--data-urlencode "order_by=name"
Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
kinetica_url = "http://localhost:9191"
username = "auser"
password = "apassword"
kinetica = gpudb.GPUdb([kinetica_url], username = username, password = password)

table_name = "example.product"
column_names = ["name", "category", "description", "stock"]
expr = "stock > 100000"
order = ["name"]

response = kinetica.get_records_json(table_name, column_names, expression = expr, orderby_columns = order)
Java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
String url = "http://localhost:9191"
GPUdb.Options options = new GPUdb.Options();
options.setUsername(username);
options.setPassword(password);
GPUdb kdb = new GPUdb(url, options);

String tableName = "product";
List<String> columnNames = GPUdb.list("name", "category", "description", "stock");
String expression = "stock > 100000";
List<String> order = GPUdb.list("name");

GetRecordsJsonResponse response =
        kdb.getRecordsJson(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order);
JavaScript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
const kinetica_url = 'http://localhost:9191'
const username = 'auser'
const password = 'apassword'
const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

let tableName = 'product';
const columnNames = ['name', 'category', 'description', 'stock'];
const expression = 'stock > 100000';
const order = ['name'];

db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, null, (err,  response) => {
    if (err)
        console.error(err);
    else
        console.info("Filtered records:");
        response.records.forEach(element => {
            console.info(element);
        });
});
Node.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
const kinetica_url = 'http://localhost:9191'
const username = 'auser'
const password = 'apassword'
const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

let tableName = 'product';
const columnNames = ['name', 'category', 'description', 'stock'];
const expression = 'stock > 100000';
const order = ['name'];

db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, null, (err,  response) => {
    if (err)
        console.error(err);
    else
        console.info("Filtered records:");
        response.records.forEach(element => {
            console.info(element);
        });
});

Egress with Aggregation

cURL
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
KINETICA_URL=http://localhost:9191
USERNAME=auser
PASSWORD=apassword
TABLE_NAME=product

# Using data-urlencode can make params easier to read than appending to URL
#   Use the G option to pass the data-urlencode options as GET query parameters
curl -sSG ${KINETICA_URL}/get/records/json \
--header "Content-Type: application/json" \
--user "${USERNAME}:${PASSWORD}" \
--data-urlencode "table_name=${TABLE_NAME}" \
--data-urlencode "column_names=category,COUNT(1) AS total_products" \
--data-urlencode "expression=stock >= 1000" \
--data-urlencode "having=COUNT(1) > 1"
Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
kinetica_url = "http://localhost:9191"
username = "auser"
password = "apassword"
kinetica = gpudb.GPUdb([kinetica_url], username = username, password = password)

table_name = "example.product"
column_names = ["category", "COUNT(1) AS total_products"]
expr = "stock >= 1000"
having = "COUNT(1) > 1"

response = kinetica.get_records_json(table_name, column_names, expression = expr, having_clause = having)
Java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
String url = "http://localhost:9191"
GPUdb.Options options = new GPUdb.Options();
options.setUsername(username);
options.setPassword(password);
GPUdb kdb = new GPUdb(url, options);

String tableName = "product";
List<String> columnNames = GPUdb.list("category", "COUNT(1) AS total_products");
String expression = "stock > 1000";
String having = "COUNT(1) > 1";

GetRecordsJsonResponse response =
        kdb.getRecordsJson(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, having);
JavaScript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
const kinetica_url = 'http://localhost:9191'
const username = 'auser'
const password = 'apassword'
const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

let tableName = 'product';
const columnNames = ['category', 'COUNT(1) AS total_products'];
const expression = 'stock >= 1000';
const having = 'COUNT(1) > 1';
const order = [];

db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, having, (err,  response) => {
    if (err)
        console.error(err);
    else
        console.info("Aggregated records:");
        response.records.forEach(element => {
            console.info(element);
        });
});
Node.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
const kinetica_url = 'http://localhost:9191'
const username = 'auser'
const password = 'apassword'
const db = new GPUdb([kinetica_url], {'username': username, 'password': password});

let tableName = 'product';
const columnNames = ['category', 'COUNT(1) AS total_products'];
const expression = 'stock >= 1000';
const having = 'COUNT(1) > 1';
const order = [];

db.get_records_json(tableName, columnNames, 0, GPUdb.END_OF_SET, expression, order, having, (err,  response) => {
    if (err)
        console.error(err);
    else
        console.info("Aggregated records:");
        response.records.forEach(element => {
            console.info(element);
        });
});