-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sqllab] add support for Jinja templating #1426
Conversation
visualization capabilities | ||
- Browse database metadata: tables, columns, indexes, partitions | ||
- Support for long-running queries | ||
- uses the Celery async framework to dispatch query handling to workers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we link to Celery docs here?
SQL Lab | ||
======= | ||
|
||
SQL Lab is a modern, feature-rich SQL IDE written in React. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we link to react docs here: https://facebook.github.io/react/
- uses the Celery async framework to dispatch query handling to workers | ||
- supports defining a "result backend" to persist query results | ||
- A search engine to find queries executed in the past | ||
- Supports templating using the ``jinja`` templating language, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we link to jinja docs here?
Templating allows for getting the power and capabilities of a | ||
programming language inside your SQL. | ||
|
||
It also enables for writing generic queries as templates that can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggested edit: Templates can also be used to write generic queries that are parameterized so they can be re-used easily.
knows about the database it is operating in. | ||
|
||
This means that object methods are only available for the active database | ||
and are given access the ``models.Database`` object and schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/given access the/given access to the
nice!! excited about templating for sql lab!! 🎉 |
part_field = indexes[0]['column_names'][0] | ||
sql = self._partition_query(table_name, 1, [(part_field, True)]) | ||
df = self.database.get_df(sql, self.schema) | ||
return df.to_records(index=False)[0][0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question: Why do these two functions look the same?
@@ -438,5 +438,11 @@ def test_extra_table_metadata(self): | |||
'/caravel/extra_table_metadata/{dbid}/' | |||
'ab_permission_view/panoramix/'.format(**locals())) | |||
|
|||
def test_process_template(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add test to the sql_lab tests demonstrating how it works end to end ?
def test_process_template(self): | ||
sql = "SELECT '{{ datetime(2017, 1, 1).isoformat() }}'" | ||
rendered = jinja_context.process_template(sql) | ||
self.assertEqual("SELECT '2017-01-01T00:00:00'", rendered) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great to have tests for all exposed modules, optional.
0570149
to
c6034da
Compare
Looks great! |
@bkyryliuk @ascott @vera-liu