semanticdb-v2 2.0.0-alpha.5 → 2.0.0-alpha.7

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 (94) hide show
  1. package/README.md +272 -7
  2. package/dist/cache/redis-query-cache.esm.js +1 -1
  3. package/dist/cache/redis-query-cache.js +1 -1
  4. package/dist/cache/types.d.ts +2 -0
  5. package/dist/executor/connection-registry.d.ts +1 -12
  6. package/dist/executor/execute-query.d.ts +6 -1
  7. package/dist/executor/federated-execution.d.ts +37 -0
  8. package/dist/executor/fetch-entities.d.ts +3 -1
  9. package/dist/executor/result-hydrator/types.d.ts +2 -0
  10. package/dist/executor/total.d.ts +11 -0
  11. package/dist/executor/types.d.ts +33 -4
  12. package/dist/index.d.ts +9 -7
  13. package/dist/logicform-types.d.ts +44 -12
  14. package/dist/normalizer/core.d.ts +9 -0
  15. package/dist/normalizer/pred-expression.d.ts +6 -0
  16. package/dist/operators/builtins/query-expression.d.ts +3 -0
  17. package/dist/operators/index.d.ts +1 -1
  18. package/dist/operators/types.d.ts +39 -8
  19. package/dist/physical/clickhouse-provider.d.ts +20 -2
  20. package/dist/physical/connection-registry.d.ts +13 -0
  21. package/dist/physical/connection.d.ts +57 -15
  22. package/dist/physical/dameng-provider.d.ts +66 -0
  23. package/dist/physical/databricks-provider.d.ts +88 -0
  24. package/dist/physical/db-connector.d.ts +23 -0
  25. package/dist/physical/display-query.d.ts +3 -0
  26. package/dist/physical/doris-provider.d.ts +2 -1
  27. package/dist/physical/duckdb-coordinator-provider.d.ts +37 -0
  28. package/dist/physical/gbase-provider.d.ts +11 -0
  29. package/dist/physical/index.d.ts +24 -9
  30. package/dist/physical/load-driver.d.ts +1 -0
  31. package/dist/physical/maxcompute-provider.d.ts +44 -0
  32. package/dist/physical/mysql-protocol-provider.d.ts +24 -6
  33. package/dist/physical/mysql-provider.d.ts +2 -1
  34. package/dist/physical/oracle-provider.d.ts +20 -4
  35. package/dist/physical/postgresql-provider.d.ts +23 -4
  36. package/dist/physical/provider.d.ts +57 -1
  37. package/dist/physical/snowflake-provider.d.ts +19 -3
  38. package/dist/physical/sqlserver-provider.d.ts +69 -0
  39. package/dist/physical/starrocks-provider.d.ts +2 -1
  40. package/dist/physical/table-description.d.ts +5 -0
  41. package/dist/physical/table-discovery.d.ts +10 -0
  42. package/dist/planner/build-lineage.d.ts +1 -1
  43. package/dist/planner/create-logical-plan.d.ts +7 -0
  44. package/dist/planner/index.d.ts +4 -2
  45. package/dist/planner/mapping-granularity.d.ts +7 -0
  46. package/dist/planner/rewrite-nested-components.d.ts +8 -0
  47. package/dist/planner/select-schema-mapping.d.ts +16 -2
  48. package/dist/planner/semantics/index.d.ts +0 -4
  49. package/dist/planner/semantics/periods.d.ts +13 -0
  50. package/dist/planner/semantics/registry-defaults.d.ts +2 -1
  51. package/dist/planner/types.d.ts +71 -34
  52. package/dist/plugins/hierarchy/index.d.ts +1 -1
  53. package/dist/plugins/hierarchy/mapping-granularity.d.ts +4 -0
  54. package/dist/plugins/hierarchy/types.d.ts +17 -0
  55. package/dist/plugins/index.d.ts +10 -1
  56. package/dist/{planner/semantics → plugins}/observation/classification.d.ts +1 -1
  57. package/dist/plugins/observation/index.d.ts +17 -0
  58. package/dist/{planner/semantics → plugins}/observation/operator-policy.d.ts +2 -3
  59. package/dist/{planner/semantics → plugins}/observation/periods.d.ts +2 -3
  60. package/dist/{planner/semantics → plugins}/observation/rule.d.ts +1 -1
  61. package/dist/{planner/semantics → plugins}/observation/types.d.ts +1 -1
  62. package/dist/plugins/property-hierarchy/index.d.ts +11 -0
  63. package/dist/plugins/recursive/index.d.ts +26 -0
  64. package/dist/plugins/temporal/index.d.ts +13 -0
  65. package/dist/plugins/types.d.ts +165 -1
  66. package/dist/plugins/validity/classification.d.ts +5 -0
  67. package/dist/{planner/semantics → plugins}/validity/index.d.ts +9 -0
  68. package/dist/{planner/semantics → plugins}/validity/periods.d.ts +2 -3
  69. package/dist/{planner/semantics → plugins}/validity/query-policy.d.ts +1 -2
  70. package/dist/{planner/semantics → plugins}/validity/rule.d.ts +1 -1
  71. package/dist/plugins/validity/semantic-types.d.ts +3 -0
  72. package/dist/schema-mappings/freshness.d.ts +1 -1
  73. package/dist/schema-mappings/granularity.d.ts +5 -0
  74. package/dist/schema-mappings/index.d.ts +2 -1
  75. package/dist/schema-mappings/registry.d.ts +5 -3
  76. package/dist/schema-mappings/types.d.ts +43 -0
  77. package/dist/schema-mappings/yiask.d.ts +6 -2
  78. package/dist/semantic-types/index.d.ts +5 -3
  79. package/dist/semantic-types/registry.d.ts +2 -0
  80. package/dist/semantic-types/resolve-schema.d.ts +1 -1
  81. package/dist/semantic-types/types.d.ts +0 -14
  82. package/dist/semantic-types/validate-resolved-schema.d.ts +2 -5
  83. package/dist/semanticdb.esm.js +5 -3
  84. package/dist/semanticdb.js +5 -3
  85. package/package.json +46 -5
  86. package/dist/planner/semantics/annual-periods.d.ts +0 -11
  87. package/dist/planner/semantics/lifecycle/classification.d.ts +0 -5
  88. package/dist/planner/semantics/lifecycle/index.d.ts +0 -3
  89. package/dist/planner/semantics/lifecycle/query-policy.d.ts +0 -2
  90. package/dist/planner/semantics/lifecycle/rule.d.ts +0 -2
  91. package/dist/planner/semantics/observation/index.d.ts +0 -6
  92. package/dist/planner/semantics/validity/classification.d.ts +0 -14
  93. package/dist/semantic-types/builtins/end-date.d.ts +0 -2
  94. package/dist/semantic-types/builtins/start-date.d.ts +0 -2
package/README.md CHANGED
@@ -1,9 +1,23 @@
1
1
  # SemanticDB
2
2
 
3
- SemanticDB translates its own LogicForm into SQL and executes it on a single core compute layer.
3
+ SemanticDB translates its own LogicForm into SQL and executes it on one or more core compute layers.
4
4
  Callers provide schemas, schema mappings, operators, and database connection information.
5
5
  SemanticDB creates the matching provider and owns its connection lifecycle.
6
6
 
7
+ Install SemanticDB together with only the database driver used by the application. Database
8
+ drivers are optional peer dependencies and are loaded on the first execution for that connection;
9
+ Redis cache support is included by the main package.
10
+
11
+ ```bash
12
+ npm install semanticdb-v2 mysql2
13
+ ```
14
+
15
+ Use `@clickhouse/client`, `@databricks/sql`, `dmdb`, `mysql2` (MySQL, Doris, StarRocks, and GBase),
16
+ `mssql`, `pg`, `snowflake-sdk`, or `oracledb` for the corresponding connection kind. MaxCompute
17
+ uses a caller-supplied parameterized execution client. If a configured driver is missing, execution
18
+ fails with an installation command for that driver. SemanticDB caches its internally created
19
+ providers across executions; call `await Logicform.close()` during application shutdown.
20
+
7
21
  ## Public API
8
22
 
9
23
  ```ts
@@ -50,6 +64,11 @@ const response = await Logicform.execute(
50
64
  );
51
65
  ```
52
66
 
67
+ A successful response always includes `total`, the number of result rows before global
68
+ `limit`/`page` pagination. For grouped LogicForms this is the number of groups after `having` and
69
+ `limitBy`. Paginated physical queries include a separate `sqls` entry with `type: 'total'` for the
70
+ count query; unpaginated and executor-merged results derive the value without another SQL query.
71
+
53
72
  Every executable LogicForm, including LogicForm objects used as subqueries, must declare `version`. This
54
73
  SDK accepts semantic versions greater than or equal to `2.0`; missing, malformed, or older versions
55
74
  fail with `UNSUPPORTED_LOGICFORM_VERSION` before Schema resolution or database access. A relation
@@ -100,12 +119,18 @@ Plugins may own Schema metadata, legacy conversion, `entity_id` selection, and O
100
119
  remaining scoped to one execution. See [Register an external plugin](docs/register-plugin.md).
101
120
 
102
121
  Parent-child Schemas may declare `parentProperty`. `$recursive` filters a property to a root node and
103
- all descendants; object properties infer the tree Schema from `ref`. MySQL, Doris, StarRocks, and
104
- PostgreSQL compile this as a parameterized recursive CTE.
122
+ all descendants; object properties infer the tree Schema from `ref`. MySQL, Doris, StarRocks,
123
+ PostgreSQL, ClickHouse 24.4+, and Databricks compile this as a parameterized recursive CTE.
105
124
 
106
125
  Top-level projections may set `schema` to read metrics from another registered Schema. SemanticDB
107
126
  splits those projections into independent provider queries, aligns shared query/groupby dimensions,
108
127
  and merges rows by the group keys before applying `having`, `sort`, `limitBy`, and pagination.
128
+ When the selected Schema mappings use separate physical connections, SemanticDB executes every
129
+ single-connection fragment with its native provider and registers the aggregated fragment results
130
+ in an in-process DuckDB coordinator. DuckDB applies the final full-outer group merge, cross-fragment
131
+ conditions, ordering, totals, and pagination. It is embedded in the Node.js process and does not
132
+ require a service or listening port. `federation.maxMaterializedRows` limits the total number of
133
+ fragment rows admitted to the coordinator and defaults to 100,000.
109
134
 
110
135
  The progress stream emits `started`, `validated`, `normalized`, `planned`, `lineage`,
111
136
  `compiled`, `executing`, `hydrating`, `result`, and `completed`. Every event includes a cumulative
@@ -118,7 +143,9 @@ SQL string for diagnostics:
118
143
 
119
144
  ```ts
120
145
  interface ExecutedSql {
121
- type: 'semantic-resolution' | 'computation';
146
+ type: 'semantic-resolution' | 'computation' | 'total';
147
+ connectionId?: string;
148
+ provider?: CoreComputeProvider['kind'];
122
149
  explain: string;
123
150
  logicform: LogicformType;
124
151
  sql: string;
@@ -131,11 +158,123 @@ interface ExecutedSql {
131
158
  time-watermark resolution and object entity population. `computation` identifies SQL that calculates
132
159
  the requested LogicForm result. `sqls` includes every physical SQL involved in the execution; an
133
160
  entry remains visible when its result is served by the query cache.
161
+ Coordinator SQL uses the reserved connection id `__semanticdb_coordinator__` and provider
162
+ `duckdb`; other entries identify the physical connection that executed them. Successful results
163
+ also expose `providers`, the physical connection/provider pairs that contributed rows. The legacy
164
+ singular `provider` field is `duckdb` for a federated result.
134
165
 
135
166
  Providers execute only parameterized `sql + parameters`; SemanticDB never executes `displaySql`.
136
167
  Because `displaySql` contains literal values and may expose sensitive data, use it only in trusted
137
168
  debugging and observability channels.
138
169
 
170
+ ### Native SQL and table discovery
171
+
172
+ `DBConnector` provides trusted physical database operations independently of LogicForm execution:
173
+
174
+ ```ts
175
+ import { DBConnector, Logicform } from 'semanticdb-v2';
176
+ import type { DatabaseConnection } from 'semanticdb-v2';
177
+
178
+ const connection = {
179
+ id: 'analytics',
180
+ kind: 'mysql',
181
+ host: 'localhost',
182
+ user: 'analytics',
183
+ password: process.env.MYSQL_PASSWORD ?? '',
184
+ database: 'analytics',
185
+ } satisfies DatabaseConnection;
186
+
187
+ const tables = await DBConnector.getTableList({ connection });
188
+ // [{ name: 'orders', database: 'analytics', type: 'table' }, ...]
189
+
190
+ const description = await DBConnector.describeTable({ connection, table: 'orders' });
191
+ // {
192
+ // columns: [{ name: 'id', type: 'int', comment: 'Order ID', primaryKey: true, exampleValue: 42 }, ...],
193
+ // tableInfo: { name: 'orders', database: 'analytics', type: 'table', comment: 'Orders' },
194
+ // }
195
+
196
+ const { rows } = await DBConnector.runSQL({
197
+ connection,
198
+ sql: 'SELECT * FROM orders WHERE status = ?',
199
+ parameters: ['paid'],
200
+ });
201
+
202
+ const updated = await DBConnector.runSQL({
203
+ connection,
204
+ sql: 'UPDATE orders SET status = ? WHERE id = ?',
205
+ parameters: ['shipped', 42],
206
+ });
207
+ // { rows: [], affectedRows: 1 }
208
+
209
+ // The exact same object belongs in Logicform.execute's connections array:
210
+ // await Logicform.execute(logicform, { connections: [connection], schemas, schemaMappings });
211
+
212
+ await Logicform.close(); // DBConnector.close() is the same shutdown operation.
213
+ ```
214
+
215
+ Both APIs share providers and connection pools by connection ID and `providerRegistry`. An ID must
216
+ retain the same configuration until shutdown. Providers and pools are initialized lazily. Either
217
+ `close()` releases **all** SDK-managed connections, including those used by the other API; it does
218
+ not close just the last connector connection.
219
+
220
+ `runSQL` returns `{ rows: DataRow[], affectedRows?: number }`. Commands without a result set return
221
+ an empty array; affected-row counts are included only when the driver reports them. SQL is passed
222
+ through without automatic LIMIT, dialect translation, Schema mapping, hydration, generated `_id`,
223
+ or query caching. It does **not** enforce `ExecuteOptions.permissions`: use trusted callers and
224
+ appropriately restricted database accounts. Supply values through `parameters` using the native
225
+ provider placeholders: `?` for MySQL-compatible databases, Databricks, Dameng, Snowflake and MaxCompute;
226
+ `$1` for PostgreSQL; `@p0` for SQL Server; `:1` for Oracle; typed `{p0:String}`-style
227
+ placeholders for ClickHouse. ClickHouse uses JSONEachRow output; do not override it with another
228
+ FORMAT. Each call is independent, with Oracle/Dameng command execution automatically committed;
229
+ cross-call transactions and multi-statement/multi-result execution are not supported.
230
+
231
+ `getTableList` returns `{ name, database?, schema?, type: 'table' | 'view' }[]` for accessible tables
232
+ and views, retaining namespaces to distinguish same-name tables. Optional `database` and `schema`
233
+ override only this metadata lookup, never the cached connection configuration:
234
+
235
+ - MySQL, Doris, StarRocks, GBase and ClickHouse: `database`; `schema` is rejected.
236
+ - PostgreSQL, Oracle and Dameng: `schema`; cross-database overrides are rejected. Defaults to the
237
+ current schema (or the configured Dameng schema).
238
+ - SQL Server and Snowflake: `database` and `schema`. SQL Server lists all accessible schemas in
239
+ the database by default; Snowflake defaults to the current schema.
240
+ - Databricks: `database` means catalog, and `schema` means schema. Defaults come from the connection's
241
+ `catalog` and `schema` (`connection.database` remains the existing legacy alias for schema).
242
+ - MaxCompute: the existing injected client handles `SHOW TABLES`, returning rows with `table_name`.
243
+ It may implement `getTableList(request)` for project/schema overrides and view metadata, and
244
+ `runSQL(request)` for affected-row counts. Otherwise commands must return `[]` through `execute`.
245
+
246
+ `describeTable({ connection, table, database?, schema?, includeSample? })` inspects one physical
247
+ table or view. `table` is a literal **unqualified** name; provide its namespace separately, using
248
+ the same scope rules as `getTableList`. A dot inside `table` is part of the identifier, not a separator.
249
+ Do not pass a SQL expression or the legacy semantic Schema/`from` object. SQL Server descriptions
250
+ default to the connection's current default schema; pass `schema` explicitly when describing a
251
+ table returned from another schema. Column order follows the database's definition.
252
+
253
+ The result has `columns: { name, type, comment, primaryKey?, exampleValue? }[]` and
254
+ `tableInfo: { name, database?, schema?, type, comment }`. These are physical names/native types,
255
+ not semantic Properties; no `_id` is added. Comments default to an empty string. Primary-key
256
+ membership includes every column of composite keys; unique-only indexes are not primary keys.
257
+ ClickHouse reports its storage primary key, which does not imply relational uniqueness. If the
258
+ adapter cannot determine primary-key membership (Databricks/Snowflake), `primaryKey` is omitted
259
+ rather than guessed. Example values preserve driver types, including `null`.
260
+
261
+ Like the legacy API, descriptions read one example row by default. Set `includeSample: false`
262
+ for metadata-only inspection, avoiding a data read. Empty tables and failed sample queries still
263
+ return metadata without example values; metadata failures, tables not found in the selected namespace, and
264
+ cancellation reject. All SQL uses bound metadata values and quoted identifiers, bypassing
265
+ LogicForm permissions and caching just like `runSQL`.
266
+
267
+ MaxCompute clients may implement `describeTable(request)` to provide project/schema-aware
268
+ metadata. Otherwise the fallback runs `DESC` and expects structured rows with `column_name`,
269
+ `column_type`, optional `column_comment` and `is_primary_key`. Legacy UDBC ASCII `Info` reports
270
+ must be normalized by the client; unparsed reports are rejected rather than producing empty columns.
271
+
272
+ All operations accept `signal` and the same optional `providerRegistry` as `Logicform.execute`.
273
+ Custom providers opt in through `runSQL(request)`, `getTableList(request)` and `describeTable(request)`; missing capabilities
274
+ fail explicitly without changing the existing provider `execute` contract. Unsupported discovery
275
+ scopes are rejected rather than silently ignored. Cancellation does not guarantee rollback of
276
+ commands that have already reached the database.
277
+
139
278
  ### Permissions
140
279
 
141
280
  Pass table, row, and column permissions together through `ExecuteOptions.permissions`:
@@ -200,10 +339,18 @@ names shared by both sides unless an exceptional custom operator explicitly supp
200
339
  See [Register an operator](docs/register-operator.md) for the component contract.
201
340
 
202
341
  The root entry point accepts a `connections` array of `DatabaseConnection` items. Every item has a unique `id`; set `kind` to `mysql`,
203
- `doris`, `starrocks`, `clickhouse`, `snowflake`, `oracle`, or `postgresql`, then add that driver's
342
+ `doris`, `starrocks`, `gbase`, `maxcompute`, `clickhouse`, `databricks`, `dameng`, `snowflake`,
343
+ `sqlserver`, `oracle`, or `postgresql`, then add that driver's
204
344
  native connection fields directly on the item. Each Schema Mapping selects an item through
205
345
  `connectionId`. SemanticDB lazily creates and reuses the matching internal provider. Call
206
346
  `await Logicform.close()` during application shutdown to close every connection pool and session.
347
+ One LogicForm may reference mappings on multiple connections. This is one logical execution, not
348
+ one cross-database SQL statement: physical fragments run independently and their aggregate results
349
+ are combined by the embedded coordinator. A relation join whose two sides themselves live on
350
+ different connections is not yet materialized automatically. When the related Schema has replicas
351
+ on multiple connections, the Planner selects the mapping colocated with the main mapping and emits
352
+ the `LEFT JOIN` on that connection. It fails explicitly only when no target mapping exists on the
353
+ main connection.
207
354
 
208
355
  MySQL-compatible providers default to 30 connections, at most 10 idle connections, a 60-second
209
356
  idle timeout, and TCP keepalive. Native `mysql2` pool options on the connection item override these
@@ -239,6 +386,66 @@ pagination, date, aggregate, string, regex, parameter, and display-SQL behavior
239
386
  MySQL-compatible SQL helper. Database-specific differences should be implemented by overriding the
240
387
  corresponding internal dialect capability.
241
388
 
389
+ ### GBase connection
390
+
391
+ GBase 8a uses its MySQL-compatible protocol through `mysql2`. It defaults to port `5258`; all
392
+ ordinary `mysql2` connection and pool fields remain available:
393
+
394
+ ```ts
395
+ const gbase = {
396
+ id: 'gbase-main',
397
+ kind: 'gbase',
398
+ host: process.env.GBASE_HOST,
399
+ user: process.env.GBASE_USER,
400
+ password: process.env.GBASE_PASSWORD,
401
+ database: process.env.GBASE_DATABASE,
402
+ } as const;
403
+ ```
404
+
405
+ ### MaxCompute connection
406
+
407
+ MaxCompute requires a caller-owned client that preserves the Provider's parameterized execution
408
+ contract. The client receives SQL and parameters separately and owns the actual MaxCompute/JDBC
409
+ transport:
410
+
411
+ ```ts
412
+ const maxcompute = {
413
+ id: 'maxcompute-main',
414
+ kind: 'maxcompute',
415
+ client: {
416
+ execute: ({ sql, parameters, signal }) => maxComputeGateway.execute({
417
+ sql, parameters, signal,
418
+ }),
419
+ close: () => maxComputeGateway.close(),
420
+ },
421
+ } as const;
422
+ ```
423
+
424
+ The legacy UDBC `Statement` endpoint accepts only a complete SQL string, so SemanticDB does not
425
+ use it or interpolate values locally. A gateway implementation must bind `parameters` before this
426
+ connection can execute queries.
427
+
428
+ ### SQL Server connection
429
+
430
+ SQL Server uses `mssql`, bracket-quoted identifiers, and named `@p0`, `@p1` parameters:
431
+
432
+ ```ts
433
+ const sqlserver = {
434
+ id: 'sqlserver-main',
435
+ kind: 'sqlserver',
436
+ host: process.env.SQLSERVER_HOST,
437
+ port: 1433,
438
+ user: process.env.SQLSERVER_USER,
439
+ password: process.env.SQLSERVER_PASSWORD,
440
+ database: process.env.SQLSERVER_DATABASE,
441
+ options: { encrypt: true },
442
+ } as const;
443
+ ```
444
+
445
+ Pagination uses `OFFSET ... FETCH`; SemanticDB supplies a neutral top-level ordering when the
446
+ LogicForm has no sort. JSON array relations use `OPENJSON`. SQL Server has no native regular
447
+ expression predicate, so `$regex` is rejected explicitly.
448
+
242
449
  ### Snowflake connection
243
450
 
244
451
  Snowflake connection fields are passed to the official `snowflake-sdk`:
@@ -261,6 +468,52 @@ await Logicform.execute(logicform, {
261
468
  });
262
469
  ```
263
470
 
471
+ ### Databricks connection
472
+
473
+ Databricks uses `@databricks/sql` and supports a personal access token or OAuth M2M. `catalog` and
474
+ `schema` select the initial SQL Warehouse session namespace (`database` is accepted as a legacy
475
+ alias for `schema`):
476
+
477
+ ```ts
478
+ const databricks = {
479
+ id: 'databricks-main',
480
+ kind: 'databricks',
481
+ host: process.env.DATABRICKS_SERVER_HOSTNAME,
482
+ path: process.env.DATABRICKS_HTTP_PATH,
483
+ authType: 'databricks-oauth',
484
+ oauthClientId: process.env.DATABRICKS_CLIENT_ID,
485
+ oauthClientSecret: process.env.DATABRICKS_CLIENT_SECRET,
486
+ catalog: 'main',
487
+ schema: 'analytics',
488
+ } as const;
489
+ ```
490
+
491
+ Use `authType: 'access-token'` with `token` for PAT authentication. Values are sent through the
492
+ driver's ordinal parameter binding and are not interpolated into executable SQL. `authType` is
493
+ required: PAT and OAuth fields are mutually exclusive, and authentication is never inferred from
494
+ the presence of credentials.
495
+
496
+ ### Dameng connection
497
+
498
+ Dameng uses the official `dmdb` pool and the `dameng` connection kind:
499
+
500
+ ```ts
501
+ const dameng = {
502
+ id: 'dameng-main',
503
+ kind: 'dameng',
504
+ host: process.env.DAMENG_HOST,
505
+ port: 5236,
506
+ user: process.env.DAMENG_USER,
507
+ password: process.env.DAMENG_PASSWORD,
508
+ schema: process.env.DAMENG_SCHEMA,
509
+ } as const;
510
+ ```
511
+
512
+ The provider uses positional binds and object-format result rows. Recursive hierarchy queries and
513
+ JSON-array relations are rejected until their behavior can be verified against supported DM server
514
+ versions; scalar queries, grouping, date operations, regex, windows, joins, and pagination compile
515
+ with the DM/Oracle-style dialect.
516
+
264
517
  ### Oracle connection
265
518
 
266
519
  Oracle uses the official `oracledb` driver in Thin mode and does not require Oracle Client
@@ -331,9 +584,20 @@ comments, or parameter placeholders. Property UDFs do not support the legacy `fu
331
584
 
332
585
  All compiled provider queries, including the internal time-watermark query, can share one
333
586
  caller-owned query cache. Redis is published from `semanticdb-v2/cache/redis`; cache identity
334
- includes namespace, provider, SQL, and parameters. Physical expiration belongs to each Schema
587
+ includes namespace, connection id, provider, SQL, and parameters. Physical expiration belongs to each Schema
335
588
  mapping's `freshness` policy. See [Query cache and Redis](docs/query-cache.md).
336
589
 
590
+ Schema mappings can also expose same-connection entity feature tables as lazy physical
591
+ enrichments. A mapped feature property adds a `LEFT JOIN` only when referenced, and a point-in-time
592
+ feature can be assigned to the containing valid-time entity row. See
593
+ [Schema Mapping feature enrichments](docs/schema-mapping-enrichments.md).
594
+
595
+ For aggregate sources, set `granularity` on mapped date or hierarchy Properties.
596
+ Other available dimensions are inferred from their Property mappings, so there is no
597
+ separate Schema Mapping `dimensions` field. The planner selects a source that covers
598
+ the requested properties and physical time or hierarchy grain. See
599
+ [Schema Mapping physical granularity](docs/schema-mapping-granularity.md).
600
+
337
601
  When Redis is shared with other applications, pass an application-specific key prefix:
338
602
 
339
603
  ```ts
@@ -455,7 +719,8 @@ npm run debug
455
719
 
456
720
  ## Current scope
457
721
 
458
- - ClickHouse, MySQL, Oracle, and Snowflake core compute providers
722
+ - ClickHouse, Databricks, Dameng, Doris, GBase, MaxCompute, MySQL, Oracle, PostgreSQL, Snowflake,
723
+ SQL Server, and StarRocks core compute providers
459
724
  - Projections, conditional aggregates, and `$sum`, `$count`, `$countDistinct`, `$avg`, `$min`, `$max`
460
725
  - Structured arithmetic, share-of-total, period comparison, period-boundary, date-bucket,
461
726
  cumulative period, trusted SQL expression, string, case, and window operators
@@ -1 +1 @@
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
+ import{createClient as b}from"redis";import{createHash as g}from"node:crypto";const 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)?e.map(o):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,o(r)])):e,d=e=>g("sha256").update(JSON.stringify(o(e))).digest("hex"),A=e=>d({namespace:e.namespace,provider:e.provider,connectionId:e.connectionId,sql:e.sql,parameters:e.parameters}),S=(e,t)=>d({namespace:e,source:t}),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)?{type:"array",value:e.map(a)}:e&&typeof e=="object"?{type:"object",value:Object.entries(e).map(([t,r])=>[t,a(r)])}:e,f=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(f);case"object":return Object.fromEntries(e.value.map(([t,r])=>[t,f(r)]))}},w=e=>JSON.stringify(a(e)),x=e=>{const t=f(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),y=w(r),c=i.expiresAt?.getTime(),m=c??l,s=this.#e.multi();c===void 0?s.set(n,y):s.set(n,y,{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 +1 @@
1
- "use strict";var b=require("redis"),g=require("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.createHash("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),u=w(r),c=i.expiresAt?.getTime(),h=c??l,s=this.#e.multi();c===void 0?s.set(n,u):s.set(n,u,{PXAT:c});for(const m of new Set(i.sources)){const f=this.#i(t.namespace,m);s.zRemRangeByScore(f,0,Date.now()),s.zAdd(f,{score:h,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 C=async(e={})=>{const t=b.createClient(e.url?{url:e.url}:{});return t.on("error",()=>{}),await t.connect(),new p(t,{...e.keyPrefix?{keyPrefix:e.keyPrefix}:{},ownsClient:!0})};exports.RedisQueryCache=p,exports.createRedisQueryCache=C;
1
+ "use strict";var b=require("redis"),g=require("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.createHash("sha256").update(JSON.stringify(a(e))).digest("hex"),A=e=>d({namespace:e.namespace,provider:e.provider,connectionId:e.connectionId,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,u=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(u);case"object":return Object.fromEntries(e.value.map(([t,r])=>[t,u(r)]))}},w=e=>JSON.stringify(o(e)),x=e=>{const t=u(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),y=w(r),c=i.expiresAt?.getTime(),h=c??l,s=this.#e.multi();c===void 0?s.set(n,y):s.set(n,y,{PXAT:c});for(const m of new Set(i.sources)){const f=this.#i(t.namespace,m);s.zRemRangeByScore(f,0,Date.now()),s.zAdd(f,{score:h,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 C=async(e={})=>{const t=b.createClient(e.url?{url:e.url}:{});return t.on("error",()=>{}),await t.connect(),new p(t,{...e.keyPrefix?{keyPrefix:e.keyPrefix}:{},ownsClient:!0})};exports.RedisQueryCache=p,exports.createRedisQueryCache=C;
@@ -2,6 +2,8 @@ import type { CoreComputeProvider, DataRow, SqlParameters } from '../physical/in
2
2
  export interface QueryCacheIdentity {
3
3
  readonly namespace: string;
4
4
  readonly provider: CoreComputeProvider['kind'];
5
+ /** Distinguishes separate databases using the same provider dialect. */
6
+ readonly connectionId?: string;
5
7
  readonly sql: string;
6
8
  readonly parameters: SqlParameters;
7
9
  }
@@ -1,12 +1 @@
1
- import type { CoreComputeProvider, DatabaseConnection } from '../physical/index';
2
- type ProviderFactory = (connection: DatabaseConnection) => CoreComputeProvider;
3
- export declare class ConnectionRegistry {
4
- #private;
5
- private readonly create;
6
- constructor(create?: ProviderFactory);
7
- get(connection: DatabaseConnection): CoreComputeProvider;
8
- close(): Promise<void>;
9
- }
10
- export declare const getConnectionProvider: (connection: DatabaseConnection) => CoreComputeProvider;
11
- export declare const closeConnections: () => Promise<void>;
12
- export {};
1
+ export { ConnectionRegistry, getConnectionProvider, closeConnections } from '../physical/index';
@@ -1,13 +1,18 @@
1
1
  import type { CompiledQuery } from '../compiler/index';
2
2
  import type { DataRow } from '../physical/index';
3
3
  import type { LogicalPlan } from '../planner/index';
4
+ import type { SchemaMappingDefinition, SchemaMappingRegistry } from '../schema-mappings/index';
4
5
  import type { InternalExecuteOptions } from './types';
5
6
  export interface PhysicalQuerySource {
6
7
  readonly schemaId: string;
7
8
  readonly source: string;
9
+ readonly connectionId?: string;
10
+ /** Base mapping source that owns an enrichment source. */
11
+ readonly mappingSource?: string;
8
12
  }
13
+ export declare const resolvePhysicalSourceMapping: (source: PhysicalQuerySource, mappings: SchemaMappingRegistry) => SchemaMappingDefinition | undefined;
9
14
  export declare const collectPlanSources: (plan: LogicalPlan) => readonly PhysicalQuerySource[];
10
15
  export declare const mergePhysicalSources: (groups: readonly (readonly PhysicalQuerySource[])[]) => readonly PhysicalQuerySource[];
11
- export declare const executeCompiledQuery: (compiled: CompiledQuery, sources: readonly PhysicalQuerySource[], options: Pick<InternalExecuteOptions, "cache" | "provider" | "schemaMappings" | "signal">) => Promise<DataRow[]>;
16
+ export declare const executeCompiledQuery: (compiled: CompiledQuery, sources: readonly PhysicalQuerySource[], options: Pick<InternalExecuteOptions, "cache" | "provider" | "schemaMappings" | "signal" | "connectionId">) => Promise<DataRow[]>;
12
17
  /** Apply final SQL shaping after all plans, views, and derived sources are compiled. */
13
18
  export declare const shortenCompiledQuery: (compiled: CompiledQuery) => CompiledQuery;
@@ -0,0 +1,37 @@
1
+ import type { CompiledQuery } from '../compiler/index';
2
+ import type { LogicformType } from '../logicform-types';
3
+ import type { OperatorRegistry } from '../operators/index';
4
+ import type { CoreComputeProvider, DataRow } from '../physical/index';
5
+ import type { LogicalPlan } from '../planner/index';
6
+ import type { SchemaMappingRegistry } from '../schema-mappings/index';
7
+ import type { InternalExecuteOptions } from './types';
8
+ export declare const coordinatorConnectionId = "__semanticdb_coordinator__";
9
+ export interface FederatedCompiledQuery {
10
+ readonly compiled: CompiledQuery;
11
+ readonly connectionId: string;
12
+ readonly provider: CoreComputeProvider;
13
+ readonly type: 'computation' | 'total';
14
+ readonly logicform: LogicformType;
15
+ }
16
+ interface FederatedExecutionOptions {
17
+ readonly logicform: LogicformType;
18
+ readonly operators: OperatorRegistry;
19
+ readonly schemaMappings: SchemaMappingRegistry;
20
+ readonly providerForConnection: (connectionId: string) => CoreComputeProvider;
21
+ readonly cache?: InternalExecuteOptions['cache'];
22
+ readonly signal?: AbortSignal;
23
+ readonly maxMaterializedRows: number;
24
+ readonly onCompiled: (query: FederatedCompiledQuery) => void;
25
+ }
26
+ export interface FederatedExecutionResult {
27
+ readonly rows: DataRow[];
28
+ readonly total: number;
29
+ readonly connections: readonly {
30
+ readonly connectionId: string;
31
+ readonly provider: CoreComputeProvider['kind'];
32
+ }[];
33
+ }
34
+ export declare const planConnectionIds: (plan: LogicalPlan, schemaMappings: SchemaMappingRegistry) => readonly string[];
35
+ export declare const isFederatedComposition: (plan: LogicalPlan, schemaMappings: SchemaMappingRegistry) => boolean;
36
+ export declare const executeFederatedComposition: (plan: LogicalPlan, options: FederatedExecutionOptions) => Promise<FederatedExecutionResult>;
37
+ export {};
@@ -21,9 +21,11 @@ interface FetchEntityOptions {
21
21
  readonly resolveSchema: (schemaId: string) => ResolvedSemanticSchema;
22
22
  readonly permissions?: Permissions;
23
23
  readonly provider: CoreComputeProvider;
24
+ readonly providerForConnection?: (connectionId: string) => CoreComputeProvider;
25
+ readonly preferredConnectionId?: string;
24
26
  readonly cache?: QueryCacheExecutionOptions;
25
27
  readonly signal?: AbortSignal;
26
- readonly onCompiled?: (compiled: CompiledQuery, logicform: LogicformType) => void;
28
+ readonly onCompiled?: (compiled: CompiledQuery, logicform: LogicformType, provider: CoreComputeProvider, connectionId?: string) => void;
27
29
  }
28
30
  export declare const fetchEntities: (request: EntityFetchRequest, options: FetchEntityOptions) => Promise<DataRow[]>;
29
31
  export {};
@@ -1,6 +1,7 @@
1
1
  import type { ResultProperty } from '../../operators/index';
2
2
  import type { DataRow } from '../../physical/index';
3
3
  import type { ResolvedSemanticProperty, ResolvedSemanticSchema, SemanticTypeRegistry } from '../../semantic-types/index';
4
+ import type { SemanticDBPlugin } from '../../plugins/index';
4
5
  export type HydrationProperty = Pick<ResultProperty, 'isArray' | 'name' | 'primal_type' | 'ref' | 'type'> | ResolvedSemanticProperty;
5
6
  export interface EntityFetchRequest {
6
7
  readonly schema: ResolvedSemanticSchema;
@@ -11,4 +12,5 @@ export interface ResultHydratorOptions {
11
12
  readonly semanticTypes: SemanticTypeRegistry;
12
13
  readonly resolveSchema: (schemaId: string) => ResolvedSemanticSchema;
13
14
  readonly fetchEntities: (request: EntityFetchRequest) => Promise<readonly DataRow[]>;
15
+ readonly plugins?: readonly SemanticDBPlugin[];
14
16
  }
@@ -0,0 +1,11 @@
1
+ import type { CompiledQuery } from '../compiler/index';
2
+ import type { CoreComputeProvider, DataRow } from '../physical/index';
3
+ import type { LogicalPlan } from '../planner/index';
4
+ import type { LogicformType } from '../logicform-types';
5
+ /** Remove global result paging while retaining HAVING and per-group limitBy semantics. */
6
+ export declare const withoutGlobalPagination: (plan: LogicalPlan) => LogicalPlan;
7
+ /** Describe the total SQL with the same unpaged global result as its plan. */
8
+ export declare const withoutGlobalPaginationLogicform: (logicform: LogicformType) => LogicformType;
9
+ /** Count the rows produced by a complete unpaginated logical result. */
10
+ export declare const compileTotalQuery: (unpaged: CompiledQuery, provider: CoreComputeProvider) => CompiledQuery;
11
+ export declare const readTotal: (rows: readonly DataRow[]) => number;
@@ -1,8 +1,8 @@
1
1
  import type { OperatorDefinition, OperatorRegistry } from '../operators/index';
2
- import type { CoreComputeProvider, DataRow, SqlParameters } from '../physical/index';
2
+ import type { CoreComputeProvider, DataRow, ProviderRegistry, SqlParameters } from '../physical/index';
3
3
  import type { DatabaseConnection } from '../physical/index';
4
4
  import type { LogicalPlan, QueryLineage } from '../planner/index';
5
- import type { SchemaMappingDefinition, SchemaMappingRegistry } from '../schema-mappings/index';
5
+ import type { SchemaMappingDefinition, SchemaMappingRegistry, SchemaMappingSelection } from '../schema-mappings/index';
6
6
  import type { ResolvedSemanticSchema, SemanticSchemaDraft, SemanticTypeRegistry, TimeWatermarkPolicy } from '../semantic-types/index';
7
7
  import type { LogicformType, PublicLogicformType } from '../logicform-types';
8
8
  import type { QueryCacheExecutionOptions } from '../cache/index';
@@ -36,6 +36,7 @@ export type ExecuteProgressEvent = {
36
36
  } | {
37
37
  readonly stage: 'executing';
38
38
  readonly provider: CoreComputeProvider['kind'];
39
+ readonly connectionId?: string;
39
40
  readonly partialResult: PartialExecuteResult;
40
41
  } | {
41
42
  readonly stage: 'hydrating';
@@ -56,8 +57,9 @@ export type ExecuteProgressEvent = {
56
57
  export type ProgressCallback = (event: ExecuteProgressEvent) => void | Promise<void>;
57
58
  interface ExecuteBaseOptions {
58
59
  readonly schemas: Readonly<Record<string, SemanticSchemaDraft>>;
60
+ /** Caller-owned Registry; plugin SemanticTypes are copied into the execution Registry. */
59
61
  readonly semanticTypes?: SemanticTypeRegistry;
60
- /** Caller-defined operators supplied as plain definition objects. */
62
+ /** Caller-defined Operators; explicit definitions override same-name built-ins or plugin Operators. */
61
63
  readonly operators?: OperatorDefinition | readonly OperatorDefinition[];
62
64
  /** Caller-owned capability plugins appended to the built-in plugin set for this execution. */
63
65
  readonly plugins?: readonly SemanticDBPlugin[];
@@ -73,30 +75,54 @@ interface ExecuteBaseOptions {
73
75
  readonly signal?: AbortSignal;
74
76
  /** Default time watermark policy; Schema and Property policies override it. */
75
77
  readonly timeWatermark?: TimeWatermarkPolicy;
78
+ /** Resource limits for in-process combination of separate physical connections. */
79
+ readonly federation?: {
80
+ /** Defaults to 100,000 rows across all materialized aggregate branches. */
81
+ readonly maxMaterializedRows?: number;
82
+ };
76
83
  }
77
84
  export interface ExecuteOptions extends ExecuteBaseOptions {
78
85
  /** Physical mappings supplied as JSON definitions. */
79
86
  readonly schemaMappings: readonly SchemaMappingDefinition[];
80
87
  /** Database connections addressable by SchemaMappingDefinition.connectionId. */
81
88
  readonly connections: readonly DatabaseConnection[];
89
+ /** Provider factories used for built-in or application-defined connection kinds. */
90
+ readonly providerRegistry?: ProviderRegistry;
82
91
  }
83
92
  /** Internal execution seam used by executor tests after a provider has been resolved. */
84
93
  export interface InternalExecuteOptions extends Omit<ExecuteBaseOptions, 'operators'> {
85
94
  readonly operators?: OperatorRegistry;
95
+ /** The public execution boundary has already merged built-in, plugin, and explicit Operators. */
96
+ readonly operatorsResolved?: boolean;
97
+ /** The public execution boundary has already merged plugin SemanticTypes. */
98
+ readonly semanticTypesResolved?: boolean;
86
99
  readonly localeRegistry?: LocaleRegistry;
87
100
  readonly provider: CoreComputeProvider;
101
+ /** Resolve providers for additional physical connections in a federated execution. */
102
+ readonly providerForConnection?: (connectionId: string) => CoreComputeProvider;
88
103
  readonly schemaMappings: SchemaMappingRegistry;
89
104
  /** Selected connection for public execution; omitted only by internal provider tests. */
90
105
  readonly connectionId?: string;
91
106
  }
92
107
  export interface ExecuteSuccessResult {
93
108
  readonly result: DataRow[];
109
+ /** Result rows or grouped rows before global limit/page pagination. */
110
+ readonly total: number;
94
111
  /** Schema describing the computed result rows. */
95
112
  readonly schema: ResolvedSemanticSchema;
96
113
  readonly normedLogicform: PublicLogicformType;
97
114
  readonly sqls: readonly ExecutedSql[];
98
115
  readonly lineage: QueryLineage;
99
116
  readonly provider: CoreComputeProvider['kind'];
117
+ /** Physical connections that contributed rows to this result. */
118
+ readonly providers: readonly {
119
+ readonly connectionId: string;
120
+ readonly provider: CoreComputeProvider['kind'];
121
+ }[];
122
+ /** Physical mapping decisions, including why every non-selected candidate lost. */
123
+ readonly schemaMappingSelections: readonly SchemaMappingSelection[];
124
+ /** Plugin-owned materialization for a custom LogicForm output type. */
125
+ readonly output?: unknown;
100
126
  }
101
127
  export interface ExecuteFailureResult {
102
128
  readonly errorCode: '100';
@@ -109,10 +135,13 @@ export interface ExecuteFailureResult {
109
135
  readonly lineage?: QueryLineage;
110
136
  }
111
137
  export type ExecuteResult = ExecuteSuccessResult | ExecuteFailureResult;
112
- export type ExecutedSqlType = 'computation' | 'semantic-resolution';
138
+ export type ExecutedSqlType = 'computation' | 'semantic-resolution' | 'total';
113
139
  export interface ExecutedSql {
114
140
  /** Why this SQL participates in the LogicForm execution. */
115
141
  readonly type: ExecutedSqlType;
142
+ /** Physical connection that executed this SQL, or the in-process coordinator id. */
143
+ readonly connectionId?: string;
144
+ readonly provider?: CoreComputeProvider['kind'];
116
145
  /** Human-readable, localized explanation of why this SQL is executed. */
117
146
  readonly explain: string;
118
147
  /** Normalized LogicForm represented by this SQL statement. */