Skip to content

Commit

Permalink
add jinja variables to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
karakanb committed Nov 18, 2024
1 parent fe0edb9 commit 4cd69a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 63 deletions.
31 changes: 15 additions & 16 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ export default defineConfig({

],
},
{
text: "Data Platforms",
collapsed: false,
items: [
{ text: "AWS Athena", link: "/platforms/athena" },
{ text: "Databricks", link: "/platforms/databricks" },
{ text: "DuckDB", link: "/platforms/duckdb" },
{ text: "Google BigQuery", link: "/platforms/bigquery" },
{ text: "Microsoft SQL Server", link: "/platforms/mssql" },
{ text: "Postgres", link: "/platforms/postgres" },
{ text: "Redshift", link: "/platforms/redshift" },
{ text: "Snowflake", link: "/platforms/snowflake" },
{ text: "Synapse", link: "/platforms/synapse" },
],
},
{
text: "Assets",
collapsed: false,
Expand All @@ -65,22 +80,6 @@ export default defineConfig({
},
],
},

{
text: "Data Platforms",
collapsed: false,
items: [
{ text: "AWS Athena", link: "/platforms/athena" },
{ text: "Databricks", link: "/platforms/databricks" },
{ text: "DuckDB", link: "/platforms/duckdb" },
{ text: "Google BigQuery", link: "/platforms/bigquery" },
{ text: "Microsoft SQL Server", link: "/platforms/mssql" },
{ text: "Postgres", link: "/platforms/postgres" },
{ text: "Redshift", link: "/platforms/redshift" },
{ text: "Snowflake", link: "/platforms/snowflake" },
{ text: "Synapse", link: "/platforms/synapse" },
],
},
{
text: "Data Ingestion",
collapsed: false,
Expand Down
7 changes: 5 additions & 2 deletions docs/assets/templating/filters.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Filters

Bruin supports Jinja filters to modify any given variable before they are converted to SQL. Filters are separated from the variable by a pipe symbol (`|`) and may have optional arguments in parentheses. Multiple filters can be chained. The output of one filter is applied to the next.
Bruin supports Jinja filters to modify any given variable before they are converted to string. Filters are separated from the variable by a pipe symbol (`|`) and may have optional arguments in parentheses. Multiple filters can be chained. The output of one filter is applied to the next.

```sql
SELECT * FROM my_table WHERE dt BETWEEN '{{ start_date | date_format('%Y-%m-%d') }}' AND '{{ end_date | date_format('%Y-%m-%d') }}'
SELECT *
FROM my_table
WHERE dt BETWEEN '{{ start_date | date_format('%Y-%m-%d') }}'
AND '{{ end_date | date_format('%Y-%m-%d') }}'
```

## Default Filters
Expand Down
27 changes: 26 additions & 1 deletion docs/assets/templating/templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,29 @@ SELECT
FROM user_cohorts
GROUP BY 1,2
```
You can read more about [Jinja here](https://jinja.palletsprojects.com/en/3.1.x/).
You can read more about [Jinja here](https://jinja.palletsprojects.com/en/3.1.x/).

## Available variables

Bruin injects various variables by default:
| Variable | Description | Example |
|----------|-------------|---------|
| `start_date` | The start date in YYYY-MM-DD format | "2023-12-01" |
| `start_datetime` | The start date and time in YYYY-MM-DDThh:mm:ss format | "2023-12-01T15:30:00" |
| `start_timestamp` | The start timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339) format | "2023-12-01T15:30:00.000000Z07:00" |
| `end_date` | The end date in YYYY-MM-DD format | "2023-12-02" |
| `end_datetime` | The end date and time in YYYY-MM-DDThh:mm:ss format | "2023-12-02T15:30:00" |
| `end_timestamp` | The end timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339) format | "2023-12-02T15:30:00.000000Z07:00" |
| `pipeline` | The name of the currently executing pipeline | `my_pipeline` |
| `run_id` | The unique identifier for the current [pipeline run](../../getting-started/concepts.md#pipeline-run) | `run_1234567890` |

You can use these variables in your SQL queries by referencing them with the `{{ }}` syntax:
```sql
SELECT * FROM my_table
WHERE dt BETWEEN '{{ start_date }}' AND '{{ end_date }}'
```

> [!NOTE]
> Date-related variables are passed in as strings, and they will be driven by the flags given to the `bruin run` command, read more on that [here](../../commands/run.md).
You can modify these variables with the use of [filters](./filters.md).
44 changes: 0 additions & 44 deletions docs/platforms/templating.md

This file was deleted.

0 comments on commit 4cd69a3

Please sign in to comment.