Skip to main content
create_projection(table_name=None, projection_name=None, column_names=None, options=)[source]

Creates a new projection of an existing table. A projection represents a subset of the columns (potentially including derived columns) of a table.

For projection details and examples, see Projections. For limitations, see Projection Limitations and Cautions.

Window functions, which can perform operations like moving averages, are available through this endpoint as well as GPUdb.get_records_by_column().

A projection can be created with a different shard key than the source table. By specifying shard_key, the projection will be sharded according to the specified columns, regardless of how the source table is sharded. The source table can even be unsharded or replicated.

If input parameter table_name is empty, selection is performed against a single-row virtual table. This can be useful in executing temporal (NOW()), identity (USER()), or constant-based functions (GEODIST(-77.11, 38.88, -71.06, 42.36)).

Parameters

table_name (str) –

Name of the existing table on which the projection is to be applied, in [schema_name.]table_name format, using standard name resolution rules. An empty table name creates a projection from a single-row virtual table, where columns specified should be constants or constant expressions.

projection_name (str) –

Name of the projection to be created, in [schema_name.]table_name format, using standard name resolution rules and meeting table naming criteria.

column_names (list of str) –

List of columns from input parameter table_name to be included in the projection. Can include derived columns. Can be specified as aliased via the syntax ‘column_name as alias’. The user can provide a single element (which will be automatically promoted to a list internally) or a list.

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 input parameter projection_name. If 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_projection_name. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • collection_name – [DEPRECATED–please specify the containing schema for the projection as part of input parameter projection_name and use GPUdb.create_schema() to create the schema if non-existent] Name of a schema for the projection. If the schema is non-existent, it will be automatically created. The default value is ‘’.

  • expression – An optional filter expression to be applied to the source table prior to the projection. The default value is ‘’.

  • is_replicated – If true then the projection will be replicated even if the source table is not. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • offset – The number of initial results to skip (this can be useful for paging through the results). The default value is ‘0’.

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

  • 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 parameter column_names. 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 this projection.

  • chunk_column_max_memory – Indicates the target maximum data size for each column in a chunk to be used for this projection.

  • chunk_max_memory – Indicates the target maximum data size for all columns in a chunk to be used for this projection.

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

  • ttl – Sets the TTL of the projection specified in input parameter projection_name.

  • shard_key – Comma-separated list of the columns to be sharded on; e.g. ‘column1, column2’. The columns specified must be present in input parameter column_names. If any alias is given for any column name, the alias must be used, rather than the original column name. The default value is ‘’.

  • persist – If true, then the projection specified in input parameter projection_name will be persisted and will not expire unless a ttl is specified. If false, then the projection 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’.

  • preserve_dict_encoding – If true, then columns that were dict encoded in the source table will be dict encoded in the projection. Allowed values are:

    • true

    • false

    The default value is ‘true’.

  • retain_partitions – Determines whether the created projection will retain the partitioning scheme from the source table. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • partition_typePartitioning scheme to use. Allowed values are:

  • partition_keys – Comma-separated list of partition keys, which are the columns or column expressions by which records will be assigned to partitions defined by partition_definitions.

  • partition_definitions – Comma-separated list of partition definitions, whose format depends on the choice of partition_type. See range partitioning, interval partitioning, list partitioning, hash partitioning, or series partitioning for example formats.

  • is_automatic_partition – If true, a new partition will be created for values which don’t fall into an existing partition. Currently only supported for list partitions. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • view_id – ID of view of which this projection is a member. The default value is ‘’.

  • strategy_definition – The tier strategy for the table and its columns.

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

  • join_window_functions – If set, window functions which require a reshard will be computed separately and joined back together, if the width of the projection is greater than the join_window_functions_threshold. The default value is ‘true’.

  • join_window_functions_threshold – If the projection is greater than this width (in bytes), then window functions which require a reshard will be computed separately and joined back together. The default value is ‘’.

  • qualify_filter – An optional filter expression applied to the projection after window function evaluation, equivalent to a SQL QUALIFY clause. May reference window function aliases as well as any other column in the projection. Rows for which the expression evaluates to false (or NULL) are removed from the projection. The default value is ‘’.

The default value is an empty dict ( ).

Returns

A dict with the following entries–

projection_name (str) –

Value of input parameter projection_name.

info (dict of str to str) –

Additional information. Allowed keys are:

  • count – Number of records in the final table.

  • qualified_projection_name – The fully qualified name of the projection (i.e. including the schema).

The default value is an empty dict ( ).