Skip to content

Commit 6610b26

Browse files
committed
Add docs
1 parent b2e4bf1 commit 6610b26

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

docs/pages/product/data-modeling/syntax.mdx

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,73 @@ the [template context](/reference/python/cube#templatecontext-class).
602602

603603
</ReferenceBox>
604604

605+
### Curly braces and escaping
606+
607+
As you can see in the examples above, within [SQL expressions][self-sql-expressions],
608+
curly braces are used to reference cubes and members.
609+
610+
In YAML data models, use `{reference}`:
611+
612+
```yaml
613+
cubes:
614+
- name: orders
615+
sql: >
616+
SELECT id, created_at
617+
FROM {other_cube.sql()}
618+
619+
dimensions:
620+
- name: status
621+
sql: status
622+
type: string
623+
624+
- name: status_x2
625+
sql: "{status} || ' ' || {status}"
626+
type: string
627+
```
628+
629+
In JavaScript data models, use `${reference}` in [JavaScript template
630+
literals][link-js-template-literals] (mind the dollar sign):
631+
632+
```javascript
633+
cube(`orders`, {
634+
sql: `
635+
SELECT id, created_at
636+
FROM ${other_cube.sql()}
637+
`,
638+
639+
dimensions: {
640+
status: {
641+
sql: `status`,
642+
type: `string`
643+
},
644+
645+
status_x2: {
646+
sql: `${status} || ' ' || ${status}`,
647+
type: `string`
648+
}
649+
}
650+
})
651+
```
652+
653+
If you need to use literal, non-referential curly braces in YAML, e.g.,
654+
to define a JSON object, you can escape them with a backslash:
655+
656+
```yaml
657+
cubes:
658+
- name: json_object_in_postgres
659+
sql: SELECT CAST('\{"key":"value"\}'::JSON AS TEXT) AS json_column
660+
661+
- name: csv_from_s3_in_duckdb
662+
sql: >
663+
SELECT *
664+
FROM read_csv(
665+
's3://bbb/aaa.csv',
666+
delim = ',',
667+
header = true,
668+
columns=\{'time':'DATE','count':'NUMERIC'\}
669+
)
670+
```
671+
605672
### Non-SQL references
606673
607674
Outside [SQL expressions][self-sql-expressions], `column` is not recognized
@@ -693,4 +760,5 @@ defining dynamic data models.
693760
[ref-custom-granularities]: /reference/data-model/dimensions#granularities
694761
[ref-style-guide]: /guides/style-guide
695762
[ref-polymorphism]: /product/data-modeling/concepts/polymorphic-cubes
696-
[ref-data-blending]: /product/data-modeling/concepts/data-blending
763+
[ref-data-blending]: /product/data-modeling/concepts/data-blending
764+
[link-js-template-literals]: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/Strings#embedding_javascript

0 commit comments

Comments
 (0)