@malloy-publisher/server 0.13.0 → 0.13.1
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/dist/instrumentation.mjs +1 -1
- package/dist/package_load_worker.mjs +393 -58
- package/dist/server.mjs +9346 -8863
- package/package.json +1 -1
package/dist/instrumentation.mjs
CHANGED
|
@@ -166531,7 +166531,7 @@ var init_telemetry = __esm(() => {
|
|
|
166531
166531
|
});
|
|
166532
166532
|
|
|
166533
166533
|
// package.json
|
|
166534
|
-
var version = "0.13.
|
|
166534
|
+
var version = "0.13.1";
|
|
166535
166535
|
var init_package = () => {};
|
|
166536
166536
|
|
|
166537
166537
|
// src/version.ts
|
|
@@ -27934,16 +27934,7 @@ var init_materialization_metrics = __esm(() => {
|
|
|
27934
27934
|
900000,
|
|
27935
27935
|
3600000
|
|
27936
27936
|
];
|
|
27937
|
-
BUILD_READ_BYTES_BUCKETS = [
|
|
27938
|
-
1e6,
|
|
27939
|
-
1e7,
|
|
27940
|
-
1e8,
|
|
27941
|
-
1e9,
|
|
27942
|
-
10000000000,
|
|
27943
|
-
100000000000,
|
|
27944
|
-
1000000000000,
|
|
27945
|
-
10000000000000
|
|
27946
|
-
];
|
|
27937
|
+
BUILD_READ_BYTES_BUCKETS = [1e6, 1e7, 1e8, 1e9, 10000000000, 100000000000, 1000000000000, 10000000000000];
|
|
27947
27938
|
runCounter = lazyCounter("publisher_materialization_runs_total", "Materialization builds completed. Labels: mode ('auto'|'orchestrated'), outcome ('success'|'partial'|'failed'|'cancelled').");
|
|
27948
27939
|
runDuration = lazyHistogram("publisher_materialization_run_duration_ms", "Wall-clock duration of a materialization build. Label: mode ('auto'|'orchestrated').");
|
|
27949
27940
|
buildCounter = lazyCounter("publisher_materialization_build_total", "Source builds, one per source per run at its finish or failure. Labels: " + "kind ('materialize'|'persist'|'rollup'|'view'|'pair'), tier " + "('colocated'|'storage'), outcome ('built'|'reused'|'refused'|'failed'|" + "'cancelled'), failure_class ('none' unless outcome is 'failed'; then " + "'deterministic'|'transient'|'unclassified'|'billed_read_lost'). " + "'billed_read_lost' is the expensive one: the warehouse read ran and was " + "charged and its rows were not captured, so a retry pays for it again.");
|
|
@@ -30053,6 +30044,197 @@ var init_probe_compiler = __esm(() => {
|
|
|
30053
30044
|
CURRENT_TIME_SQL = /\b(?:current_timestamp|current_date|current_time|current_datetime|localtimestamp|localtime|sysdate|sysdatetime|sysutcdatetime|sysdatetimeoffset|getdate|getutcdate|transaction_timestamp|statement_timestamp|clock_timestamp|today|unix_timestamp|now)\b/gi;
|
|
30054
30045
|
});
|
|
30055
30046
|
|
|
30047
|
+
// src/service/governance/ir/array_query.ts
|
|
30048
|
+
import { isSourceDef as isSourceDef9 } from "@malloydata/malloy";
|
|
30049
|
+
function isObject(v) {
|
|
30050
|
+
return v !== null && typeof v === "object";
|
|
30051
|
+
}
|
|
30052
|
+
function stringPath(v) {
|
|
30053
|
+
return Array.isArray(v) && v.every((p) => typeof p === "string") ? v : undefined;
|
|
30054
|
+
}
|
|
30055
|
+
function arrayQueryParts(obj) {
|
|
30056
|
+
if (obj.node !== "arrayQuery")
|
|
30057
|
+
return;
|
|
30058
|
+
const array = isObject(obj.kids) ? obj.kids.array : undefined;
|
|
30059
|
+
const arrayPath = isObject(array) && array.node === "field" ? stringPath(array.path) : undefined;
|
|
30060
|
+
const pipeline = Array.isArray(obj.pipeline) ? obj.pipeline : [];
|
|
30061
|
+
return { arrayPath, firstStage: pipeline[0] };
|
|
30062
|
+
}
|
|
30063
|
+
function elementDeclaredNames(stage) {
|
|
30064
|
+
const names = new Set;
|
|
30065
|
+
const extend = isObject(stage) ? stage.extendSource : undefined;
|
|
30066
|
+
for (const f of Array.isArray(extend) ? extend : []) {
|
|
30067
|
+
if (!isObject(f) || f.join && isSourceDef9(f))
|
|
30068
|
+
continue;
|
|
30069
|
+
const name = typeof f.as === "string" ? f.as : f.name;
|
|
30070
|
+
if (typeof name === "string")
|
|
30071
|
+
names.add(name);
|
|
30072
|
+
}
|
|
30073
|
+
return names;
|
|
30074
|
+
}
|
|
30075
|
+
function forEachFieldPath(e, visit, options) {
|
|
30076
|
+
const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
30077
|
+
const seen = new Map;
|
|
30078
|
+
const walk = (v, prefix, declared, depth) => {
|
|
30079
|
+
if (!isObject(v) || depth > maxDepth)
|
|
30080
|
+
return;
|
|
30081
|
+
const key = prefix.join("\x00");
|
|
30082
|
+
let at = seen.get(key);
|
|
30083
|
+
if (!at)
|
|
30084
|
+
seen.set(key, at = new Set);
|
|
30085
|
+
if (at.has(v))
|
|
30086
|
+
return;
|
|
30087
|
+
at.add(v);
|
|
30088
|
+
if (Array.isArray(v)) {
|
|
30089
|
+
for (const item of v)
|
|
30090
|
+
walk(item, prefix, declared, depth + 1);
|
|
30091
|
+
return;
|
|
30092
|
+
}
|
|
30093
|
+
const path10 = v.node === "field" || options.fieldrefs && v.type === "fieldref" ? stringPath(v.path) : undefined;
|
|
30094
|
+
if (path10 && !(path10.length > 0 && declared.has(path10[0]))) {
|
|
30095
|
+
visit([...prefix, ...path10]);
|
|
30096
|
+
}
|
|
30097
|
+
const parts = arrayQueryParts(v);
|
|
30098
|
+
if (parts?.arrayPath) {
|
|
30099
|
+
walk(v.kids, prefix, declared, depth + 1);
|
|
30100
|
+
walk(parts.firstStage, [...prefix, ...parts.arrayPath], elementDeclaredNames(parts.firstStage), depth + 1);
|
|
30101
|
+
return;
|
|
30102
|
+
}
|
|
30103
|
+
for (const [k, child] of Object.entries(v)) {
|
|
30104
|
+
if (options.skipKeys.has(k))
|
|
30105
|
+
continue;
|
|
30106
|
+
walk(child, prefix, declared, depth + 1);
|
|
30107
|
+
}
|
|
30108
|
+
};
|
|
30109
|
+
walk(e, [], new Set, 0);
|
|
30110
|
+
}
|
|
30111
|
+
function locationOf(f) {
|
|
30112
|
+
const loc = isObject(f.location) ? f.location : undefined;
|
|
30113
|
+
if (!loc)
|
|
30114
|
+
return;
|
|
30115
|
+
const range = isObject(loc.range) ? loc.range : undefined;
|
|
30116
|
+
const start = range && isObject(range.start) ? range.start : undefined;
|
|
30117
|
+
return {
|
|
30118
|
+
...typeof loc.url === "string" ? { url: loc.url } : {},
|
|
30119
|
+
...typeof start?.line === "number" ? { line: start.line + 1 } : {}
|
|
30120
|
+
};
|
|
30121
|
+
}
|
|
30122
|
+
function joinsInside(arrayQuery) {
|
|
30123
|
+
const found = [];
|
|
30124
|
+
const seen = new Set;
|
|
30125
|
+
const walk = (v) => {
|
|
30126
|
+
if (!isObject(v) || seen.has(v))
|
|
30127
|
+
return;
|
|
30128
|
+
seen.add(v);
|
|
30129
|
+
if (Array.isArray(v.extendSource)) {
|
|
30130
|
+
for (const f of v.extendSource) {
|
|
30131
|
+
if (isObject(f) && f.join && isSourceDef9(f)) {
|
|
30132
|
+
const alias = typeof f.as === "string" ? f.as : f.name;
|
|
30133
|
+
const at = locationOf(f);
|
|
30134
|
+
found.push({
|
|
30135
|
+
alias: typeof alias === "string" ? alias : "",
|
|
30136
|
+
...at ? { at } : {}
|
|
30137
|
+
});
|
|
30138
|
+
}
|
|
30139
|
+
}
|
|
30140
|
+
}
|
|
30141
|
+
for (const [k, child] of Object.entries(v)) {
|
|
30142
|
+
if (!NOT_IR.has(k))
|
|
30143
|
+
walk(child);
|
|
30144
|
+
}
|
|
30145
|
+
};
|
|
30146
|
+
walk(arrayQuery);
|
|
30147
|
+
return found;
|
|
30148
|
+
}
|
|
30149
|
+
function arrayQueryJoins(root) {
|
|
30150
|
+
const inProgress = new Set;
|
|
30151
|
+
const walk = (v) => {
|
|
30152
|
+
if (!isObject(v))
|
|
30153
|
+
return [];
|
|
30154
|
+
const memo = joinsMemo.get(v);
|
|
30155
|
+
if (memo)
|
|
30156
|
+
return memo;
|
|
30157
|
+
if (inProgress.has(v))
|
|
30158
|
+
return [];
|
|
30159
|
+
inProgress.add(v);
|
|
30160
|
+
let found = NO_JOINS;
|
|
30161
|
+
if (v.node === "arrayQuery") {
|
|
30162
|
+
found = joinsInside(v);
|
|
30163
|
+
} else {
|
|
30164
|
+
for (const [k, child] of Object.entries(v)) {
|
|
30165
|
+
if (NOT_IR.has(k))
|
|
30166
|
+
continue;
|
|
30167
|
+
const under = walk(child);
|
|
30168
|
+
if (under.length > 0)
|
|
30169
|
+
found = [...found, ...under];
|
|
30170
|
+
}
|
|
30171
|
+
}
|
|
30172
|
+
inProgress.delete(v);
|
|
30173
|
+
joinsMemo.set(v, found);
|
|
30174
|
+
return found;
|
|
30175
|
+
};
|
|
30176
|
+
return walk(root);
|
|
30177
|
+
}
|
|
30178
|
+
function governsAccess(root) {
|
|
30179
|
+
if (!isObject(root))
|
|
30180
|
+
return false;
|
|
30181
|
+
const memo = governsMemo.get(root);
|
|
30182
|
+
if (memo !== undefined)
|
|
30183
|
+
return memo;
|
|
30184
|
+
const seen = new Set;
|
|
30185
|
+
const walk = (v) => {
|
|
30186
|
+
if (!isObject(v) || seen.has(v))
|
|
30187
|
+
return false;
|
|
30188
|
+
seen.add(v);
|
|
30189
|
+
if (Array.isArray(v))
|
|
30190
|
+
return v.some(walk);
|
|
30191
|
+
for (const key of ["notes", "blockNotes"]) {
|
|
30192
|
+
const notes = v[key];
|
|
30193
|
+
if (!Array.isArray(notes))
|
|
30194
|
+
continue;
|
|
30195
|
+
for (const note of notes) {
|
|
30196
|
+
const text = isObject(note) ? note.text : undefined;
|
|
30197
|
+
if (typeof text === "string" && GOVERNING_ROUTES.some((route) => isOnRoute(text, route))) {
|
|
30198
|
+
return true;
|
|
30199
|
+
}
|
|
30200
|
+
}
|
|
30201
|
+
}
|
|
30202
|
+
for (const [k, child] of Object.entries(v)) {
|
|
30203
|
+
if (k === "at" || k === "location")
|
|
30204
|
+
continue;
|
|
30205
|
+
if (walk(child))
|
|
30206
|
+
return true;
|
|
30207
|
+
}
|
|
30208
|
+
return false;
|
|
30209
|
+
};
|
|
30210
|
+
const governs = walk(root);
|
|
30211
|
+
governsMemo.set(root, governs);
|
|
30212
|
+
return governs;
|
|
30213
|
+
}
|
|
30214
|
+
function arrayQueryJoinRefusal(where, joins) {
|
|
30215
|
+
if (joins.length === 0)
|
|
30216
|
+
return;
|
|
30217
|
+
const named = Array.from(new Set(joins.map((j) => {
|
|
30218
|
+
const line = j.at?.line !== undefined ? ` (line ${j.at.line})` : "";
|
|
30219
|
+
return `\`${j.alias}\`${line}`;
|
|
30220
|
+
}))).join(", ");
|
|
30221
|
+
return `${where} joins a source inside a query on an array (\`items -> { extend: { join_one: … } }\`): ${named}. ` + `Publisher cannot follow what such a join reads, so #(authorize), #(access_filter), #(carries), ` + `#(classification) and the access record cannot account for it, and a model that declares any ` + `of them refuses it. Remove the join from the array query.`;
|
|
30222
|
+
}
|
|
30223
|
+
var GOVERNING_ROUTES, NO_JOINS, joinsMemo, NOT_IR, governsMemo;
|
|
30224
|
+
var init_array_query = __esm(() => {
|
|
30225
|
+
init_annotation_reader();
|
|
30226
|
+
GOVERNING_ROUTES = [
|
|
30227
|
+
"authorize",
|
|
30228
|
+
"access_filter",
|
|
30229
|
+
"carries",
|
|
30230
|
+
"classification"
|
|
30231
|
+
];
|
|
30232
|
+
NO_JOINS = [];
|
|
30233
|
+
joinsMemo = new WeakMap;
|
|
30234
|
+
NOT_IR = new Set(["at", "location", "annotations"]);
|
|
30235
|
+
governsMemo = new WeakMap;
|
|
30236
|
+
});
|
|
30237
|
+
|
|
30056
30238
|
// src/service/materialization/plan/persist_dynamic_terms.ts
|
|
30057
30239
|
import { Annotations as Annotations3 } from "@malloydata/malloy";
|
|
30058
30240
|
function givenNames(node) {
|
|
@@ -30452,24 +30634,11 @@ function readRollingWindows(entry) {
|
|
|
30452
30634
|
};
|
|
30453
30635
|
return walk(e, 0) ? out : undefined;
|
|
30454
30636
|
}
|
|
30455
|
-
function fieldPaths(node, out
|
|
30456
|
-
|
|
30457
|
-
|
|
30458
|
-
|
|
30459
|
-
|
|
30460
|
-
for (const item of node)
|
|
30461
|
-
fieldPaths(item, out, depth + 1);
|
|
30462
|
-
return;
|
|
30463
|
-
}
|
|
30464
|
-
const record = node;
|
|
30465
|
-
if (record.node === "field" && Array.isArray(record.path) && record.path.length > 0 && record.path.every((p) => typeof p === "string")) {
|
|
30466
|
-
out.add(record.path.join("."));
|
|
30467
|
-
}
|
|
30468
|
-
for (const [key, value] of Object.entries(record)) {
|
|
30469
|
-
if (key === "at" || key === "location" || key === "annotations")
|
|
30470
|
-
continue;
|
|
30471
|
-
fieldPaths(value, out, depth + 1);
|
|
30472
|
-
}
|
|
30637
|
+
function fieldPaths(node, out) {
|
|
30638
|
+
forEachFieldPath(node, (path10) => {
|
|
30639
|
+
if (path10.length > 0)
|
|
30640
|
+
out.add(path10.join("."));
|
|
30641
|
+
}, { skipKeys: FIELD_PATH_SKIPPED_KEYS, maxDepth: MAX_WALK_DEPTH2 });
|
|
30473
30642
|
}
|
|
30474
30643
|
function dependsOnCurrentTime(path10, timeFields) {
|
|
30475
30644
|
const parts = path10.split(".");
|
|
@@ -30545,11 +30714,12 @@ function fieldsDependingOn(fields, reads, depth = 0) {
|
|
|
30545
30714
|
}
|
|
30546
30715
|
return out;
|
|
30547
30716
|
}
|
|
30548
|
-
var MAX_WALK_DEPTH2 = 200, JOIN_ONLY_KEYS, MAX_JOIN_DEPTH = 4, COMPARISONS, MIRROR;
|
|
30717
|
+
var MAX_WALK_DEPTH2 = 200, JOIN_ONLY_KEYS, MAX_JOIN_DEPTH = 4, COMPARISONS, MIRROR, FIELD_PATH_SKIPPED_KEYS;
|
|
30549
30718
|
var init_persist_dynamic_terms = __esm(() => {
|
|
30550
30719
|
init_motly();
|
|
30551
30720
|
init_given();
|
|
30552
30721
|
init_probe_compiler();
|
|
30722
|
+
init_array_query();
|
|
30553
30723
|
init_malloy_text();
|
|
30554
30724
|
JOIN_ONLY_KEYS = [
|
|
30555
30725
|
"join",
|
|
@@ -30565,6 +30735,7 @@ var init_persist_dynamic_terms = __esm(() => {
|
|
|
30565
30735
|
"<": ">",
|
|
30566
30736
|
"<=": ">="
|
|
30567
30737
|
};
|
|
30738
|
+
FIELD_PATH_SKIPPED_KEYS = new Set(["at", "location", "annotations"]);
|
|
30568
30739
|
});
|
|
30569
30740
|
|
|
30570
30741
|
// src/service/materialization/plan/incremental_declaration.ts
|
|
@@ -31922,7 +32093,7 @@ var init_query_text = __esm(() => {
|
|
|
31922
32093
|
});
|
|
31923
32094
|
|
|
31924
32095
|
// src/service/materialization/plan/source_map.ts
|
|
31925
|
-
import { isSourceDef as
|
|
32096
|
+
import { isSourceDef as isSourceDef10 } from "@malloydata/malloy";
|
|
31926
32097
|
function structRefSourceId(structRef) {
|
|
31927
32098
|
if (typeof structRef === "string")
|
|
31928
32099
|
return structRef;
|
|
@@ -32067,7 +32238,7 @@ function reachableSourceIDs(roots, modelDef) {
|
|
|
32067
32238
|
add(structRefSourceId(member));
|
|
32068
32239
|
visit(typeof member === "string" ? byId(modelDef, member) : member);
|
|
32069
32240
|
}
|
|
32070
|
-
if (modelDef !== undefined &&
|
|
32241
|
+
if (modelDef !== undefined && isSourceDef10(node)) {
|
|
32071
32242
|
const struct = node;
|
|
32072
32243
|
const model = modelDef;
|
|
32073
32244
|
const declared = resolveDeclaredSource(struct, model);
|
|
@@ -36122,6 +36293,18 @@ function pairKeyChecks(pair, blocks, sourceID, build, connection) {
|
|
|
36122
36293
|
...on
|
|
36123
36294
|
});
|
|
36124
36295
|
});
|
|
36296
|
+
const hops = p.hops ?? [];
|
|
36297
|
+
const last = hops[hops.length - 1];
|
|
36298
|
+
const leafNames = [p.join, ...hops.map((h) => h.join)];
|
|
36299
|
+
out.push({
|
|
36300
|
+
join: leafNames.join("."),
|
|
36301
|
+
keyColumn: last?.key ?? p.childKey,
|
|
36302
|
+
queryName: `${build}__pair_leaf_key__${leafNames.join("__")}`,
|
|
36303
|
+
joinedSourceID: last?.sourceID ?? p.childSourceID,
|
|
36304
|
+
pairLevel: leafNames.length,
|
|
36305
|
+
recordOnly: true,
|
|
36306
|
+
...on
|
|
36307
|
+
});
|
|
36125
36308
|
}
|
|
36126
36309
|
return out;
|
|
36127
36310
|
}
|
|
@@ -36954,6 +37137,8 @@ function uniquenessCheckCompiler(check) {
|
|
|
36954
37137
|
}
|
|
36955
37138
|
async function assertInlinedJoinsUnique(plan2, connection, ledger, storedJoin) {
|
|
36956
37139
|
for (const check of plan2?.uniquenessChecks ?? []) {
|
|
37140
|
+
if (check.recordOnly)
|
|
37141
|
+
continue;
|
|
36957
37142
|
if (!check.sql) {
|
|
36958
37143
|
throw new InlinedJoinNotUniqueError(plan2?.sourceName ?? "", check.join, check.keyColumn, true, check.pairLevel);
|
|
36959
37144
|
}
|
|
@@ -36990,6 +37175,15 @@ async function assertInlinedJoinsUnique(plan2, connection, ledger, storedJoin) {
|
|
|
36990
37175
|
}
|
|
36991
37176
|
}
|
|
36992
37177
|
}
|
|
37178
|
+
function pairLeafKeyChecksOf(plan2) {
|
|
37179
|
+
return (plan2?.uniquenessChecks ?? []).flatMap((check) => check.recordOnly && check.sql ? [
|
|
37180
|
+
{
|
|
37181
|
+
sourceID: check.joinedSourceID,
|
|
37182
|
+
keyColumn: check.keyColumn,
|
|
37183
|
+
sql: check.sql
|
|
37184
|
+
}
|
|
37185
|
+
] : []);
|
|
37186
|
+
}
|
|
36993
37187
|
function storedKeyCheckSql(quotedTable, keyColumn) {
|
|
36994
37188
|
const k = `"${keyColumn.replace(/"/g, '""')}"`;
|
|
36995
37189
|
return `SELECT ${k} FROM ${quotedTable} GROUP BY ${k} HAVING COUNT(*) > 1 OR ${k} IS NULL LIMIT 1`;
|
|
@@ -37289,13 +37483,138 @@ function duckdbTypeToMalloyType(duckdbType) {
|
|
|
37289
37483
|
return { unmapped: "unrecognized" };
|
|
37290
37484
|
}
|
|
37291
37485
|
}
|
|
37292
|
-
function
|
|
37293
|
-
const
|
|
37294
|
-
|
|
37295
|
-
|
|
37296
|
-
|
|
37297
|
-
|
|
37298
|
-
return
|
|
37486
|
+
function storedMalloyType(stored) {
|
|
37487
|
+
const parsed = parseStoredType(stored);
|
|
37488
|
+
return parsed && renderStoredType(parsed);
|
|
37489
|
+
}
|
|
37490
|
+
function storedMalloyTypeFor(stored, field, keepsBigIntegers) {
|
|
37491
|
+
const parsed = parseStoredType(stored);
|
|
37492
|
+
return parsed && fitStoredType(parsed, field, keepsBigIntegers);
|
|
37493
|
+
}
|
|
37494
|
+
function parseStoredType(stored) {
|
|
37495
|
+
const parsed = parseNestedType(stored.trim());
|
|
37496
|
+
if (parsed === undefined || parsed.rest.trim() !== "")
|
|
37497
|
+
return;
|
|
37498
|
+
return parsed.type;
|
|
37499
|
+
}
|
|
37500
|
+
function renderStoredType(t) {
|
|
37501
|
+
switch (t.kind) {
|
|
37502
|
+
case "scalar":
|
|
37503
|
+
return t.malloyType;
|
|
37504
|
+
case "array":
|
|
37505
|
+
return `${renderStoredType(t.element)}[]`;
|
|
37506
|
+
case "record":
|
|
37507
|
+
return `{ ${t.fields.map((f) => `${identifier(f.name)}::${renderStoredType(f.type)}`).join(", ")} }`;
|
|
37508
|
+
}
|
|
37509
|
+
}
|
|
37510
|
+
function fitStoredType(t, field, keepsBigIntegers) {
|
|
37511
|
+
const live = field ?? {};
|
|
37512
|
+
switch (t.kind) {
|
|
37513
|
+
case "array": {
|
|
37514
|
+
if (live.type !== "array")
|
|
37515
|
+
return;
|
|
37516
|
+
const element = live.elementTypeDef;
|
|
37517
|
+
const inner = fitStoredType(t.element, element?.type === "record_element" ? { type: "record", fields: live.fields } : element, keepsBigIntegers);
|
|
37518
|
+
return inner && `${inner}[]`;
|
|
37519
|
+
}
|
|
37520
|
+
case "record": {
|
|
37521
|
+
if (live.type !== "record" || !Array.isArray(live.fields)) {
|
|
37522
|
+
return;
|
|
37523
|
+
}
|
|
37524
|
+
const liveFields = live.fields;
|
|
37525
|
+
if (liveFields.length !== t.fields.length)
|
|
37526
|
+
return;
|
|
37527
|
+
const parts = [];
|
|
37528
|
+
for (const f of t.fields) {
|
|
37529
|
+
const match = liveFields.find((l) => (l.as ?? l.name) === f.name);
|
|
37530
|
+
const inner = match && fitStoredType(f.type, match, keepsBigIntegers);
|
|
37531
|
+
if (!inner)
|
|
37532
|
+
return;
|
|
37533
|
+
parts.push(`${identifier(f.name)}::${inner}`);
|
|
37534
|
+
}
|
|
37535
|
+
return `{ ${parts.join(", ")} }`;
|
|
37536
|
+
}
|
|
37537
|
+
case "scalar":
|
|
37538
|
+
if (live.type === "number") {
|
|
37539
|
+
return t.malloyType === "number" && !(keepsBigIntegers && live.numberType === "bigint") ? "number" : undefined;
|
|
37540
|
+
}
|
|
37541
|
+
if (live.type === "timestamptz" && t.malloyType === "timestamp" && /^(TIMESTAMP WITH TIME ZONE|TIMESTAMPTZ)$/i.test(t.raw.trim())) {
|
|
37542
|
+
return "timestamptz";
|
|
37543
|
+
}
|
|
37544
|
+
return live.type === t.malloyType ? t.malloyType : undefined;
|
|
37545
|
+
}
|
|
37546
|
+
}
|
|
37547
|
+
function parseNestedType(s, depth = 0) {
|
|
37548
|
+
if (depth > 16)
|
|
37549
|
+
return;
|
|
37550
|
+
let type;
|
|
37551
|
+
let rest;
|
|
37552
|
+
const struct = /^STRUCT\s*\(/i.exec(s);
|
|
37553
|
+
if (struct) {
|
|
37554
|
+
rest = s.slice(struct[0].length);
|
|
37555
|
+
const fields = [];
|
|
37556
|
+
for (;; ) {
|
|
37557
|
+
const name = /^\s*("(?:[^"]|"")*"|[A-Za-z_][A-Za-z0-9_]*)\s+/.exec(rest);
|
|
37558
|
+
if (!name)
|
|
37559
|
+
return;
|
|
37560
|
+
const fieldName3 = name[1].startsWith('"') ? name[1].slice(1, -1).replace(/""/g, '"') : name[1];
|
|
37561
|
+
const inner = parseNestedType(rest.slice(name[0].length), depth + 1);
|
|
37562
|
+
if (!inner)
|
|
37563
|
+
return;
|
|
37564
|
+
fields.push({ name: fieldName3, type: inner.type });
|
|
37565
|
+
rest = inner.rest.trimStart();
|
|
37566
|
+
if (rest.startsWith(",")) {
|
|
37567
|
+
rest = rest.slice(1);
|
|
37568
|
+
continue;
|
|
37569
|
+
}
|
|
37570
|
+
if (!rest.startsWith(")"))
|
|
37571
|
+
return;
|
|
37572
|
+
rest = rest.slice(1);
|
|
37573
|
+
break;
|
|
37574
|
+
}
|
|
37575
|
+
type = { kind: "record", fields };
|
|
37576
|
+
} else {
|
|
37577
|
+
const scalar = /^[A-Za-z_][A-Za-z0-9_ ]*?(\([0-9,\s]*\))?(?=\s*(\[|,|\)|$))/.exec(s);
|
|
37578
|
+
if (!scalar)
|
|
37579
|
+
return;
|
|
37580
|
+
const mapped = duckdbTypeToMalloyType(scalar[0]);
|
|
37581
|
+
if (!("type" in mapped))
|
|
37582
|
+
return;
|
|
37583
|
+
type = { kind: "scalar", raw: scalar[0], malloyType: mapped.type };
|
|
37584
|
+
rest = s.slice(scalar[0].length);
|
|
37585
|
+
}
|
|
37586
|
+
for (;; ) {
|
|
37587
|
+
const list2 = /^\s*\[\s*\]/.exec(rest);
|
|
37588
|
+
if (!list2)
|
|
37589
|
+
break;
|
|
37590
|
+
type = { kind: "array", element: type };
|
|
37591
|
+
rest = rest.slice(list2[0].length);
|
|
37592
|
+
}
|
|
37593
|
+
return { type, rest };
|
|
37594
|
+
}
|
|
37595
|
+
function declarableColumns(schema) {
|
|
37596
|
+
const declared = [];
|
|
37597
|
+
const leftOut = [];
|
|
37598
|
+
for (const c of schema) {
|
|
37599
|
+
const malloyType = storedMalloyType(c.type);
|
|
37600
|
+
if (malloyType !== undefined)
|
|
37601
|
+
declared.push({ ...c, malloyType });
|
|
37602
|
+
else
|
|
37603
|
+
leftOut.push({ name: c.name, type: c.type.trim() });
|
|
37604
|
+
}
|
|
37605
|
+
return { declared, leftOut };
|
|
37606
|
+
}
|
|
37607
|
+
function reportLeftOutColumns(sourceName, leftOut) {
|
|
37608
|
+
if (leftOut.length === 0)
|
|
37609
|
+
return;
|
|
37610
|
+
for (const c of leftOut) {
|
|
37611
|
+
const mapped = duckdbTypeToMalloyType(c.type);
|
|
37612
|
+
recordServeShapeTypeFallback("unmapped" in mapped ? mapped.unmapped : "unrecognized");
|
|
37613
|
+
}
|
|
37614
|
+
logger.warn("Stored columns no Malloy type declaration reads faithfully were left out of the serve shape; queries reading them answer live", { sourceName, columns: leftOut.map((c) => `${c.name} ${c.type}`) });
|
|
37615
|
+
}
|
|
37616
|
+
function describeColumns(columns) {
|
|
37617
|
+
return columns.map((c) => `'${c.name}' (${c.type})`).join(", ");
|
|
37299
37618
|
}
|
|
37300
37619
|
function buildServeShapeModel(sourceName, binding) {
|
|
37301
37620
|
const fragment = serveShapeFragment({
|
|
@@ -37317,7 +37636,9 @@ function serveShapeGivenLine(given) {
|
|
|
37317
37636
|
function serveShapeFragment(binding) {
|
|
37318
37637
|
const shapeTypeName = identifier(`${binding.sourceName}__shape`);
|
|
37319
37638
|
const sourceName = identifier(binding.sourceName);
|
|
37320
|
-
const
|
|
37639
|
+
const { declared, leftOut } = declarableColumns(binding.schema);
|
|
37640
|
+
reportLeftOutColumns(binding.sourceName, leftOut);
|
|
37641
|
+
const fields = declared.map((c) => ` ${identifier(c.name)}::${c.malloyType}`).join(`,
|
|
37321
37642
|
`);
|
|
37322
37643
|
const virtual = `${identifier(binding.destinationName)}.virtual(${stringLiteral(binding.virtualHandle)})::${shapeTypeName}`;
|
|
37323
37644
|
const casts = new Map((binding.readCasts ?? []).map((c) => [c.column, c]));
|
|
@@ -37329,12 +37650,12 @@ function serveShapeFragment(binding) {
|
|
|
37329
37650
|
const stored = identifier(`${binding.sourceName}__stored`);
|
|
37330
37651
|
prelude = `source: ${stored} is ${virtual}
|
|
37331
37652
|
`;
|
|
37332
|
-
const select =
|
|
37653
|
+
const select = declared.map((c) => {
|
|
37333
37654
|
const name = identifier(c.name);
|
|
37334
37655
|
const cast = casts.get(c.name);
|
|
37335
37656
|
if (!cast)
|
|
37336
37657
|
return name;
|
|
37337
|
-
return cast.native ? `${name} is ${name}::${doubleQuotedString(cast.castTo)}` : `${name} is ${name}::${
|
|
37658
|
+
return cast.native ? `${name} is ${name}::${doubleQuotedString(cast.castTo)}` : `${name} is ${name}::${storedMalloyType(cast.castTo) ?? doubleQuotedString(cast.castTo)}`;
|
|
37338
37659
|
}).join(", ");
|
|
37339
37660
|
source = `source: ${sourceName} is ${stored} -> { select: ${select} }`;
|
|
37340
37661
|
}
|
|
@@ -37808,6 +38129,17 @@ function buildVirtualMap(bindings) {
|
|
|
37808
38129
|
return map;
|
|
37809
38130
|
}
|
|
37810
38131
|
async function assertServesInDuckDB(sourceName, binding, connections) {
|
|
38132
|
+
const refuse = (detail) => {
|
|
38133
|
+
recordEligibilityRefused("not_duckdb_portable");
|
|
38134
|
+
throw new MaterializationEligibilityError({
|
|
38135
|
+
reason: "not_duckdb_portable",
|
|
38136
|
+
message: `Source '${sourceName}' cannot be served from its storage ` + `destination: ${detail}. A source materialized into a ` + `DuckDB/DuckLake store must have a DuckDB-portable served shape.`
|
|
38137
|
+
});
|
|
38138
|
+
};
|
|
38139
|
+
const { declared, leftOut } = declarableColumns(binding.schema);
|
|
38140
|
+
if (declared.length === 0 && leftOut.length > 0) {
|
|
38141
|
+
refuse(`no stored column has a Malloy type that reads it back faithfully ` + `(${describeColumns(leftOut)})`);
|
|
38142
|
+
}
|
|
37811
38143
|
const { modelText } = buildServeShapeModel(sourceName, binding);
|
|
37812
38144
|
const root = "file:///serve-shape/";
|
|
37813
38145
|
const urlReader = new InMemoryURLReader(new Map([[`${root}shape.malloy`, modelText]]));
|
|
@@ -37817,10 +38149,7 @@ async function assertServesInDuckDB(sourceName, binding, connections) {
|
|
|
37817
38149
|
importBaseURL: new URL(root)
|
|
37818
38150
|
}).getModel();
|
|
37819
38151
|
} catch (err) {
|
|
37820
|
-
|
|
37821
|
-
throw new MaterializationEligibilityError({
|
|
37822
|
-
message: `Source '${sourceName}' cannot be served from its storage ` + `destination: its materialized shape does not compile in DuckDB ` + `(${err instanceof Error ? err.message : String(err)}). A source ` + `materialized into a DuckDB/DuckLake store must have a ` + `DuckDB-portable served shape.`
|
|
37823
|
-
});
|
|
38152
|
+
refuse(`its materialized shape does not compile in DuckDB ` + `(${err instanceof Error ? err.message : String(err)})` + (leftOut.length > 0 ? `; left out of it: ${describeColumns(leftOut)}` : ""));
|
|
37824
38153
|
}
|
|
37825
38154
|
}
|
|
37826
38155
|
var NEVER_THINNED, REFINEMENT_TIER_KINDS, liftContextByModel, UNREPRODUCIBLE_FILTER = "__unreproducible_filter__";
|
|
@@ -37906,6 +38235,12 @@ function castToDeclaredTypes(selectSQL, declared, options = {}) {
|
|
|
37906
38235
|
return selectSQL;
|
|
37907
38236
|
return `SELECT * REPLACE (${casts.join(", ")}) ${fromSubselect(selectSQL, "__declared_types")}`;
|
|
37908
38237
|
}
|
|
38238
|
+
function keepsWarehouseType(warehouseType, declaredType) {
|
|
38239
|
+
if (declaredType !== "string")
|
|
38240
|
+
return false;
|
|
38241
|
+
const base = warehouseType.replace(/\(.*\)/, "").trim().toUpperCase();
|
|
38242
|
+
return base === "BLOB" || base === "BYTEA" || base === "INTERVAL";
|
|
38243
|
+
}
|
|
37909
38244
|
function buildCastTarget(declaredType, options = {}) {
|
|
37910
38245
|
if (declaredType === "date" && options.queryTimezone)
|
|
37911
38246
|
return;
|
|
@@ -37949,7 +38284,7 @@ function faithfulCastTarget(m, options = {}) {
|
|
|
37949
38284
|
return;
|
|
37950
38285
|
}
|
|
37951
38286
|
function rebuildWouldRecast(schema, declared, options = {}) {
|
|
37952
|
-
const recast = storedColumnTypeMismatches(schema, declared).filter((m) => buildCastTarget(m.declaredType, options) !== undefined);
|
|
38287
|
+
const recast = storedColumnTypeMismatches(schema, declared).filter((m) => buildCastTarget(m.declaredType, options) !== undefined && !keepsWarehouseType(m.storedType, m.declaredType));
|
|
37953
38288
|
const sure = recast.every((m) => m.declaredType === "string" || faithfulCastTarget(m, options) !== undefined);
|
|
37954
38289
|
return sure ? recast : [];
|
|
37955
38290
|
}
|
|
@@ -39735,7 +40070,7 @@ var init_plan_layers = __esm(() => {
|
|
|
39735
40070
|
// src/service/materialization/plan/build_plan.ts
|
|
39736
40071
|
import * as path14 from "path";
|
|
39737
40072
|
import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL7 } from "url";
|
|
39738
|
-
import { Annotations as Annotations9, isSourceDef as
|
|
40073
|
+
import { Annotations as Annotations9, isSourceDef as isSourceDef11 } from "@malloydata/malloy";
|
|
39739
40074
|
function wireTerm(term) {
|
|
39740
40075
|
return { code: term.code, givens: term.givens };
|
|
39741
40076
|
}
|
|
@@ -39830,7 +40165,7 @@ function declaredPersistSourceIDs(malloyModel) {
|
|
|
39830
40165
|
const ids = [];
|
|
39831
40166
|
try {
|
|
39832
40167
|
for (const def of Object.values(malloyModel._modelDef?.contents ?? {})) {
|
|
39833
|
-
if (!
|
|
40168
|
+
if (!isSourceDef11(def) || !def.annotations)
|
|
39834
40169
|
continue;
|
|
39835
40170
|
try {
|
|
39836
40171
|
if (routeHasKey(new Annotations9(def.annotations), "@", "persist")) {
|
|
@@ -39846,7 +40181,7 @@ function sourceIDsWithNoteAt(malloyModel, at) {
|
|
|
39846
40181
|
const ids = [];
|
|
39847
40182
|
try {
|
|
39848
40183
|
for (const def of Object.values(malloyModel._modelDef?.contents ?? {})) {
|
|
39849
|
-
if (!
|
|
40184
|
+
if (!isSourceDef11(def) || !def.annotations || !def.sourceID)
|
|
39850
40185
|
continue;
|
|
39851
40186
|
try {
|
|
39852
40187
|
const notes = new Annotations9(def.annotations).forRoute("@");
|
|
@@ -39991,7 +40326,7 @@ async function collectGeneratedMaterialize(parts, args) {
|
|
|
39991
40326
|
recordTarget(parts, sourceID, source);
|
|
39992
40327
|
parts.sourceModelPaths[sourceID] = args.modelPath;
|
|
39993
40328
|
parts.materializePlans[sourceID] = plan2;
|
|
39994
|
-
const authorSource = Object.values(authorDef.contents ?? {}).find((object) =>
|
|
40329
|
+
const authorSource = Object.values(authorDef.contents ?? {}).find((object) => isSourceDef11(object) && object.sourceID === sourceID);
|
|
39995
40330
|
parts.sourceGateOutcomes[sourceID] = authorSource ? await classifyPersistSourceGate({ _sourceDef: authorSource, sourceID }, authorDef, args.materializer, deps, args.modelPath) : { classification: "rejected", attributed: false };
|
|
39996
40331
|
}
|
|
39997
40332
|
}
|
|
@@ -40097,7 +40432,7 @@ async function collectGeneratedPersistedViews(parts, args) {
|
|
|
40097
40432
|
parts.sources[source.sourceID] = source;
|
|
40098
40433
|
recordTarget(parts, source.sourceID, source);
|
|
40099
40434
|
parts.sourceModelPaths[source.sourceID] = args.modelPath;
|
|
40100
|
-
const authorSource = Object.values(authorDef.contents ?? {}).find((object) =>
|
|
40435
|
+
const authorSource = Object.values(authorDef.contents ?? {}).find((object) => isSourceDef11(object) && object.sourceID === plan2.sourceID);
|
|
40101
40436
|
parts.sourceGateOutcomes[source.sourceID] = authorSource ? await classifyPersistSourceGate({ _sourceDef: authorSource, sourceID: plan2.sourceID }, authorDef, args.materializer, deps, args.modelPath) : { classification: "rejected", attributed: false };
|
|
40102
40437
|
}
|
|
40103
40438
|
if (kept > 0)
|
|
@@ -40663,14 +40998,14 @@ var toString, getPrototypeOf, iterator, toStringTag, hasOwnProperty, isUnsafeObj
|
|
|
40663
40998
|
}, kindOf2, kindOfTest = (type) => {
|
|
40664
40999
|
type = type.toLowerCase();
|
|
40665
41000
|
return (thing) => kindOf2(thing) === type;
|
|
40666
|
-
}, typeOfTest = (type) => (thing) => typeof thing === type, isArray, isUndefined, isArrayBuffer, isString, isFunction, isNumber,
|
|
40667
|
-
if (!
|
|
41001
|
+
}, typeOfTest = (type) => (thing) => typeof thing === type, isArray, isUndefined, isArrayBuffer, isString, isFunction, isNumber, isObject2 = (thing) => thing !== null && typeof thing === "object", isBoolean = (thing) => thing === true || thing === false, isPlainObject = (val) => {
|
|
41002
|
+
if (!isObject2(val)) {
|
|
40668
41003
|
return false;
|
|
40669
41004
|
}
|
|
40670
41005
|
const prototype = getPrototypeOf(val);
|
|
40671
41006
|
return (prototype === null || prototype === Object.prototype || getPrototypeOf(prototype) === null) && !hasOwnInPrototypeChain(val, toStringTag) && !hasOwnInPrototypeChain(val, iterator);
|
|
40672
41007
|
}, isEmptyObject = (val) => {
|
|
40673
|
-
if (!
|
|
41008
|
+
if (!isObject2(val) || isBuffer(val)) {
|
|
40674
41009
|
return false;
|
|
40675
41010
|
}
|
|
40676
41011
|
try {
|
|
@@ -40680,7 +41015,7 @@ var toString, getPrototypeOf, iterator, toStringTag, hasOwnProperty, isUnsafeObj
|
|
|
40680
41015
|
}
|
|
40681
41016
|
}, isDate, isFile, isReactNativeBlob = (value) => {
|
|
40682
41017
|
return !!(value && typeof value.uri !== "undefined");
|
|
40683
|
-
}, isReactNative = (formData) => formData && typeof formData.getParts !== "undefined", isBlob, isFileList, isSet, isStream = (val) =>
|
|
41018
|
+
}, isReactNative = (formData) => formData && typeof formData.getParts !== "undefined", isBlob, isFileList, isSet, isStream = (val) => isObject2(val) && isFunction(val.pipe), G, FormDataCtor, isFormData = (thing) => {
|
|
40684
41019
|
if (!thing)
|
|
40685
41020
|
return false;
|
|
40686
41021
|
if (FormDataCtor && thing instanceof FormDataCtor)
|
|
@@ -40838,7 +41173,7 @@ var toString, getPrototypeOf, iterator, toStringTag, hasOwnProperty, isUnsafeObj
|
|
|
40838
41173
|
}, toJSONObject = (obj) => {
|
|
40839
41174
|
const visited = new WeakSet;
|
|
40840
41175
|
const visit = (source) => {
|
|
40841
|
-
if (
|
|
41176
|
+
if (isObject2(source)) {
|
|
40842
41177
|
if (visited.has(source)) {
|
|
40843
41178
|
return;
|
|
40844
41179
|
}
|
|
@@ -40868,7 +41203,7 @@ var toString, getPrototypeOf, iterator, toStringTag, hasOwnProperty, isUnsafeObj
|
|
|
40868
41203
|
return source;
|
|
40869
41204
|
};
|
|
40870
41205
|
return visit(obj);
|
|
40871
|
-
}, isAsyncFn, isThenable = (thing) => thing && (
|
|
41206
|
+
}, isAsyncFn, isThenable = (thing) => thing && (isObject2(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch), _setImmediate, asap, isIterable = (thing) => thing != null && isFunction(thing[iterator]), isSafeIterable = (thing) => thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing), utils_default;
|
|
40872
41207
|
var init_utils2 = __esm(() => {
|
|
40873
41208
|
({ toString } = Object.prototype);
|
|
40874
41209
|
({ getPrototypeOf } = Object);
|
|
@@ -40938,7 +41273,7 @@ var init_utils2 = __esm(() => {
|
|
|
40938
41273
|
isString,
|
|
40939
41274
|
isNumber,
|
|
40940
41275
|
isBoolean,
|
|
40941
|
-
isObject,
|
|
41276
|
+
isObject: isObject2,
|
|
40942
41277
|
isPlainObject,
|
|
40943
41278
|
isEmptyObject,
|
|
40944
41279
|
isReadableStream,
|