sortkeys

LookML
Version

On this Page
Docs Menu

Go to View Parameter List

Usage

sortkeys is a child of
derived_table is a child of
view
view: my_view
derived_table:
...
1st
Tab
2nd
Tab
sortkeys: [column_name]
one or more columns from
the derived table sql

Definition

sortkeys enables you to specify one or more columns of a persistent derived table on which to apply a regular sort key. Currently, sortkeys only works with Redshift databases. You can also create an interleaved sort key by using indexes instead. You cannot use both at the same time, but at least one is required.

Traditional SQL dialects (such as MySQL and Postgres) should use indexes; sortkeys will not work with these databases.

Generally speaking, a sort key should be applied to date or time columns in the derived table, and possibly to columns that will be used frequently as filters. More information can be found in the Amazon Redshift documentation.

Examples

Create a customer_day_facts derived table with a sortkey on date:

- view: customer_day_facts derived_table: sql: | SELECT customer_id, DATE(order_time) AS date, COUNT(*) AS num_orders FROM order GROUP BY customer_id persist_for: 24 hours sortkeys: [date]

Create a customer_day_facts derived table with a sortkey on date and customer_id:

- view: customer_day_facts derived_table: sql: | SELECT customer_id, DATE(order_time) AS date, COUNT(*) AS num_orders FROM order GROUP BY customer_id persist_for: 24 hours sortkeys: [date, customer_id]

Common Challenges

sortkeys Only Works With Derived Tables That Are Persisted

Derived tables can be calculated at query time, or they can be made persistent using persist_for or sql_trigger_value. sortkeys only works with persistent derived tables.

Still have questions?
Go to Discourse - or - Email Support
Top