@clickzetta/cz-cli-darwin-x64 0.3.92 → 0.3.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cz-cli +0 -0
- package/bin/skills/clickzetta-ai-function/SKILL.md +109 -0
- package/bin/skills/clickzetta-ai-function/eval_cases.jsonl +4 -0
- package/bin/skills/clickzetta-ai-function/references/ai-function-ddl.md +106 -0
- package/bin/skills/clickzetta-batch-sync-pipeline/SKILL.md +124 -124
- package/bin/skills/clickzetta-batch-sync-pipeline/eval_cases.jsonl +5 -5
- package/bin/skills/clickzetta-bi-connect/SKILL.md +79 -78
- package/bin/skills/clickzetta-bi-connect/references/bi-tools.md +56 -56
- package/bin/skills/clickzetta-cdc-sync-pipeline/SKILL.md +386 -382
- package/bin/skills/clickzetta-cdc-sync-pipeline/eval_cases.jsonl +5 -5
- package/bin/skills/clickzetta-data-ingest-pipeline/SKILL.md +73 -212
- package/bin/skills/clickzetta-data-science/SKILL.md +57 -56
- package/bin/skills/clickzetta-data-science/references/bitmap-profile.md +38 -38
- package/bin/skills/clickzetta-data-science/references/data-patterns.md +16 -16
- package/bin/skills/clickzetta-data-science/references/setup.md +28 -28
- package/bin/skills/clickzetta-data-science/references/stats-functions.md +44 -44
- package/bin/skills/clickzetta-data-science/references/write-and-infer.md +22 -22
- package/bin/skills/clickzetta-data-science/references/zettapark-api.md +32 -32
- package/bin/skills/clickzetta-dw-modeling/SKILL.md +1 -1
- package/bin/skills/clickzetta-external-function/SKILL.md +51 -109
- package/bin/skills/clickzetta-external-function/eval_cases.jsonl +4 -4
- package/bin/skills/clickzetta-external-function/references/external-function-ddl.md +39 -77
- package/bin/skills/clickzetta-java-sdk/SKILL.md +49 -48
- package/bin/skills/clickzetta-java-sdk/eval_cases.jsonl +12 -12
- package/bin/skills/clickzetta-java-sdk/references/bulkload.md +34 -34
- package/bin/skills/clickzetta-java-sdk/references/realtime.md +44 -44
- package/bin/skills/clickzetta-kafka-ingest-pipeline/SKILL.md +273 -507
- package/bin/skills/clickzetta-kafka-ingest-pipeline/references/kafka-pipe-syntax.md +197 -231
- package/bin/skills/clickzetta-oss-ingest-pipeline/SKILL.md +231 -304
- package/bin/skills/clickzetta-realtime-sync-pipeline/SKILL.md +180 -179
- package/bin/skills/clickzetta-realtime-sync-pipeline/eval_cases.jsonl +5 -5
- package/bin/skills/clickzetta-semantic-view/SKILL.md +74 -72
- package/bin/skills/clickzetta-semantic-view/eval_cases.jsonl +12 -12
- package/bin/skills/clickzetta-semantic-view/references/semantic-view-reference.md +75 -75
- package/bin/skills/clickzetta-sql-migration/SKILL.md +128 -0
- package/bin/skills/clickzetta-sql-migration/eval_cases.jsonl +10 -0
- package/bin/skills/clickzetta-sql-migration/references/ddl-reference.md +350 -0
- package/bin/skills/clickzetta-sql-migration/references/dml-differences.md +192 -0
- package/bin/skills/clickzetta-sql-migration/references/dml-reference.md +279 -0
- package/bin/skills/{clickzetta-sql-syntax-guide → clickzetta-sql-migration}/references/dql-reference.md +128 -128
- package/bin/skills/clickzetta-sql-migration/references/function-mapping.md +194 -0
- package/bin/skills/clickzetta-sql-migration/references/functions-reference.md +372 -0
- package/bin/skills/clickzetta-sql-migration/references/implicit-type-conversion.md +143 -0
- package/bin/skills/clickzetta-sql-migration/references/migration-databricks.md +260 -0
- package/bin/skills/{clickzetta-sql-syntax-guide → clickzetta-sql-migration}/references/migration-snowflake.md +112 -112
- package/bin/skills/clickzetta-sql-migration/references/vs-snowflake.md +346 -0
- package/bin/skills/clickzetta-sql-migration/references/vs-spark.md +229 -0
- package/bin/skills/clickzetta-studio-task-manager/SKILL.md +326 -329
- package/bin/skills/clickzetta-table-lineage/SKILL.md +57 -55
- package/bin/skills/clickzetta-table-lineage/eval_cases.jsonl +1 -1
- package/bin/skills/clickzetta-table-lineage/references/normalize_func.sql +5 -5
- package/bin/skills/clickzetta-table-lineage/references/table_cost.sql +6 -6
- package/bin/skills/clickzetta-table-lineage/references/table_relation.sql +2 -2
- package/bin/skills/clickzetta-volume-manager/SKILL.md +186 -100
- package/bin/skills/clickzetta-volume-manager/references/volume-ddl.md +153 -52
- package/package.json +1 -1
- package/bin/skills/clickzetta-dynamic-table/best-practices/scheduling-guide.md +0 -135
- package/bin/skills/clickzetta-dynamic-table/dt-creator/references/dt-declaration-strategy.md +0 -185
- package/bin/skills/clickzetta-dynamic-table/dt-creator/references/refresh-history-guide.md +0 -260
- package/bin/skills/clickzetta-dynamic-table/dynamic-table-alter/SKILL.md +0 -191
- package/bin/skills/clickzetta-sql-syntax-guide/SKILL.md +0 -249
- package/bin/skills/clickzetta-sql-syntax-guide/eval_cases.jsonl +0 -3
- package/bin/skills/clickzetta-sql-syntax-guide/references/ddl-reference.md +0 -350
- package/bin/skills/clickzetta-sql-syntax-guide/references/dml-reference.md +0 -279
- package/bin/skills/clickzetta-sql-syntax-guide/references/functions-reference.md +0 -372
- package/bin/skills/clickzetta-sql-syntax-guide/references/migration-databricks.md +0 -260
- package/bin/skills/clickzetta-sql-syntax-guide/references/vs-snowflake.md +0 -346
- package/bin/skills/clickzetta-sql-syntax-guide/references/vs-spark.md +0 -229
- /package/bin/skills/{clickzetta-sql-syntax-guide → clickzetta-sql-migration}/LICENSE +0 -0
|
@@ -1,79 +1,81 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clickzetta-semantic-view
|
|
3
3
|
description: |
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
4
|
+
Create and query ClickZetta Lakehouse Semantic Views. A Semantic View is a schema-level logical
|
|
5
|
+
data model object that encapsulates complex multi-table JOINs and aggregation logic into a
|
|
6
|
+
business-friendly semantic layer by declaring logical tables, dimensions, metrics, and filters.
|
|
7
|
+
Query using the semantic_view() function without writing JOINs manually.
|
|
8
|
+
Currently in invite-only preview (since version 1.3).
|
|
9
|
+
Triggered when user says "create semantic view", "semantic view", "semantic layer",
|
|
10
|
+
"define metrics", "define dimensions", "how to use semantic_view()",
|
|
11
|
+
"unified metric definitions", "business semantic model", "logical table",
|
|
12
|
+
"DIMENSIONS", "METRICS", "FILTERS", "DROP SEMANTIC VIEW",
|
|
13
|
+
"SHOW SEMANTIC VIEWS".
|
|
12
14
|
Keywords: semantic view, dimension, metric, logical model, unified metrics, semantic layer
|
|
13
15
|
---
|
|
14
16
|
|
|
15
|
-
# ClickZetta
|
|
17
|
+
# ClickZetta Semantic View
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
Read [references/semantic-view-reference.md](references/semantic-view-reference.md) for the complete syntax reference.
|
|
18
20
|
|
|
19
21
|
---
|
|
20
22
|
|
|
21
|
-
##
|
|
23
|
+
## Overview
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
A Semantic View is a **schema-level logical data model object** in ClickZetta Lakehouse that solves two core problems:
|
|
24
26
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
+
- **Data Analysis**: Unifies dimension and metric definitions so business users can query cross-table data without writing complex JOINs
|
|
28
|
+
- **Data Governance**: Centrally manages table relationships, dimension and metric definitions, ensuring the entire organization uses consistent data definitions
|
|
27
29
|
|
|
28
|
-
> ⚠️
|
|
30
|
+
> ⚠️ Currently in **invite-only preview** (version 1.3). Contact technical support to enable.
|
|
29
31
|
|
|
30
32
|
---
|
|
31
33
|
|
|
32
|
-
##
|
|
34
|
+
## Four Core Components
|
|
33
35
|
|
|
34
|
-
|
|
|
36
|
+
| Component | Keyword | Description |
|
|
35
37
|
|---|---|---|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
38
|
+
| Logical Tables | `TABLES` | Maps physical tables, declares primary and foreign key relationships; the engine handles JOINs automatically |
|
|
39
|
+
| Dimensions | `DIMENSIONS` | Categorical attributes (who/what/where/when), supports computed dimensions |
|
|
40
|
+
| Metrics | `METRICS` | Aggregate measures (SUM/AVG/COUNT/MIN/MAX), business KPIs |
|
|
41
|
+
| Filters | `FILTERS` | Predefined reusable filter conditions (semantic annotations, cannot be passed directly to queries) |
|
|
40
42
|
|
|
41
43
|
---
|
|
42
44
|
|
|
43
|
-
##
|
|
45
|
+
## Creating a Semantic View
|
|
44
46
|
|
|
45
47
|
```sql
|
|
46
|
-
CREATE SEMANTIC VIEW
|
|
48
|
+
CREATE SEMANTIC VIEW <view_name>
|
|
47
49
|
TABLES (
|
|
48
|
-
|
|
49
|
-
PRIMARY KEY (
|
|
50
|
-
[ FOREIGN KEY (
|
|
51
|
-
[ WITH SYNONYMS ('
|
|
52
|
-
[ COMMENT = '
|
|
50
|
+
<table_alias> AS <schema>.<physical_table>
|
|
51
|
+
PRIMARY KEY (<column_name>)
|
|
52
|
+
[ FOREIGN KEY (<column_name>) REFERENCES <other_table_alias> ]
|
|
53
|
+
[ WITH SYNONYMS ('<synonym>') ]
|
|
54
|
+
[ COMMENT = '<description>' ]
|
|
53
55
|
[ , ... ]
|
|
54
56
|
)
|
|
55
57
|
[ FILTERS (
|
|
56
|
-
|
|
58
|
+
<table_alias>.<filter_name> AS <boolean_expression>
|
|
57
59
|
[ , ... ]
|
|
58
60
|
) ]
|
|
59
61
|
DIMENSIONS (
|
|
60
|
-
{
|
|
61
|
-
[ WITH SYNONYMS = ('
|
|
62
|
+
{ <table_alias>.<dimension_name> | <dimension_name> } AS <expression>
|
|
63
|
+
[ WITH SYNONYMS = ('<synonym>' [ , ... ]) ]
|
|
62
64
|
[ is_unique = { true | false } ]
|
|
63
65
|
[ is_time = { true | false } ]
|
|
64
|
-
[ enum_values = [
|
|
65
|
-
[ COMMENT = '
|
|
66
|
+
[ enum_values = [ <value1>, <value2>, ... ] ]
|
|
67
|
+
[ COMMENT = '<description>' ]
|
|
66
68
|
[ , ... ]
|
|
67
69
|
)
|
|
68
70
|
METRICS (
|
|
69
|
-
|
|
70
|
-
[ COMMENT = '
|
|
71
|
+
<table_alias>.<metric_name> AS <aggregate_expression>
|
|
72
|
+
[ COMMENT = '<description>' ]
|
|
71
73
|
[ , ... ]
|
|
72
74
|
)
|
|
73
|
-
[ COMMENT = '
|
|
75
|
+
[ COMMENT = '<view_description>' ];
|
|
74
76
|
```
|
|
75
77
|
|
|
76
|
-
###
|
|
78
|
+
### Complete Example (TPC-H Revenue Analysis)
|
|
77
79
|
|
|
78
80
|
```sql
|
|
79
81
|
DROP SEMANTIC VIEW IF EXISTS tpch_rev_analysis;
|
|
@@ -81,60 +83,60 @@ CREATE SEMANTIC VIEW tpch_rev_analysis
|
|
|
81
83
|
TABLES (
|
|
82
84
|
customers AS tpch.customer
|
|
83
85
|
PRIMARY KEY (c_custkey)
|
|
84
|
-
COMMENT = '
|
|
86
|
+
COMMENT = 'Customer master table',
|
|
85
87
|
orders AS tpch.orders
|
|
86
88
|
PRIMARY KEY (o_orderkey)
|
|
87
89
|
FOREIGN KEY (o_custkey) REFERENCES customers
|
|
88
|
-
WITH SYNONYMS ('
|
|
89
|
-
COMMENT = '
|
|
90
|
+
WITH SYNONYMS ('sales orders')
|
|
91
|
+
COMMENT = 'Orders table',
|
|
90
92
|
line_items AS tpch.lineitem
|
|
91
93
|
PRIMARY KEY (l_orderkey, l_linenumber)
|
|
92
94
|
FOREIGN KEY (l_orderkey) REFERENCES orders
|
|
93
|
-
COMMENT = '
|
|
95
|
+
COMMENT = 'Order line items'
|
|
94
96
|
)
|
|
95
97
|
FILTERS (
|
|
96
98
|
customers.is_building AS customers.c_mktsegment = 'BUILDING'
|
|
97
99
|
)
|
|
98
100
|
DIMENSIONS (
|
|
99
101
|
customers.customer_name AS c_name
|
|
100
|
-
WITH SYNONYMS = ('
|
|
102
|
+
WITH SYNONYMS = ('customer name')
|
|
101
103
|
is_unique = true
|
|
102
|
-
COMMENT = '
|
|
104
|
+
COMMENT = 'Customer name',
|
|
103
105
|
orders.order_date AS o_orderdate
|
|
104
106
|
is_time = true
|
|
105
|
-
COMMENT = '
|
|
107
|
+
COMMENT = 'Order date',
|
|
106
108
|
orders.order_year AS YEAR(o_orderdate)
|
|
107
|
-
COMMENT = '
|
|
109
|
+
COMMENT = 'Order year',
|
|
108
110
|
orders.order_status AS o_orderstatus
|
|
109
111
|
enum_values = ['O', 'F', 'P']
|
|
110
|
-
COMMENT = '
|
|
112
|
+
COMMENT = 'Order status'
|
|
111
113
|
)
|
|
112
114
|
METRICS (
|
|
113
115
|
customers.customer_count AS COUNT(c_custkey)
|
|
114
|
-
COMMENT = '
|
|
116
|
+
COMMENT = 'Total customer count',
|
|
115
117
|
orders.avg_order_value AS AVG(o_totalprice)
|
|
116
|
-
COMMENT = '
|
|
118
|
+
COMMENT = 'Average order value',
|
|
117
119
|
orders.total_revenue AS SUM(o_totalprice)
|
|
118
|
-
COMMENT = '
|
|
120
|
+
COMMENT = 'Total revenue'
|
|
119
121
|
)
|
|
120
|
-
COMMENT = '
|
|
122
|
+
COMMENT = 'Revenue analysis semantic view';
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
---
|
|
124
126
|
|
|
125
|
-
##
|
|
127
|
+
## Querying a Semantic View
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
Use the `semantic_view()` table function — **no need to write JOINs or GROUP BY manually**:
|
|
128
130
|
|
|
129
131
|
```sql
|
|
130
|
-
--
|
|
132
|
+
-- Basic query: average order value by order date
|
|
131
133
|
SELECT * FROM semantic_view(
|
|
132
134
|
tpch_rev_analysis,
|
|
133
135
|
DIMENSIONS orders.order_date,
|
|
134
136
|
METRICS orders.avg_order_value
|
|
135
137
|
);
|
|
136
138
|
|
|
137
|
-
--
|
|
139
|
+
-- Multi-dimension query: by date and customer name
|
|
138
140
|
SELECT * FROM semantic_view(
|
|
139
141
|
tpch_rev_analysis,
|
|
140
142
|
DIMENSIONS orders.order_date,
|
|
@@ -142,7 +144,7 @@ SELECT * FROM semantic_view(
|
|
|
142
144
|
METRICS orders.avg_order_value
|
|
143
145
|
);
|
|
144
146
|
|
|
145
|
-
--
|
|
147
|
+
-- Using short names (table alias prefix can be omitted when names are unique)
|
|
146
148
|
SELECT * FROM semantic_view(
|
|
147
149
|
tpch_rev_analysis,
|
|
148
150
|
DIMENSIONS order_date,
|
|
@@ -150,7 +152,7 @@ SELECT * FROM semantic_view(
|
|
|
150
152
|
METRICS avg_order_value
|
|
151
153
|
);
|
|
152
154
|
|
|
153
|
-
--
|
|
155
|
+
-- Adding WHERE filter (filter columns must be defined as DIMENSIONS)
|
|
154
156
|
SELECT * FROM semantic_view(
|
|
155
157
|
tpch_rev_analysis,
|
|
156
158
|
DIMENSIONS customers.customer_name,
|
|
@@ -159,16 +161,16 @@ SELECT * FROM semantic_view(
|
|
|
159
161
|
) WHERE order_status = 'O';
|
|
160
162
|
```
|
|
161
163
|
|
|
162
|
-
###
|
|
164
|
+
### Comparison with Traditional SQL
|
|
163
165
|
|
|
164
166
|
```sql
|
|
165
|
-
--
|
|
167
|
+
-- Traditional SQL (requires manual JOIN + GROUP BY)
|
|
166
168
|
SELECT o.o_orderdate, c.c_name, AVG(o.o_totalprice)
|
|
167
169
|
FROM tpch.orders o
|
|
168
170
|
JOIN tpch.customer c ON o.o_custkey = c.c_custkey
|
|
169
171
|
GROUP BY o.o_orderdate, c.c_name;
|
|
170
172
|
|
|
171
|
-
--
|
|
173
|
+
-- Semantic View (JOINs and aggregation handled automatically)
|
|
172
174
|
SELECT * FROM semantic_view(
|
|
173
175
|
tpch_rev_analysis,
|
|
174
176
|
DIMENSIONS order_date,
|
|
@@ -179,29 +181,29 @@ SELECT * FROM semantic_view(
|
|
|
179
181
|
|
|
180
182
|
---
|
|
181
183
|
|
|
182
|
-
##
|
|
184
|
+
## Management Commands
|
|
183
185
|
|
|
184
186
|
```sql
|
|
185
|
-
--
|
|
187
|
+
-- Drop (recommended: drop before create for idempotency)
|
|
186
188
|
DROP SEMANTIC VIEW IF EXISTS tpch_rev_analysis;
|
|
187
189
|
|
|
188
|
-
--
|
|
190
|
+
-- List all semantic views in the current schema
|
|
189
191
|
SHOW SEMANTIC VIEWS;
|
|
190
192
|
SHOW SEMANTIC VIEWS IN my_schema;
|
|
191
193
|
|
|
192
|
-
--
|
|
194
|
+
-- View detailed definition (logical tables, dimensions, metrics, foreign keys)
|
|
193
195
|
DESC EXTENDED tpch_rev_analysis;
|
|
194
196
|
```
|
|
195
197
|
|
|
196
198
|
---
|
|
197
199
|
|
|
198
|
-
##
|
|
200
|
+
## Important Notes
|
|
199
201
|
|
|
200
|
-
1. **TABLES
|
|
201
|
-
2. **FILTERS
|
|
202
|
-
3. **WHERE
|
|
203
|
-
4.
|
|
204
|
-
5.
|
|
205
|
-
6.
|
|
206
|
-
7.
|
|
207
|
-
8. **DIMENSIONS
|
|
202
|
+
1. **TABLES definition order**: Tables referenced by foreign keys must be defined first (e.g., `customers` must come before `orders`)
|
|
203
|
+
2. **FILTERS are semantic annotations**: Named filters in `FILTERS` cannot be passed as parameters to `semantic_view()`; WHERE clauses can only reference column short names defined in `DIMENSIONS`, not physical column names
|
|
204
|
+
3. **WHERE only accepts DIMENSION short names**: `WHERE customer_name = 'Alice'` ✅, `WHERE c_name = 'Alice'` ❌
|
|
205
|
+
4. **Short names vs qualified names**: Use short names when unique within the view; use `table_alias.name` when there are conflicts
|
|
206
|
+
5. **Idempotent creation**: Always `DROP SEMANTIC VIEW IF EXISTS` before creating to avoid errors on repeated execution
|
|
207
|
+
6. **Computed dimensions**: DIMENSIONS supports expressions, e.g., `YEAR(CAST(order_date AS DATE))` to extract year
|
|
208
|
+
7. **Metric aggregate functions**: Only `COUNT`, `AVG`, `SUM`, `MIN`, `MAX` are supported
|
|
209
|
+
8. **DIMENSIONS and METRICS can be used independently**: You can query only METRICS (global aggregation) or only DIMENSIONS (deduplicated list)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{"case_id":"001","type":"should_call","user_input":"
|
|
2
|
-
{"case_id":"002","type":"should_call","user_input":"semantic_view()
|
|
3
|
-
{"case_id":"003","type":"should_call","user_input":"
|
|
4
|
-
{"case_id":"004","type":"should_call","user_input":"
|
|
5
|
-
{"case_id":"005","type":"should_call","user_input":"SHOW SEMANTIC VIEWS
|
|
6
|
-
{"case_id":"006","type":"should_call","user_input":"
|
|
7
|
-
{"case_id":"007","type":"should_call","user_input":"DROP SEMANTIC VIEW
|
|
8
|
-
{"case_id":"008","type":"should_not_call","user_input":"
|
|
9
|
-
{"case_id":"009","type":"should_not_call","user_input":"
|
|
10
|
-
{"case_id":"010","type":"should_not_call","user_input":"
|
|
11
|
-
{"case_id":"011","type":"should_not_call","user_input":"Superset
|
|
12
|
-
{"case_id":"012","type":"should_not_call","user_input":"
|
|
1
|
+
{"case_id":"001","type":"should_call","user_input":"How to create a semantic view","expected_skill":"clickzetta-semantic-view","expected_output_contains":["CREATE SEMANTIC VIEW"]}
|
|
2
|
+
{"case_id":"002","type":"should_call","user_input":"How to query with semantic_view() function","expected_skill":"clickzetta-semantic-view","expected_output_contains":["semantic_view"]}
|
|
3
|
+
{"case_id":"003","type":"should_call","user_input":"How to define dimensions and metrics in a semantic view","expected_skill":"clickzetta-semantic-view","expected_output_contains":["DIMENSIONS","METRICS"]}
|
|
4
|
+
{"case_id":"004","type":"should_call","user_input":"How to use the semantic layer to unify metric definitions","expected_skill":"clickzetta-semantic-view","expected_output_contains":["semantic"]}
|
|
5
|
+
{"case_id":"005","type":"should_call","user_input":"How to use SHOW SEMANTIC VIEWS","expected_skill":"clickzetta-semantic-view","expected_output_contains":["SHOW SEMANTIC VIEWS"]}
|
|
6
|
+
{"case_id":"006","type":"should_call","user_input":"How to define FILTERS in a semantic view","expected_skill":"clickzetta-semantic-view","expected_output_contains":["FILTERS"]}
|
|
7
|
+
{"case_id":"007","type":"should_call","user_input":"How to drop a semantic view with DROP SEMANTIC VIEW","expected_skill":"clickzetta-semantic-view","expected_output_contains":["DROP SEMANTIC VIEW"]}
|
|
8
|
+
{"case_id":"008","type":"should_not_call","user_input":"How to create a regular view","forbidden_skill":"clickzetta-semantic-view"}
|
|
9
|
+
{"case_id":"009","type":"should_not_call","user_input":"Help me build a data dashboard","forbidden_skill":"clickzetta-semantic-view"}
|
|
10
|
+
{"case_id":"010","type":"should_not_call","user_input":"How to do data modeling","forbidden_skill":"clickzetta-semantic-view"}
|
|
11
|
+
{"case_id":"011","type":"should_not_call","user_input":"How to connect Superset","forbidden_skill":"clickzetta-semantic-view"}
|
|
12
|
+
{"case_id":"012","type":"should_not_call","user_input":"How to create a materialized view","forbidden_skill":"clickzetta-semantic-view"}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Semantic View Complete Syntax Reference
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
>
|
|
3
|
+
> Source: https://www.yunqi.tech/documents/semantic_view
|
|
4
|
+
> Feature status: Invite-only preview (since version 1.3)
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
## CREATE SEMANTIC VIEW
|
|
8
|
+
## CREATE SEMANTIC VIEW Full Syntax
|
|
9
9
|
|
|
10
10
|
```sql
|
|
11
|
-
CREATE SEMANTIC VIEW
|
|
11
|
+
CREATE SEMANTIC VIEW <view_name>
|
|
12
12
|
TABLES (
|
|
13
|
-
|
|
13
|
+
<logical_table_definition> [ , ... ]
|
|
14
14
|
)
|
|
15
15
|
[ FILTERS (
|
|
16
|
-
|
|
16
|
+
<filter_definition> [ , ... ]
|
|
17
17
|
) ]
|
|
18
18
|
DIMENSIONS (
|
|
19
|
-
|
|
19
|
+
<dimension_definition> [ , ... ]
|
|
20
20
|
)
|
|
21
21
|
METRICS (
|
|
22
|
-
|
|
22
|
+
<metric_definition> [ , ... ]
|
|
23
23
|
)
|
|
24
|
-
[ COMMENT = '
|
|
24
|
+
[ COMMENT = '<view_description>' ];
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
**Constraint**: At least one of `DIMENSIONS` or `METRICS` must be included.
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
|
-
##
|
|
31
|
+
## Logical Table Definition Syntax
|
|
32
32
|
|
|
33
33
|
```sql
|
|
34
|
-
|
|
35
|
-
PRIMARY KEY (
|
|
36
|
-
[ FOREIGN KEY (
|
|
37
|
-
[ WITH SYNONYMS ( '
|
|
38
|
-
[ COMMENT = '
|
|
34
|
+
<table_alias> AS <schema>.<physical_table_name>
|
|
35
|
+
PRIMARY KEY ( <column_name> [ , ... ] )
|
|
36
|
+
[ FOREIGN KEY ( <column_name> ) REFERENCES <other_logical_table_alias> ]
|
|
37
|
+
[ WITH SYNONYMS ( '<synonym>' [ , ... ] ) ]
|
|
38
|
+
[ COMMENT = '<description>' ]
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
|
|
|
41
|
+
| Parameter | Description |
|
|
42
42
|
|---|---|
|
|
43
|
-
|
|
|
44
|
-
| `PRIMARY KEY` |
|
|
45
|
-
| `FOREIGN KEY ... REFERENCES` |
|
|
46
|
-
| `WITH SYNONYMS` |
|
|
43
|
+
| `<table_alias> AS <schema>.<physical_table>` | Assigns a logical alias to a physical table; dimensions/metrics/foreign keys reference this alias |
|
|
44
|
+
| `PRIMARY KEY` | Primary key columns, used to determine relationship types between tables (one-to-many/one-to-one) |
|
|
45
|
+
| `FOREIGN KEY ... REFERENCES` | Foreign key relationship; the engine uses this to handle JOINs automatically; target must be a logical table alias |
|
|
46
|
+
| `WITH SYNONYMS` | Logical table synonyms to enhance discoverability |
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
**Note**: Tables referenced by foreign keys must be defined first in the TABLES clause.
|
|
49
49
|
|
|
50
50
|
---
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## Filter Definition Syntax
|
|
53
53
|
|
|
54
54
|
```sql
|
|
55
|
-
|
|
55
|
+
<logical_table_alias>.<filter_name> AS <boolean_expression>
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Example:
|
|
59
59
|
```sql
|
|
60
60
|
FILTERS (
|
|
61
61
|
customers.is_building AS customers.c_mktsegment = 'BUILDING',
|
|
@@ -63,105 +63,105 @@ FILTERS (
|
|
|
63
63
|
)
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
**Important**: FILTERS are semantic annotations for AI/metadata layers and **cannot** be passed directly as parameters to the `semantic_view()` function. To filter in queries, define the corresponding column as a DIMENSION and use an outer WHERE clause.
|
|
67
67
|
|
|
68
68
|
---
|
|
69
69
|
|
|
70
|
-
##
|
|
70
|
+
## Dimension Definition Syntax
|
|
71
71
|
|
|
72
72
|
```sql
|
|
73
|
-
{
|
|
74
|
-
[ WITH SYNONYMS = ( '
|
|
73
|
+
{ <logical_table_alias>.<dimension_name> | <dimension_name> } AS <expression>
|
|
74
|
+
[ WITH SYNONYMS = ( '<synonym>' [ , ... ] ) ]
|
|
75
75
|
[ is_unique = { true | false } ]
|
|
76
76
|
[ is_time = { true | false } ]
|
|
77
|
-
[ enum_values = [
|
|
78
|
-
[ COMMENT = '
|
|
77
|
+
[ enum_values = [ <value1>, <value2>, ... ] ]
|
|
78
|
+
[ COMMENT = '<description>' ]
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
|
|
|
81
|
+
| Parameter | Description |
|
|
82
82
|
|---|---|
|
|
83
|
-
| `AS
|
|
84
|
-
| `WITH SYNONYMS` |
|
|
85
|
-
| `is_unique = true` |
|
|
86
|
-
| `is_time = true` |
|
|
87
|
-
| `enum_values` |
|
|
83
|
+
| `AS <expression>` | Can be a column name or a computed expression (e.g., `YEAR(o_orderdate)`) |
|
|
84
|
+
| `WITH SYNONYMS` | Dimension synonyms allowing users to reference the same dimension with different business terms |
|
|
85
|
+
| `is_unique = true` | Indicates the dimension values are unique (e.g., customer name), helps the engine optimize |
|
|
86
|
+
| `is_time = true` | Identifies as a time-type dimension (e.g., order date) |
|
|
87
|
+
| `enum_values` | Restricts allowed enumeration values, improves query accuracy |
|
|
88
88
|
|
|
89
89
|
---
|
|
90
90
|
|
|
91
|
-
##
|
|
91
|
+
## Metric Definition Syntax
|
|
92
92
|
|
|
93
93
|
```sql
|
|
94
|
-
|
|
95
|
-
[ COMMENT = '
|
|
94
|
+
<logical_table_alias>.<metric_name> AS <aggregate_expression>
|
|
95
|
+
[ COMMENT = '<description>' ]
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
Supported aggregate functions: `COUNT`, `AVG`, `SUM`, `MIN`, `MAX`
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Example:
|
|
101
101
|
```sql
|
|
102
102
|
METRICS (
|
|
103
103
|
orders.total_revenue AS SUM(o_totalprice)
|
|
104
|
-
COMMENT = '
|
|
104
|
+
COMMENT = 'Total revenue',
|
|
105
105
|
orders.avg_order_value AS AVG(o_totalprice)
|
|
106
|
-
COMMENT = '
|
|
106
|
+
COMMENT = 'Average order value',
|
|
107
107
|
customers.customer_count AS COUNT(c_custkey)
|
|
108
|
-
COMMENT = '
|
|
108
|
+
COMMENT = 'Total customer count'
|
|
109
109
|
)
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
-
## semantic_view()
|
|
114
|
+
## semantic_view() Query Function Syntax
|
|
115
115
|
|
|
116
116
|
```sql
|
|
117
117
|
SELECT *
|
|
118
118
|
FROM semantic_view(
|
|
119
|
-
|
|
120
|
-
DIMENSIONS
|
|
121
|
-
METRICS
|
|
119
|
+
<view_name>,
|
|
120
|
+
DIMENSIONS <dimension_name> [ , DIMENSIONS <dimension_name> ... ],
|
|
121
|
+
METRICS <metric_name> [ , METRICS <metric_name> ... ]
|
|
122
122
|
)
|
|
123
|
-
[ WHERE
|
|
123
|
+
[ WHERE <filter_condition> ];
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
- WHERE
|
|
126
|
+
- Dimension names can use qualified names (`table_alias.dimension_name`) or short names (when unique)
|
|
127
|
+
- Results are automatically grouped by specified dimensions — no GROUP BY needed
|
|
128
|
+
- Column names in WHERE clauses use short names (without table alias prefix)
|
|
129
129
|
|
|
130
130
|
---
|
|
131
131
|
|
|
132
|
-
##
|
|
132
|
+
## Management Commands
|
|
133
133
|
|
|
134
|
-
|
|
|
134
|
+
| Command | Description |
|
|
135
135
|
|---|---|
|
|
136
|
-
| `CREATE SEMANTIC VIEW` |
|
|
137
|
-
| `DROP SEMANTIC VIEW IF EXISTS
|
|
138
|
-
| `SHOW SEMANTIC VIEWS` |
|
|
139
|
-
| `SHOW SEMANTIC VIEWS IN <schema>` |
|
|
140
|
-
| `DESC EXTENDED
|
|
136
|
+
| `CREATE SEMANTIC VIEW` | Create a semantic view |
|
|
137
|
+
| `DROP SEMANTIC VIEW IF EXISTS <name>` | Drop a semantic view |
|
|
138
|
+
| `SHOW SEMANTIC VIEWS` | List all semantic views in the current schema |
|
|
139
|
+
| `SHOW SEMANTIC VIEWS IN <schema>` | List semantic views in a specified schema |
|
|
140
|
+
| `DESC EXTENDED <name>` | View detailed definition (logical tables/dimensions/metrics/foreign keys/indexes) |
|
|
141
141
|
|
|
142
142
|
---
|
|
143
143
|
|
|
144
|
-
##
|
|
144
|
+
## Best Practices
|
|
145
145
|
|
|
146
146
|
```sql
|
|
147
|
-
-- 1.
|
|
147
|
+
-- 1. Idempotent creation (always drop before create)
|
|
148
148
|
DROP SEMANTIC VIEW IF EXISTS my_view;
|
|
149
149
|
CREATE SEMANTIC VIEW my_view ...;
|
|
150
150
|
|
|
151
|
-
-- 2.
|
|
152
|
-
--
|
|
153
|
-
--
|
|
151
|
+
-- 2. Use meaningful business terminology for naming
|
|
152
|
+
-- Good: customer_name, total_revenue, order_date
|
|
153
|
+
-- Bad: c_name, sum_totalprice, o_orderdate
|
|
154
154
|
|
|
155
|
-
-- 3.
|
|
156
|
-
-- is_time=true
|
|
157
|
-
-- is_unique=true
|
|
158
|
-
-- enum_values
|
|
155
|
+
-- 3. Set dimension metadata appropriately
|
|
156
|
+
-- is_time=true for date/time dimensions
|
|
157
|
+
-- is_unique=true for primary-key-like dimensions (e.g., customer ID, order number)
|
|
158
|
+
-- enum_values for status-type dimensions (e.g., order status)
|
|
159
159
|
|
|
160
|
-
-- 4.
|
|
160
|
+
-- 4. Computed dimension examples
|
|
161
161
|
DIMENSIONS (
|
|
162
|
-
orders.order_year AS YEAR(o_orderdate) --
|
|
163
|
-
COMMENT = '
|
|
164
|
-
orders.order_month AS MONTH(o_orderdate) --
|
|
165
|
-
COMMENT = '
|
|
162
|
+
orders.order_year AS YEAR(o_orderdate) -- Extract year from date
|
|
163
|
+
COMMENT = 'Order year',
|
|
164
|
+
orders.order_month AS MONTH(o_orderdate) -- Extract month from date
|
|
165
|
+
COMMENT = 'Order month'
|
|
166
166
|
)
|
|
167
167
|
```
|