An aggregate unpivot in-memory table is created by specifying the
result_table
option while using the
/aggregate/unpivot endpoint. Aggregate unpivot
in-memory tables are also not persisted by default but can
be persisted (like a table) using the result_table_persist
option. Aggregate unpivot in-memory tables can be created from any table or
view.
The aggregate unpivot in-memory table will be sharded
if the shard key is not part of the pivoted_columns
parameter. The
aggregate unpivot in-memory table will be replicated if
the source table or view is replicated.
Several limitations are discussed in further detail in the Limitations section.
To create an aggregate unpivot in-memory table using the /aggregate/unpivot endpoint requires six parameters:
Given source table customers
that lists the phone numbers for a
customer in the database, an aggregate unpivot in-memory table can be
created in Python like so:
gpudb.aggregate_unpivot(
table_name = "customers",
variable_column_name = "phone_type",
value_column_name = "phone_num",
pivoted_columns = ["phone1", "phone2", "phone3"],
encoding = "json",
options = {
"result_table":"customer_phone_nums"
}
)
Creating a persisted aggregate unpivot table in Python using a students
table that lists a student's ID and grades per quarter:
gpudb.aggregate_unpivot(
table_name = "students",
variable_column_name = "quarter",
value_column_name = "grade",
pivoted_columns = ["q1", "q2", "q3", "q4"],
encoding = "json",
options = {
"result_table":"student_grades",
"result_table_persist":"true"
}
)
There are a few limitations and cautions when creating and using aggregate unpivot in-memory tables:
pivoted_columns
must match, e.g., int8
to
int8
, char4
to char4
, etc.