@gscdump/engine 0.9.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_chunks/dispatch.mjs +11 -17
- package/dist/_chunks/engine.mjs +622 -0
- package/dist/_chunks/pg-adapter.mjs +1 -10
- package/dist/_chunks/registry.d.mts +137 -15
- package/dist/_chunks/resolver.mjs +2 -25
- package/dist/_chunks/snapshot.d.mts +14 -0
- package/dist/_chunks/storage.d.mts +1 -20
- package/dist/adapters/node.d.mts +91 -0
- package/dist/adapters/node.mjs +133 -0
- package/dist/analyzer/index.d.mts +4 -50
- package/dist/analyzer/index.mjs +17 -8
- package/dist/entities.d.mts +116 -2
- package/dist/entities.mjs +453 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +7 -621
- package/dist/planner.d.mts +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/resolver/index.d.mts +1 -23
- package/dist/resolver/index.mjs +3 -3
- package/dist/rollups.d.mts +196 -0
- package/dist/rollups.mjs +546 -0
- package/dist/schedule.d.mts +19 -0
- package/dist/schedule.mjs +100 -0
- package/dist/snapshot.d.mts +1 -13
- package/dist/source/index.d.mts +30 -8
- package/dist/source/index.mjs +42 -7
- package/package.json +15 -5
- package/dist/_chunks/source-types.d.mts +0 -31
- /package/dist/_chunks/{planner.mjs → compiler.mjs} +0 -0
package/dist/source/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { F as TenantCtx, O as StorageEngine, T as Row } from "../_chunks/storage.mjs";
|
|
2
|
+
import { o as ResolverAdapter } from "../_chunks/types.mjs";
|
|
2
3
|
import { n as AnalysisResult, t as AnalysisParams } from "../_chunks/analysis-types.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { t as AnalyzerRegistry } from "../_chunks/registry.mjs";
|
|
4
|
+
import { C as ExecuteSqlOptions, E as SourceCapabilities, S as AnalysisSourceKind, T as QueryRow, t as AnalyzerRegistry, w as FileSet, x as AnalysisQuerySource } from "../_chunks/registry.mjs";
|
|
5
5
|
import { PlannerCapabilities } from "gscdump/query/plan";
|
|
6
6
|
import { BuilderState } from "gscdump/query";
|
|
7
7
|
interface AttachedTableRunner {
|
|
@@ -28,6 +28,13 @@ interface AttachedTableSourceOptions {
|
|
|
28
28
|
* paying the SQL execution cost. Omit to disable the check.
|
|
29
29
|
*/
|
|
30
30
|
attachedTables?: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* Dialect adapter surfaced on the source for analyzers that compose SQL
|
|
33
|
+
* from a `BuilderState` at plan-build time (e.g. `data-query`,
|
|
34
|
+
* `data-detail`). Attached-table sources execute pg-flavored DuckDB SQL,
|
|
35
|
+
* so callers should pass `pgResolverAdapter` here.
|
|
36
|
+
*/
|
|
37
|
+
adapter?: ResolverAdapter<any>;
|
|
31
38
|
}
|
|
32
39
|
declare class AttachedTableMissingError extends Error {
|
|
33
40
|
readonly missing: readonly string[];
|
|
@@ -39,6 +46,21 @@ declare class AttachedTableMissingError extends Error {
|
|
|
39
46
|
*/
|
|
40
47
|
declare function rewriteForTableSource(sql: string, schema: string, fileSets: Record<string, FileSet>): string;
|
|
41
48
|
declare function createAttachedTableSource(runner: AttachedTableRunner, options: AttachedTableSourceOptions): AnalysisQuerySource;
|
|
49
|
+
interface CreateSqlQuerySourceOptions<TKey extends string> {
|
|
50
|
+
/** Debug-only identifier surfaced on the source for error messages. */
|
|
51
|
+
name: string;
|
|
52
|
+
/** Telemetry tag stamped onto analyzer result meta. */
|
|
53
|
+
kind?: AnalysisSourceKind;
|
|
54
|
+
/** Dialect-specific adapter; compiles `BuilderState` → `{ sql, params }`. */
|
|
55
|
+
adapter: ResolverAdapter<TKey>;
|
|
56
|
+
/** Drives the underlying DB. Called for both typed queries and raw SQL. */
|
|
57
|
+
execute: (sql: string, params: unknown[]) => Promise<QueryRow[]>;
|
|
58
|
+
/** Tenant id for multi-tenant dialects; forwarded to `resolveToSQL`. */
|
|
59
|
+
siteId?: string | number;
|
|
60
|
+
/** Additional capability flags merged on top of `adapter.capabilities`. */
|
|
61
|
+
extraCapabilities?: Partial<SourceCapabilities>;
|
|
62
|
+
}
|
|
63
|
+
declare function createSqlQuerySource<TKey extends string>(options: CreateSqlQuerySourceOptions<TKey>): AnalysisQuerySource;
|
|
42
64
|
/**
|
|
43
65
|
* Capabilities the engine query path honors. Matches what the DuckDB compiler
|
|
44
66
|
* passes to `buildLogicalPlan`: regex pushes down; comparison joins and
|
|
@@ -51,12 +73,12 @@ interface EngineQuerySourceOptions {
|
|
|
51
73
|
ctx: TenantCtx;
|
|
52
74
|
}
|
|
53
75
|
/**
|
|
54
|
-
* Wraps a storage engine as
|
|
55
|
-
* builder-state queries; `executeSql` delegates to
|
|
56
|
-
* requires `opts.fileSets` (with a `FILES` entry so the
|
|
57
|
-
* resolved for partition lookup).
|
|
76
|
+
* Wraps a storage engine as an `AnalysisQuerySource` with SQL execution.
|
|
77
|
+
* `queryRows` runs typed builder-state queries; `executeSql` delegates to
|
|
78
|
+
* `engine.runSQL` and requires `opts.fileSets` (with a `FILES` entry so the
|
|
79
|
+
* target table can be resolved for partition lookup).
|
|
58
80
|
*/
|
|
59
|
-
declare function createEngineQuerySource(options: EngineQuerySourceOptions):
|
|
81
|
+
declare function createEngineQuerySource(options: EngineQuerySourceOptions): AnalysisQuerySource;
|
|
60
82
|
/**
|
|
61
83
|
* Convenience: wrap a storage engine + tenant ctx in a source and dispatch.
|
|
62
84
|
* Equivalent to
|
|
@@ -75,4 +97,4 @@ declare function queryComparisonRows<TRow = QueryRow>(source: AnalysisQuerySourc
|
|
|
75
97
|
current: TRow[];
|
|
76
98
|
previous: TRow[];
|
|
77
99
|
}>;
|
|
78
|
-
export { AttachedTableMissingError, type AttachedTableRunner, type AttachedTableSourceOptions, ENGINE_QUERY_CAPABILITIES, EngineQuerySourceOptions, TypedQuery, createAttachedTableSource, createEngineQuerySource, queryComparisonRows, queryRows, rewriteForTableSource, runAnalyzerWithEngine, typedQuery };
|
|
100
|
+
export { type AnalysisQuerySource, type AnalysisSourceKind, AttachedTableMissingError, type AttachedTableRunner, type AttachedTableSourceOptions, type CreateSqlQuerySourceOptions, ENGINE_QUERY_CAPABILITIES, EngineQuerySourceOptions, type ExecuteSqlOptions, type FileSet, type QueryRow, type SourceCapabilities, TypedQuery, createAttachedTableSource, createEngineQuerySource, createSqlQuerySource, queryComparisonRows, queryRows, rewriteForTableSource, runAnalyzerWithEngine, typedQuery };
|
package/dist/source/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { h as resolveToSQL, n as pgResolverAdapter, s as assertDimensionsSupported } from "../_chunks/pg-adapter.mjs";
|
|
2
|
+
import { i as getFilterDimensions } from "../_chunks/resolver.mjs";
|
|
3
3
|
import { n as runAnalyzerFromSource } from "../_chunks/dispatch.mjs";
|
|
4
4
|
var AttachedTableMissingError = class extends Error {
|
|
5
5
|
constructor(missing) {
|
|
@@ -11,7 +11,12 @@ var AttachedTableMissingError = class extends Error {
|
|
|
11
11
|
const ATTACHED_TABLE_CAPABILITIES = {
|
|
12
12
|
fileSets: true,
|
|
13
13
|
attachedTables: true,
|
|
14
|
-
regex: true
|
|
14
|
+
regex: true,
|
|
15
|
+
executeSql: true
|
|
16
|
+
};
|
|
17
|
+
const ATTACHED_TABLE_CAPABILITIES_WITH_ADAPTER = {
|
|
18
|
+
...ATTACHED_TABLE_CAPABILITIES,
|
|
19
|
+
adapter: true
|
|
15
20
|
};
|
|
16
21
|
function rewriteForTableSource(sql, schema, fileSets) {
|
|
17
22
|
let out = sql;
|
|
@@ -22,11 +27,13 @@ function rewriteForTableSource(sql, schema, fileSets) {
|
|
|
22
27
|
return out;
|
|
23
28
|
}
|
|
24
29
|
function createAttachedTableSource(runner, options) {
|
|
25
|
-
const { schema, signal, attachedTables } = options;
|
|
30
|
+
const { schema, signal, attachedTables, adapter } = options;
|
|
26
31
|
const attachedSet = attachedTables ? new Set(attachedTables) : null;
|
|
27
32
|
return {
|
|
28
33
|
name: "attached-table",
|
|
29
|
-
|
|
34
|
+
kind: "browser",
|
|
35
|
+
capabilities: adapter ? ATTACHED_TABLE_CAPABILITIES_WITH_ADAPTER : ATTACHED_TABLE_CAPABILITIES,
|
|
36
|
+
adapter,
|
|
30
37
|
async queryRows() {
|
|
31
38
|
throw new Error("attached-table source: queryRows is not supported; use SQL analyzers");
|
|
32
39
|
},
|
|
@@ -43,6 +50,31 @@ function createAttachedTableSource(runner, options) {
|
|
|
43
50
|
}
|
|
44
51
|
};
|
|
45
52
|
}
|
|
53
|
+
function createSqlQuerySource(options) {
|
|
54
|
+
const { name, kind, adapter, execute, siteId, extraCapabilities } = options;
|
|
55
|
+
return {
|
|
56
|
+
name,
|
|
57
|
+
kind,
|
|
58
|
+
capabilities: {
|
|
59
|
+
...adapter.capabilities,
|
|
60
|
+
...extraCapabilities,
|
|
61
|
+
executeSql: true,
|
|
62
|
+
adapter: true
|
|
63
|
+
},
|
|
64
|
+
adapter,
|
|
65
|
+
siteId,
|
|
66
|
+
async queryRows(state) {
|
|
67
|
+
const resolved = resolveToSQL(state, {
|
|
68
|
+
adapter,
|
|
69
|
+
siteId
|
|
70
|
+
});
|
|
71
|
+
return execute(resolved.sql, resolved.params);
|
|
72
|
+
},
|
|
73
|
+
executeSql(sql, params) {
|
|
74
|
+
return execute(sql, params ?? []);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
46
78
|
function isMetricDimension(dim) {
|
|
47
79
|
return [
|
|
48
80
|
"clicks",
|
|
@@ -60,13 +92,16 @@ const ENGINE_QUERY_CAPABILITIES = {
|
|
|
60
92
|
const ENGINE_SOURCE_CAPABILITIES = {
|
|
61
93
|
...ENGINE_QUERY_CAPABILITIES,
|
|
62
94
|
fileSets: true,
|
|
63
|
-
|
|
95
|
+
executeSql: true,
|
|
96
|
+
adapter: true
|
|
64
97
|
};
|
|
65
98
|
function createEngineQuerySource(options) {
|
|
66
99
|
const { engine, ctx } = options;
|
|
67
100
|
return {
|
|
68
101
|
name: "engine",
|
|
102
|
+
kind: "local",
|
|
69
103
|
capabilities: ENGINE_SOURCE_CAPABILITIES,
|
|
104
|
+
adapter: pgResolverAdapter,
|
|
70
105
|
async queryRows(state) {
|
|
71
106
|
const filterDims = getFilterDimensions(state.filter, isMetricDimension);
|
|
72
107
|
assertDimensionsSupported([...state.dimensions, ...filterDims], "stored", "engine query source");
|
|
@@ -110,4 +145,4 @@ async function queryComparisonRows(source, current, previous) {
|
|
|
110
145
|
previous: previousRows
|
|
111
146
|
};
|
|
112
147
|
}
|
|
113
|
-
export { AttachedTableMissingError, ENGINE_QUERY_CAPABILITIES, createAttachedTableSource, createEngineQuerySource, queryComparisonRows, queryRows, rewriteForTableSource, runAnalyzerWithEngine, typedQuery };
|
|
148
|
+
export { AttachedTableMissingError, ENGINE_QUERY_CAPABILITIES, createAttachedTableSource, createEngineQuerySource, createSqlQuerySource, queryComparisonRows, queryRows, rewriteForTableSource, runAnalyzerWithEngine, typedQuery };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/engine",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"description": "Append-only Parquet/DuckDB storage engine + planner + adapters for the gscdump pipeline. Node + edge runtimes; opt-in heavy peers.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -61,15 +61,25 @@
|
|
|
61
61
|
"import": "./dist/sql-fragments.mjs",
|
|
62
62
|
"default": "./dist/sql-fragments.mjs"
|
|
63
63
|
},
|
|
64
|
+
"./schedule": {
|
|
65
|
+
"types": "./dist/schedule.d.mts",
|
|
66
|
+
"import": "./dist/schedule.mjs",
|
|
67
|
+
"default": "./dist/schedule.mjs"
|
|
68
|
+
},
|
|
64
69
|
"./entities": {
|
|
65
70
|
"types": "./dist/entities.d.mts",
|
|
66
71
|
"import": "./dist/entities.mjs",
|
|
67
72
|
"default": "./dist/entities.mjs"
|
|
68
73
|
},
|
|
74
|
+
"./rollups": {
|
|
75
|
+
"types": "./dist/rollups.d.mts",
|
|
76
|
+
"import": "./dist/rollups.mjs",
|
|
77
|
+
"default": "./dist/rollups.mjs"
|
|
78
|
+
},
|
|
69
79
|
"./node": {
|
|
70
|
-
"types": "./dist/adapters/
|
|
71
|
-
"import": "./dist/adapters/
|
|
72
|
-
"default": "./dist/adapters/
|
|
80
|
+
"types": "./dist/adapters/node.d.mts",
|
|
81
|
+
"import": "./dist/adapters/node.mjs",
|
|
82
|
+
"default": "./dist/adapters/node.mjs"
|
|
73
83
|
},
|
|
74
84
|
"./filesystem": {
|
|
75
85
|
"types": "./dist/adapters/filesystem.d.mts",
|
|
@@ -159,7 +169,7 @@
|
|
|
159
169
|
"dependencies": {
|
|
160
170
|
"drizzle-orm": "^0.45.2",
|
|
161
171
|
"proper-lockfile": "^4.1.2",
|
|
162
|
-
"gscdump": "0.
|
|
172
|
+
"gscdump": "0.11.0"
|
|
163
173
|
},
|
|
164
174
|
"devDependencies": {
|
|
165
175
|
"@duckdb/duckdb-wasm": "^1.32.0",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { PlannerCapabilities } from "gscdump/query/plan";
|
|
2
|
-
import { TableName } from "gscdump/contracts";
|
|
3
|
-
import { BuilderState } from "gscdump/query";
|
|
4
|
-
type QueryRow = Record<string, unknown>;
|
|
5
|
-
interface FileSet {
|
|
6
|
-
table: TableName;
|
|
7
|
-
partitions: string[];
|
|
8
|
-
}
|
|
9
|
-
interface ExecuteSqlOptions {
|
|
10
|
-
fileSets?: Record<string, FileSet>;
|
|
11
|
-
}
|
|
12
|
-
interface SourceCapabilities extends PlannerCapabilities {
|
|
13
|
-
attachedTables?: boolean;
|
|
14
|
-
fileSets?: boolean;
|
|
15
|
-
localSource?: boolean;
|
|
16
|
-
}
|
|
17
|
-
interface RowQuerySource {
|
|
18
|
-
name?: string;
|
|
19
|
-
capabilities: SourceCapabilities;
|
|
20
|
-
queryRows: (state: BuilderState) => Promise<QueryRow[]>;
|
|
21
|
-
readonly executeSql?: undefined;
|
|
22
|
-
}
|
|
23
|
-
interface SqlQuerySource {
|
|
24
|
-
name?: string;
|
|
25
|
-
capabilities: SourceCapabilities;
|
|
26
|
-
queryRows: (state: BuilderState) => Promise<QueryRow[]>;
|
|
27
|
-
executeSql: (sql: string, params?: unknown[], opts?: ExecuteSqlOptions) => Promise<QueryRow[]>;
|
|
28
|
-
}
|
|
29
|
-
type AnalysisQuerySource = RowQuerySource | SqlQuerySource;
|
|
30
|
-
declare function isSqlQuerySource(s: AnalysisQuerySource): s is SqlQuerySource;
|
|
31
|
-
export { RowQuerySource as a, isSqlQuerySource as c, QueryRow as i, ExecuteSqlOptions as n, SourceCapabilities as o, FileSet as r, SqlQuerySource as s, AnalysisQuerySource as t };
|
|
File without changes
|