Skip to main content
aggregate_unique_and_decode(table_name=None, column_name=None, offset=0, limit=-9999, encoding=‘binary’, options=, record_type=None, force_primitive_return_types=True, get_column_major=True)[source]

Returns all the unique values from a particular column (specified by input parameter column_name) of a particular table or view (specified by input parameter table_name). If input parameter column_name is a numeric column, the values will be in output parameter binary_encoded_response. Otherwise if input parameter column_name is a string column, the values will be in output parameter json_encoded_response. The results can be paged via input parameter offset and input parameter limit parameters.

“limit”:”10”,”sort_order”:”descending”

The response is returned as a dynamic schema. For details see: dynamic schemas documentation.

If a result_table name is specified in the input parameter options, the results are stored in a new table with that name–no results are returned in the response. Both the table name and resulting column name must adhere to standard naming conventions; any column expression will need to be aliased. If the source table’s shard key is used as the input parameter column_name, the result table will be sharded, in all other cases it will be replicated. Sorting will properly function only if the result table is replicated or if there is only one processing node and should not be relied upon in other cases. Not available if the value of input parameter column_name is an unrestricted-length string.

Parameters

table_name (str) –

Name of an existing table or view on which the operation will be performed, in [schema_name.]table_name format, using standard name resolution rules.

column_name (str) –

Name of the column or an expression containing one or more column names on which the unique function would be applied.

offset (long) –

A positive integer indicating the number of initial results to skip (this can be useful for paging through the results). The default value is 0. The minimum allowed value is 0. The maximum allowed value is MAX_INT.

limit (long) –

A positive integer indicating the maximum number of results to be returned, or END_OF_SET (-9999) to indicate that the maximum number of results allowed by the server should be returned. The number of records returned will never exceed the server’s own limit, defined by the max_get_records_size parameter in the server configuration. Use output parameter has_more_records to see if more records exist in the result to be fetched, and input parameter offset and input parameter limit to request subsequent pages of results. The default value is -9999.

encoding (str) –

Specifies the encoding for returned records. Allowed values are:

  • binary – Indicates that the returned records should be binary encoded.

  • json – Indicates that the returned records should be JSON-encoded.

The default value is ‘binary’.

options (dict of str to str) –

Optional parameters. Allowed keys are:

  • create_temp_table – If true, a unique temporary table name will be generated in the sys_temp schema and used in place of result_table. If result_table_persist is false (or unspecified), then this is always allowed even if the caller does not have permission to create tables. The generated name is returned in qualified_result_table_name. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • collection_name – [DEPRECATED–please specify the containing schema as part of result_table and use GPUdb.create_schema() to create the schema if non-existent] Name of a schema which is to contain the table specified in result_table. If the schema provided is non-existent, it will be automatically created.

  • expression – Filter expression to apply to the table.

  • sort_order – String indicating how the returned values should be sorted. Allowed values are:

    • ascending

    • descending

    The default value is ‘ascending’.

  • order_by – Comma-separated list of the columns to be sorted by as well as the sort direction, e.g., ‘timestamp asc, x desc’. The default value is ‘’.

  • result_table – The name of the table used to store the results, in [schema_name.]table_name format, using standard name resolution rules and meeting table naming criteria. If present, no results are returned in the response. Not available if input parameter column_name is an unrestricted-length string.

  • result_table_persist – If true, then the result table specified in result_table will be persisted and will not expire unless a ttl is specified. If false, then the result table will be an in-memory table and will expire unless a ttl is specified otherwise. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • result_table_force_replicated – Force the result table to be replicated (ignores any sharding). Must be used in combination with the result_table option. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • result_table_generate_pk – If true then set a primary key for the result table. Must be used in combination with the result_table option. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • ttl – Sets the TTL of the table specified in result_table.

  • chunk_size – Indicates the number of records per chunk to be used for the result table. Must be used in combination with the result_table option.

  • chunk_column_max_memory – Indicates the target maximum data size for each column in a chunk to be used for the result table. Must be used in combination with the result_table option.

  • chunk_max_memory – Indicates the target maximum data size for all columns in a chunk to be used for the result table. Must be used in combination with the result_table option.

  • compression_codec – The default compression codec for the result table’s columns.

  • view_id – ID of view of which the result table will be a member. The default value is ‘’.

The default value is an empty dict ( ).

record_type (RecordType or None) –

The record type expected in the results, or None to determine the appropriate type automatically. If known, providing this may improve performance in binary mode. Not used in JSON mode. The default value is None.

force_primitive_return_types (bool) –

If True, then OrderedDict objects will be returned, where string sub-type columns will have their values converted back to strings; for example, the Python datetime structs, used for datetime type columns would have their values returned as strings. If False, then Record objects will be returned, which for string sub-types, will return native or custom structs; no conversion to string takes place. String conversions, when returning OrderedDicts, incur a speed penalty, and it is strongly recommended to use the Record object option instead. If True, but none of the returned columns require a conversion, then the original Record objects will be returned. Default value is True.

get_column_major (bool) –

Indicates if the decoded records will be transposed to be column-major or returned as is (row-major). Default value is True.

Returns

A dict with the following entries–

table_name (str) –

The same table name as was passed in the parameter list.

response_schema_str (str) –

Avro schema of output parameter binary_encoded_response or output parameter json_encoded_response.

has_more_records (bool) –

Too many records. Returned a partial set.

info (dict of str to str) –

Additional information. Allowed keys are:

  • qualified_result_table_name – The fully qualified name of the table (i.e. including the schema) used to store the results.

The default value is an empty dict ( ).

records (list of Record) –

A list of Record objects which contain the decoded records.