@rasmusengelbrecht/pi-semantic-query 0.1.1 → 0.1.3
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/README.md +20 -1
- package/extensions/semantic-query.ts +5 -1
- package/package.json +5 -1
- package/skills/semantic-query/SKILL.md +62 -0
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ pi -e /absolute/path/to/pi-semantic-query
|
|
|
40
40
|
|
|
41
41
|
## Tools
|
|
42
42
|
|
|
43
|
-
The package registers these pi tools:
|
|
43
|
+
The package registers a bundled `semantic-query` skill plus these pi tools:
|
|
44
44
|
|
|
45
45
|
- `semantic_metrics` — list metrics with discovery metadata
|
|
46
46
|
- `semantic_search_metrics` — search metrics by id, name, description, synonyms, and teams
|
|
@@ -48,6 +48,8 @@ The package registers these pi tools:
|
|
|
48
48
|
- `semantic_validate` — validate a semantic model
|
|
49
49
|
- `semantic_compile` — compile a metric request to SQL
|
|
50
50
|
|
|
51
|
+
The skill teaches pi the default workflow: search before guessing metric IDs, describe ambiguous metrics, validate model changes, prefer `period`, and never present compiled SQL as executed results.
|
|
52
|
+
|
|
51
53
|
All tools shell out to the local `semantic` CLI. By default they look for one of:
|
|
52
54
|
|
|
53
55
|
- `semantic.yml`
|
|
@@ -83,6 +85,23 @@ Example request shape for `semantic_compile`:
|
|
|
83
85
|
}
|
|
84
86
|
```
|
|
85
87
|
|
|
88
|
+
For target series, pass `targetTable`. Use `targetProject` and `targetSchema` when the warehouse needs a qualified target relation but you want to keep the table name generic:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"metricId": "revenue",
|
|
93
|
+
"period": "current year",
|
|
94
|
+
"dialect": "bigquery",
|
|
95
|
+
"targetProject": "warehouse-project",
|
|
96
|
+
"targetSchema": "analytics",
|
|
97
|
+
"targetTable": "metric_targets",
|
|
98
|
+
"request": {
|
|
99
|
+
"timeGrain": "monthly",
|
|
100
|
+
"targetSeries": "budget_current"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
86
105
|
## Safety boundary
|
|
87
106
|
|
|
88
107
|
This package is compile-only by design. `semantic_compile` returns SQL; it does not run the SQL. Query execution touches credentials, cost, and data access, so execution should stay in the caller's existing warehouse tooling or a separate explicitly configured integration.
|
|
@@ -65,7 +65,9 @@ const CompileParams = Type.Intersect([
|
|
|
65
65
|
Type.Literal("json"),
|
|
66
66
|
Type.Literal("explain"),
|
|
67
67
|
], { description: "Output format. Defaults to sql." })),
|
|
68
|
-
targetTable: Type.Optional(Type.String({ description: "Optional target table for targetSeries requests." })),
|
|
68
|
+
targetTable: Type.Optional(Type.String({ description: "Optional target table for targetSeries requests. May be fully qualified, or bare when targetProject/targetSchema are supplied." })),
|
|
69
|
+
targetProject: Type.Optional(Type.String({ description: "Optional target table project/catalog." })),
|
|
70
|
+
targetSchema: Type.Optional(Type.String({ description: "Optional target table schema/dataset." })),
|
|
69
71
|
targetMetricColumn: Type.Optional(Type.String({ description: "Target metric id column. Defaults to metric_id." })),
|
|
70
72
|
targetSeriesColumn: Type.Optional(Type.String({ description: "Target series column. Defaults to target_series." })),
|
|
71
73
|
targetTimeColumn: Type.Optional(Type.String({ description: "Target time column. Defaults to metric_time." })),
|
|
@@ -249,6 +251,8 @@ export default function semanticQueryExtension(pi: ExtensionAPI) {
|
|
|
249
251
|
if (params.dialect) args.push("--dialect", params.dialect);
|
|
250
252
|
if (params.format) args.push("--format", params.format);
|
|
251
253
|
if (params.targetTable) args.push("--target-table", params.targetTable);
|
|
254
|
+
if (params.targetProject) args.push("--target-project", params.targetProject);
|
|
255
|
+
if (params.targetSchema) args.push("--target-schema", params.targetSchema);
|
|
252
256
|
if (params.targetMetricColumn) args.push("--target-metric-column", params.targetMetricColumn);
|
|
253
257
|
if (params.targetSeriesColumn) args.push("--target-series-column", params.targetSeriesColumn);
|
|
254
258
|
if (params.targetTimeColumn) args.push("--target-time-column", params.targetTimeColumn);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rasmusengelbrecht/pi-semantic-query",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Compile and inspect governed semantic metrics from pi coding agent",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -25,10 +25,14 @@
|
|
|
25
25
|
"pi": {
|
|
26
26
|
"extensions": [
|
|
27
27
|
"./extensions"
|
|
28
|
+
],
|
|
29
|
+
"skills": [
|
|
30
|
+
"./skills"
|
|
28
31
|
]
|
|
29
32
|
},
|
|
30
33
|
"files": [
|
|
31
34
|
"extensions",
|
|
35
|
+
"skills",
|
|
32
36
|
"README.md",
|
|
33
37
|
"package.json"
|
|
34
38
|
],
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: semantic-query
|
|
3
|
+
description: Compile and inspect governed semantic metrics with semantic-query-compiler from pi. Use when the user asks for semantic metrics, metric discovery, governed SQL compilation, semantic model validation, or SQL for a metric request.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Semantic Query
|
|
7
|
+
|
|
8
|
+
Use the `semantic_*` tools from this package to discover governed metrics and compile inspectable SQL. These tools do **not** execute warehouse queries.
|
|
9
|
+
|
|
10
|
+
## Default workflow
|
|
11
|
+
|
|
12
|
+
1. Start with `semantic_search_metrics` when the user describes a metric in business language.
|
|
13
|
+
2. Use `semantic_metrics` when they ask what metrics exist or when search is too narrow.
|
|
14
|
+
3. Use `semantic_describe` before compiling if the metric semantics, grain, filters, dimensions, teams, or formula are unclear.
|
|
15
|
+
4. Use `semantic_validate` after model edits, before trusting a new model, or when compile errors suggest the model may be invalid.
|
|
16
|
+
5. Use `semantic_compile` to generate SQL for the chosen metric and request.
|
|
17
|
+
6. Say clearly that compiled SQL is not executed results.
|
|
18
|
+
|
|
19
|
+
## Request guidance
|
|
20
|
+
|
|
21
|
+
Prefer period-based requests for CLI/agent workflows:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"metricId": "revenue",
|
|
26
|
+
"period": "last 12 complete months",
|
|
27
|
+
"dialect": "bigquery",
|
|
28
|
+
"request": {
|
|
29
|
+
"timeGrain": "monthly",
|
|
30
|
+
"breakdownDimensionIds": ["country"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
For target series, pass `targetTable`. If the warehouse needs qualified table names, prefer generic relation parts instead of hard-coded company presets:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"metricId": "revenue",
|
|
40
|
+
"period": "current year",
|
|
41
|
+
"dialect": "bigquery",
|
|
42
|
+
"targetProject": "warehouse-project",
|
|
43
|
+
"targetSchema": "analytics",
|
|
44
|
+
"targetTable": "metric_targets",
|
|
45
|
+
"request": {
|
|
46
|
+
"timeGrain": "monthly",
|
|
47
|
+
"targetSeries": "budget_current"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use raw `fromDate` / `toDate` only when the user needs exact fixed boundaries or provides a request JSON shape that already has them.
|
|
53
|
+
|
|
54
|
+
## Safety boundary
|
|
55
|
+
|
|
56
|
+
`semantic_compile` returns SQL only. Do not claim row counts, metric values, parity, or dashboard results unless a separate warehouse/query tool actually executed the SQL.
|
|
57
|
+
|
|
58
|
+
If the user asks to run the query, use their normal warehouse tooling or ask which execution environment to use. This package intentionally does not handle credentials, warehouse cost, or data access.
|
|
59
|
+
|
|
60
|
+
## Model discovery
|
|
61
|
+
|
|
62
|
+
By default, tools look for common model filenames in the current project (`semantic.yml`, `model.yml`, `semantic_layer.yml`, and `.yaml` variants). Pass `model` explicitly when the model lives elsewhere.
|