semanticdb-v2 2.0.0-alpha.2 → 2.0.0-alpha.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.
Files changed (171) hide show
  1. package/README.md +22 -17
  2. package/dist/cache/redis-query-cache.js +1 -1
  3. package/dist/compatibility/index.d.ts +1 -1
  4. package/dist/compatibility/logicform.d.ts +1 -7
  5. package/dist/compiler/compile-cte.d.ts +17 -2
  6. package/dist/compiler/index.d.ts +2 -1
  7. package/dist/executor/types.d.ts +11 -12
  8. package/dist/index.d.ts +5 -7
  9. package/dist/logicform-types.d.ts +11 -12
  10. package/dist/normalizer/core.d.ts +2 -2
  11. package/dist/normalizer/property-resolve.d.ts +5 -0
  12. package/dist/operators/builtins/constant.d.ts +2 -0
  13. package/dist/operators/builtins/period-value.d.ts +2 -0
  14. package/dist/operators/builtins/scalar-extremum.d.ts +3 -0
  15. package/dist/operators/index.d.ts +1 -1
  16. package/dist/operators/types.d.ts +25 -21
  17. package/dist/physical/mysql-protocol-provider.d.ts +1 -0
  18. package/dist/physical/provider.d.ts +1 -0
  19. package/dist/planner/semantics/observation/operator-policy.d.ts +1 -1
  20. package/dist/planner/semantics/observation/types.d.ts +1 -1
  21. package/dist/planner/types.d.ts +5 -2
  22. package/dist/plugins/hierarchy/types.d.ts +3 -2
  23. package/dist/schema/entity-identity.d.ts +1 -1
  24. package/dist/schema-mappings/index.d.ts +3 -1
  25. package/dist/schema-mappings/types.d.ts +9 -8
  26. package/dist/schema-mappings/yiask.d.ts +22 -0
  27. package/dist/semantic-types/index.d.ts +1 -1
  28. package/dist/semantic-types/types.d.ts +12 -1
  29. package/dist/semanticdb.js +3 -0
  30. package/package.json +4 -3
  31. package/dist/cache/expiry.js +0 -1
  32. package/dist/cache/identity.js +0 -1
  33. package/dist/cache/serialization.js +0 -1
  34. package/dist/calendar/constants.js +0 -1
  35. package/dist/calendar/provider-relation-store.js +0 -1
  36. package/dist/calendar/resolver.js +0 -1
  37. package/dist/calendar/system-schemas.js +0 -1
  38. package/dist/compatibility/logicform.js +0 -1
  39. package/dist/compiler/compile-cte.js +0 -1
  40. package/dist/compiler/compile-plan.js +0 -1
  41. package/dist/compiler/shorten-sql.js +0 -3
  42. package/dist/custom-functions/custom-functions.d.ts +0 -6
  43. package/dist/custom-functions/custom-functions.js +0 -1
  44. package/dist/custom-functions/index.d.ts +0 -3
  45. package/dist/custom-functions/operator-adapter.d.ts +0 -12
  46. package/dist/custom-functions/operator-adapter.js +0 -1
  47. package/dist/custom-functions/types.d.ts +0 -62
  48. package/dist/errors.js +0 -1
  49. package/dist/executor/compatibility.js +0 -1
  50. package/dist/executor/components.js +0 -1
  51. package/dist/executor/connection-registry.js +0 -1
  52. package/dist/executor/evaluate.js +0 -1
  53. package/dist/executor/execute-query.js +0 -1
  54. package/dist/executor/execute.js +0 -1
  55. package/dist/executor/fetch-entities.js +0 -1
  56. package/dist/executor/result-hydrator/entity-loader.js +0 -1
  57. package/dist/executor/result-hydrator/format-values.js +0 -1
  58. package/dist/executor/result-hydrator/hydrate-result.js +0 -1
  59. package/dist/executor/result-hydrator/missing-entity.js +0 -1
  60. package/dist/executor/result-hydrator/populate-entities.js +0 -1
  61. package/dist/executor/row-identity.js +0 -1
  62. package/dist/index.js +0 -1
  63. package/dist/logicform-types.js +0 -1
  64. package/dist/normalizer/core.js +0 -1
  65. package/dist/normalizer/default-pred-name.js +0 -1
  66. package/dist/normalizer/entity-id.js +0 -1
  67. package/dist/normalizer/groupby.js +0 -1
  68. package/dist/normalizer/normalize-logicform.js +0 -1
  69. package/dist/normalizer/pagination.js +0 -1
  70. package/dist/normalizer/pred-query-name.js +0 -1
  71. package/dist/normalizer/preds.js +0 -1
  72. package/dist/normalizer/query.js +0 -1
  73. package/dist/normalizer/version.js +0 -1
  74. package/dist/operators/builtins/abs.js +0 -1
  75. package/dist/operators/builtins/accumulate.js +0 -1
  76. package/dist/operators/builtins/add.js +0 -1
  77. package/dist/operators/builtins/arithmetic.js +0 -1
  78. package/dist/operators/builtins/average-per-period.js +0 -1
  79. package/dist/operators/builtins/avg.js +0 -1
  80. package/dist/operators/builtins/case.js +0 -1
  81. package/dist/operators/builtins/concat.js +0 -1
  82. package/dist/operators/builtins/count-distinct.js +0 -1
  83. package/dist/operators/builtins/count.js +0 -1
  84. package/dist/operators/builtins/date-bucket.js +0 -1
  85. package/dist/operators/builtins/divide.js +0 -1
  86. package/dist/operators/builtins/index.js +0 -1
  87. package/dist/operators/builtins/max.js +0 -1
  88. package/dist/operators/builtins/min.js +0 -1
  89. package/dist/operators/builtins/multiply.js +0 -1
  90. package/dist/operators/builtins/newly.js +0 -1
  91. package/dist/operators/builtins/period-boundary.js +0 -1
  92. package/dist/operators/builtins/period-difference.js +0 -1
  93. package/dist/operators/builtins/period-growth.js +0 -1
  94. package/dist/operators/builtins/period-name.js +0 -1
  95. package/dist/operators/builtins/period-shift.js +0 -1
  96. package/dist/operators/builtins/rank.js +0 -1
  97. package/dist/operators/builtins/row-number.js +0 -1
  98. package/dist/operators/builtins/share-of-total.js +0 -1
  99. package/dist/operators/builtins/sql.js +0 -1
  100. package/dist/operators/builtins/substring.js +0 -1
  101. package/dist/operators/builtins/subtract.js +0 -1
  102. package/dist/operators/builtins/sum.js +0 -1
  103. package/dist/operators/builtins/time-range.js +0 -1
  104. package/dist/operators/groupby.js +0 -1
  105. package/dist/operators/index.js +0 -1
  106. package/dist/operators/registry.js +0 -1
  107. package/dist/operators/sql-expression.js +0 -1
  108. package/dist/permissions/permissions.js +0 -1
  109. package/dist/physical/clickhouse-provider.js +0 -1
  110. package/dist/physical/connection.js +0 -1
  111. package/dist/physical/display-query.js +0 -1
  112. package/dist/physical/doris-provider.js +0 -1
  113. package/dist/physical/mysql-compatible-sql.js +0 -1
  114. package/dist/physical/mysql-protocol-provider.js +0 -1
  115. package/dist/physical/mysql-provider.js +0 -1
  116. package/dist/physical/oracle-provider.js +0 -1
  117. package/dist/physical/postgresql-provider.js +0 -1
  118. package/dist/physical/snowflake-provider.js +0 -1
  119. package/dist/physical/starrocks-provider.js +0 -1
  120. package/dist/planner/build-lineage.js +0 -1
  121. package/dist/planner/create-logical-plan.js +0 -1
  122. package/dist/planner/select-schema-mapping.js +0 -1
  123. package/dist/planner/semantics/lifecycle/classification.js +0 -1
  124. package/dist/planner/semantics/lifecycle/query-policy.js +0 -1
  125. package/dist/planner/semantics/lifecycle/rule.js +0 -1
  126. package/dist/planner/semantics/observation/classification.js +0 -1
  127. package/dist/planner/semantics/observation/operator-policy.js +0 -1
  128. package/dist/planner/semantics/observation/rule.js +0 -1
  129. package/dist/planner/semantics/registry-defaults.js +0 -1
  130. package/dist/planner/semantics/registry.js +0 -1
  131. package/dist/planner/types.js +0 -1
  132. package/dist/plugins/hierarchy/compatibility.js +0 -1
  133. package/dist/plugins/hierarchy/entity-identity.js +0 -1
  134. package/dist/plugins/hierarchy/index.js +0 -1
  135. package/dist/plugins/hierarchy/operator.js +0 -1
  136. package/dist/plugins/hierarchy/resolve-schema.js +0 -1
  137. package/dist/plugins/index.js +0 -1
  138. package/dist/schema/entity-identity.js +0 -1
  139. package/dist/schema/resolve-property-path.js +0 -1
  140. package/dist/schema/schema-registry.js +0 -1
  141. package/dist/schema-mappings/freshness.js +0 -1
  142. package/dist/schema-mappings/registry.js +0 -1
  143. package/dist/semantic-types/builtins/boolean.js +0 -1
  144. package/dist/semantic-types/builtins/category.js +0 -1
  145. package/dist/semantic-types/builtins/currency.js +0 -1
  146. package/dist/semantic-types/builtins/date.js +0 -1
  147. package/dist/semantic-types/builtins/duration.js +0 -1
  148. package/dist/semantic-types/builtins/end-date.js +0 -1
  149. package/dist/semantic-types/builtins/entity.js +0 -1
  150. package/dist/semantic-types/builtins/file.js +0 -1
  151. package/dist/semantic-types/builtins/human-name.js +0 -1
  152. package/dist/semantic-types/builtins/id.js +0 -1
  153. package/dist/semantic-types/builtins/image.js +0 -1
  154. package/dist/semantic-types/builtins/index.js +0 -1
  155. package/dist/semantic-types/builtins/int.js +0 -1
  156. package/dist/semantic-types/builtins/name.js +0 -1
  157. package/dist/semantic-types/builtins/number.js +0 -1
  158. package/dist/semantic-types/builtins/object.js +0 -1
  159. package/dist/semantic-types/builtins/order.js +0 -1
  160. package/dist/semantic-types/builtins/percentage.js +0 -1
  161. package/dist/semantic-types/builtins/start-date.js +0 -1
  162. package/dist/semantic-types/builtins/string.js +0 -1
  163. package/dist/semantic-types/builtins/timestamp.js +0 -1
  164. package/dist/semantic-types/index.js +0 -1
  165. package/dist/semantic-types/primal-types/date.js +0 -1
  166. package/dist/semantic-types/primal-types/index.js +0 -1
  167. package/dist/semantic-types/registry.js +0 -1
  168. package/dist/semantic-types/resolve-schema.js +0 -1
  169. package/dist/semantic-types/validate-resolved-schema.js +0 -1
  170. package/dist/utils/clone.js +0 -1
  171. /package/dist/operators/builtins/{period-boundary.d.ts → period-boundary-expression.d.ts} +0 -0
package/README.md CHANGED
@@ -8,16 +8,16 @@ SemanticDB creates the matching provider and owns its connection lifecycle.
8
8
 
9
9
  ```ts
10
10
  import { Logicform } from 'semanticdb-v2';
11
- import { SchemaMappingRegistry } from 'semanticdb-v2';
12
11
 
13
- const schemaMappings = new SchemaMappingRegistry([
12
+ const schemaMappings = [
14
13
  {
15
14
  schemaId: 'sales',
16
15
  connectionId: 'analytics',
17
16
  source: 'analytics.sales_detail',
17
+ mappings: [],
18
18
  freshness: { mode: 'ttl', ttlSeconds: 300 },
19
19
  },
20
- ]);
20
+ ];
21
21
 
22
22
  const response = await Logicform.execute(
23
23
  {
@@ -49,7 +49,7 @@ const response = await Logicform.execute(
49
49
  );
50
50
  ```
51
51
 
52
- Every executable LogicForm, including LogicForms used as subqueries, must declare `version`. This
52
+ Every executable LogicForm, including LogicForm objects used as subqueries, must declare `version`. This
53
53
  SDK accepts semantic versions greater than or equal to `2.0`; missing, malformed, or older versions
54
54
  fail with `UNSUPPORTED_LOGICFORM_VERSION` before Schema resolution or database access. A relation
55
55
  query shaped as `{ schema, query }` is part of its parent LogicForm and inherits the parent's version.
@@ -69,7 +69,7 @@ operators.register({
69
69
  });
70
70
  ```
71
71
 
72
- The same locale applies to `preds`, `groupby`, nested expressions, custom-function components,
72
+ The same locale applies to `preds`, `groupby`, nested expressions, custom-function subqueries,
73
73
  and entity-population queries. A PredItem's normalized `query` is included in its
74
74
  generated name, for example `门店为上海的销售额合计`. Operator-specific `args` also participate
75
75
  through each operator's `defaultName()`; period operators distinguish同比、环比 and other offsets.
@@ -78,7 +78,8 @@ An explicitly authored `name` is preserved unchanged.
78
78
  `entity_id` identifies one entity by `hierarchy.property` on hierarchy Schemas and by the unique
79
79
  `type: 'ID'` property on other Schemas. Normalization adds that identity filter unless the query
80
80
  already contains one, in which case the explicit query wins. The legacy value `placeholder` is
81
- preserved as entity context but never becomes a SQL filter. This also applies to relation queries
81
+ preserved as entity context but never becomes a SQL filter. String IDs and safe-integer IDs are
82
+ accepted and retain their original type. This also applies to relation queries
82
83
  shaped as `{ schema, query, entity_id }`. `representation` is presentation metadata for frontend
83
84
  consumers and does not change normalization, planning, or execution. See
84
85
  [Hierarchy plugin](docs/hierarchy-plugin.md) for Schema configuration, `$hierarchyLevel`, legacy
@@ -117,7 +118,7 @@ interface ExecutedSql {
117
118
  ```
118
119
 
119
120
  `semantic-resolution` identifies supporting SQL used to resolve semantic input or output, such as
120
- latest-data-date lookup and object entity population. `computation` identifies SQL that calculates
121
+ time-watermark resolution and object entity population. `computation` identifies SQL that calculates
121
122
  the requested LogicForm result. `sqls` includes every physical SQL involved in the execution; an
122
123
  entry remains visible when its result is served by the query cache.
123
124
 
@@ -167,20 +168,20 @@ await Logicform.execute(logicform, {
167
168
 
168
169
  When `permissions` is omitted, execution remains unrestricted. When it is present, its Schema keys
169
170
  are the table allowlist. `rowPermissions` is always combined with the caller query using `AND`,
170
- including internal latest-data-date queries, related-table joins, and object population queries.
171
+ including internal time-watermark queries, related-table joins, and object population queries.
171
172
  `columnPermissions.whitelist` accepts property names or IDs and restricts caller projections,
172
173
  filters, grouping, operator inputs, and relation paths. A row policy may still use a non-whitelisted
173
174
  column as an internal filter. If an ID is not whitelisted, SemanticDB generates the executor-owned
174
175
  result-row `_id` instead of exposing the physical ID as that identity.
175
176
 
176
- ### Custom composite metrics
177
+ ### Component operators
177
178
 
178
- Pass legacy-compatible `genComponents`, `mergeComponents`, and `genMergeSQL` definitions through
179
- `ExecuteOptions.customFunctions`. JavaScript merge supports async callbacks; SQL merge compiles
180
- components into CTEs. `Logicform.genComponents()` expands the same definitions into an indicator
181
- tree without accessing a database. Cross-Schema components independently pass table, row, and
182
- column permissions. See [Custom composite metrics](docs/custom-functions.md) for the complete
183
- contract, merge-mode selection, and trusted function-string behavior.
179
+ Composite metrics are regular `OperatorDefinition` values with `kind: 'component'`. Their
180
+ `createComponent` hook can return query components merged through a CTE or JavaScript. Register
181
+ them in the same `OperatorRegistry` as scalar and aggregate operators. Operator names are free-form;
182
+ the `$` prefix is a convention used by built-in operators, not a requirement.
183
+
184
+ See [Register an operator](docs/register-operator.md) for the component contract.
184
185
 
185
186
  The root entry point accepts a `connections` array of `DatabaseConnection` items. Every item has a unique `id`; set `kind` to `mysql`,
186
187
  `doris`, `starrocks`, `clickhouse`, `snowflake`, `oracle`, or `postgresql`, then add that driver's
@@ -188,6 +189,10 @@ native connection fields directly on the item. Each Schema Mapping selects an it
188
189
  `connectionId`. SemanticDB lazily creates and reuses the matching internal provider. Call
189
190
  `await Logicform.close()` during application shutdown to close every connection pool and session.
190
191
 
192
+ MySQL-compatible providers default to 30 connections, at most 10 idle connections, a 60-second
193
+ idle timeout, and TCP keepalive. Native `mysql2` pool options on the connection item override these
194
+ defaults.
195
+
191
196
  ### PostgreSQL connection
192
197
 
193
198
  PostgreSQL uses the official `pg` pool and PostgreSQL-native `$1`, `$2` parameters:
@@ -308,7 +313,7 @@ comments, or parameter placeholders. Property UDFs do not support the legacy `fu
308
313
 
309
314
  ### Query cache
310
315
 
311
- All compiled provider queries, including the internal latest-data-date query, can share one
316
+ All compiled provider queries, including the internal time-watermark query, can share one
312
317
  caller-owned query cache. Redis is published from `semanticdb-v2/cache/redis`; cache identity
313
318
  includes namespace, provider, SQL, and parameters. Physical expiration belongs to each Schema
314
319
  mapping's `freshness` policy. See [Query cache and Redis](docs/query-cache.md).
@@ -444,7 +449,7 @@ npm run debug
444
449
  - `$and` and `$or`, HAVING, sorting, row-count and percentage pagination, and per-group `limitBy`
445
450
  - Query-level and output-column lineage
446
451
  - Multi-level scalar and array object relation paths, array groupby, and batched entity population
447
- - Nested `from` LogicForms compiled as parameterized derived tables
452
+ - Nested `from` LogicForm objects compiled as parameterized derived tables
448
453
 
449
454
  Exports and metadata persistence are intentionally deferred. Directly selected array-object
450
455
  properties are populated without expanding the root result rows.
@@ -1 +1 @@
1
- import{createClient as y}from"redis";import{queryCacheIdentityHash as d,sourceCacheIndexHash as f}from"./identity.js";import{deserializeQueryRows as w,serializeQueryRows as x}from"./serialization.js";const m=Number.MAX_SAFE_INTEGER;class u{#e;#t;#s;constructor(e,t={}){this.#e=e,this.#t=t.keyPrefix??"semanticdb:cache",this.#s=t.ownsClient??!1}#r(e){return`${this.#t}:query:${d(e)}`}#i(e,t){return`${this.#t}:source:${f(e,t)}`}async get(e){const t=await this.#e.get(this.#r(e));if(t!==null)return w(t)}async set(e,t,i){const s=this.#r(e),a=x(t),c=i.expiresAt?.getTime(),l=c??m,n=this.#e.multi();c===void 0?n.set(s,a):n.set(s,a,{PXAT:c});for(const h of new Set(i.sources)){const o=this.#i(e.namespace,h);n.zRemRangeByScore(o,0,Date.now()),n.zAdd(o,{score:l,value:s})}await n.exec()}async invalidateSource(e,t){const i=this.#i(e,t),s=await this.#e.zRange(i,0,-1);s.length>0&&await this.#e.del(s),await this.#e.del(i)}async close(){this.#s&&await this.#e.close()}}const C=async(r={})=>{const e=y(r.url?{url:r.url}:{});return e.on("error",()=>{}),await e.connect(),new u(e,{...r.keyPrefix?{keyPrefix:r.keyPrefix}:{},ownsClient:!0})};export{u as RedisQueryCache,C as createRedisQueryCache};
1
+ import{createClient as b}from"redis";import{createHash as g}from"node:crypto";const a=e=>e===void 0?{type:"undefined"}:typeof e=="bigint"?{type:"bigint",value:e.toString()}:typeof e=="number"&&!Number.isFinite(e)?{type:"number",value:String(e)}:e instanceof Date?{type:"date",value:e.toISOString()}:Array.isArray(e)?e.map(a):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,a(r)])):e,d=e=>g("sha256").update(JSON.stringify(a(e))).digest("hex"),A=e=>d({namespace:e.namespace,provider:e.provider,sql:e.sql,parameters:e.parameters}),S=(e,t)=>d({namespace:e,source:t}),o=e=>e===void 0?{type:"undefined"}:typeof e=="bigint"?{type:"bigint",value:e.toString()}:typeof e=="number"&&!Number.isFinite(e)?{type:"number",value:String(e)}:e instanceof Date?{type:"date",value:e.toISOString()}:Array.isArray(e)?{type:"array",value:e.map(o)}:e&&typeof e=="object"?{type:"object",value:Object.entries(e).map(([t,r])=>[t,o(r)])}:e,y=e=>{if(e===null||typeof e!="object")return e;switch(e.type){case"undefined":return;case"bigint":return BigInt(e.value);case"number":return Number(e.value);case"date":return new Date(e.value);case"array":return e.value.map(y);case"object":return Object.fromEntries(e.value.map(([t,r])=>[t,y(r)]))}},w=e=>JSON.stringify(o(e)),x=e=>{const t=y(JSON.parse(e));if(!(!Array.isArray(t)||t.some(r=>!r||typeof r!="object"||Array.isArray(r))))return t},l=Number.MAX_SAFE_INTEGER;class p{#e;#t;#r;constructor(t,r={}){this.#e=t,this.#t=r.keyPrefix??"semanticdb:cache",this.#r=r.ownsClient??!1}#n(t){return`${this.#t}:query:${A(t)}`}#i(t,r){return`${this.#t}:source:${S(t,r)}`}async get(t){const r=await this.#e.get(this.#n(t));if(r!==null)return x(r)}async set(t,r,i){const n=this.#n(t),f=w(r),c=i.expiresAt?.getTime(),m=c??l,s=this.#e.multi();c===void 0?s.set(n,f):s.set(n,f,{PXAT:c});for(const h of new Set(i.sources)){const u=this.#i(t.namespace,h);s.zRemRangeByScore(u,0,Date.now()),s.zAdd(u,{score:m,value:n})}await s.exec()}async invalidateSource(t,r){const i=this.#i(t,r),n=await this.#e.zRange(i,0,-1);n.length>0&&await this.#e.del(n),await this.#e.del(i)}async close(){this.#r&&await this.#e.close()}}const j=async(e={})=>{const t=b(e.url?{url:e.url}:{});return t.on("error",()=>{}),await t.connect(),new p(t,{...e.keyPrefix?{keyPrefix:e.keyPrefix}:{},ownsClient:!0})};export{p as RedisQueryCache,j as createRedisQueryCache};
@@ -1,2 +1,2 @@
1
- export { assertNoLegacyLogicformFields, normalizeLegacyLogicform, splitLegacySchemas, } from './logicform';
1
+ export { assertNoLegacyLogicformFields, normalizeLegacyLogicform, } from './logicform';
2
2
  export { normalizeSchemas } from '../executor/compatibility';
@@ -1,13 +1,7 @@
1
1
  import type { LogicformType } from '../logicform-types';
2
2
  type SchemaRegistry = Readonly<Record<string, unknown>>;
3
3
  /** Converts a legacy LogicForm tree into the v2 wire shape without mutating input. */
4
- export declare const normalizeLegacyLogicform: (logicform: unknown) => LogicformType;
5
- /**
6
- * Converts the legacy `pred.schema` fan-out into v2 composition. The planner
7
- * intentionally rejects cross-schema PredItems, so this has to happen before
8
- * the v2 normalizer sees the tree.
9
- */
10
- export declare const splitLegacySchemas: (logicform: LogicformType, schemas?: SchemaRegistry) => LogicformType;
4
+ export declare const normalizeLegacyLogicform: (logicform: unknown, schemas?: SchemaRegistry) => LogicformType;
11
5
  /** Rejects legacy wire fields when a caller explicitly declares a v2 LogicForm. */
12
6
  export declare const assertNoLegacyLogicformFields: (logicform: unknown) => void;
13
7
  export {};
@@ -1,4 +1,4 @@
1
- import type { OperatorCteCalculation, OperatorGroupKeyShift } from '../operators/index';
1
+ import type { OperatorComponentCalculation, OperatorGroupKeyShift } from '../operators/index';
2
2
  import type { CoreComputeProvider } from '../physical/index';
3
3
  import type { LogicalPlan } from '../planner/index';
4
4
  import type { CompiledQuery } from './types';
@@ -9,4 +9,19 @@ export interface PreparedCteComponent {
9
9
  readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
10
10
  readonly joinKeys?: readonly string[];
11
11
  }
12
- export declare const compileCteCalculation: (calculation: OperatorCteCalculation, components: readonly PreparedCteComponent[], outputPlan: LogicalPlan, provider: CoreComputeProvider, operators: OperatorRegistry) => CompiledQuery;
12
+ /** A compiled top-level execution unit that can be joined into one SQL query. */
13
+ export interface PreparedCteQuery {
14
+ readonly plan: LogicalPlan;
15
+ readonly compiled: CompiledQuery;
16
+ /** Result projection names exposed by this execution unit (excluding groups). */
17
+ readonly outputs: readonly string[];
18
+ }
19
+ /**
20
+ * Combine independent SQL execution units into one statement.
21
+ *
22
+ * Component operators are compiled independently because their input ranges can
23
+ * differ (for example, current and previous periods). Keeping each unit as a
24
+ * CTE preserves those ranges while allowing the provider to execute one query.
25
+ */
26
+ export declare const compileCteQueries: (units: readonly PreparedCteQuery[], outputPlan: LogicalPlan, provider: CoreComputeProvider, operators?: OperatorRegistry) => CompiledQuery;
27
+ export declare const compileCteCalculation: (calculation: OperatorComponentCalculation, components: readonly PreparedCteComponent[], outputPlan: LogicalPlan, provider: CoreComputeProvider, operators: OperatorRegistry) => CompiledQuery;
@@ -1,4 +1,5 @@
1
1
  export { compilePlan } from './compile-plan';
2
- export { compileCteCalculation } from './compile-cte';
2
+ export { compileCteCalculation, compileCteQueries } from './compile-cte';
3
+ export type { PreparedCteQuery } from './compile-cte';
3
4
  export { shortenSQL } from './shorten-sql';
4
5
  export type { CompiledQuery } from './types';
@@ -2,12 +2,11 @@ import type { OperatorRegistry } from '../operators/index';
2
2
  import type { CoreComputeProvider, DataRow, SqlParameters } from '../physical/index';
3
3
  import type { DatabaseConnection } from '../physical/index';
4
4
  import type { LogicalPlan, QueryLineage } from '../planner/index';
5
- import type { SchemaMappingRegistry } from '../schema-mappings/index';
6
- import type { ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeRegistry } from '../semantic-types/index';
7
- import type { LogicformType } from '../logicform-types';
5
+ import type { SchemaMappingDefinition, SchemaMappingRegistry } from '../schema-mappings/index';
6
+ import type { ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeRegistry, TimeWatermarkPolicy } from '../semantic-types/index';
7
+ import type { LogicformType, PublicLogicformType } from '../logicform-types';
8
8
  import type { QueryCacheExecutionOptions } from '../cache/index';
9
9
  import type { Permissions } from '../permissions/index';
10
- import type { CustomFunctions } from '../custom-functions/index';
11
10
  import type { SemanticDBPlugin } from '../plugins/index';
12
11
  export type ExecuteProgressEvent = {
13
12
  readonly stage: 'started';
@@ -56,7 +55,6 @@ export type ExecuteProgressEvent = {
56
55
  export type ProgressCallback = (event: ExecuteProgressEvent) => void | Promise<void>;
57
56
  interface ExecuteBaseOptions {
58
57
  readonly schemas: Readonly<Record<string, SemanticSchemaDraft>>;
59
- readonly schemaMappings: SchemaMappingRegistry;
60
58
  readonly semanticTypes?: SemanticTypeRegistry;
61
59
  readonly operators?: OperatorRegistry;
62
60
  /** Caller-owned capability plugins appended to the built-in plugin set for this execution. */
@@ -65,22 +63,23 @@ interface ExecuteBaseOptions {
65
63
  readonly locale?: string;
66
64
  /** Table, row, and column permissions for this execution. */
67
65
  readonly permissions?: Permissions;
68
- /** Legacy-compatible dynamically supplied composite metric definitions. */
69
- readonly customFunctions?: CustomFunctions;
70
- /** Third argument passed to mergeComponents/genMergeSQL callbacks. */
71
- readonly customFunctionConfig?: Readonly<Record<string, unknown>>;
72
66
  /** Optional caller-owned cache shared across executions. */
73
67
  readonly cache?: QueryCacheExecutionOptions;
74
68
  readonly onProgress?: ProgressCallback;
75
69
  readonly signal?: AbortSignal;
70
+ /** Default time watermark policy; Schema and Property policies override it. */
71
+ readonly timeWatermark?: TimeWatermarkPolicy;
76
72
  }
77
73
  export interface ExecuteOptions extends ExecuteBaseOptions {
74
+ /** Physical mappings supplied as JSON definitions. */
75
+ readonly schemaMappings: readonly SchemaMappingDefinition[];
78
76
  /** Database connections addressable by SchemaMappingDefinition.connectionId. */
79
77
  readonly connections: readonly DatabaseConnection[];
80
78
  }
81
79
  /** Internal execution seam used by executor tests after a provider has been resolved. */
82
80
  export interface InternalExecuteOptions extends ExecuteBaseOptions {
83
81
  readonly provider: CoreComputeProvider;
82
+ readonly schemaMappings: SchemaMappingRegistry;
84
83
  /** Selected connection for public execution; omitted only by internal provider tests. */
85
84
  readonly connectionId?: string;
86
85
  }
@@ -88,7 +87,7 @@ export interface ExecuteSuccessResult {
88
87
  readonly result: DataRow[];
89
88
  /** Schema describing the computed result rows. */
90
89
  readonly schema: ResolvedSemanticSchema;
91
- readonly normedLogicform: LogicformType;
90
+ readonly normedLogicform: PublicLogicformType;
92
91
  readonly sqls: readonly ExecutedSql[];
93
92
  readonly lineage: QueryLineage;
94
93
  readonly provider: CoreComputeProvider['kind'];
@@ -98,7 +97,7 @@ export interface ExecuteFailureResult {
98
97
  readonly error: string;
99
98
  readonly result: readonly [];
100
99
  readonly schema?: ResolvedSemanticSchema;
101
- readonly normedLogicform: LogicformType;
100
+ readonly normedLogicform: PublicLogicformType;
102
101
  readonly sqls: readonly ExecutedSql[];
103
102
  readonly provider?: CoreComputeProvider['kind'];
104
103
  readonly lineage?: QueryLineage;
@@ -111,7 +110,7 @@ export interface ExecutedSql {
111
110
  /** Human-readable, localized explanation of why this SQL is executed. */
112
111
  readonly explain: string;
113
112
  /** Normalized LogicForm represented by this SQL statement. */
114
- readonly logicform: LogicformType;
113
+ readonly logicform: PublicLogicformType;
115
114
  /** Parameterized SQL used for provider execution and cache identity. */
116
115
  readonly sql: string;
117
116
  readonly parameters: SqlParameters;
package/dist/index.d.ts CHANGED
@@ -1,26 +1,24 @@
1
1
  export declare const Logicform: Readonly<{
2
2
  execute: (inputLogicform: import("./logicform-types").LogicformType, inputOptions: import(".").ExecuteOptions) => Promise<import(".").ExecuteResult>;
3
3
  close: () => Promise<void>;
4
- genComponents: (pred: import("./logicform-types").PredItemType, options: import(".").GenMetricComponentsOptions) => import(".").MetricComponentNode;
5
4
  }>;
6
5
  export { SemanticDBError } from './errors';
7
6
  export { builtinSemanticTypes, createSemanticTypeRegistry, resolveSchema, SemanticTypeRegistry, validateResolvedSchema, } from './semantic-types/index';
8
7
  export { builtinOperators, createOperatorRegistry, OperatorRegistry, } from './operators/index';
9
8
  export type { LegacySchemaPluginContext, SchemaMetadataPlugin, SemanticDBPlugin, } from './plugins/index';
10
- export { SchemaMappingRegistry, } from './schema-mappings/index';
11
- export type { AbsoluteDateValue, CompareOperator, CalendarDateValue, DateTimeValue, DateValue, ExpressionItemType, LogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, RecursiveQueryType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
9
+ export { SchemaMappingRegistry, fromYiAskSchemaMapping, } from './schema-mappings/index';
10
+ export type { AbsoluteDateValue, CompareOperator, CalendarDateValue, DateTimeValue, DateValue, EntityIdType, ExpressionItemType, LogicformType, PublicLogicformType, PeriodShiftTime, PredItemType, QueryLogicalOperand, RecursiveQueryType, RelationQueryType, QueryType, QueryValueType, QueryValueTypeWithCompareOperator, RelativeDateValue, RepresentationType, } from './logicform-types';
12
11
  export { CALENDAR_DATES_TABLE, CALENDAR_RELATIONS_TABLE, CALENDAR_SYSTEM_SCHEMA_IDS, calendarSystemSchemas, ProviderCalendarRelationStore, resolveCalendarPeriod, resolveCalendarPeriodFromStore, selectCalendarDates, } from './calendar/index';
13
12
  export type { CalendarAlignment, CalendarComparison, CalendarDateRow, CalendarRelation, CalendarRelationRow, ResolvedCalendarPeriod, } from './calendar/index';
14
13
  export type { CalendarRelationStore } from './calendar/index';
15
- export type { PrimalType, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TemporalSemantics, TimeGranularity, } from './semantic-types/index';
14
+ export type { PrimalType, PropertySqlDefinition, ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeNormalizeContext, SemanticPropertyDraft, SemanticSchemaDraft, SemanticTypeDefinition, SemanticTypeResultContext, SemanticTypeResultProperty, TemporalSemantics, TimeGranularity, TimeWatermarkPolicy, } from './semantic-types/index';
16
15
  export type { HierarchyDefinition, HierarchyLevelDefinition, ResolvedHierarchyDefinition, } from './plugins/hierarchy/index';
17
16
  export type { DataRow, SqlParameters, DatabaseConnection, } from './physical/index';
18
- export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorCteCalculation, OperatorCteComponent, OperatorCteSqlContext, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './operators/index';
19
- export type { SchemaMappingDefinition, SchemaMappingPredDefinition, SchemaMappingPredMatch, SourceFreshnessPolicy, } from './schema-mappings/index';
17
+ export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorPlanInputContext, OperatorPlannedInput, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './operators/index';
18
+ export type { SchemaMappingDefinition, SchemaMappingItem, SchemaMappingPredDefinition, SchemaMappingPredMatch, SourceFreshnessPolicy, YiAskSchemaMappingItem, YiAskSchemaMappingRecord, } from './schema-mappings/index';
20
19
  export type { QueryCache, QueryCacheExecutionOptions, QueryCacheIdentity, QueryCacheWriteOptions, } from './cache/index';
21
20
  export type { ExecuteOptions, ExecuteFailureResult, ExecuteProgressEvent, ExecuteResult, ExecuteSuccessResult, ExecutedSql, ExecutedSqlType, PartialExecuteResult, ProgressCallback, } from './executor/index';
22
21
  export type { ColumnPermissions, Permissions, SchemaPermissions, } from './permissions/index';
23
- export type { CustomFunctionColumnProperty, CustomFunctionDefinition, CustomFunctionHelpers, CustomFunctionSqlContext, CustomFunctions, GenComponents, GenComponentsContext, GenMergeSQL, GenMetricComponentsOptions, MergeComponents, MetricComponentNode, } from './custom-functions/index';
24
22
  export type { CreateLogicalPlanOptions, LogicalPlan, QueryLineage, } from './planner/index';
25
23
  export { PlannerSemanticRegistry, createPlannerSemanticRegistry, } from './planner/index';
26
24
  export type { PlannerSemanticResolution, PlannerSemanticQueryContext, PlannerSemanticRule, PlannerSemanticRuleContext, } from './planner/index';
@@ -34,6 +34,8 @@ export interface CalendarDateValue {
34
34
  export type PeriodShiftTime = RelativeDateValue | AbsoluteDateValue;
35
35
  /** A date value before semantic-type normalization. */
36
36
  export type DateValue = string | RelativeDateValue | AbsoluteDateValue | CalendarDateValue;
37
+ /** Stable entity identity. Numeric IDs must be safe integers. */
38
+ export type EntityIdType = string | number;
37
39
  export type CompareOperator = '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$in' | '$nin' | '$exists' | '$regex' | '$contains' | '$recursive' | '$and' | '$or';
38
40
  export interface RecursiveQueryType {
39
41
  readonly schema?: string;
@@ -50,7 +52,7 @@ export interface RelationQueryType {
50
52
  readonly schema: string;
51
53
  readonly query: QueryType;
52
54
  /** Stable entity identity. `placeholder` preserves context without adding an ID filter. */
53
- readonly entity_id?: string;
55
+ readonly entity_id?: EntityIdType;
54
56
  }
55
57
  export type QueryLogicalOperand = QueryValueType | QueryValueTypeWithCompareOperator;
56
58
  export type QueryValueTypeWithCompareOperator = Partial<{
@@ -80,16 +82,14 @@ export type QueryType = Record<string, QueryValueType | QueryValueTypeWithCompar
80
82
  };
81
83
  export interface ExpressionItemType {
82
84
  operator?: string;
83
- pred?: string | ExpressionItemType;
84
- /** Structural operands for multi-input operators. Operator options remain in `args`. */
85
- components?: ExpressionItemType[];
85
+ /** Operator input. Arrays represent ordered multi-input predicates. */
86
+ pred?: string | ExpressionItemType | (string | ExpressionItemType)[];
86
87
  name?: string;
87
88
  schema?: string;
88
89
  args?: Record<string, unknown>;
89
90
  }
90
91
  export interface PredItemType extends ExpressionItemType {
91
- pred?: string | PredItemType;
92
- components?: PredItemType[];
92
+ pred?: string | PredItemType | (string | PredItemType)[];
93
93
  query?: QueryType;
94
94
  }
95
95
  export type LogicformOutputTypeValue = 'url' | 'data' | 'export' | 'sql' | 'sqlComponents';
@@ -102,10 +102,10 @@ export interface LogicformType {
102
102
  version: string;
103
103
  /** Required for a physical leaf. Derived and composed nodes inherit their field space. */
104
104
  schema?: string;
105
- /** Complete child LogicForms whose result columns are combined by their shared row identity. */
106
- logicforms?: LogicformType[];
107
105
  query?: QueryType;
108
106
  preds?: PredItemType[];
107
+ /** Output/reference aliases for properties contributed by another Schema. */
108
+ propertyResolve?: Readonly<Record<string, Readonly<Record<string, string>>>>;
109
109
  groupby?: PredItemType[];
110
110
  sort?: Record<string, 1 | -1>;
111
111
  having?: QueryType;
@@ -115,11 +115,10 @@ export interface LogicformType {
115
115
  page?: number;
116
116
  representation?: RepresentationType;
117
117
  /** Stable entity identity. `placeholder` preserves context without adding an ID filter. */
118
- entity_id?: string;
118
+ entity_id?: EntityIdType;
119
119
  from?: LogicformType;
120
120
  currency?: string;
121
121
  }
122
+ /** Public normalized shape; composition is represented by Planner subplans. */
123
+ export type PublicLogicformType = LogicformType;
122
124
  export declare const isLogicform: (value: unknown) => value is LogicformType;
123
- export declare const isComposedLogicform: (value: LogicformType) => value is LogicformType & {
124
- readonly logicforms: LogicformType[];
125
- };
@@ -10,10 +10,10 @@ export interface NormalizeLogicformOptions {
10
10
  readonly locale?: string;
11
11
  readonly now?: Date;
12
12
  readonly resolveSchema?: (schemaId: string) => ResolvedSemanticSchema;
13
- readonly requestLatestDataDate?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty) => Promise<Date | undefined>;
13
+ readonly requestTimeWatermark?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty, requestedUpperBound: Date) => Promise<Date | undefined>;
14
14
  readonly resolveFromSchema?: (normalizedFrom: LogicformType, outerSchema: ResolvedSemanticSchema) => ResolvedSemanticSchema;
15
15
  readonly canProjectProperty?: (schema: ResolvedSemanticSchema, property: ResolvedSemanticProperty) => boolean;
16
16
  /** Internal recursion hook installed by normalizeLogicform. */
17
17
  readonly normalizeNestedLogicform?: (logicform: LogicformType) => Promise<LogicformType>;
18
18
  }
19
- export declare const resolveLogicformSchema: (logicform: LogicformType, currentSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => ResolvedSemanticSchema;
19
+ export declare const resolveFormSchema: (logicform: LogicformType, currentSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => ResolvedSemanticSchema;
@@ -0,0 +1,5 @@
1
+ import type { LogicformType } from '../logicform-types';
2
+ import type { ResolvedSemanticSchema } from '../semantic-types/index';
3
+ import type { NormalizeLogicformOptions } from './core';
4
+ /** Adds cross-Schema aliases after both legacy and v2 forms share normalization. */
5
+ export declare const normalizePropertyResolve: (logicform: LogicformType, rootSchema: ResolvedSemanticSchema, options: NormalizeLogicformOptions) => LogicformType;
@@ -0,0 +1,2 @@
1
+ import type { OperatorDefinition } from '../types';
2
+ export declare const constantOperator: OperatorDefinition;
@@ -0,0 +1,2 @@
1
+ import type { OperatorDefinition } from '../types';
2
+ export declare const periodValueOperator: OperatorDefinition;
@@ -0,0 +1,3 @@
1
+ import type { OperatorDefinition } from '../types';
2
+ export declare const leastOperator: OperatorDefinition;
3
+ export declare const greatestOperator: OperatorDefinition;
@@ -2,6 +2,6 @@ import type { SemanticDBPlugin } from '../plugins/index';
2
2
  import { OperatorRegistry } from './registry';
3
3
  export { OperatorRegistry } from './registry';
4
4
  export { bindTrustedSqlExpression } from './sql-expression';
5
- export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorCteCalculation, OperatorCteComponent, OperatorCteSqlContext, OperatorExecutionComponent, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorObservationPolicy, OperatorObservationPolicyContext, OperatorNormalizePredContext, OperatorPlanExpressionContext, OperatorPeriodEvaluationContext, OperatorPlanInputContext, OperatorPlannedInput, OperatorRewriteLogicformContext, OperatorValidatePlanContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './types';
5
+ export type { OperatorDefinition, OperatorDefaultNameContext, OperatorComponentContext, OperatorComponentCalculation, OperatorComponentQuery, OperatorExecutionComponent, OperatorGroupKeyShift, OperatorJavaScriptCalculation, OperatorQueryComponent, OperatorEvaluateContext, OperatorOutputPropertyContext, OperatorObservationPolicy, OperatorObservationPolicyContext, OperatorNormalizePredContext, OperatorPlanExpressionContext, OperatorPeriodEvaluationContext, OperatorPlanInputContext, OperatorPlannedInput, OperatorRewriteLogicformContext, OperatorValidatePlanContext, OperatorSqlCapabilities, OperatorSqlContext, ResultProperty, ResultPropertyTemporalMetadata, } from './types';
6
6
  export declare const builtinOperators: readonly import("./types").OperatorDefinition[];
7
7
  export declare const createOperatorRegistry: (plugins?: readonly SemanticDBPlugin[]) => OperatorRegistry;
@@ -10,6 +10,9 @@ export interface OperatorSqlCapabilities {
10
10
  concat(expressions: readonly string[]): string;
11
11
  substring(expression: string, start: number, length: number): string;
12
12
  dateBucket(expression: string, granularity: TimeGranularity): string;
13
+ dateShift(expression: string, granularity: TimeGranularity, offset: number): string;
14
+ /** Render a period boundary directly when the dialect has a concise native form. */
15
+ datePeriodBoundary?(expression: string, granularity: TimeGranularity, boundary: 'start' | 'end'): string;
13
16
  /** Bind a literal as a SQL parameter. */
14
17
  value(value: unknown): string;
15
18
  /** Compile a field-local LogicForm condition against an expression. */
@@ -20,7 +23,7 @@ export interface OperatorSqlContext {
20
23
  readonly sql: OperatorSqlCapabilities;
21
24
  /** SQL for the nested input expression, when this operator has one. */
22
25
  readonly expression?: string;
23
- /** SQL expressions produced by a multi-input operator's structural components. */
26
+ /** SQL expressions produced by a multi-input pred. */
24
27
  readonly expressions?: readonly string[];
25
28
  /** Quoted physical column for a leaf-property operator. */
26
29
  readonly column?: string;
@@ -76,8 +79,8 @@ export interface OperatorOutputPropertyContext {
76
79
  readonly property?: ResolvedSemanticProperty;
77
80
  /** Semantic metadata produced by a nested expression. */
78
81
  readonly inputProperty?: ResultProperty;
79
- /** Semantic metadata produced by structural components. */
80
- readonly componentProperties?: readonly ResultProperty[];
82
+ /** Semantic metadata produced by a multi-input pred. */
83
+ readonly inputProperties?: readonly ResultProperty[];
81
84
  /** Operator-specific LogicForm arguments. */
82
85
  readonly args: Readonly<Record<string, unknown>>;
83
86
  }
@@ -89,12 +92,12 @@ export interface OperatorPeriodEvaluationContext {
89
92
  readonly inputProperty?: ResolvedSemanticProperty;
90
93
  }
91
94
  export interface OperatorDefaultNameContext {
92
- /** Name produced by the direct pred, structural components, or localized row label. */
95
+ /** Name produced by the direct pred inputs or localized row label. */
93
96
  readonly operandName: string;
94
97
  /** Name of a direct or nested pred input. */
95
98
  readonly inputName?: string;
96
- /** Names of structural component inputs. */
97
- readonly componentNames: readonly string[];
99
+ /** Names of multi-input pred values. */
100
+ readonly inputNames: readonly string[];
98
101
  /** Operator-specific LogicForm arguments. */
99
102
  readonly args: Readonly<Record<string, unknown>>;
100
103
  /** Requested locale. Each operator owns its own localized default names. */
@@ -121,7 +124,7 @@ export interface OperatorPlanExpressionContext {
121
124
  readonly pred: PredItemType;
122
125
  readonly input?: Expression;
123
126
  readonly inputProperty?: ResultProperty;
124
- readonly components: readonly Expression[];
127
+ readonly inputs: readonly Expression[];
125
128
  readonly args: Readonly<Record<string, unknown>>;
126
129
  readonly resolveKey: (reference: string) => Expression;
127
130
  readonly getOperator: (name: string) => OperatorDefinition;
@@ -143,6 +146,8 @@ export interface OperatorValidatePlanContext {
143
146
  export interface OperatorRewriteLogicformContext {
144
147
  readonly logicform: LogicformType;
145
148
  readonly schema: ResolvedSemanticSchema;
149
+ /** Resolve operator metadata while rewriting nested expressions. */
150
+ readonly getOperator?: (name: string) => OperatorDefinition;
146
151
  }
147
152
  export interface OperatorComponentContext {
148
153
  /** Fully normalized LogicForm containing this top-level operator projection. */
@@ -173,31 +178,30 @@ export interface OperatorQueryComponent {
173
178
  /** SQL-side transformations that align this component's group keys with the base component. */
174
179
  readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
175
180
  }
176
- export interface OperatorCteSqlContext {
177
- readonly values: Readonly<Record<string, string>>;
178
- readonly quoteIdentifier: (identifier: string) => string;
179
- }
180
- export interface OperatorCteComponent {
181
+ export interface OperatorComponentQuery {
181
182
  readonly name: string;
182
- readonly component: OperatorQueryComponent;
183
+ readonly logicform: LogicformType;
184
+ readonly prepare?: boolean;
185
+ readonly mapResult?: (rows: readonly DataRow[]) => DataRow[];
186
+ readonly groupKeyShifts?: readonly OperatorGroupKeyShift[];
183
187
  /** Group output names used to join this component back to the first component. */
184
188
  readonly joinKeys?: readonly string[];
185
189
  }
186
- export interface OperatorCteCalculation {
187
- readonly kind: 'cte';
188
- readonly components: readonly OperatorCteComponent[];
190
+ export interface OperatorComponentCalculation {
191
+ readonly components: readonly OperatorComponentQuery[];
192
+ /** Provider-independent formula referring to component names. */
193
+ readonly expression: string;
189
194
  readonly outputName?: string;
190
- readonly toSQL: (context: OperatorCteSqlContext) => string;
191
195
  readonly exposeComponents?: boolean;
192
196
  }
193
197
  export interface OperatorJavaScriptCalculation {
194
198
  readonly kind: 'js';
195
- readonly components: readonly OperatorCteComponent[];
199
+ readonly components: readonly OperatorComponentQuery[];
196
200
  readonly outputName: string;
197
201
  readonly mergeRow: (values: DataRow) => unknown;
198
202
  readonly exposeComponents?: boolean;
199
203
  }
200
- export type OperatorExecutionComponent = OperatorQueryComponent | OperatorCteCalculation | OperatorJavaScriptCalculation;
204
+ export type OperatorExecutionComponent = OperatorQueryComponent | OperatorComponentCalculation | OperatorJavaScriptCalculation;
201
205
  /**
202
206
  * Extension contract for one LogicForm operator.
203
207
  *
@@ -207,7 +211,7 @@ export type OperatorExecutionComponent = OperatorQueryComponent | OperatorCteCal
207
211
  * `getOutputProperty` to describe the resulting one-column logical schema.
208
212
  */
209
213
  interface OperatorDefinitionBase {
210
- /** Public registry key, normally using the `$name` convention. */
214
+ /** Public registry key. Built-in operators commonly use a `$` prefix, but it is not required. */
211
215
  readonly name: string;
212
216
  /** Produce the normalized output name when the PredItem does not declare one. */
213
217
  readonly defaultName: (context: OperatorDefaultNameContext) => string;
@@ -227,7 +231,7 @@ interface OperatorDefinitionBase {
227
231
  readonly observationPolicy?: (context: OperatorObservationPolicyContext) => OperatorObservationPolicy | undefined;
228
232
  /** Validate this operator against the completed group key set. */
229
233
  readonly validatePlan?: (context: OperatorValidatePlanContext) => void;
230
- /** Expand high-level operator semantics into ordinary nested LogicForms before planning. */
234
+ /** Expand high-level operator semantics into ordinary nested LogicForm objects before planning. */
231
235
  readonly rewriteLogicform?: (context: OperatorRewriteLogicformContext) => LogicformType | undefined;
232
236
  /** Whether this operator requires one evaluation per time bucket. */
233
237
  readonly requiresPerPeriodEvaluation?: (context: OperatorPeriodEvaluationContext) => boolean;
@@ -20,6 +20,7 @@ export declare abstract class MySQLProtocolProvider implements CoreComputeProvid
20
20
  displayQuery(sql: string, parameters: SqlParameters): string;
21
21
  dateBucket(expression: string, level: string): string;
22
22
  dateShift(expression: string, granularity: string, offset: number): string;
23
+ datePeriodBoundary(expression: string, granularity: string, boundary: 'start' | 'end'): string;
23
24
  aggregateFunction(name: string, expression?: string): string;
24
25
  stringify(expression: string): string;
25
26
  concat(expressions: readonly string[]): string;
@@ -13,6 +13,7 @@ export interface SqlRenderCapabilities {
13
13
  paginate(sql: string, pageSize: number, offset: number): string;
14
14
  dateBucket(expression: string, level: string): string;
15
15
  dateShift(expression: string, granularity: string, offset: number): string;
16
+ datePeriodBoundary?(expression: string, granularity: string, boundary: 'start' | 'end'): string;
16
17
  aggregateFunction(name: string, expression?: string): string;
17
18
  stringify(expression: string): string;
18
19
  concat(expressions: readonly string[]): string;
@@ -1,6 +1,6 @@
1
1
  import type { PredItemType } from '../../../logicform-types';
2
2
  import type { OperatorDefinition } from '../../../operators/index';
3
- declare const periodBoundaryOperator = "$periodBoundary";
3
+ declare const periodBoundaryOperator = "$periodValue";
4
4
  export interface ObservationOperatorPolicy {
5
5
  readonly operator: typeof periodBoundaryOperator;
6
6
  readonly boundary: 'start' | 'end';
@@ -1,3 +1,3 @@
1
1
  import type { ResultPropertyTemporalMetadata } from '../../../operators/index';
2
2
  export type ObservationTemporalMetadata = ResultPropertyTemporalMetadata;
3
- export type ObservationOperator = '$periodBoundary';
3
+ export type ObservationOperator = '$periodValue';
@@ -1,4 +1,5 @@
1
1
  import type { CoreComputeProvider } from '../physical/index';
2
+ import type { LogicformType } from '../logicform-types';
2
3
  import type { ResultProperty } from '../operators/index';
3
4
  import type { ComparableCategoryDefinition, TimeGranularity } from '../semantic-types/index';
4
5
  export interface FieldReferencePlan {
@@ -66,7 +67,7 @@ export type Expression = {
66
67
  readonly qualifier?: string;
67
68
  readonly schemaId?: string;
68
69
  readonly input?: Expression;
69
- readonly components?: readonly Expression[];
70
+ readonly inputs?: readonly Expression[];
70
71
  readonly args: Readonly<Record<string, unknown>>;
71
72
  readonly query?: Readonly<Record<string, unknown>>;
72
73
  } | {
@@ -165,9 +166,11 @@ export interface LogicalPlan {
165
166
  /** Physical mapping selected by the Planner for this logical Schema. */
166
167
  readonly mappingId?: string;
167
168
  /** Child relations combined by their compatible group identity. */
168
- readonly composition?: readonly LogicalPlan[];
169
+ readonly subplans?: readonly LogicalPlan[];
169
170
  /** Optional query plan compiled as the derived-table source of this plan. */
170
171
  readonly sourcePlan?: LogicalPlan;
172
+ /** Normalized LogicForm corresponding to sourcePlan when generated rewrites need execution. */
173
+ readonly sourceLogicform?: LogicformType;
171
174
  readonly sourceAlias?: string;
172
175
  readonly fields: Readonly<Record<string, string>>;
173
176
  readonly fieldReferences?: Readonly<Record<string, FieldReferencePlan>>;
@@ -1,11 +1,12 @@
1
1
  export interface HierarchyLevelDefinition {
2
2
  readonly name: string;
3
- readonly synonyms?: readonly string[];
3
+ readonly syno?: readonly string[];
4
4
  readonly codeLength: number;
5
5
  }
6
6
  export interface HierarchyDefinition {
7
7
  /** Property that physically stores the complete hierarchy code. */
8
- readonly property: string;
8
+ /** Property storing the complete hierarchy code. Defaults to the Schema's only ID Property. */
9
+ readonly property?: string;
9
10
  /** Compact codes stop at their level; zero-padded codes fill remaining segments with zeroes. */
10
11
  readonly storage?: 'compact' | 'zero-padded';
11
12
  readonly levels: readonly HierarchyLevelDefinition[];