-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f14e4f
commit 774e6c7
Showing
6 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Jinja2 templating | ||
|
||
{% hint style="info" %} | ||
**Supported connections:** BigQuery, Postgres, Presto, Redshift, Snowflake | ||
{% endhint %} | ||
|
||
All metrics calculations and executed SQL queries will be passed through the Jinja2 engine, so any basic Jinja2 templating, as you might expect, is supported. If you're not familiar with Jinja2, a basic example is shown below. | ||
|
||
```text | ||
{% set table = census.public_data %} | ||
select count(*) from {{ table }} | ||
``` | ||
|
||
## Reusable templates | ||
|
||
On top of this, we provide support for **reusable templates**, which should be saved in the `~/.whale/templates` folder and **named after the name of the warehouse connection that you would like to use this template for**. Connection names can be found by running `wh connections`, in the `name` field of each yaml block. | ||
|
||
```text | ||
.whale | ||
└── templates | ||
└── warehouse-connection-name.sql | ||
``` | ||
|
||
For example, consider the following BigQuery connection setup: | ||
|
||
```text | ||
--- | ||
name: bq-1 | ||
metadata_source: Bigquery | ||
key_path: ~ | ||
project_credentials: ~ | ||
project_id: my-bigquery-project | ||
``` | ||
|
||
The name of the connection here is `bq-1`, so you'll need to create a file as follows: | ||
|
||
```text | ||
.whale | ||
└── templates | ||
└── bq-1.sql | ||
``` | ||
|
||
And the template within will automatically be pre-pended to queries against this connection. | ||
|
||
## Template example | ||
|
||
The following snippet enables the value `{{ last_day }}` to be used to performantly get data from the latest partition in BigQuery. | ||
|
||
```text | ||
{% set last_day = "_PARTITIONDATE = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)" %} | ||
``` | ||
|
||
The following query, then, could be run by `whale`: | ||
|
||
```text | ||
select count(*) from table.schema where {{ last_day }} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters