Skip to main content
aggregate_unpivot(table_name=None, column_names=None, variable_column_name=, value_column_name=, pivoted_columns=None, encoding=‘binary’, options=)[source]

Rotate the column values into rows values.

For unpivot details and examples, see Unpivot. For limitations, see Unpivot Limitations.

Unpivot is used to normalize tables that are built for cross tabular reporting purposes. The unpivot operator rotates the column values for all the pivoted columns. A variable column, value column and all columns from the source table except the unpivot columns are projected into the result table. The variable column and value columns in the result table indicate the pivoted column name and values respectively.

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

Parameters

table_name (str) –

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

column_names (list of str) –

List of column names or expressions. A wildcard ‘*’ can be used to include all the non-pivoted columns from the source table. The user can provide a single element (which will be automatically promoted to a list internally) or a list.

variable_column_name (str) –

Specifies the variable/parameter column name. The default value is ‘’.

value_column_name (str) –

Specifies the value column name. The default value is ‘’.

pivoted_columns (list of str) –

List of one or more values typically the column names of the input table. All the columns in the source table must have the same data type. The user can provide a single element (which will be automatically promoted to a list internally) or a list.

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 is non-existent, it will be automatically created.

  • result_table – The name of a 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.

  • 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’.

  • expression – Filter expression to apply to the table prior to unpivot processing.

  • order_by – Comma-separated list of the columns to be sorted by; e.g. ‘timestamp asc, x desc’. The columns specified must be present in input table. If any alias is given for any column name, the alias must be used, rather than the original column name. The default value is ‘’.

  • 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.

  • limit – The number of records to keep. The default value is ‘’.

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

  • view_id – View this result table is part of. The default value is ‘’.

  • create_indexes – Comma-separated list of columns on which to create indexes on the table specified in result_table. The columns specified must be present in output column names. If any alias is given for any column name, the alias must be used, rather than the original column name.

  • 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’.

The default value is an empty dict ( ).

Returns

A dict with the following entries–

table_name (str) –

Typically shows the result-table name if provided in the request (Ignore otherwise).

response_schema_str (str) –

Avro schema of output parameter binary_encoded_response or output parameter json_encoded_response.

binary_encoded_response (bytes) –

Avro binary encoded response.

json_encoded_response (str) –

Avro JSON encoded response.

total_number_of_records (long) –

Total/Filtered number of records.

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 ( ).

record_type (RecordType or None) –

A RecordType object using which the user can decode the binary data by using GPUdbRecord.decode_binary_data(). If JSON encoding is used, then None.