Sie sind auf Seite 1von 3

Docs  » SQL Lab

SQL Lab
SQL Lab is a modern, feature‐rich SQL IDE wri en in React.

Feature Overview
Connects to just about any database backend
A mul ‐tab environment to work on mul ple queries at a  me
A smooth flow to visualize your query results using Superset’s rich visualiza on
capabili es
Browse database metadata: tables, columns, indexes, par ons
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 templa ng using the Jinja templa ng language which allows for using macros in
your SQL code

Extra features
Hit  alt + enter  as a keyboard shortcut to run your query
Templating with Jinja

SELECT * 
FROM some_table 
WHERE partition_key = '{{ presto.latest_partition('some_table') }}' 

Templa ng unleashes the power and capabili es 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

Jinja’s buil n filters can be also be applied where needed.

c⑲ass superset.jinja_context.PrestoTemplateProcessor(database×None, query×None,
tab⑲e×None, {{kwargs) [source]

Presto Jinja context

The methods described here are namespaced under  presto  in the jinja context as in


SELECT '{{ presto.some_macro_call() }}'

t×None)
superset.jinja_context.url_param(param, defau⑲ [source]

Read a url or post parameter and use it in your SQL Lab query

When in SQL Lab, it’s possible to add arbitrary URL “query string” parameters, and use
those in your SQL code. For instance you can alter your url and add ! foo×bar, as in
[domain]«superset«sq⑲ ⑲ab! foo×bar. Then if your query is something like SELECT * FROM
foo = ‘{{ url_param(‘foo’) }}’, it will be parsed at run me and replaced by the value in the
URL.

As you create a visualiza on form this SQL Lab query, you can pass parameters in the
explore view as well as from the dashboard, and it should carry through to your queries.
Parameters: param (str) – the parameter to lookup
default (str) – the value to return in the absence of the parameter

umn, defau⑲
superset.jinja_context.filter_values(co⑲ t×None) [source]

Gets a values for a par cular filter as a list

This is useful if:

you want to use a filter box to filter a query where the name of filter box column
doesn’t match the one in the select statement
you want to have the ability for filter inside the main query for speed purposes

This searches for “filters” and “extra_filters” in form_data for a match

Usage example:

SELECT ac on, count(*) as  mes FROM logs WHERE ac on in ( {{ “’” +


“’,’”.join(filter_values(‘ac on_type’)) + “’” }} ) GROUP BY 1

Parameters: column (str) – column/filter name to lookup
default (str) – default value to return if there’s no matching columns

Returns: returns a list of filter values

Type: list

Extending macros

As men oned in the Installa on & Configura on documenta on, it’s possible for


administrators to expose more more macros in their environment using the configura on
variable  JINJA_CONTEXT_ADDONS . All objects referenced in this dic onary will become available
for users to integrate in their queries in SQL Lab.

Das könnte Ihnen auch gefallen