Class GPUdbRecord

class gpudb.GPUdbRecord(record_type, column_values)[source]

Bases: object

Represent the data for a given record in GPUdb. Has convenience functions for encoding/decoding the data.

Create a GPUdbRecord object which holds the data for a given record.

Parameters

record_type (GPUdbRecordType) –
A GPUdbRecordType object that describes the columns of this record.
column_values (dict or list) –
Either a dict or a list that contains the values for the columns. In either case, must contain values for ALL columns. If a list, then the columns must be in the correct order.
static decode_binary_data(record_type, binary_data)[source]

Decode binary encoded data (generally returned by GPUdb) using the schema for the data. Return the decoded data.

Parameters

record_type (str or RecordType) –
If string, then the schema string for the record type, or a RecordType object representing the type.
binary_data (obj or list) –
The binary encoded data. Could be a single object or a list of data.

Returns

The decoded data (a single object or a list)
static decode_dynamic_binary_data(record_type, binary_data)[source]

Decode binary encoded data (generally returned by GPUdb) using the schema for the data. Return the decoded data.

Parameters

record_type (str or RecordType) –
If string, then the schema string for the record type, or a RecordType object representing the type.
binary_data (obj or list) –
The binary encoded data. Could be a single object or a list of data.

Returns

The decoded data (a single object or a list)
static decode_json_string_data(json_string_data)[source]

Decode binary encoded data in string form (generally returned by GPUdb). Return the decoded data.

Parameters

json_string_data (str) –
The stringified json encoded data. Could be a single object or a list of data.

Returns

The decoded data (a single object or a list)
static decode_dynamic_json_data_column_major(dynamic_json_data, dynamic_schema)[source]

Decode JSON encoded data (generally returned by GPUdb) using the embedded dynamic schema for the data. Return the decoded data.

Parameters

dynamic_json_data (dict) –
The JSON encoded data with a dynamic schema.
dynamic_schema (str) –
The schema string for the data

Returns

The decoded data (a single object or a list)
static decode_dynamic_json_data_row_major(dynamic_json_data, dynamic_schema)[source]

Decode JSON encoded data (generally returned by GPUdb) using the embedded dynamic schema for the data. Return the decoded data.

Parameters

dynamic_json_data (dict) –
The JSON encoded data with a dynamic schema.
dynamic_schema (str) –
The schema string for the data

Returns

The decoded data in row-format (a single object or a list)
static convert_data_col_major_to_row_major(col_major_data, col_major_schema_str)[source]

Given some column major data, convert it to row major data.

Parameters

col_major_data (OrderedDict) –
An OrderedDict of arrays containing the data by column names.
col_major_schema_str (str) –
A JSON schema string describing the column major data.

Returns

A list of GPUdbRecord objects.
static transpose_data_to_col_major(row_major_data)[source]

Given some row major data, convert it to column major data.

Parameters

row_major_data (list of Record or collections.OrderedDicts) –
A list of Record or collections.OrderedDicts objects containing the data.

Returns

A dict of lists where the keys are column names and the values are –

lists (containing the values for the pertinent column of all the records)

record_type

The type for this record.

column_values

The values for this record.

data

The values for this record.

binary_data

The binary encoded values for this record.

json_data_string

The stringified JSON encoded values for this record.

keys()[source]

Return a list of the column names of the record.

values()[source]

Return a list of the values of the record.

insert_record(gpudb, table_name, encoding='binary', options=None)[source]

Insert this record into GPUdb.

Parameters

gpudb (GPUdb) –
A GPUdb client handle.
table_name (str) –
The name of the table into which we need to insert the record.
encoding (str) –
Optional encoding with which to perform the insertion. Default is binary encoding.
options (dict) –
Optional parameter. If given, use the options for the insertion function.

Returns

The response from GPUdb.