Skip to content

Commit 5dbe0ab

Browse files
authored
docs: Document FILTER_PARAMS in YAML (#7365)
1 parent ac4037e commit 5dbe0ab

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

docs/docs-new/pages/product/data-modeling/concepts/code-reusability-extending-cubes.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ in any `sql` property, then extending cubes can do one of two things:
151151
cubes:
152152
- name: product_purchases
153153
sql: >
154-
SELECT * FROM events WHERE
155-
{FILTER_PARAMS.product_purchases.timestamp.filter('time')}
154+
SELECT *
155+
FROM events
156+
WHERE {FILTER_PARAMS.product_purchases.timestamp.filter('time')}
156157
157158
# ...
158159
```
@@ -180,7 +181,9 @@ in any `sql` property, then extending cubes can do one of two things:
180181
cubes:
181182
- name: base_events
182183
sql: >
183-
SELECT * FROM events WHERE
184+
SELECT *
185+
FROM events
186+
WHERE
184187
{FILTER_PARAMS.base_events.timestamp.filter('time')} AND
185188
{FILTER_PARAMS.product_purchases.timestamp.filter('time')} AND
186189
{FILTER_PARAMS.page_views.timestamp.filter('time')}

docs/docs-new/pages/reference/data-model/context-variables.mdx

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ cubes:
9393
- name: name
9494
sql: "{CUBE}.name"
9595
type: string
96+
97+
98+
99+
100+
101+
102+
103+
104+
96105
```
97106

98107
</CodeTabs>
@@ -125,7 +134,7 @@ data source.
125134
FILTER_PARAMS.cube_name.member_name.filter(sql_expression)
126135
```
127136

128-
The `filter()` function accepts the SQL expression, which could be either
137+
The `filter()` function accepts a SQL expression, which could be either
129138
a plain string or a function returning one.
130139

131140
### String
@@ -173,6 +182,11 @@ cubes:
173182
- name: date
174183
sql: date
175184
type: time
185+
186+
187+
188+
189+
176190
```
177191

178192
</CodeTabs>
@@ -196,7 +210,6 @@ WHERE
196210
"time_dimensions": [
197211
{
198212
"dimension": "order_facts.date",
199-
"granularity": "day",
200213
"dateRange": ["2018-01-01", "2018-12-31"]
201214
}
202215
]
@@ -205,20 +218,43 @@ WHERE
205218

206219
### Function
207220

208-
You can also pass a function instead of a SQL expression as a `filter()`
209-
argument. This way, you can add BigQuery shard filtering, which will reduce
210-
your billing cost.
221+
You can also pass a function as a `filter()` argument. This way, you can
222+
add BigQuery shard filtering, which will reduce your billing cost.
223+
224+
<CodeTabs>
225+
226+
```yaml
227+
cubes:
228+
- name: events
229+
sql: >
230+
SELECT *
231+
FROM schema.`events*`
232+
WHERE {FILTER_PARAMS.events.date.filter(
233+
lambda x, y: f"""
234+
_TABLE_SUFFIX >= FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP({x})) AND
235+
_TABLE_SUFFIX <= FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP({y}))
236+
"""
237+
)}
238+
239+
dimensions:
240+
- name: date
241+
sql: date
242+
type: time
243+
244+
245+
246+
```
211247

212248
```javascript
213249
cube(`events`, {
214250
sql: `
215251
SELECT *
216252
FROM schema.\`events*\`
217253
WHERE ${FILTER_PARAMS.events.date.filter(
218-
(from, to) => `
219-
_TABLE_SUFFIX >= FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP(${from})) AND
220-
_TABLE_SUFFIX <= FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP(${to}))
221-
`
254+
(x, y) => `
255+
_TABLE_SUFFIX >= FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP(${x})) AND
256+
_TABLE_SUFFIX <= FORMAT_TIMESTAMP('%Y%m%d', TIMESTAMP(${y}))
257+
`
222258
)}
223259
`,
224260

@@ -231,6 +267,8 @@ cube(`events`, {
231267
});
232268
```
233269

270+
</CodeTabs>
271+
234272
<InfoBox>
235273

236274
When a function is passed to `filter()`, its arguments are passed as
@@ -297,6 +335,9 @@ cubes:
297335
- name: created_at
298336
sql: created_at
299337
type: time
338+
339+
340+
300341
```
301342

302343
</CodeTabs>

0 commit comments

Comments
 (0)