SQL Lab¶
SQL Lab is a modern, feature-rich SQL IDE written in React.
Feature Overview¶
Connects to just about any database backend
A multi-tab environment to work on multiple queries at a time
A smooth flow to visualize your query results using Superset’s rich visualization capabilities
Browse database metadata: tables, columns, indexes, partitions
Support for long-running queries - uses the Celery distributed queue
to dispatch query handling to workers
- supports defining a “results backend” to persist query results
A search engine to find queries executed in the past
Supports templating using the Jinja templating language which allows for using macros in your SQL code
Extra features¶
- Hit
alt + enteras a keyboard shortcut to run your query
Templating with Jinja¶
SELECT *
FROM some_table
WHERE partition_key = '{{ presto.latest_partition('some_table') }}'
Templating unleashes the power and capabilities of a programming language within your SQL code.
Templates can also be used to write generic queries that are parameterized so they can be re-used easily.
Available macros¶
We expose certain modules from Python’s standard library in
Superset’s Jinja context:
- time: time
- datetime: datetime.datetime
- uuid: uuid
- random: random
- relativedelta: dateutil.relativedelta.relativedelta
- more to come!
Jinja’s builtin filters can be also be applied where needed.
-
class
superset.jinja_context.PrestoTemplateProcessor(database=None, query=None, table=None)[source]¶ Presto Jinja context
The methods described here are namespaced under
prestoin the jinja context as inSELECT '{{ presto.some_macro_call() }}'-
latest_partition(table_name)[source]¶ Returns the latest (max) partition value for a table
Parameters: table_name (str) – the name of the table, can be just the table name or a fully qualified table name as schema_name.table_name>>> latest_partition('foo_table') '2018-01-01'
-
latest_sub_partition(table_name, **kwargs)[source]¶ Returns the latest (max) partition value for a table
A filtering criteria should be passed for all fields that are partitioned except for the field to be returned. For example, if a table is partitioned by (
ds,event_typeandevent_category) and you want the latestds, you’ll want to provide a filter as keyword arguments for bothevent_typeandevent_categoryas in ``latest_sub_partition(‘my_table’,event_category=’page’, event_type=’click’)``Parameters: - table_name (str) – the name of the table, can be just the table
name or a fully qualified table name as
schema_name.table_name - kwargs (str) – keyword arguments define the filtering criteria on the partition list. There can be many of these.
>>> latest_sub_partition('sub_partition_table', event_type='click') '2018-01-01'
- table_name (str) – the name of the table, can be just the table
name or a fully qualified table name as
-