@malloy-publisher/server 0.18.3 → 0.18.5
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/app/api-doc.yaml +67 -9
- package/dist/app/assets/{EnvironmentPage-CsFUI8IX.js → EnvironmentPage-C3gdsp81.js} +1 -1
- package/dist/app/assets/{HomePage-B_FVtnN-.js → HomePage-DqgKtxBQ.js} +1 -1
- package/dist/app/assets/{MainPage-wFF9nPEr.js → MainPage-BnTI-1vD.js} +1 -1
- package/dist/app/assets/{ModelPage-CxenqDcz.js → ModelPage-eLIQM9Js.js} +2 -2
- package/dist/app/assets/{PackagePage-dcF6vrvw.js → PackagePage-CejLNGDv.js} +1 -1
- package/dist/app/assets/{PackageSplatRoute-CASBZk0k.js → PackageSplatRoute-CXdCJTYw.js} +2 -2
- package/dist/app/assets/{RenderedResult--fYcsY1h.es-DzOt5Lwv.js → RenderedResult-cJiP774J.es-CZC2lkLE.js} +1 -1
- package/dist/app/assets/{RouteError-CUIolYwb.js → RouteError-_sExFuNk.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-DgU2YYq6.js → ThemeEditorPage-CaJX95t_.js} +1 -1
- package/dist/app/assets/{ToggleButtonGroup-Dmr-hVlD.js → ToggleButtonGroup-DogvpiUV.js} +1 -1
- package/dist/app/assets/{documentRoutes-Drv-WDwO.js → documentRoutes-G_kvP2a6.js} +1 -1
- package/dist/app/assets/{editPageMounted-C5yJiIVi.js → editPageMounted-CM_VLUwp.js} +2 -2
- package/dist/app/assets/{index-BIoSdsU9.js → index-CYndXhSx.js} +1 -1
- package/dist/app/assets/{index-Dtw4eTxH.js → index-D9nJPs77.js} +1 -1
- package/dist/app/assets/{index-DxF3kMLJ.js → index-O_b7OJ2r.js} +1 -1
- package/dist/app/assets/{index-BSyL0zds.js → index-b7pou7Vk.js} +15 -15
- package/dist/app/assets/{index.es-CX9m4CBD.js → index.es-DQ-xbkiQ.js} +1 -1
- package/dist/app/assets/usePackageLinkNavigate-Lw9XmylW.js +1 -0
- package/dist/app/assets/{usePackageRoute-wJGaZEiY.js → usePackageRoute-yIGqS2C8.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/instrumentation.mjs +1 -1
- package/dist/package_load_worker.mjs +1366 -558
- package/dist/server.mjs +2275 -503
- package/package.json +2 -2
- package/dist/app/assets/usePackageLinkNavigate-qNjcXPcY.js +0 -1
|
@@ -12805,7 +12805,7 @@ function errorMapping(error) {
|
|
|
12805
12805
|
function errorReason(error) {
|
|
12806
12806
|
return resolve(errorMapping(error).reason, error);
|
|
12807
12807
|
}
|
|
12808
|
-
var GENERIC_INTERNAL_MESSAGE = "Internal server error.", GENERIC_UPSTREAM_MESSAGE = "Upstream connection error.", GENERIC_UNREACHABLE_MESSAGE = "The database connection is down: the database could not be reached, so the query did not run.", GENERIC_AUTH_MESSAGE = "The database rejected the connection's credentials. Check the connection's user, password, key or token.", MAX_LOGGED_DETAIL_CHARS = 2000, PACKAGE_VERSION_ERROR_STATUS, PackageVersionError, FILESYSTEM_ACCESS_DESCRIPTIONS, POSTGRES_STATEMENT_SQLSTATES, POSTGRES_UNDEFINED_TABLE = "42P01", POSTGRES_RELATION_MISSING, BuildPlanUnavailableError, BuildPlanRefreshingError, NotImplementedError, BadRequestError, BuildInstructionsInvalidError, TableOwnershipError, InvalidArgumentError, CompileRefusedError, InvalidModelPathError, InvalidQueryRequestError, RenderTagRefusedError, UnparseableTextError, EnvironmentNotFoundError, PackageNotFoundError, ModelNotFoundError, DashboardNotFoundError, SkillNotFoundError, AgentNotFoundError, ConflictError, ConnectionNotFoundError, TableNotFoundError, ConnectionError, ConnectionFailedError, ResultTruncatedError, UnconfiguredConnectionError, ConnectionPoolExhaustedError, ResultShapeError, DestinationNotFoundError, StorageDestinationNotFoundError, StorageCatalogNotFoundError, ConnectionAuthError, StorageAccessDeniedError, UnsupportedCatalogFormatError, ModelCompilationError, VersionFilesMissingError, PackageManifestError, MaterializationEligibilityError, ChainedUpstreamMissingError, ChainedShapeNotCarriedError, ContractCaptureFailedError, SchemaIncompatibleError, PublisherConfigError, ServerConfigurationError, FrozenConfigError, AccessDeniedError, QueryCompileError, NotQueryableError, OffSurfaceError, MaterializationNotFoundError, MaterializationConflictError, MaterializedTableDropRefusedError, WriteConflictError, InstalledFromLocationError, WriteRolledBackError, ManifestBindFailedError, WriteRollbackFailedError, ConnectionSaveError, WriteVerifyError, InvalidStateTransitionError, ServiceUnavailableError, PackageAdmissionRefusedError, DryRunCapacityError, PayloadTooLargeError, ResponseUnserializableError, QueryTimeoutError, ERROR_CLASSES, UNHANDLED_LOG, UNHANDLED, NOT_TRANSIENT_CHANGE_QUERY = "This is not transient. The same query will fail the same way, so change the query rather than retrying it.", BACK_PRESSURE_SUGGESTIONS, BACK_PRESSURE, TOO_LARGE, BAD_REQUEST, NOT_FOUND, CONNECTION, ERROR_TABLE;
|
|
12808
|
+
var GENERIC_INTERNAL_MESSAGE = "Internal server error.", GENERIC_UPSTREAM_MESSAGE = "Upstream connection error.", GENERIC_UNREACHABLE_MESSAGE = "The database connection is down: the database could not be reached, so the query did not run.", GENERIC_AUTH_MESSAGE = "The database rejected the connection's credentials. Check the connection's user, password, key or token.", MAX_LOGGED_DETAIL_CHARS = 2000, PACKAGE_VERSION_ERROR_STATUS, PackageVersionError, FILESYSTEM_ACCESS_DESCRIPTIONS, POSTGRES_STATEMENT_SQLSTATES, POSTGRES_UNDEFINED_TABLE = "42P01", POSTGRES_RELATION_MISSING, BuildPlanUnavailableError, BuildPlanRefreshingError, NotImplementedError, BadRequestError, BuildInstructionsInvalidError, TableOwnershipError, InvalidArgumentError, CompileRefusedError, InvalidModelPathError, InvalidQueryRequestError, RenderTagRefusedError, UnparseableTextError, EnvironmentNotFoundError, PackageNotFoundError, ModelNotFoundError, DashboardNotFoundError, SkillNotFoundError, AgentNotFoundError, ConflictError, ConnectionNotFoundError, TableNotFoundError, ConnectionError, ConnectionFailedError, ResultTruncatedError, UnconfiguredConnectionError, ConnectionPoolExhaustedError, ResultShapeError, DestinationNotFoundError, ContainerNotFoundError, StorageDestinationNotFoundError, StorageCatalogNotFoundError, ConnectionAuthError, StorageAccessDeniedError, UnsupportedCatalogFormatError, ModelCompilationError, VersionFilesMissingError, PackageManifestError, MaterializationEligibilityError, ChainedUpstreamMissingError, ChainedShapeNotCarriedError, ContractCaptureFailedError, SchemaIncompatibleError, PublisherConfigError, ServerConfigurationError, FrozenConfigError, AccessDeniedError, QueryCompileError, NotQueryableError, OffSurfaceError, MaterializationNotFoundError, MaterializationConflictError, MaterializedTableDropRefusedError, WriteConflictError, InstalledFromLocationError, WriteRolledBackError, ManifestBindFailedError, WriteRollbackFailedError, ConnectionSaveError, WriteVerifyError, InvalidStateTransitionError, ServiceUnavailableError, PackageAdmissionRefusedError, DryRunCapacityError, PayloadTooLargeError, ResponseUnserializableError, QueryTimeoutError, ERROR_CLASSES, UNHANDLED_LOG, UNHANDLED, NOT_TRANSIENT_CHANGE_QUERY = "This is not transient. The same query will fail the same way, so change the query rather than retrying it.", BACK_PRESSURE_SUGGESTIONS, BACK_PRESSURE, TOO_LARGE, BAD_REQUEST, NOT_FOUND, CONNECTION, ERROR_TABLE;
|
|
12809
12809
|
var init_errors2 = __esm(() => {
|
|
12810
12810
|
init_constants();
|
|
12811
12811
|
init_logger();
|
|
@@ -13090,6 +13090,15 @@ var init_errors2 = __esm(() => {
|
|
|
13090
13090
|
super(message);
|
|
13091
13091
|
}
|
|
13092
13092
|
};
|
|
13093
|
+
ContainerNotFoundError = class ContainerNotFoundError extends Error {
|
|
13094
|
+
get kind() {
|
|
13095
|
+
return "container_not_found";
|
|
13096
|
+
}
|
|
13097
|
+
constructor(message) {
|
|
13098
|
+
super(message);
|
|
13099
|
+
this.name = "ContainerNotFoundError";
|
|
13100
|
+
}
|
|
13101
|
+
};
|
|
13093
13102
|
StorageDestinationNotFoundError = class StorageDestinationNotFoundError extends Error {
|
|
13094
13103
|
get kind() {
|
|
13095
13104
|
return "storage_destination_not_found";
|
|
@@ -13489,6 +13498,7 @@ var init_errors2 = __esm(() => {
|
|
|
13489
13498
|
result_truncated: ResultTruncatedError,
|
|
13490
13499
|
result_shape: ResultShapeError,
|
|
13491
13500
|
destination_not_found: DestinationNotFoundError,
|
|
13501
|
+
container_not_found: ContainerNotFoundError,
|
|
13492
13502
|
storage_destination_not_found: StorageDestinationNotFoundError,
|
|
13493
13503
|
storage_catalog_not_found: StorageCatalogNotFoundError,
|
|
13494
13504
|
connection_auth: ConnectionAuthError,
|
|
@@ -13694,6 +13704,7 @@ var init_errors2 = __esm(() => {
|
|
|
13694
13704
|
},
|
|
13695
13705
|
storage_catalog_not_found: { status: 404, mcp: { advice: "internal" } },
|
|
13696
13706
|
destination_not_found: { status: 422, mcp: { advice: "internal" } },
|
|
13707
|
+
container_not_found: { status: 422, mcp: { advice: "internal" } },
|
|
13697
13708
|
connection_auth: {
|
|
13698
13709
|
status: 424,
|
|
13699
13710
|
message: GENERIC_AUTH_MESSAGE,
|
|
@@ -20380,6 +20391,21 @@ function kindOf(def, base) {
|
|
|
20380
20391
|
return "rename";
|
|
20381
20392
|
return "query";
|
|
20382
20393
|
}
|
|
20394
|
+
function detachedNode(def) {
|
|
20395
|
+
const d = def;
|
|
20396
|
+
if (!d || typeof d !== "object" || typeof d.sourceID !== "string") {
|
|
20397
|
+
return;
|
|
20398
|
+
}
|
|
20399
|
+
const base = baseEdgeOf(d, undefined);
|
|
20400
|
+
return {
|
|
20401
|
+
sourceID: d.sourceID,
|
|
20402
|
+
name: undefined,
|
|
20403
|
+
kind: kindOf(d, base),
|
|
20404
|
+
base,
|
|
20405
|
+
members: compositeMemberIds(d),
|
|
20406
|
+
def: d
|
|
20407
|
+
};
|
|
20408
|
+
}
|
|
20383
20409
|
function sourceChain(struct, modelDef) {
|
|
20384
20410
|
return SourceMap.of(modelDef).chainOf(struct);
|
|
20385
20411
|
}
|
|
@@ -29804,7 +29830,8 @@ var init_dialect = __esm(() => {
|
|
|
29804
29830
|
catalogHidesTables: false,
|
|
29805
29831
|
stringCollation: undefined,
|
|
29806
29832
|
ungroupableTypes: undefined,
|
|
29807
|
-
binary64Types: undefined
|
|
29833
|
+
binary64Types: undefined,
|
|
29834
|
+
containerCatalog: undefined
|
|
29808
29835
|
});
|
|
29809
29836
|
CAPABILITIES = {
|
|
29810
29837
|
duckdb: Object.freeze({
|
|
@@ -29823,10 +29850,12 @@ var init_dialect = __esm(() => {
|
|
|
29823
29850
|
utcSessions: true,
|
|
29824
29851
|
leafBudget: 120,
|
|
29825
29852
|
stringCollation: "instance",
|
|
29826
|
-
binary64Types: ["DOUBLE", "FLOAT8"]
|
|
29853
|
+
binary64Types: ["DOUBLE", "FLOAT8"],
|
|
29854
|
+
containerCatalog: "duckdb_schemas"
|
|
29827
29855
|
}),
|
|
29828
29856
|
postgres: Object.freeze({
|
|
29829
29857
|
...NONE,
|
|
29858
|
+
containerCatalog: "pg_namespace",
|
|
29830
29859
|
stringCollation: "column",
|
|
29831
29860
|
passthroughNumericAsDouble: true,
|
|
29832
29861
|
incrementalSourceRange: true,
|
|
@@ -29872,6 +29901,7 @@ var init_dialect = __esm(() => {
|
|
|
29872
29901
|
onlyBigIntegerType: "INT64",
|
|
29873
29902
|
leafBudget: 120,
|
|
29874
29903
|
stringCollation: "dataset",
|
|
29904
|
+
containerCatalog: "dataset",
|
|
29875
29905
|
ungroupableTypes: {
|
|
29876
29906
|
malloy: ["json", "array", "record"],
|
|
29877
29907
|
native: ["geography"]
|
|
@@ -29879,6 +29909,7 @@ var init_dialect = __esm(() => {
|
|
|
29879
29909
|
}),
|
|
29880
29910
|
snowflake: Object.freeze({
|
|
29881
29911
|
...NONE,
|
|
29912
|
+
containerCatalog: "schemata",
|
|
29882
29913
|
decodedTablePath: true,
|
|
29883
29914
|
catalogHidesTables: true,
|
|
29884
29915
|
incrementalSourceRange: true,
|
|
@@ -33720,7 +33751,46 @@ function namesServedCopyAlias(text) {
|
|
|
33720
33751
|
function withoutServedCopyAliases(text) {
|
|
33721
33752
|
return text.replace(new RegExp(`'?__publisher_storage_${TOKEN}_\\d+'?`, "g"), "the storage destination");
|
|
33722
33753
|
}
|
|
33723
|
-
function
|
|
33754
|
+
function destinationOfAlias(name) {
|
|
33755
|
+
return destinationsByAlias.get(name);
|
|
33756
|
+
}
|
|
33757
|
+
function servedConnectionLabel(name) {
|
|
33758
|
+
const destination = destinationsByAlias.get(name);
|
|
33759
|
+
return destination !== undefined ? `storage destination '${destination}'` : `connection '${name}'`;
|
|
33760
|
+
}
|
|
33761
|
+
function underAlias(connection, alias) {
|
|
33762
|
+
let views = aliasedViews.get(connection);
|
|
33763
|
+
if (!views) {
|
|
33764
|
+
views = new Map;
|
|
33765
|
+
aliasedViews.set(connection, views);
|
|
33766
|
+
}
|
|
33767
|
+
const known = views.get(alias);
|
|
33768
|
+
if (known)
|
|
33769
|
+
return known;
|
|
33770
|
+
const view = new Proxy(connection, {
|
|
33771
|
+
get(target, prop) {
|
|
33772
|
+
if (prop === "name")
|
|
33773
|
+
return alias;
|
|
33774
|
+
if (prop === "fetchSchemaForTables") {
|
|
33775
|
+
return async (...args) => {
|
|
33776
|
+
const fetched = await target.fetchSchemaForTables(...args);
|
|
33777
|
+
return {
|
|
33778
|
+
...fetched,
|
|
33779
|
+
schemas: Object.fromEntries(Object.entries(fetched.schemas).map(([key, def]) => [
|
|
33780
|
+
key,
|
|
33781
|
+
{ ...def, connection: alias }
|
|
33782
|
+
]))
|
|
33783
|
+
};
|
|
33784
|
+
};
|
|
33785
|
+
}
|
|
33786
|
+
const value = Reflect.get(target, prop, target);
|
|
33787
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
33788
|
+
}
|
|
33789
|
+
});
|
|
33790
|
+
views.set(alias, view);
|
|
33791
|
+
return view;
|
|
33792
|
+
}
|
|
33793
|
+
function servedCopyConfig(packageConfig, destinations, allowed, tablesUnderAlias = new Set) {
|
|
33724
33794
|
const base = toMalloyConfig(packageConfig);
|
|
33725
33795
|
const config = new MalloyConfig2({ connections: {} });
|
|
33726
33796
|
config.wrapConnections(() => ({
|
|
@@ -33731,7 +33801,8 @@ function servedCopyConfig(packageConfig, destinations, allowed) {
|
|
|
33731
33801
|
if (!allowed.has(destination)) {
|
|
33732
33802
|
throw new Error(`A storage destination is not available to this served copy`);
|
|
33733
33803
|
}
|
|
33734
|
-
|
|
33804
|
+
const connection = await destinations.connections.lookupConnection(destination);
|
|
33805
|
+
return tablesUnderAlias.has(destination) ? underAlias(connection, name) : connection;
|
|
33735
33806
|
}
|
|
33736
33807
|
}
|
|
33737
33808
|
return base.connections.lookupConnection(name);
|
|
@@ -33739,16 +33810,35 @@ function servedCopyConfig(packageConfig, destinations, allowed) {
|
|
|
33739
33810
|
}));
|
|
33740
33811
|
return config;
|
|
33741
33812
|
}
|
|
33742
|
-
var TOKEN, aliases, destinationsByAlias;
|
|
33813
|
+
var TOKEN, aliases, destinationsByAlias, aliasedViews;
|
|
33743
33814
|
var init_served_copy_config = __esm(() => {
|
|
33744
33815
|
init_model_runtime();
|
|
33745
33816
|
TOKEN = randomBytes(12).toString("hex");
|
|
33746
33817
|
aliases = new Map;
|
|
33747
33818
|
destinationsByAlias = new Map;
|
|
33819
|
+
aliasedViews = new WeakMap;
|
|
33748
33820
|
});
|
|
33749
33821
|
|
|
33750
33822
|
// src/service/materialization/text/cross_connection_text.ts
|
|
33751
33823
|
import { MalloyError as MalloyError3 } from "@malloydata/malloy";
|
|
33824
|
+
function refusedJoinConnections(message) {
|
|
33825
|
+
const named = /which is on connection '([^']*)', into a source on connection '([^']*)'/.exec(message ?? "");
|
|
33826
|
+
return named ? { joined: named[1], into: named[2] } : undefined;
|
|
33827
|
+
}
|
|
33828
|
+
function refusedJoinPairs(error) {
|
|
33829
|
+
if (!isCrossConnectionRefusal(error))
|
|
33830
|
+
return;
|
|
33831
|
+
const pairs = [];
|
|
33832
|
+
for (const p of errorProblems(error) ?? []) {
|
|
33833
|
+
if (p.code !== JOIN_CONNECTION_MISMATCH)
|
|
33834
|
+
continue;
|
|
33835
|
+
const pair = refusedJoinConnections(p.message);
|
|
33836
|
+
if (!pair)
|
|
33837
|
+
return;
|
|
33838
|
+
pairs.push(pair);
|
|
33839
|
+
}
|
|
33840
|
+
return pairs;
|
|
33841
|
+
}
|
|
33752
33842
|
function isJoinConnectionMismatch(code) {
|
|
33753
33843
|
return code === JOIN_CONNECTION_MISMATCH;
|
|
33754
33844
|
}
|
|
@@ -33865,10 +33955,12 @@ async function leaveOut(args, escalated) {
|
|
|
33865
33955
|
continue;
|
|
33866
33956
|
}
|
|
33867
33957
|
cuts.push(cut);
|
|
33958
|
+
const connections = refused ? refusedJoinConnections(p.message) : undefined;
|
|
33868
33959
|
leftOut.push({
|
|
33869
33960
|
url,
|
|
33870
33961
|
...cut.left,
|
|
33871
33962
|
crossConnection: refused,
|
|
33963
|
+
...connections ? { connections } : {},
|
|
33872
33964
|
...cut !== own && own?.left.keyword.startsWith("join_") ? { join: own.left.name } : {}
|
|
33873
33965
|
});
|
|
33874
33966
|
}
|
|
@@ -33991,6 +34083,9 @@ var init_served_copy_containment = __esm(() => {
|
|
|
33991
34083
|
});
|
|
33992
34084
|
|
|
33993
34085
|
// src/service/materialization/text/kept_ancestors.ts
|
|
34086
|
+
function nodeIn(map, sourceID, elsewhere) {
|
|
34087
|
+
return map.node(sourceID) ?? detachedNode(elsewhere?.(sourceID));
|
|
34088
|
+
}
|
|
33994
34089
|
function plainRenamesOf(map, sourceID, url) {
|
|
33995
34090
|
const out = [];
|
|
33996
34091
|
const reached = new Set([sourceID]);
|
|
@@ -34040,15 +34135,15 @@ function locatedIn(def, url) {
|
|
|
34040
34135
|
const location = def?.location;
|
|
34041
34136
|
return location?.url === url && typeof location.range?.start?.line === "number" && typeof location.range?.end?.line === "number" ? location.range : undefined;
|
|
34042
34137
|
}
|
|
34043
|
-
function keptAncestorChain(map, sourceID, url) {
|
|
34138
|
+
function keptAncestorChain(map, sourceID, url, elsewhere) {
|
|
34044
34139
|
const out = [];
|
|
34045
|
-
let node = map
|
|
34140
|
+
let node = nodeIn(map, sourceID, elsewhere);
|
|
34046
34141
|
let childURL = url;
|
|
34047
34142
|
for (let hops = 0;node && hops < MAX_HOPS; hops++) {
|
|
34048
34143
|
const base = node.base;
|
|
34049
34144
|
if (!base || base.hop === "query" || base.sourceID === undefined)
|
|
34050
34145
|
break;
|
|
34051
|
-
const parent = map
|
|
34146
|
+
const parent = nodeIn(map, base.sourceID, elsewhere);
|
|
34052
34147
|
const parentURL = declaringURLOf(parent?.def);
|
|
34053
34148
|
const range = parentURL ? locatedIn(parent?.def, parentURL) : undefined;
|
|
34054
34149
|
if (!parent || !parentURL || !range)
|
|
@@ -34065,17 +34160,29 @@ function keptAncestorChain(map, sourceID, url) {
|
|
|
34065
34160
|
}
|
|
34066
34161
|
return out;
|
|
34067
34162
|
}
|
|
34068
|
-
function keptAncestorChainOrDeclared(map, sourceID, url, fileText) {
|
|
34069
|
-
const
|
|
34070
|
-
const
|
|
34071
|
-
|
|
34072
|
-
|
|
34073
|
-
|
|
34074
|
-
|
|
34075
|
-
|
|
34076
|
-
|
|
34163
|
+
function keptAncestorChainOrDeclared(map, sourceID, url, fileText, elsewhere) {
|
|
34164
|
+
const out = [];
|
|
34165
|
+
const seen = new Set([sourceID]);
|
|
34166
|
+
let tail = { sourceID, url };
|
|
34167
|
+
for (let hops = 0;hops < MAX_HOPS; hops++) {
|
|
34168
|
+
const chain = keptAncestorChain(map, tail.sourceID, tail.url, elsewhere);
|
|
34169
|
+
out.push(...chain);
|
|
34170
|
+
tail = chain.at(-1) ?? tail;
|
|
34171
|
+
const node = nodeIn(map, tail.sourceID, elsewhere);
|
|
34172
|
+
if (!node || node.base !== undefined)
|
|
34173
|
+
break;
|
|
34174
|
+
const base = declaredTableBase(node.def, tail.url, fileText, (id) => nodeIn(map, id, elsewhere));
|
|
34175
|
+
for (const a of chain)
|
|
34176
|
+
seen.add(a.sourceID);
|
|
34177
|
+
if (!base || seen.has(base.sourceID))
|
|
34178
|
+
break;
|
|
34179
|
+
seen.add(base.sourceID);
|
|
34180
|
+
out.push(base);
|
|
34181
|
+
tail = base;
|
|
34182
|
+
}
|
|
34183
|
+
return out;
|
|
34077
34184
|
}
|
|
34078
|
-
function declaredTableBase(def, url,
|
|
34185
|
+
function declaredTableBase(def, url, fileText, nodeOf) {
|
|
34079
34186
|
const own = def;
|
|
34080
34187
|
if (own?.type !== "table")
|
|
34081
34188
|
return;
|
|
@@ -34086,8 +34193,8 @@ function declaredTableBase(def, url, map, fileText) {
|
|
|
34086
34193
|
const name = declaredBaseName(text, range);
|
|
34087
34194
|
if (name === undefined)
|
|
34088
34195
|
return;
|
|
34089
|
-
const parentID =
|
|
34090
|
-
const parent = parentID ?
|
|
34196
|
+
const parentID = declaredBaseID(name, url, text, nodeOf);
|
|
34197
|
+
const parent = parentID ? nodeOf(parentID) : undefined;
|
|
34091
34198
|
const base = parent?.def;
|
|
34092
34199
|
if (!parent || base?.type !== "table" || base.connection !== own.connection || base.tablePath !== own.tablePath) {
|
|
34093
34200
|
return;
|
|
@@ -34103,6 +34210,16 @@ function declaredTableBase(def, url, map, fileText) {
|
|
|
34103
34210
|
}
|
|
34104
34211
|
return { sourceID: parent.sourceID, url: parentURL, range: parentRange };
|
|
34105
34212
|
}
|
|
34213
|
+
function declaredBaseID(name, url, text, nodeOf) {
|
|
34214
|
+
const imports = topLevelImports(text, url);
|
|
34215
|
+
if (!imports)
|
|
34216
|
+
return;
|
|
34217
|
+
const found = [
|
|
34218
|
+
`${name}@${url}`,
|
|
34219
|
+
...imports.filter((i) => i.whole).map((i) => `${name}@${i.resolved}`)
|
|
34220
|
+
].filter((id) => nodeOf(id) !== undefined);
|
|
34221
|
+
return found.length === 1 ? found[0] : undefined;
|
|
34222
|
+
}
|
|
34106
34223
|
function fieldList(def) {
|
|
34107
34224
|
return Array.isArray(def.fields) ? def.fields : [];
|
|
34108
34225
|
}
|
|
@@ -34298,6 +34415,7 @@ var MAX_HOPS = 64;
|
|
|
34298
34415
|
var init_kept_ancestors = __esm(() => {
|
|
34299
34416
|
init_declaration_text();
|
|
34300
34417
|
init_malloy_lexer_core();
|
|
34418
|
+
init_source_map();
|
|
34301
34419
|
init_table_plans();
|
|
34302
34420
|
});
|
|
34303
34421
|
|
|
@@ -37307,6 +37425,436 @@ var init_query_walks = __esm(() => {
|
|
|
37307
37425
|
walks = new Map;
|
|
37308
37426
|
});
|
|
37309
37427
|
|
|
37428
|
+
// src/service/materialization/domain/same_catalog_build.ts
|
|
37429
|
+
function isSameCatalog(source, destination) {
|
|
37430
|
+
const a = source?.type === "ducklake" ? source.ducklakeConnection : undefined;
|
|
37431
|
+
const b = destination?.type === "ducklake" ? destination.ducklakeConnection : undefined;
|
|
37432
|
+
if (!a || !b)
|
|
37433
|
+
return false;
|
|
37434
|
+
const pa = a.catalog?.postgresConnection;
|
|
37435
|
+
const pb = b.catalog?.postgresConnection;
|
|
37436
|
+
if (!pa || !pb)
|
|
37437
|
+
return false;
|
|
37438
|
+
const path = (url) => (url ?? "").replace(/\/+$/, "");
|
|
37439
|
+
const pathA = path(a.storage?.bucketUrl);
|
|
37440
|
+
const pathB = path(b.storage?.bucketUrl);
|
|
37441
|
+
return !!pa.host && pa.host === pb.host && (pa.port ?? 5432) === (pb.port ?? 5432) && !!pa.databaseName && pa.databaseName === pb.databaseName && (a.catalog.metadataSchema ?? "") === (b.catalog.metadataSchema ?? "") && (pathA === "" || pathB === "" || pathA === pathB);
|
|
37442
|
+
}
|
|
37443
|
+
function carriesAuthorSql(def) {
|
|
37444
|
+
return authorSqlCause(def) !== undefined;
|
|
37445
|
+
}
|
|
37446
|
+
function authorSqlCause(def) {
|
|
37447
|
+
const seen = new Set;
|
|
37448
|
+
const walk = (node, depth, frames) => {
|
|
37449
|
+
if (depth > MAX_DEPTH3)
|
|
37450
|
+
return { found: UNREADABLE2, frames };
|
|
37451
|
+
if (node === null || typeof node !== "object")
|
|
37452
|
+
return;
|
|
37453
|
+
if (seen.has(node))
|
|
37454
|
+
return;
|
|
37455
|
+
seen.add(node);
|
|
37456
|
+
if (Array.isArray(node)) {
|
|
37457
|
+
for (const child of node) {
|
|
37458
|
+
const hit = walk(child, depth + 1, frames);
|
|
37459
|
+
if (hit)
|
|
37460
|
+
return hit;
|
|
37461
|
+
}
|
|
37462
|
+
return;
|
|
37463
|
+
}
|
|
37464
|
+
const record = node;
|
|
37465
|
+
if (typeof record.join === "string") {
|
|
37466
|
+
frames = [
|
|
37467
|
+
...frames,
|
|
37468
|
+
{
|
|
37469
|
+
kind: "join",
|
|
37470
|
+
as: String(record.as ?? record.name ?? ""),
|
|
37471
|
+
source: sourceNameOf(record)
|
|
37472
|
+
}
|
|
37473
|
+
];
|
|
37474
|
+
}
|
|
37475
|
+
if (record.type === "sql_select") {
|
|
37476
|
+
return { found: { kind: "sql_source" }, frames };
|
|
37477
|
+
}
|
|
37478
|
+
if (record.node === "genericSQLExpr") {
|
|
37479
|
+
return { found: { kind: "sql_expression" }, frames };
|
|
37480
|
+
}
|
|
37481
|
+
if (record.type === "table" && typeof record.tablePath === "string" && !CATALOG_TABLE_PATH.test(record.tablePath)) {
|
|
37482
|
+
return {
|
|
37483
|
+
found: { kind: "file_table", path: record.tablePath },
|
|
37484
|
+
frames
|
|
37485
|
+
};
|
|
37486
|
+
}
|
|
37487
|
+
for (const [key, child] of Object.entries(record)) {
|
|
37488
|
+
if (record.node === "function_call" && key === "overload")
|
|
37489
|
+
continue;
|
|
37490
|
+
const hit = key === "fields" && Array.isArray(child) ? walkFields(child, depth + 1, frames) : walk(child, depth + 1, key === "structRef" && child !== null && typeof child === "object" ? [
|
|
37491
|
+
...frames,
|
|
37492
|
+
{
|
|
37493
|
+
kind: "reads",
|
|
37494
|
+
source: sourceNameOf(child)
|
|
37495
|
+
}
|
|
37496
|
+
] : frames);
|
|
37497
|
+
if (hit)
|
|
37498
|
+
return hit;
|
|
37499
|
+
}
|
|
37500
|
+
return;
|
|
37501
|
+
};
|
|
37502
|
+
const walkFields = (fields, depth, frames) => {
|
|
37503
|
+
if (depth > MAX_DEPTH3)
|
|
37504
|
+
return { found: UNREADABLE2, frames };
|
|
37505
|
+
if (seen.has(fields))
|
|
37506
|
+
return;
|
|
37507
|
+
seen.add(fields);
|
|
37508
|
+
for (const field of fields) {
|
|
37509
|
+
const f = field;
|
|
37510
|
+
const named = f !== null && typeof f === "object" && typeof f.name === "string" && typeof f.join !== "string";
|
|
37511
|
+
const hit = walk(field, depth + 1, named ? [...frames, { kind: "field", name: String(f.name) }] : frames);
|
|
37512
|
+
if (hit)
|
|
37513
|
+
return hit;
|
|
37514
|
+
}
|
|
37515
|
+
return;
|
|
37516
|
+
};
|
|
37517
|
+
try {
|
|
37518
|
+
if (def === null || typeof def !== "object")
|
|
37519
|
+
return describe([], UNREADABLE2);
|
|
37520
|
+
const hit = walk(def, 0, []);
|
|
37521
|
+
return hit ? describe(hit.frames, hit.found) : undefined;
|
|
37522
|
+
} catch {
|
|
37523
|
+
return describe([], UNREADABLE2);
|
|
37524
|
+
}
|
|
37525
|
+
}
|
|
37526
|
+
function sourceNameOf(record) {
|
|
37527
|
+
const id = typeof record.sourceID === "string" ? record.sourceID : "";
|
|
37528
|
+
const name = typeof record.name === "string" ? record.name : "";
|
|
37529
|
+
return id.split("@")[0] || (name.startsWith("sql://") ? "" : name);
|
|
37530
|
+
}
|
|
37531
|
+
function describe(frames, found) {
|
|
37532
|
+
if (found.kind === "unreadable") {
|
|
37533
|
+
return "its definition could not be read to check for SQL its author wrote";
|
|
37534
|
+
}
|
|
37535
|
+
frames = frames.filter((frame, i) => frame.kind !== "reads" || i === frames.length - 1 && found.kind !== "sql_expression");
|
|
37536
|
+
const parts = [];
|
|
37537
|
+
let lead = true;
|
|
37538
|
+
for (const frame of frames) {
|
|
37539
|
+
const possessive = lead ? "its" : "whose";
|
|
37540
|
+
const subject = lead ? "it" : "which";
|
|
37541
|
+
lead = false;
|
|
37542
|
+
if (frame.kind === "join") {
|
|
37543
|
+
parts.push(`${possessive} join '${frame.as}'` + (frame.source ? ` reads source '${frame.source}'` : ""));
|
|
37544
|
+
} else if (frame.kind === "reads") {
|
|
37545
|
+
parts.push(frame.source ? `${subject} reads source '${frame.source}'` : `${subject} reads a source`);
|
|
37546
|
+
} else {
|
|
37547
|
+
parts.push(`${possessive} field '${frame.name}'`);
|
|
37548
|
+
}
|
|
37549
|
+
}
|
|
37550
|
+
const last = frames[frames.length - 1];
|
|
37551
|
+
const subject = frames.length === 0 ? "it" : ", which";
|
|
37552
|
+
const what = found.kind === "sql_source" ? `${subject} is an .sql() source` : found.kind === "file_table" ? `${subject} reads '${found.path.replace(/^'|'$/g, "")}' as a table` : last?.kind === "field" ? " uses a sql_* expression" : `${subject} uses a sql_* expression`;
|
|
37553
|
+
return (parts.join(", ") + what).replace(/^ /, "");
|
|
37554
|
+
}
|
|
37555
|
+
var CATALOG_TABLE_PATH, MAX_DEPTH3 = 200, UNREADABLE2;
|
|
37556
|
+
var init_same_catalog_build = __esm(() => {
|
|
37557
|
+
CATALOG_TABLE_PATH = /^[A-Za-z_][A-Za-z0-9_$]*(\.[A-Za-z_][A-Za-z0-9_$]*)*$/;
|
|
37558
|
+
UNREADABLE2 = { kind: "unreadable" };
|
|
37559
|
+
});
|
|
37560
|
+
|
|
37561
|
+
// src/service/materialization/serve/same_catalog_reads.ts
|
|
37562
|
+
function destinationTablePath(path, move) {
|
|
37563
|
+
const parts = path.split(".");
|
|
37564
|
+
if (!PLAIN.test(move.destination) || !parts.every((p) => PLAIN.test(p))) {
|
|
37565
|
+
return;
|
|
37566
|
+
}
|
|
37567
|
+
const self2 = move.connection.toLowerCase();
|
|
37568
|
+
const readable = (s) => move.schemas.has(s.toLowerCase());
|
|
37569
|
+
const at = (schema, table) => `${move.destination}.${schema}.${table}`;
|
|
37570
|
+
if (parts.length === 1)
|
|
37571
|
+
return at("main", parts[0]);
|
|
37572
|
+
if (parts.length === 2) {
|
|
37573
|
+
const [first, table] = parts;
|
|
37574
|
+
if (first.toLowerCase() === self2) {
|
|
37575
|
+
return readable(first) ? undefined : at("main", table);
|
|
37576
|
+
}
|
|
37577
|
+
return readable(first) ? at(first, table) : undefined;
|
|
37578
|
+
}
|
|
37579
|
+
if (parts.length === 3) {
|
|
37580
|
+
const [catalog, schema, table] = parts;
|
|
37581
|
+
return catalog.toLowerCase() === self2 && readable(schema) ? at(schema, table) : undefined;
|
|
37582
|
+
}
|
|
37583
|
+
return;
|
|
37584
|
+
}
|
|
37585
|
+
function literalValue(token) {
|
|
37586
|
+
const m = /^(['"])([^'"\\]*)\1$/.exec(token?.text ?? "");
|
|
37587
|
+
return m ? m[2] : undefined;
|
|
37588
|
+
}
|
|
37589
|
+
function namesConnection(token, name) {
|
|
37590
|
+
return token.kind === "word" && token.text === name || token.text.length === name.length + 2 && token.text.startsWith("`") && token.text.endsWith("`") && token.text.slice(1, -1) === name;
|
|
37591
|
+
}
|
|
37592
|
+
function readThroughDestination(text, move) {
|
|
37593
|
+
const tokens = lexAll(text);
|
|
37594
|
+
if (!tokens)
|
|
37595
|
+
return;
|
|
37596
|
+
const edits = [];
|
|
37597
|
+
const paths = [];
|
|
37598
|
+
for (let k = 0;k < tokens.length; k++) {
|
|
37599
|
+
const t = tokens[k];
|
|
37600
|
+
if (!namesConnection(t, move.connection))
|
|
37601
|
+
continue;
|
|
37602
|
+
if (tokens[k - 1]?.text === ".")
|
|
37603
|
+
continue;
|
|
37604
|
+
if (tokens[k + 1]?.text !== ".")
|
|
37605
|
+
continue;
|
|
37606
|
+
const method = tokens[k + 2];
|
|
37607
|
+
if (method?.kind !== "word")
|
|
37608
|
+
continue;
|
|
37609
|
+
if (method.text !== "table")
|
|
37610
|
+
return;
|
|
37611
|
+
const value = literalValue(tokens[k + 4]);
|
|
37612
|
+
if (tokens[k + 3]?.text !== "(" || value === undefined || tokens[k + 5]?.text !== ")") {
|
|
37613
|
+
return;
|
|
37614
|
+
}
|
|
37615
|
+
const moved = destinationTablePath(value, move);
|
|
37616
|
+
if (moved === undefined)
|
|
37617
|
+
return;
|
|
37618
|
+
paths.push(value);
|
|
37619
|
+
edits.push({
|
|
37620
|
+
start: t.start,
|
|
37621
|
+
end: tokens[k + 5].end,
|
|
37622
|
+
text: `${identifier(move.alias)}.table(${stringLiteral(moved)})`
|
|
37623
|
+
});
|
|
37624
|
+
k += 5;
|
|
37625
|
+
}
|
|
37626
|
+
let out = text;
|
|
37627
|
+
for (const e of edits.reverse()) {
|
|
37628
|
+
out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
37629
|
+
}
|
|
37630
|
+
return { text: out, paths };
|
|
37631
|
+
}
|
|
37632
|
+
async function sameCatalogMoves(error, ports) {
|
|
37633
|
+
const pairs = refusedJoinPairs(error);
|
|
37634
|
+
if (!pairs?.length)
|
|
37635
|
+
return;
|
|
37636
|
+
const moves = new Map;
|
|
37637
|
+
for (const { joined, into } of pairs) {
|
|
37638
|
+
const intoDestination = destinationOfAlias(into);
|
|
37639
|
+
const joinedDestination = destinationOfAlias(joined);
|
|
37640
|
+
const [connection, alias, destination] = intoDestination !== undefined && joinedDestination === undefined ? [joined, into, intoDestination] : joinedDestination !== undefined && intoDestination === undefined ? [into, joined, joinedDestination] : [];
|
|
37641
|
+
if (!connection || !alias || !destination)
|
|
37642
|
+
return;
|
|
37643
|
+
const known = moves.get(connection);
|
|
37644
|
+
if (known) {
|
|
37645
|
+
if (known.alias !== alias)
|
|
37646
|
+
return;
|
|
37647
|
+
continue;
|
|
37648
|
+
}
|
|
37649
|
+
const schemas = await ports.scope(connection, alias);
|
|
37650
|
+
if (!schemas)
|
|
37651
|
+
return;
|
|
37652
|
+
moves.set(connection, { connection, alias, destination, schemas });
|
|
37653
|
+
}
|
|
37654
|
+
return [...moves.values()];
|
|
37655
|
+
}
|
|
37656
|
+
function movedAuthorSqlCause(modelDef, connections, rerooted) {
|
|
37657
|
+
const { contents } = authorModelReachContext(modelDef);
|
|
37658
|
+
for (const [name, def] of Object.entries(contents)) {
|
|
37659
|
+
const d = def;
|
|
37660
|
+
if (typeof d.connection !== "string" || !connections.has(d.connection)) {
|
|
37661
|
+
continue;
|
|
37662
|
+
}
|
|
37663
|
+
if (typeof d.sourceID === "string" && rerooted.has(d.sourceID)) {
|
|
37664
|
+
for (const field of Array.isArray(d.fields) ? d.fields : []) {
|
|
37665
|
+
const f = field;
|
|
37666
|
+
if (f.join === undefined)
|
|
37667
|
+
continue;
|
|
37668
|
+
const cause = authorSqlCause(field);
|
|
37669
|
+
if (cause)
|
|
37670
|
+
return `the join '${String(f.name)}' of '${name}': ${cause}`;
|
|
37671
|
+
}
|
|
37672
|
+
continue;
|
|
37673
|
+
}
|
|
37674
|
+
const cause = authorSqlCause(def);
|
|
37675
|
+
if (cause)
|
|
37676
|
+
return `the source '${name}': ${cause}`;
|
|
37677
|
+
}
|
|
37678
|
+
return;
|
|
37679
|
+
}
|
|
37680
|
+
function declaringFiles(modelDef, connections) {
|
|
37681
|
+
const { contents } = authorModelReachContext(modelDef);
|
|
37682
|
+
const urls = new Set;
|
|
37683
|
+
for (const def of Object.values(contents)) {
|
|
37684
|
+
const d = def;
|
|
37685
|
+
if (typeof d.connection === "string" && connections.has(d.connection) && typeof d.location?.url === "string") {
|
|
37686
|
+
urls.add(d.location.url);
|
|
37687
|
+
}
|
|
37688
|
+
}
|
|
37689
|
+
return [...urls];
|
|
37690
|
+
}
|
|
37691
|
+
async function readSameCatalogThroughDestination(args) {
|
|
37692
|
+
const moves = await sameCatalogMoves(args.error, args.ports);
|
|
37693
|
+
if (!moves) {
|
|
37694
|
+
return {
|
|
37695
|
+
declined: "a refused join is not into a managed connection's own catalog"
|
|
37696
|
+
};
|
|
37697
|
+
}
|
|
37698
|
+
const names = new Set(moves.map((m) => m.connection));
|
|
37699
|
+
const sql = movedAuthorSqlCause(args.modelDef, names, args.rerooted);
|
|
37700
|
+
if (sql)
|
|
37701
|
+
return { declined: `${sql}, which carries author SQL` };
|
|
37702
|
+
const urls = new Set([
|
|
37703
|
+
...args.files.keys(),
|
|
37704
|
+
...declaringFiles(args.modelDef, names)
|
|
37705
|
+
]);
|
|
37706
|
+
const out = new Map(args.files);
|
|
37707
|
+
for (const move of moves) {
|
|
37708
|
+
const paths = [];
|
|
37709
|
+
for (const url of urls) {
|
|
37710
|
+
const text = out.get(url) ?? args.readText(url);
|
|
37711
|
+
if (text === undefined)
|
|
37712
|
+
return { declined: "a file it cannot read" };
|
|
37713
|
+
const read = readThroughDestination(text, move);
|
|
37714
|
+
if (!read) {
|
|
37715
|
+
return {
|
|
37716
|
+
declined: `connection '${move.connection}' is named other than in a plain .table() it can place`
|
|
37717
|
+
};
|
|
37718
|
+
}
|
|
37719
|
+
if (read.paths.length === 0)
|
|
37720
|
+
continue;
|
|
37721
|
+
paths.push(...read.paths);
|
|
37722
|
+
out.set(url, read.text);
|
|
37723
|
+
}
|
|
37724
|
+
for (const path of paths) {
|
|
37725
|
+
const refused = await args.ports.pathRefusal(path, move.connection, move.schemas);
|
|
37726
|
+
if (refused !== undefined) {
|
|
37727
|
+
return {
|
|
37728
|
+
declined: `table '${path}' is outside the connection's scope`
|
|
37729
|
+
};
|
|
37730
|
+
}
|
|
37731
|
+
}
|
|
37732
|
+
const tables = [...new Set(paths)].map((path) => {
|
|
37733
|
+
const [catalog, schema, table] = destinationTablePath(path, move).split(".");
|
|
37734
|
+
return [catalog, schema, table];
|
|
37735
|
+
});
|
|
37736
|
+
if (!await args.ports.baseTables(move.alias, tables)) {
|
|
37737
|
+
return { declined: "a table it reads is not a base table" };
|
|
37738
|
+
}
|
|
37739
|
+
}
|
|
37740
|
+
return {
|
|
37741
|
+
files: out,
|
|
37742
|
+
destinations: new Set(moves.map((m) => m.destination))
|
|
37743
|
+
};
|
|
37744
|
+
}
|
|
37745
|
+
var PLAIN;
|
|
37746
|
+
var init_same_catalog_reads = __esm(() => {
|
|
37747
|
+
init_malloy_lexer_core();
|
|
37748
|
+
init_malloy_text();
|
|
37749
|
+
init_same_catalog_build();
|
|
37750
|
+
init_author_model();
|
|
37751
|
+
init_cross_connection_text();
|
|
37752
|
+
init_served_copy_config();
|
|
37753
|
+
PLAIN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
37754
|
+
});
|
|
37755
|
+
|
|
37756
|
+
// src/service/connection_type.ts
|
|
37757
|
+
function normalizeReadableSchemas(list) {
|
|
37758
|
+
const names = [
|
|
37759
|
+
...new Set(Array.isArray(list) ? list.filter((name) => typeof name === "string") : [])
|
|
37760
|
+
].filter((name) => name !== "main").sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
37761
|
+
return names.length > 0 ? names : undefined;
|
|
37762
|
+
}
|
|
37763
|
+
function managedSchemas(readableSchemas) {
|
|
37764
|
+
return new Set([
|
|
37765
|
+
"main",
|
|
37766
|
+
...normalizeReadableSchemas(readableSchemas) ?? []
|
|
37767
|
+
]);
|
|
37768
|
+
}
|
|
37769
|
+
function managedOverrideOf(connection) {
|
|
37770
|
+
const name = connection.name;
|
|
37771
|
+
return typeof name === "string" && managedOverrides.some((layer) => layer.has(name));
|
|
37772
|
+
}
|
|
37773
|
+
function overrideOf(connection) {
|
|
37774
|
+
const name = connection.name;
|
|
37775
|
+
if (typeof name !== "string")
|
|
37776
|
+
return;
|
|
37777
|
+
for (let i = overrides.length - 1;i >= 0; i--) {
|
|
37778
|
+
const type = overrides[i].get(name);
|
|
37779
|
+
if (type !== undefined)
|
|
37780
|
+
return type;
|
|
37781
|
+
}
|
|
37782
|
+
return;
|
|
37783
|
+
}
|
|
37784
|
+
function recordConnectionType(connection, type, options = {}) {
|
|
37785
|
+
const recordedType = overrideOf(connection) ?? type;
|
|
37786
|
+
if (recordedType)
|
|
37787
|
+
recorded.set(connection, recordedType);
|
|
37788
|
+
if (options.config)
|
|
37789
|
+
configs.set(connection, options.config);
|
|
37790
|
+
if (options.managed === true || managedOverrideOf(connection)) {
|
|
37791
|
+
managed.set(connection, options.schemas ?? MAIN_ONLY);
|
|
37792
|
+
}
|
|
37793
|
+
return connection;
|
|
37794
|
+
}
|
|
37795
|
+
function connectionConfigOf(connection) {
|
|
37796
|
+
return connection ? configs.get(connection) : undefined;
|
|
37797
|
+
}
|
|
37798
|
+
function isManagedConnection(connection) {
|
|
37799
|
+
return !!connection && managed.has(connection);
|
|
37800
|
+
}
|
|
37801
|
+
function managedSchemasOf(connection) {
|
|
37802
|
+
return connection ? managed.get(connection) : undefined;
|
|
37803
|
+
}
|
|
37804
|
+
function resolveManagedConnections(connections) {
|
|
37805
|
+
return [...connections].filter(([, connection]) => managed.has(connection)).map(([name]) => name).sort();
|
|
37806
|
+
}
|
|
37807
|
+
function connectionTypeOf(connection) {
|
|
37808
|
+
return connection ? recorded.get(connection) : undefined;
|
|
37809
|
+
}
|
|
37810
|
+
function resolveConnectionTypes(connections) {
|
|
37811
|
+
const types = {};
|
|
37812
|
+
for (const [name, connection] of connections) {
|
|
37813
|
+
const type = connectionTypeOf(connection);
|
|
37814
|
+
if (type !== undefined)
|
|
37815
|
+
types[name] = type;
|
|
37816
|
+
}
|
|
37817
|
+
return types;
|
|
37818
|
+
}
|
|
37819
|
+
var recorded, managed, configs, MAIN_ONLY, overrides, managedOverrides;
|
|
37820
|
+
var init_connection_type = __esm(() => {
|
|
37821
|
+
recorded = new WeakMap;
|
|
37822
|
+
managed = new WeakMap;
|
|
37823
|
+
configs = new WeakMap;
|
|
37824
|
+
MAIN_ONLY = managedSchemas();
|
|
37825
|
+
overrides = [];
|
|
37826
|
+
managedOverrides = [];
|
|
37827
|
+
});
|
|
37828
|
+
|
|
37829
|
+
// src/service/same_catalog_destination.ts
|
|
37830
|
+
async function sameCatalogScope(config, connection, alias) {
|
|
37831
|
+
const [source, destination] = await Promise.all([
|
|
37832
|
+
config.connections.lookupConnection(connection).catch(() => {
|
|
37833
|
+
return;
|
|
37834
|
+
}),
|
|
37835
|
+
config.connections.lookupConnection(alias).catch(() => {
|
|
37836
|
+
return;
|
|
37837
|
+
})
|
|
37838
|
+
]);
|
|
37839
|
+
const schemas = managedSchemasOf(source);
|
|
37840
|
+
return schemas && isSameCatalog(connectionConfigOf(source), connectionConfigOf(destination)) ? schemas : undefined;
|
|
37841
|
+
}
|
|
37842
|
+
async function allBaseTables(config, alias, tables) {
|
|
37843
|
+
const destination = await config.connections.lookupConnection(alias);
|
|
37844
|
+
for (const [catalog, schema, table] of tables) {
|
|
37845
|
+
const result = await destination.runSQL("SELECT table_type FROM information_schema.tables " + `WHERE table_catalog = '${catalog}' ` + `AND lower(table_schema) = lower('${schema}') ` + `AND lower(table_name) = lower('${table}')`);
|
|
37846
|
+
const rows = result.rows;
|
|
37847
|
+
if (rows.length !== 1 || rows[0].table_type !== "BASE TABLE") {
|
|
37848
|
+
return false;
|
|
37849
|
+
}
|
|
37850
|
+
}
|
|
37851
|
+
return true;
|
|
37852
|
+
}
|
|
37853
|
+
var init_same_catalog_destination = __esm(() => {
|
|
37854
|
+
init_connection_type();
|
|
37855
|
+
init_same_catalog_build();
|
|
37856
|
+
});
|
|
37857
|
+
|
|
37310
37858
|
// src/service/materialization/serve/result_reads.ts
|
|
37311
37859
|
function nonStringType2(t) {
|
|
37312
37860
|
return typeof t === "string" && t !== "string";
|
|
@@ -38155,27 +38703,54 @@ import {
|
|
|
38155
38703
|
function servedConnectionOf(b) {
|
|
38156
38704
|
return isDatabase(b) ? b.destinationName : servedCopyAlias(b.destinationName);
|
|
38157
38705
|
}
|
|
38158
|
-
function
|
|
38706
|
+
function leftOutJoinDetail(joins) {
|
|
38707
|
+
const named = joins.map((j) => {
|
|
38708
|
+
const join = j.join ?? j.name;
|
|
38709
|
+
const source = j.declaration ?? (j.join !== undefined ? j.name : undefined);
|
|
38710
|
+
const where = source ? ` of \`${source}\`` : "";
|
|
38711
|
+
const across = j.connections ? ` (${servedConnectionLabel(j.connections.joined)} into ` + `${servedConnectionLabel(j.connections.into)})` : "";
|
|
38712
|
+
return `\`${join}\`${where}${across}`;
|
|
38713
|
+
});
|
|
38714
|
+
const subject = named.length === 0 ? "a join" : `the join${named.length === 1 ? "" : "s"} ${named.join(", ")}`;
|
|
38715
|
+
return `The query uses ${subject}, whose joined source is on another connection ` + "than the storage destination its table is read from, so it is answered live.";
|
|
38716
|
+
}
|
|
38717
|
+
function leftOutJoinsRead(compiled, error, queryString) {
|
|
38159
38718
|
if (!compiled.leftOut?.length)
|
|
38160
|
-
return
|
|
38161
|
-
|
|
38719
|
+
return;
|
|
38720
|
+
const read = missingNamesRead(new Set(compiled.leftOut.map((l) => l.name)), error, queryString);
|
|
38721
|
+
if (read === undefined)
|
|
38722
|
+
return;
|
|
38723
|
+
const joins = compiled.leftOut.filter((l) => l.crossConnection);
|
|
38724
|
+
const direct = joins.filter((l) => read.has(l.name));
|
|
38725
|
+
return direct.length > 0 ? direct : joins;
|
|
38162
38726
|
}
|
|
38163
38727
|
function readsMissingName(names, error, queryString) {
|
|
38728
|
+
return missingNamesRead(names, error, queryString) !== undefined;
|
|
38729
|
+
}
|
|
38730
|
+
function missingNamesRead(names, error, queryString) {
|
|
38164
38731
|
if (!(error instanceof MalloyError4))
|
|
38165
|
-
return
|
|
38166
|
-
|
|
38167
|
-
|
|
38168
|
-
|
|
38169
|
-
|
|
38732
|
+
return;
|
|
38733
|
+
const read = new Set;
|
|
38734
|
+
let any = false;
|
|
38735
|
+
for (const p of error.problems) {
|
|
38736
|
+
if (p.code === undefined || !MISSING_FIELD_CODES.has(p.code))
|
|
38737
|
+
continue;
|
|
38170
38738
|
const start = p.at?.range?.start;
|
|
38171
38739
|
const offset = start ? offsetOf(queryString, start) : -1;
|
|
38172
|
-
|
|
38173
|
-
|
|
38174
|
-
|
|
38175
|
-
|
|
38176
|
-
|
|
38177
|
-
|
|
38178
|
-
|
|
38740
|
+
const path = offset < 0 ? undefined : /^[`A-Za-z0-9_.]+/.exec(queryString.slice(offset))?.[0];
|
|
38741
|
+
if (!path) {
|
|
38742
|
+
any = true;
|
|
38743
|
+
continue;
|
|
38744
|
+
}
|
|
38745
|
+
for (const part of path.split(".")) {
|
|
38746
|
+
const name = part.replace(/^`|`$/g, "");
|
|
38747
|
+
if (names.has(name)) {
|
|
38748
|
+
read.add(name);
|
|
38749
|
+
any = true;
|
|
38750
|
+
}
|
|
38751
|
+
}
|
|
38752
|
+
}
|
|
38753
|
+
return any ? read : undefined;
|
|
38179
38754
|
}
|
|
38180
38755
|
function rerootFailureKey(packagePath, modelPath, bindings, overlay) {
|
|
38181
38756
|
const hash = createHash2("sha256");
|
|
@@ -38303,6 +38878,21 @@ class ServedCopyServe {
|
|
|
38303
38878
|
async loadQuery(queryString, givens, pinned = this.current()) {
|
|
38304
38879
|
return this.answer(await this.ensureCompiled(pinned), queryString, givens, pinned);
|
|
38305
38880
|
}
|
|
38881
|
+
async queriedSourceIDs(compiled, queryString) {
|
|
38882
|
+
if (!compiled.leftOutColumns?.size)
|
|
38883
|
+
return;
|
|
38884
|
+
try {
|
|
38885
|
+
const prepared = await this.host.authorPreparedQuery?.(queryString);
|
|
38886
|
+
if (prepared === undefined)
|
|
38887
|
+
return;
|
|
38888
|
+
const view = preparedQueryView(prepared);
|
|
38889
|
+
const modelDef = view.modelDef ?? this.host.modelDef();
|
|
38890
|
+
const struct = resolveStructRefSource(view.structRef, modelDef);
|
|
38891
|
+
return struct ? sourceIDsReadThrough(struct, modelDef) : undefined;
|
|
38892
|
+
} catch {
|
|
38893
|
+
return;
|
|
38894
|
+
}
|
|
38895
|
+
}
|
|
38306
38896
|
async beginAttempt(compiled, queryString, givens) {
|
|
38307
38897
|
if (!compiled.materializer || compiled.rerooted.length === 0) {
|
|
38308
38898
|
const crossConnection = compiled.problems.some((p) => p.reason === "cross_connection_unbuilt");
|
|
@@ -38330,8 +38920,10 @@ class ServedCopyServe {
|
|
|
38330
38920
|
try {
|
|
38331
38921
|
return await work();
|
|
38332
38922
|
} catch (error) {
|
|
38333
|
-
|
|
38334
|
-
|
|
38923
|
+
const leftOutJoins = leftOutJoinsRead(compiled, error, queryString);
|
|
38924
|
+
if (leftOutJoins) {
|
|
38925
|
+
const detail = leftOutJoinDetail(leftOutJoins);
|
|
38926
|
+
decline(`the query reads a join the served copy leaves out across connections: ${detail}`, "served_copy_cross_connection", detail);
|
|
38335
38927
|
}
|
|
38336
38928
|
const zoned = new Set([...compiled.zonedLeftOut?.values() ?? []].flatMap((n) => [
|
|
38337
38929
|
...n
|
|
@@ -38339,24 +38931,9 @@ class ServedCopyServe {
|
|
|
38339
38931
|
if (zoned.size > 0 && readsMissingName(zoned, error, queryString)) {
|
|
38340
38932
|
decline(ZONED_TRUNCATION_REASON, "served_copy_time_zone");
|
|
38341
38933
|
}
|
|
38342
|
-
const
|
|
38343
|
-
|
|
38344
|
-
|
|
38345
|
-
if (storedLeftOut.size > 0 && readsMissingName(storedLeftOut, error, queryString)) {
|
|
38346
|
-
const missing = new Set([
|
|
38347
|
-
...String(error instanceof Error ? error.message : error).matchAll(/'([^']+)' is not defined/g)
|
|
38348
|
-
].map((m) => m[1]));
|
|
38349
|
-
const read = [...storedLeftOut].filter((n) => missing.has(n));
|
|
38350
|
-
const named = read.length > 0 ? read : [...storedLeftOut];
|
|
38351
|
-
const sourceIDs = new Set([...compiled.leftOutColumns ?? []].filter(([, names]) => names.some((n) => named.includes(n))).map(([sourceID]) => sourceID));
|
|
38352
|
-
const tableIds = compiled.aliased.filter((b) => b.sourceIDs?.some((id) => sourceIDs.has(id))).map((b) => b.virtualHandle);
|
|
38353
|
-
const why = [
|
|
38354
|
-
...new Set(named.flatMap((c) => {
|
|
38355
|
-
const reasons = [...sourceIDs].map((id) => compiled.leftOutWhy?.get(id)?.get(c)).filter((w) => w !== undefined);
|
|
38356
|
-
return reasons.length > 0 ? reasons : [noCastPhrase("a stored column")];
|
|
38357
|
-
}))
|
|
38358
|
-
];
|
|
38359
|
-
decline("the query reads a stored column the served copy leaves out of its table's type", "served_copy_column_left_out", `the stored table cannot answer with live's columns: ${why.join("; ")}`, tableIds);
|
|
38934
|
+
const leftOut = columnLeftOutDecline(compiled, error, queryString, await this.queriedSourceIDs(compiled, queryString));
|
|
38935
|
+
if (leftOut) {
|
|
38936
|
+
decline("the query reads a stored column the served copy leaves out of its table's type", "served_copy_column_left_out", leftOut.detail, leftOut.tableIds);
|
|
38360
38937
|
}
|
|
38361
38938
|
throw error;
|
|
38362
38939
|
}
|
|
@@ -38784,8 +39361,8 @@ class ServedCopyServe {
|
|
|
38784
39361
|
const plan = this.materializePlans[reroot.sourceID];
|
|
38785
39362
|
if (!plan)
|
|
38786
39363
|
return;
|
|
38787
|
-
const confirmed = confirmedAncestors(fileText, reroot.url, reroot.range, keptAncestorChainOrDeclared(map, reroot.sourceID, reroot.url, fileText));
|
|
38788
|
-
const needed = confirmed.some((a) => this.materializePlans[a.sourceID] !== undefined) || confirmed.some((a) => declaresBlocks(map.node(a.sourceID)?.def));
|
|
39364
|
+
const confirmed = confirmedAncestors(fileText, reroot.url, reroot.range, keptAncestorChainOrDeclared(map, reroot.sourceID, reroot.url, fileText, this.declarationOf));
|
|
39365
|
+
const needed = confirmed.some((a) => this.materializePlans[a.sourceID] !== undefined) || confirmed.some((a) => declaresBlocks(map.node(a.sourceID)?.def ?? this.declarationOf?.(a.sourceID)));
|
|
38789
39366
|
if (!needed)
|
|
38790
39367
|
return;
|
|
38791
39368
|
return confirmed.flatMap((a) => a.runText ? [a.runText] : []).reverse().join(" ");
|
|
@@ -39093,9 +39670,11 @@ class ServedCopyServe {
|
|
|
39093
39670
|
}));
|
|
39094
39671
|
const overlay = new Map(copy.files);
|
|
39095
39672
|
const packagePath = this.packagePath;
|
|
39096
|
-
const
|
|
39673
|
+
const packageConfig = this.packageConfig;
|
|
39674
|
+
const config = servedCopyConfig(packageConfig, destinations(), new Set(rerooted.filter((b) => !isDatabase(b)).map((b) => b.destinationName)));
|
|
39097
39675
|
const load = this.passLoader(packagePath, config);
|
|
39098
|
-
const
|
|
39676
|
+
const underAlias = this.underAliasLoader(packagePath, packageConfig, destinations, rerooted);
|
|
39677
|
+
const loaded = await this.loadCopy(state, copy, overlay, load, lift, config, underAlias);
|
|
39099
39678
|
if (loaded === "retry")
|
|
39100
39679
|
continue;
|
|
39101
39680
|
if (loaded === "failed") {
|
|
@@ -39110,6 +39689,7 @@ class ServedCopyServe {
|
|
|
39110
39689
|
};
|
|
39111
39690
|
}
|
|
39112
39691
|
const { materializer, servedDef, servedRuntime, leftOut, files } = loaded;
|
|
39692
|
+
const compiledConfig = loaded.config ?? config;
|
|
39113
39693
|
problems.push(...state.inlinedKept.filter((p) => state.candidates.some((c) => c.reroot.sourceName === p.sourceName)));
|
|
39114
39694
|
state.inlinedKept = [];
|
|
39115
39695
|
problems.push(...state.pairsDropped);
|
|
@@ -39129,7 +39709,7 @@ class ServedCopyServe {
|
|
|
39129
39709
|
materializer,
|
|
39130
39710
|
leftOut,
|
|
39131
39711
|
files,
|
|
39132
|
-
config,
|
|
39712
|
+
config: compiledConfig,
|
|
39133
39713
|
rerooted,
|
|
39134
39714
|
aliased,
|
|
39135
39715
|
throughBase
|
|
@@ -39145,6 +39725,12 @@ class ServedCopyServe {
|
|
|
39145
39725
|
problems
|
|
39146
39726
|
};
|
|
39147
39727
|
}
|
|
39728
|
+
underAliasLoader(packagePath, packageConfig, destinations, rerooted) {
|
|
39729
|
+
return (names) => {
|
|
39730
|
+
const config = servedCopyConfig(packageConfig, destinations(), new Set(rerooted.filter((b) => !isDatabase(b)).map((b) => b.destinationName)), names);
|
|
39731
|
+
return { config, load: this.passLoader(packagePath, config) };
|
|
39732
|
+
};
|
|
39733
|
+
}
|
|
39148
39734
|
passLoader(packagePath, config) {
|
|
39149
39735
|
const modelPath = this.host.modelPath();
|
|
39150
39736
|
const compiler = packageFiles(packagePath, modelPath, config);
|
|
@@ -39202,7 +39788,7 @@ class ServedCopyServe {
|
|
|
39202
39788
|
}
|
|
39203
39789
|
byKey.set(key, { error, until: asOf + REROOT_FAILURE_TTL_MS });
|
|
39204
39790
|
}
|
|
39205
|
-
async loadCopy(state, copy, overlay, load, lift) {
|
|
39791
|
+
async loadCopy(state, copy, overlay, load, lift, config, underAlias) {
|
|
39206
39792
|
const { withoutKept, problems } = state;
|
|
39207
39793
|
let materializer;
|
|
39208
39794
|
let servedDef;
|
|
@@ -39235,6 +39821,9 @@ class ServedCopyServe {
|
|
|
39235
39821
|
return "retry";
|
|
39236
39822
|
}
|
|
39237
39823
|
const byURL = new Map([...copy.files].map(([url, text]) => [url, text]));
|
|
39824
|
+
const merged = await this.readSameCatalogThroughDestination(state, err, byURL, lift, config, underAlias);
|
|
39825
|
+
if (merged)
|
|
39826
|
+
return merged;
|
|
39238
39827
|
const kept = await leaveOutCrossConnectionJoins({
|
|
39239
39828
|
firstError: err,
|
|
39240
39829
|
overlay: byURL,
|
|
@@ -39300,6 +39889,44 @@ class ServedCopyServe {
|
|
|
39300
39889
|
}
|
|
39301
39890
|
return { materializer, servedDef, servedRuntime, leftOut, files };
|
|
39302
39891
|
}
|
|
39892
|
+
async readSameCatalogThroughDestination(state, err, files, lift, config, underAlias) {
|
|
39893
|
+
const moved = await readSameCatalogThroughDestination({
|
|
39894
|
+
error: err,
|
|
39895
|
+
files,
|
|
39896
|
+
readText: (u) => lift.fileText(u),
|
|
39897
|
+
modelDef: this.host.modelDef(),
|
|
39898
|
+
rerooted: new Set(state.candidates.map((c) => c.reroot.sourceID)),
|
|
39899
|
+
ports: {
|
|
39900
|
+
scope: (connection, alias) => sameCatalogScope(config, connection, alias),
|
|
39901
|
+
pathRefusal: (path, connection, schemas) => this.host.managedTablePathRefusal ? this.host.managedTablePathRefusal(path, connection, schemas) : Promise.resolve("no managed scope check is available"),
|
|
39902
|
+
baseTables: (alias, tables) => allBaseTables(config, alias, tables)
|
|
39903
|
+
}
|
|
39904
|
+
}).catch(() => ({ declined: "a read of its connections failed" }));
|
|
39905
|
+
if ("declined" in moved) {
|
|
39906
|
+
logger.debug("A served copy's join across one catalog is not read through the destination; its joins are left out", { modelPath: this.host.modelPath(), why: moved.declined });
|
|
39907
|
+
return;
|
|
39908
|
+
}
|
|
39909
|
+
const keyed = keyedOverlay(moved.files);
|
|
39910
|
+
const { config: aliased, load } = underAlias(moved.destinations);
|
|
39911
|
+
try {
|
|
39912
|
+
const loaded = await load(keyed);
|
|
39913
|
+
logger.debug("A served copy reads a joined source on its destination's catalog through the destination", { modelPath: this.host.modelPath() });
|
|
39914
|
+
return {
|
|
39915
|
+
materializer: loaded.materializer,
|
|
39916
|
+
servedDef: loaded.def,
|
|
39917
|
+
servedRuntime: loaded.runtime,
|
|
39918
|
+
leftOut: [],
|
|
39919
|
+
files: keyed,
|
|
39920
|
+
config: aliased
|
|
39921
|
+
};
|
|
39922
|
+
} catch (again) {
|
|
39923
|
+
logger.debug("A served copy's same-catalog read does not compile; its joins are left out", {
|
|
39924
|
+
modelPath: this.host.modelPath(),
|
|
39925
|
+
codes: errorProblems(again)?.map((p) => p.code)
|
|
39926
|
+
});
|
|
39927
|
+
return;
|
|
39928
|
+
}
|
|
39929
|
+
}
|
|
39303
39930
|
contain(state, copy, error, files, mode, remembered = false) {
|
|
39304
39931
|
const { withoutKept, problems } = state;
|
|
39305
39932
|
const failing = new Map(failingReroots(error, files, copy.spans, mode).map((f) => [
|
|
@@ -39365,7 +39992,9 @@ class ServedCopyServe {
|
|
|
39365
39992
|
if (!l.crossConnection)
|
|
39366
39993
|
continue;
|
|
39367
39994
|
const sourceName = l.declaration ?? l.name;
|
|
39995
|
+
const sourceID = l.join === undefined ? candidates.find((c) => c.reroot.sourceName === sourceName && c.reroot.url === l.url)?.reroot.sourceID : undefined;
|
|
39368
39996
|
problems.push({
|
|
39997
|
+
...sourceID !== undefined ? { storedSourceID: sourceID } : {},
|
|
39369
39998
|
sourceName,
|
|
39370
39999
|
reason: "cross_connection_join",
|
|
39371
40000
|
join: l.join ?? l.name,
|
|
@@ -39638,6 +40267,66 @@ function leftOutPhrase(ref, field, storedType) {
|
|
|
39638
40267
|
function leftOutPhraseOf(subject, c) {
|
|
39639
40268
|
return leftOutPhrase(subject.columnRef(c.name), subject.fieldsByName.get(c.name), c.type);
|
|
39640
40269
|
}
|
|
40270
|
+
function sourceIDsReadThrough(struct, modelDef) {
|
|
40271
|
+
const map = SourceMap.of(modelDef);
|
|
40272
|
+
const out = new Map;
|
|
40273
|
+
const walk = (def, path, depth) => {
|
|
40274
|
+
for (const id of map.chainOf(def)) {
|
|
40275
|
+
if (!out.has(id))
|
|
40276
|
+
out.set(id, path);
|
|
40277
|
+
}
|
|
40278
|
+
if (depth >= JOIN_DEPTH_LIMIT)
|
|
40279
|
+
return;
|
|
40280
|
+
const fields = def?.fields;
|
|
40281
|
+
if (!Array.isArray(fields))
|
|
40282
|
+
return;
|
|
40283
|
+
for (const f of fields) {
|
|
40284
|
+
if (f?.join === undefined)
|
|
40285
|
+
continue;
|
|
40286
|
+
const name = f.as ?? f.name;
|
|
40287
|
+
if (!name)
|
|
40288
|
+
continue;
|
|
40289
|
+
walk(f, path ? `${path}.${name}` : name, depth + 1);
|
|
40290
|
+
}
|
|
40291
|
+
};
|
|
40292
|
+
walk(struct, "", 0);
|
|
40293
|
+
return out;
|
|
40294
|
+
}
|
|
40295
|
+
function columnLeftOutDecline(compiled, error, queryString, readIDs) {
|
|
40296
|
+
const storedLeftOut = new Set([...compiled.leftOutColumns?.values() ?? []].flatMap((n) => [...n]));
|
|
40297
|
+
if (storedLeftOut.size === 0 || !readsMissingName(storedLeftOut, error, queryString)) {
|
|
40298
|
+
return;
|
|
40299
|
+
}
|
|
40300
|
+
const missing = new Set([
|
|
40301
|
+
...String(error instanceof Error ? error.message : error).matchAll(/'([^']+)' is not defined/g)
|
|
40302
|
+
].map((m) => m[1]));
|
|
40303
|
+
const read = [...storedLeftOut].filter((n) => missing.has(n));
|
|
40304
|
+
const named = read.length > 0 ? read : [...storedLeftOut];
|
|
40305
|
+
const leaving = [...compiled.leftOutColumns ?? []].filter(([, names]) => names.some((n) => named.includes(n))).map(([sourceID]) => sourceID);
|
|
40306
|
+
const scoped = readIDs ? leaving.filter((id) => readIDs.has(id)) : [];
|
|
40307
|
+
const sourceIDs = new Set(scoped.length > 0 ? scoped : leaving);
|
|
40308
|
+
const pathOf = (id) => scoped.length > 0 ? readIDs?.get(id) : "";
|
|
40309
|
+
const tableIds = compiled.aliased.filter((b) => b.sourceIDs?.some((id) => sourceIDs.has(id))).map((b) => b.virtualHandle);
|
|
40310
|
+
const why = [
|
|
40311
|
+
...new Set(named.flatMap((c) => {
|
|
40312
|
+
const reasons = [...sourceIDs].flatMap((id) => {
|
|
40313
|
+
const phrase = compiled.leftOutWhy?.get(id)?.get(c);
|
|
40314
|
+
if (phrase === undefined)
|
|
40315
|
+
return [];
|
|
40316
|
+
const path = pathOf(id);
|
|
40317
|
+
const own = `column \`${c}\``;
|
|
40318
|
+
return [
|
|
40319
|
+
path && phrase.startsWith(own) ? `column \`${path}.${c}\`${phrase.slice(own.length)}` : phrase
|
|
40320
|
+
];
|
|
40321
|
+
});
|
|
40322
|
+
return reasons.length > 0 ? reasons : [noCastPhrase("a stored column")];
|
|
40323
|
+
}))
|
|
40324
|
+
];
|
|
40325
|
+
return {
|
|
40326
|
+
detail: `the stored table cannot answer with live's columns: ${why.join("; ")}`,
|
|
40327
|
+
tableIds
|
|
40328
|
+
};
|
|
40329
|
+
}
|
|
39641
40330
|
function noCastPhrase(ref) {
|
|
39642
40331
|
return `no cast reads ${ref} as declared`;
|
|
39643
40332
|
}
|
|
@@ -40500,7 +41189,7 @@ function zonedTruncations(columns, def, fieldsByName, chainZone, restatesStageZo
|
|
|
40500
41189
|
restated: []
|
|
40501
41190
|
};
|
|
40502
41191
|
}
|
|
40503
|
-
var NOTHING_PINNED, NO_DESTINATIONS = () => new MalloyConfig3({ connections: {} }), PAIR_BLOCKS_DETAIL = "The table stores more than one inlined join_many, one block of rows each, and the query reads more than one of them (live aggregates each by its own key over their cross product, which no block holds), so it is answered without this table.",
|
|
41192
|
+
var NOTHING_PINNED, NO_DESTINATIONS = () => new MalloyConfig3({ connections: {} }), PAIR_BLOCKS_DETAIL = "The table stores more than one inlined join_many, one block of rows each, and the query reads more than one of them (live aggregates each by its own key over their cross product, which no block holds), so it is answered without this table.", MISSING_FIELD_CODES, SERVED_COPY_WARNING_CODE = "served-copy-not-served", DECLINED_LIMIT = 1000, knownRerootFailures, REROOT_FAILURE_TTL_MS, ESCAPED_FAILURE_RETRY_MS = 30000, REROOT_FAILURES_PER_CONFIG = 64, GATE_GRAFT_DECLINE, HIDDEN_COLUMN = "a hidden column", JOIN_DEPTH_LIMIT = 8;
|
|
40504
41193
|
var init_served_copy_serve = __esm(() => {
|
|
40505
41194
|
init_ducklake_catalog_unavailable();
|
|
40506
41195
|
init_served_copy_lanes();
|
|
@@ -40536,6 +41225,8 @@ var init_served_copy_serve = __esm(() => {
|
|
|
40536
41225
|
init_utils();
|
|
40537
41226
|
init_served_copy_checks();
|
|
40538
41227
|
init_query_walks();
|
|
41228
|
+
init_same_catalog_reads();
|
|
41229
|
+
init_same_catalog_destination();
|
|
40539
41230
|
init_chain_string_reads();
|
|
40540
41231
|
NOTHING_PINNED = pin(EMPTY_SNAPSHOT, new Date(0));
|
|
40541
41232
|
MISSING_FIELD_CODES = new Set([
|
|
@@ -40807,6 +41498,216 @@ var init_error_wire = __esm(() => {
|
|
|
40807
41498
|
init_errors2();
|
|
40808
41499
|
});
|
|
40809
41500
|
|
|
41501
|
+
// src/package_load/job_files.ts
|
|
41502
|
+
import {
|
|
41503
|
+
CacheManager,
|
|
41504
|
+
InMemoryModelCache
|
|
41505
|
+
} from "@malloydata/malloy";
|
|
41506
|
+
import { createHash as createHash3 } from "crypto";
|
|
41507
|
+
import * as path6 from "path";
|
|
41508
|
+
import { fileURLToPath as fileURLToPath5, pathToFileURL as pathToFileURL5 } from "url";
|
|
41509
|
+
function jobFiles(inner) {
|
|
41510
|
+
const texts = new Map;
|
|
41511
|
+
const stylesByUrl = new Map;
|
|
41512
|
+
const reads = new Map;
|
|
41513
|
+
const reader = {
|
|
41514
|
+
readURL: (url) => {
|
|
41515
|
+
const key = url.toString();
|
|
41516
|
+
let read = reads.get(key);
|
|
41517
|
+
if (!read) {
|
|
41518
|
+
read = (async () => {
|
|
41519
|
+
const contents = await inner.readURL(url);
|
|
41520
|
+
texts.set(key, contents);
|
|
41521
|
+
stylesByUrl.set(key, await dataStylesForFile(key, contents, inner));
|
|
41522
|
+
return contents;
|
|
41523
|
+
})();
|
|
41524
|
+
reads.set(key, read);
|
|
41525
|
+
read.catch(() => reads.delete(key));
|
|
41526
|
+
}
|
|
41527
|
+
return read;
|
|
41528
|
+
}
|
|
41529
|
+
};
|
|
41530
|
+
return {
|
|
41531
|
+
reader,
|
|
41532
|
+
texts,
|
|
41533
|
+
stylesByUrl,
|
|
41534
|
+
models: new Map,
|
|
41535
|
+
imported: new Set,
|
|
41536
|
+
stats: { stored: 0, reused: 0 }
|
|
41537
|
+
};
|
|
41538
|
+
}
|
|
41539
|
+
function urlKey(url) {
|
|
41540
|
+
try {
|
|
41541
|
+
return new URL(url).href;
|
|
41542
|
+
} catch {
|
|
41543
|
+
return url;
|
|
41544
|
+
}
|
|
41545
|
+
}
|
|
41546
|
+
function decodedUrl(url) {
|
|
41547
|
+
try {
|
|
41548
|
+
return decodeURI(url);
|
|
41549
|
+
} catch {
|
|
41550
|
+
return url;
|
|
41551
|
+
}
|
|
41552
|
+
}
|
|
41553
|
+
function modelFileTexts(files, modelUrl, dependencies) {
|
|
41554
|
+
const byPath = new Map;
|
|
41555
|
+
for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
|
|
41556
|
+
const key = urlKey(url);
|
|
41557
|
+
const text = files.texts.get(key);
|
|
41558
|
+
if (text !== undefined && key.startsWith("file:")) {
|
|
41559
|
+
byPath.set(fileURLToPath5(key), text);
|
|
41560
|
+
}
|
|
41561
|
+
}
|
|
41562
|
+
return byPath;
|
|
41563
|
+
}
|
|
41564
|
+
function fileTextDigests(files) {
|
|
41565
|
+
const digests = {};
|
|
41566
|
+
for (const [url, text] of files.texts) {
|
|
41567
|
+
const key = urlKey(url);
|
|
41568
|
+
if (!key.startsWith("file:"))
|
|
41569
|
+
continue;
|
|
41570
|
+
digests[key] = createHash3("sha256").update(text).digest("hex");
|
|
41571
|
+
}
|
|
41572
|
+
return digests;
|
|
41573
|
+
}
|
|
41574
|
+
function modelReadKeys(modelUrl, dependencies) {
|
|
41575
|
+
return [modelUrl, ...importReadOrder(dependencies)].map(urlKey);
|
|
41576
|
+
}
|
|
41577
|
+
function dataStylesForModel(files, modelUrl, dependencies) {
|
|
41578
|
+
let styles = {};
|
|
41579
|
+
for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
|
|
41580
|
+
styles = { ...styles, ...files.stylesByUrl.get(urlKey(url)) ?? {} };
|
|
41581
|
+
}
|
|
41582
|
+
return styles;
|
|
41583
|
+
}
|
|
41584
|
+
function importReadOrder(tree) {
|
|
41585
|
+
const order = [];
|
|
41586
|
+
const seen = new Set;
|
|
41587
|
+
const descended = new Set;
|
|
41588
|
+
const visit = (node) => {
|
|
41589
|
+
if (!node || typeof node !== "object")
|
|
41590
|
+
return;
|
|
41591
|
+
const entries = Object.entries(node);
|
|
41592
|
+
for (const [url] of entries) {
|
|
41593
|
+
if (!seen.has(url)) {
|
|
41594
|
+
seen.add(url);
|
|
41595
|
+
order.push(url);
|
|
41596
|
+
}
|
|
41597
|
+
}
|
|
41598
|
+
for (const [url, sub] of entries) {
|
|
41599
|
+
if (descended.has(url))
|
|
41600
|
+
continue;
|
|
41601
|
+
descended.add(url);
|
|
41602
|
+
visit(sub);
|
|
41603
|
+
}
|
|
41604
|
+
};
|
|
41605
|
+
visit(tree);
|
|
41606
|
+
return order;
|
|
41607
|
+
}
|
|
41608
|
+
async function compileOrder(packagePath, modelPaths, reader, imported = new Set) {
|
|
41609
|
+
const malloy = modelPaths.filter((p) => p.endsWith(MODEL_FILE_SUFFIX));
|
|
41610
|
+
const inPackage = new Set(malloy);
|
|
41611
|
+
const imports = new Map;
|
|
41612
|
+
for (const modelPath of malloy) {
|
|
41613
|
+
const url = pathToFileURL5(path6.join(packagePath, modelPath));
|
|
41614
|
+
let text = "";
|
|
41615
|
+
try {
|
|
41616
|
+
text = await reader.readURL(url);
|
|
41617
|
+
} catch {}
|
|
41618
|
+
const deps = [];
|
|
41619
|
+
for (const match of text.matchAll(IMPORT_RE)) {
|
|
41620
|
+
const target = match[1] ?? match[2];
|
|
41621
|
+
if (!target)
|
|
41622
|
+
continue;
|
|
41623
|
+
try {
|
|
41624
|
+
const resolved = new URL(target, url);
|
|
41625
|
+
if (resolved.protocol !== "file:")
|
|
41626
|
+
continue;
|
|
41627
|
+
const rel = path6.relative(packagePath, fileURLToPath5(resolved)).replace(/\\/g, "/");
|
|
41628
|
+
if (inPackage.has(rel)) {
|
|
41629
|
+
deps.push(rel);
|
|
41630
|
+
imported.add(urlKey(resolved.href));
|
|
41631
|
+
}
|
|
41632
|
+
} catch {}
|
|
41633
|
+
}
|
|
41634
|
+
imports.set(modelPath, deps);
|
|
41635
|
+
}
|
|
41636
|
+
const level = new Map;
|
|
41637
|
+
const visiting = new Set;
|
|
41638
|
+
const levelOf = (modelPath) => {
|
|
41639
|
+
const known = level.get(modelPath);
|
|
41640
|
+
if (known !== undefined)
|
|
41641
|
+
return known;
|
|
41642
|
+
if (visiting.has(modelPath))
|
|
41643
|
+
return 0;
|
|
41644
|
+
visiting.add(modelPath);
|
|
41645
|
+
let mine = 0;
|
|
41646
|
+
for (const dep of imports.get(modelPath) ?? []) {
|
|
41647
|
+
mine = Math.max(mine, levelOf(dep) + 1);
|
|
41648
|
+
}
|
|
41649
|
+
visiting.delete(modelPath);
|
|
41650
|
+
level.set(modelPath, mine);
|
|
41651
|
+
return mine;
|
|
41652
|
+
};
|
|
41653
|
+
const levels = [];
|
|
41654
|
+
const waitsOn = new Map;
|
|
41655
|
+
for (const modelPath of malloy) {
|
|
41656
|
+
const mine = levelOf(modelPath);
|
|
41657
|
+
(levels[mine] ??= []).push(modelPath);
|
|
41658
|
+
waitsOn.set(modelPath, (imports.get(modelPath) ?? []).filter((dep) => levelOf(dep) < mine));
|
|
41659
|
+
}
|
|
41660
|
+
const rest = modelPaths.filter((p) => !p.endsWith(MODEL_FILE_SUFFIX));
|
|
41661
|
+
for (const modelPath of rest)
|
|
41662
|
+
waitsOn.set(modelPath, []);
|
|
41663
|
+
return {
|
|
41664
|
+
waitsOn,
|
|
41665
|
+
levels: [
|
|
41666
|
+
...levels.filter((l) => l !== undefined && l.length > 0),
|
|
41667
|
+
...rest.length > 0 ? [rest] : []
|
|
41668
|
+
]
|
|
41669
|
+
};
|
|
41670
|
+
}
|
|
41671
|
+
var sameUrl = (a, b) => a === b || urlKey(a) === urlKey(b), ModelCacheView, IMPORT_RE;
|
|
41672
|
+
var init_job_files = __esm(() => {
|
|
41673
|
+
init_constants();
|
|
41674
|
+
init_data_styles();
|
|
41675
|
+
ModelCacheView = class ModelCacheView extends CacheManager {
|
|
41676
|
+
files;
|
|
41677
|
+
ownUrl;
|
|
41678
|
+
constructor(files, ownUrl) {
|
|
41679
|
+
super(new InMemoryModelCache);
|
|
41680
|
+
this.files = files;
|
|
41681
|
+
this.ownUrl = ownUrl;
|
|
41682
|
+
}
|
|
41683
|
+
async getCachedModelDef(...[, url]) {
|
|
41684
|
+
if (sameUrl(url, this.ownUrl))
|
|
41685
|
+
return;
|
|
41686
|
+
const hit = this.files.models.get(url);
|
|
41687
|
+
if (!hit)
|
|
41688
|
+
return;
|
|
41689
|
+
this.files.stats.reused++;
|
|
41690
|
+
return {
|
|
41691
|
+
modelDef: structuredClone(hit.modelDef),
|
|
41692
|
+
invalidationKeys: { ...hit.invalidationKeys }
|
|
41693
|
+
};
|
|
41694
|
+
}
|
|
41695
|
+
async setCachedModelDef(...[url, cached]) {
|
|
41696
|
+
if (!this.files.imported.has(urlKey(url)))
|
|
41697
|
+
return false;
|
|
41698
|
+
if (sameUrl(url, this.ownUrl) && decodedUrl(url) !== url)
|
|
41699
|
+
return false;
|
|
41700
|
+
this.files.models.set(url, {
|
|
41701
|
+
modelDef: structuredClone(cached.modelDef),
|
|
41702
|
+
invalidationKeys: { ...cached.invalidationKeys }
|
|
41703
|
+
});
|
|
41704
|
+
this.files.stats.stored++;
|
|
41705
|
+
return true;
|
|
41706
|
+
}
|
|
41707
|
+
};
|
|
41708
|
+
IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s+from\s+)?(?:"([^"]+)"|'([^']+)')/gim;
|
|
41709
|
+
});
|
|
41710
|
+
|
|
40810
41711
|
// src/service/translator_error.ts
|
|
40811
41712
|
import { MalloyError as MalloyError6 } from "@malloydata/malloy";
|
|
40812
41713
|
function translatorInvariantProblem(error) {
|
|
@@ -40947,12 +41848,12 @@ function compareText(a, b) {
|
|
|
40947
41848
|
}
|
|
40948
41849
|
|
|
40949
41850
|
// src/service/package_revision.ts
|
|
40950
|
-
import { createHash as
|
|
41851
|
+
import { createHash as createHash4, randomUUID } from "crypto";
|
|
40951
41852
|
import fs5 from "fs";
|
|
40952
41853
|
import path7 from "path";
|
|
40953
41854
|
import { pathToFileURL as pathToFileURL6 } from "url";
|
|
40954
41855
|
function computeSourceContentSha(packagePath, contentPaths, extra, contentShas) {
|
|
40955
|
-
const hash =
|
|
41856
|
+
const hash = createHash4("sha256");
|
|
40956
41857
|
for (const relativePath of [...contentPaths].sort()) {
|
|
40957
41858
|
hash.update(relativePath);
|
|
40958
41859
|
hash.update("\x00");
|
|
@@ -40964,7 +41865,7 @@ function computeSourceContentSha(packagePath, contentPaths, extra, contentShas)
|
|
|
40964
41865
|
try {
|
|
40965
41866
|
hash.update(fs5.readFileSync(confinedPackagePathSync(packagePath, pathToFileURL6(absolute))));
|
|
40966
41867
|
} catch {
|
|
40967
|
-
hash.update(
|
|
41868
|
+
hash.update(UNREADABLE3);
|
|
40968
41869
|
}
|
|
40969
41870
|
}
|
|
40970
41871
|
hash.update("\x00");
|
|
@@ -40986,12 +41887,12 @@ function boundedManifestValue(value) {
|
|
|
40986
41887
|
return "[unreadable: too deep or too large]";
|
|
40987
41888
|
}
|
|
40988
41889
|
function canonicalSha(value) {
|
|
40989
|
-
return
|
|
41890
|
+
return createHash4("sha256").update(canonicalJson(value)).digest("hex");
|
|
40990
41891
|
}
|
|
40991
41892
|
function mintServedRevision() {
|
|
40992
41893
|
return randomUUID();
|
|
40993
41894
|
}
|
|
40994
|
-
var
|
|
41895
|
+
var UNREADABLE3 = "\x00<unreadable>\x00", MANIFEST_AGENTS_MAX_BYTES;
|
|
40995
41896
|
var init_package_revision = __esm(() => {
|
|
40996
41897
|
init_utils();
|
|
40997
41898
|
MANIFEST_AGENTS_MAX_BYTES = 1024 * 1024;
|
|
@@ -42065,9 +42966,9 @@ var init_dim_index_discovery = __esm(() => {
|
|
|
42065
42966
|
});
|
|
42066
42967
|
|
|
42067
42968
|
// src/service/entities/dim_index_entity_id.ts
|
|
42068
|
-
import { createHash as
|
|
42969
|
+
import { createHash as createHash5 } from "crypto";
|
|
42069
42970
|
function computeSqlFingerprint(compiledSql) {
|
|
42070
|
-
return
|
|
42971
|
+
return createHash5("sha256").update(compiledSql, "utf8").digest("hex");
|
|
42071
42972
|
}
|
|
42072
42973
|
function buildFingerprintQuery(sourceName, dimensionPath, requiredFilterDimensions, gateDimensions = []) {
|
|
42073
42974
|
const sortedFilters = [...requiredFilterDimensions].sort();
|
|
@@ -42087,6 +42988,10 @@ var init_dim_index_entity_id = __esm(() => {
|
|
|
42087
42988
|
// src/service/entities/source_extraction.ts
|
|
42088
42989
|
import path8 from "path";
|
|
42089
42990
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
42991
|
+
import {
|
|
42992
|
+
isJoined as isJoined5,
|
|
42993
|
+
isJoinedSource
|
|
42994
|
+
} from "@malloydata/malloy";
|
|
42090
42995
|
function buildSourceToModelPathMap(explores, relpath, packageRoot) {
|
|
42091
42996
|
const sourceToModelPath = new Map;
|
|
42092
42997
|
for (const explore of explores) {
|
|
@@ -42132,6 +43037,17 @@ function parseJoinCode(joinCode, fieldName, sourceToModelPath) {
|
|
|
42132
43037
|
is_nested_index: isNestedIndex
|
|
42133
43038
|
};
|
|
42134
43039
|
}
|
|
43040
|
+
function joinMetadataOf(field, docString, sourceToModelPath) {
|
|
43041
|
+
const structDef = field.structDef;
|
|
43042
|
+
const metadata = isJoinedSource(structDef) ? parseJoinCode(extractCodeFromEntity(field, docString), field.name, sourceToModelPath) : {
|
|
43043
|
+
original_source_name: null,
|
|
43044
|
+
original_source_path: null,
|
|
43045
|
+
is_nested_index: true
|
|
43046
|
+
};
|
|
43047
|
+
if (isJoined5(structDef))
|
|
43048
|
+
metadata.relationship = structDef.join;
|
|
43049
|
+
return metadata;
|
|
43050
|
+
}
|
|
42135
43051
|
function descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, boundary) {
|
|
42136
43052
|
const targetName = joinMetadata.original_source_name;
|
|
42137
43053
|
const targetIsAtTopLevel = targetName != null && topLevelExploreNames.has(targetName);
|
|
@@ -42142,7 +43058,7 @@ function descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, bo
|
|
|
42142
43058
|
function joinDescent(explores, relativePath, packageRoot, docString, boundary) {
|
|
42143
43059
|
const sourceToModelPath = buildSourceToModelPathMap(explores, relativePath, packageRoot);
|
|
42144
43060
|
const topLevelExploreNames = new Set(explores.map((e) => e.name));
|
|
42145
|
-
return (join, parentSourceName) => descendsIntoJoin(
|
|
43061
|
+
return (join, parentSourceName) => descendsIntoJoin(joinMetadataOf(join, docString, sourceToModelPath), parentSourceName.split(".")[0], topLevelExploreNames, boundary);
|
|
42146
43062
|
}
|
|
42147
43063
|
function getEntitiesFromExplore(explore, docString, relativePath, parentPath, sourceToModelPath, dimIndexFingerprints, topLevelExploreNames, boundary, guard) {
|
|
42148
43064
|
const entities = [];
|
|
@@ -42154,8 +43070,7 @@ function getEntitiesFromExplore(explore, docString, relativePath, parentPath, so
|
|
|
42154
43070
|
}
|
|
42155
43071
|
let joinMetadata = null;
|
|
42156
43072
|
if (field.isExploreField()) {
|
|
42157
|
-
|
|
42158
|
-
joinMetadata = parseJoinCode(joinCode, field.name, sourceToModelPath);
|
|
43073
|
+
joinMetadata = joinMetadataOf(field, docString, sourceToModelPath);
|
|
42159
43074
|
const descent = descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, boundary);
|
|
42160
43075
|
if (descent !== false) {
|
|
42161
43076
|
const nestedEntities = getEntitiesFromExplore(field, docString, relativePath, sourceName, sourceToModelPath, dimIndexFingerprints, topLevelExploreNames, boundary, descent === true ? guard : guardDescent(guard, rootSourceName, descent.unlessQueryable));
|
|
@@ -42170,6 +43085,7 @@ function getEntitiesFromExplore(explore, docString, relativePath, parentPath, so
|
|
|
42170
43085
|
nameOverride = `${joinPath}.${field.name}`;
|
|
42171
43086
|
}
|
|
42172
43087
|
const codeEntity = getEntityFromMalloyField(field, entitySource, docString, explore.sourceStructDef?.connection ?? null, explore.sourceStructDef && "tablePath" in explore.sourceStructDef ? explore.sourceStructDef.tablePath ?? null : null, joinMetadata, nameOverride, explore.sourceStructDef?.dialect ?? null);
|
|
43088
|
+
inheritJoinedDoc(codeEntity, field, explore);
|
|
42173
43089
|
const fingerprint = dimIndexFingerprints.get(makeDimIndexLookupKey(sourceName, field.name));
|
|
42174
43090
|
if (fingerprint) {
|
|
42175
43091
|
codeEntity.dim_index_fingerprint = {
|
|
@@ -42181,6 +43097,39 @@ function getEntitiesFromExplore(explore, docString, relativePath, parentPath, so
|
|
|
42181
43097
|
}
|
|
42182
43098
|
return entities;
|
|
42183
43099
|
}
|
|
43100
|
+
function inheritJoinedDoc(entity, field, explore) {
|
|
43101
|
+
if (entity.description !== undefined || field.isExploreField())
|
|
43102
|
+
return;
|
|
43103
|
+
const defs = explore.structDef.fields;
|
|
43104
|
+
const pathOf = (name) => {
|
|
43105
|
+
const e = defs?.find((f) => (f.as ?? f.name) === name)?.e;
|
|
43106
|
+
return e?.node === "field" && Array.isArray(e.path) && e.path.every((p) => typeof p === "string") ? e.path : undefined;
|
|
43107
|
+
};
|
|
43108
|
+
let path = pathOf(field.name);
|
|
43109
|
+
for (let depth = 0;path?.length === 1; depth++) {
|
|
43110
|
+
const link = explore.getFieldByNameIfExists(path[0]);
|
|
43111
|
+
if (depth >= MAX_ALIAS_CHAIN || !link || link.isExploreField() || getAccessModifier(link) !== "public" /* Public */ || getDescriptionFromTags(getTags(link)) !== undefined) {
|
|
43112
|
+
return;
|
|
43113
|
+
}
|
|
43114
|
+
path = pathOf(link.name);
|
|
43115
|
+
}
|
|
43116
|
+
if (path?.length !== 2)
|
|
43117
|
+
return;
|
|
43118
|
+
const [joinName, fieldName] = path;
|
|
43119
|
+
const join = explore.getFieldByNameIfExists(joinName);
|
|
43120
|
+
if (!join?.isExploreField() || getAccessModifier(join) !== "public" /* Public */) {
|
|
43121
|
+
return;
|
|
43122
|
+
}
|
|
43123
|
+
const joined = join.getFieldByNameIfExists(fieldName);
|
|
43124
|
+
if (!joined || joined.isExploreField() || getAccessModifier(joined) !== "public" /* Public */) {
|
|
43125
|
+
return;
|
|
43126
|
+
}
|
|
43127
|
+
const doc = getDescriptionFromTags(getTags(joined));
|
|
43128
|
+
if (doc === undefined)
|
|
43129
|
+
return;
|
|
43130
|
+
entity.description = doc;
|
|
43131
|
+
entity.doc_inherited_from = `${joinName}.${fieldName}`;
|
|
43132
|
+
}
|
|
42184
43133
|
function planJoinAuthorizeMetadata(explore, docString, relativePath, parentPath, parentAuthorize, sourceToModelPath, topLevelExploreNames, boundary, modelGivens, modelAuthorize, alwaysSeenSourceKeys, guarded, sourceDefsByName) {
|
|
42185
43134
|
const plan = [];
|
|
42186
43135
|
const sourceName = composeSourceName(parentPath, explore.name);
|
|
@@ -42191,8 +43140,7 @@ function planJoinAuthorizeMetadata(explore, docString, relativePath, parentPath,
|
|
|
42191
43140
|
}
|
|
42192
43141
|
if (getAccessModifier(field) !== "public" /* Public */)
|
|
42193
43142
|
continue;
|
|
42194
|
-
const
|
|
42195
|
-
const joinMetadata = parseJoinCode(joinCode, field.name, sourceToModelPath);
|
|
43143
|
+
const joinMetadata = joinMetadataOf(field, docString, sourceToModelPath);
|
|
42196
43144
|
const targetName = joinMetadata.original_source_name;
|
|
42197
43145
|
const descent = descendsIntoJoin(joinMetadata, rootSourceName, topLevelExploreNames, boundary);
|
|
42198
43146
|
const joinedExplore = field;
|
|
@@ -42282,7 +43230,7 @@ function resolveJoinMetadata(plan, nonQueryableSourceNames, rootIsQueryable, see
|
|
|
42282
43230
|
resolveJoinMetadata(descend.children, nonQueryableSourceNames, rootIsQueryable, seenSourceKeys, out);
|
|
42283
43231
|
}
|
|
42284
43232
|
}
|
|
42285
|
-
var extractDocsFromExplore = (explore) => {
|
|
43233
|
+
var MAX_ALIAS_CHAIN = 8, extractDocsFromExplore = (explore) => {
|
|
42286
43234
|
const parts = getDirectTaglines(explore).map((text) => parseDocAnnotation(text)).filter((doc) => !!doc && doc.length > 0);
|
|
42287
43235
|
return parts.length > 0 ? parts.join(`
|
|
42288
43236
|
`) : null;
|
|
@@ -42841,7 +43789,7 @@ var init_package_relative_text = __esm(() => {
|
|
|
42841
43789
|
});
|
|
42842
43790
|
|
|
42843
43791
|
// src/service/package_retrieval_settings.ts
|
|
42844
|
-
import { createHash as
|
|
43792
|
+
import { createHash as createHash6 } from "crypto";
|
|
42845
43793
|
import * as fs8 from "fs";
|
|
42846
43794
|
import * as path10 from "path";
|
|
42847
43795
|
import { pathToFileURL as pathToFileURL9 } from "url";
|
|
@@ -42857,26 +43805,26 @@ function fcjSettingsOf(retrieval) {
|
|
|
42857
43805
|
function fail(message) {
|
|
42858
43806
|
throw new PackageManifestError(message);
|
|
42859
43807
|
}
|
|
42860
|
-
function
|
|
43808
|
+
function describe2(value) {
|
|
42861
43809
|
return JSON.stringify(value) ?? "nothing";
|
|
42862
43810
|
}
|
|
42863
43811
|
function resolvePromptPath(packageRoot, rel, promptKey = "judge") {
|
|
42864
43812
|
const key = `retrieval.prompts.${promptKey}`;
|
|
42865
43813
|
const fix = `Fix: use a path inside the package, e.g. "prompts/${promptKey}.md".`;
|
|
42866
43814
|
if (rel.includes("\x00") || path10.isAbsolute(rel) || /^[A-Za-z]:[\\/]/.test(rel) || rel.startsWith("\\")) {
|
|
42867
|
-
fail(`Invalid publisher.json ${key}: ${
|
|
43815
|
+
fail(`Invalid publisher.json ${key}: ${describe2(rel)} is an absolute path. ${fix}`);
|
|
42868
43816
|
}
|
|
42869
43817
|
const root = path10.resolve(packageRoot);
|
|
42870
43818
|
const resolved = path10.resolve(root, rel);
|
|
42871
43819
|
const within = path10.relative(root, resolved);
|
|
42872
43820
|
if (within === "" || stepsOutside(within)) {
|
|
42873
|
-
fail(`Invalid publisher.json ${key}: ${
|
|
43821
|
+
fail(`Invalid publisher.json ${key}: ${describe2(rel)} resolves outside the package directory. ${fix}`);
|
|
42874
43822
|
}
|
|
42875
43823
|
return resolved;
|
|
42876
43824
|
}
|
|
42877
43825
|
function objectBlock(raw, key, valid, fix) {
|
|
42878
43826
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
42879
|
-
fail(`Invalid publisher.json ${key}: expected an object, got ${
|
|
43827
|
+
fail(`Invalid publisher.json ${key}: expected an object, got ${describe2(raw)}. Fix: ${fix}`);
|
|
42880
43828
|
}
|
|
42881
43829
|
const obj = raw;
|
|
42882
43830
|
const unknown = Object.keys(obj).filter((k) => !valid.includes(k));
|
|
@@ -42890,7 +43838,7 @@ function parseEnabled(value, key) {
|
|
|
42890
43838
|
return "auto";
|
|
42891
43839
|
if (value === "auto" || value === true || value === false)
|
|
42892
43840
|
return value;
|
|
42893
|
-
return fail(`Invalid publisher.json ${key}: expected "auto", true or false, got ${
|
|
43841
|
+
return fail(`Invalid publisher.json ${key}: expected "auto", true or false, got ${describe2(value)}. ` + `Fix: "enabled": "auto" (on when the server has an LLM), true (require one) or false.`);
|
|
42894
43842
|
}
|
|
42895
43843
|
function parseSourceSummary(raw) {
|
|
42896
43844
|
const obj = objectBlock(raw, "retrieval.sourceSummary", SOURCE_SUMMARY_KEYS, `"sourceSummary": { "enabled": "auto" }`);
|
|
@@ -42902,42 +43850,42 @@ function fcjNumber(obj, key, check) {
|
|
|
42902
43850
|
const value = obj[key] ?? DEFAULT_FCJ_SETTINGS[key];
|
|
42903
43851
|
const ok = typeof value === "number" && Number.isFinite(value) && value >= check.min && value <= check.max && (!check.integer || Number.isSafeInteger(value));
|
|
42904
43852
|
if (!ok) {
|
|
42905
|
-
fail(`Invalid publisher.json retrieval.fcj.${key}: expected ${check.integer ? "an integer" : "a number"} from ${check.min} to ${check.max}, got ${
|
|
43853
|
+
fail(`Invalid publisher.json retrieval.fcj.${key}: expected ${check.integer ? "an integer" : "a number"} from ${check.min} to ${check.max}, got ${describe2(obj[key])}. ` + `Fix: "${key}": ${JSON.stringify(DEFAULT_FCJ_SETTINGS[key])}`);
|
|
42906
43854
|
}
|
|
42907
43855
|
return value;
|
|
42908
43856
|
}
|
|
42909
43857
|
function fcjBoolean(obj, key) {
|
|
42910
43858
|
const value = obj[key] ?? DEFAULT_FCJ_SETTINGS[key];
|
|
42911
43859
|
if (typeof value !== "boolean") {
|
|
42912
|
-
fail(`Invalid publisher.json retrieval.fcj.${key}: expected true or false, got ${
|
|
43860
|
+
fail(`Invalid publisher.json retrieval.fcj.${key}: expected true or false, got ${describe2(obj[key])}. ` + `Fix: "${key}": ${JSON.stringify(DEFAULT_FCJ_SETTINGS[key])}`);
|
|
42913
43861
|
}
|
|
42914
43862
|
return value;
|
|
42915
43863
|
}
|
|
42916
43864
|
function fcjConnect(obj) {
|
|
42917
43865
|
const value = obj.connect ?? DEFAULT_FCJ_SETTINGS.connect;
|
|
42918
43866
|
if (!FCJ_CONNECT_MODES.includes(value)) {
|
|
42919
|
-
fail(`Invalid publisher.json retrieval.fcj.connect: expected one of ${FCJ_CONNECT_MODES.join(", ")}, got ${
|
|
43867
|
+
fail(`Invalid publisher.json retrieval.fcj.connect: expected one of ${FCJ_CONNECT_MODES.join(", ")}, got ${describe2(obj.connect)}. ` + `Fix: "connect": "clusters" (source groups) or "list" (the find stage's top listTopK per target).`);
|
|
42920
43868
|
}
|
|
42921
43869
|
return value;
|
|
42922
43870
|
}
|
|
42923
43871
|
function fcjQuestionsPrompt(obj) {
|
|
42924
43872
|
const value = obj.questionsPrompt ?? DEFAULT_FCJ_SETTINGS.questionsPrompt;
|
|
42925
43873
|
if (!QUESTIONS_PROMPTS.includes(value)) {
|
|
42926
|
-
fail(`Invalid publisher.json retrieval.fcj.questionsPrompt: expected one of ${QUESTIONS_PROMPTS.join(", ")}, got ${
|
|
43874
|
+
fail(`Invalid publisher.json retrieval.fcj.questionsPrompt: expected one of ${QUESTIONS_PROMPTS.join(", ")}, got ${describe2(obj.questionsPrompt)}. ` + `Fix: "questionsPrompt": "questions" (what a person asks), "phrases" (what an agent types as a search target) or "values" (questions that filter by the field's values).`);
|
|
42927
43875
|
}
|
|
42928
43876
|
return value;
|
|
42929
43877
|
}
|
|
42930
43878
|
function fcjAlsoLikely(obj) {
|
|
42931
43879
|
const value = obj.alsoLikely ?? DEFAULT_FCJ_SETTINGS.alsoLikely;
|
|
42932
43880
|
if (!FCJ_ALSO_LIKELY.includes(value)) {
|
|
42933
|
-
fail(`Invalid publisher.json retrieval.fcj.alsoLikely: expected "auto", true or false, got ${
|
|
43881
|
+
fail(`Invalid publisher.json retrieval.fcj.alsoLikely: expected "auto", true or false, got ${describe2(obj.alsoLikely)}. ` + `Fix: "alsoLikely": "auto" (on with connect "list", off with "clusters").`);
|
|
42934
43882
|
}
|
|
42935
43883
|
return value;
|
|
42936
43884
|
}
|
|
42937
43885
|
function fcjJoinedCopies(obj) {
|
|
42938
43886
|
const value = obj.joinedCopies ?? DEFAULT_FCJ_SETTINGS.joinedCopies;
|
|
42939
43887
|
if (!FCJ_JOINED_COPIES.includes(value)) {
|
|
42940
|
-
fail(`Invalid publisher.json retrieval.fcj.joinedCopies: expected one of ${FCJ_JOINED_COPIES.join(", ")}, got ${
|
|
43888
|
+
fail(`Invalid publisher.json retrieval.fcj.joinedCopies: expected one of ${FCJ_JOINED_COPIES.join(", ")}, got ${describe2(obj.joinedCopies)}. ` + `Fix: "joinedCopies": "indexed" (joined copies are searchable rows) or "routes" (each field is searched on its own source and shown with its routes).`);
|
|
42941
43889
|
}
|
|
42942
43890
|
return value;
|
|
42943
43891
|
}
|
|
@@ -42948,7 +43896,7 @@ function fcjJudgeLlm(obj) {
|
|
|
42948
43896
|
const example = `"judgeLlm": { "model": "claude-haiku-5-5" }`;
|
|
42949
43897
|
const o = objectBlock(raw, "retrieval.fcj.judgeLlm", ["model"], example);
|
|
42950
43898
|
if (typeof o.model !== "string" || o.model.trim() === "") {
|
|
42951
|
-
fail(`Invalid publisher.json retrieval.fcj.judgeLlm.model: expected a non-empty string, got ${
|
|
43899
|
+
fail(`Invalid publisher.json retrieval.fcj.judgeLlm.model: expected a non-empty string, got ${describe2(o.model)}. ` + `The provider, host and key are the server's retrieval.llm settings. Fix: ${example}`);
|
|
42952
43900
|
}
|
|
42953
43901
|
return { model: o.model.trim() };
|
|
42954
43902
|
}
|
|
@@ -42997,7 +43945,7 @@ function parsePackageRetrieval(raw) {
|
|
|
42997
43945
|
return { promptPaths: {} };
|
|
42998
43946
|
}
|
|
42999
43947
|
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
43000
|
-
fail(`Invalid publisher.json retrieval: expected an object, got ${
|
|
43948
|
+
fail(`Invalid publisher.json retrieval: expected an object, got ${describe2(raw)}. ` + `Fix: "retrieval": { "fcj": { "perTarget": 30 } }`);
|
|
43001
43949
|
}
|
|
43002
43950
|
const obj = raw;
|
|
43003
43951
|
const unknown = Object.keys(obj).filter((k) => !RETRIEVAL_KEYS.includes(k) && !(k in IGNORED_RETRIEVAL_KEYS));
|
|
@@ -43009,7 +43957,7 @@ function parsePackageRetrieval(raw) {
|
|
|
43009
43957
|
const promptPaths = {};
|
|
43010
43958
|
if (obj.prompts !== undefined && obj.prompts !== null) {
|
|
43011
43959
|
if (typeof obj.prompts !== "object" || Array.isArray(obj.prompts)) {
|
|
43012
|
-
fail(`Invalid publisher.json retrieval.prompts: expected an object, got ${
|
|
43960
|
+
fail(`Invalid publisher.json retrieval.prompts: expected an object, got ${describe2(obj.prompts)}. ` + `Fix: "prompts": { "judge": "prompts/judge.md" }`);
|
|
43013
43961
|
}
|
|
43014
43962
|
const prompts = obj.prompts;
|
|
43015
43963
|
const badPrompt = Object.keys(prompts).filter((k) => !PROMPT_KEYS.includes(k) && !(k in IGNORED_PROMPT_KEYS));
|
|
@@ -43021,7 +43969,7 @@ function parsePackageRetrieval(raw) {
|
|
|
43021
43969
|
if (value === undefined || value === null)
|
|
43022
43970
|
continue;
|
|
43023
43971
|
if (typeof value !== "string" || value.trim() === "") {
|
|
43024
|
-
fail(`Invalid publisher.json retrieval.prompts.${key}: expected a file path inside the package, got ${
|
|
43972
|
+
fail(`Invalid publisher.json retrieval.prompts.${key}: expected a file path inside the package, got ${describe2(value)}. ` + `Fix: "${key}": "prompts/${key}.md"`);
|
|
43025
43973
|
}
|
|
43026
43974
|
promptPaths[key] = value;
|
|
43027
43975
|
}
|
|
@@ -43067,21 +44015,21 @@ async function readPromptFile(packageRoot, key, rel) {
|
|
|
43067
44015
|
} catch (error) {
|
|
43068
44016
|
if (!(error instanceof ImportOutsidePackageError))
|
|
43069
44017
|
throw error;
|
|
43070
|
-
return fail(`Invalid publisher.json ${at}: ${
|
|
44018
|
+
return fail(`Invalid publisher.json ${at}: ${describe2(rel)} resolves outside the package directory through a link. ` + `Fix: copy the file into the package.`);
|
|
43071
44019
|
}
|
|
43072
44020
|
text = await fs8.promises.readFile(realFile, "utf8");
|
|
43073
44021
|
} catch (error) {
|
|
43074
44022
|
if (error instanceof PackageManifestError)
|
|
43075
44023
|
throw error;
|
|
43076
|
-
return fail(`Invalid publisher.json ${at}: cannot read ${
|
|
44024
|
+
return fail(`Invalid publisher.json ${at}: cannot read ${describe2(rel)} (${callerVisibleText(error.message, packageRoot)}). ` + `Fix: create the file inside the package or remove the key.`);
|
|
43077
44025
|
}
|
|
43078
44026
|
if (text.trim() === "") {
|
|
43079
|
-
fail(`Invalid publisher.json ${at}: ${
|
|
44027
|
+
fail(`Invalid publisher.json ${at}: ${describe2(rel)} is empty. ` + `Fix: write the prompt, or remove the key to use the built-in one.`);
|
|
43080
44028
|
}
|
|
43081
44029
|
return {
|
|
43082
44030
|
path: rel,
|
|
43083
44031
|
text,
|
|
43084
|
-
hash:
|
|
44032
|
+
hash: createHash6("sha256").update(text).digest("hex")
|
|
43085
44033
|
};
|
|
43086
44034
|
}
|
|
43087
44035
|
async function readPackageRetrieval(packageRoot, raw) {
|
|
@@ -43281,73 +44229,6 @@ var init_render_tag_targets = __esm(() => {
|
|
|
43281
44229
|
init_malloy_text();
|
|
43282
44230
|
});
|
|
43283
44231
|
|
|
43284
|
-
// src/service/connection_type.ts
|
|
43285
|
-
function normalizeReadableSchemas(list) {
|
|
43286
|
-
const names = [
|
|
43287
|
-
...new Set(Array.isArray(list) ? list.filter((name) => typeof name === "string") : [])
|
|
43288
|
-
].filter((name) => name !== "main").sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
43289
|
-
return names.length > 0 ? names : undefined;
|
|
43290
|
-
}
|
|
43291
|
-
function managedSchemas(readableSchemas) {
|
|
43292
|
-
return new Set([
|
|
43293
|
-
"main",
|
|
43294
|
-
...normalizeReadableSchemas(readableSchemas) ?? []
|
|
43295
|
-
]);
|
|
43296
|
-
}
|
|
43297
|
-
function managedOverrideOf(connection) {
|
|
43298
|
-
const name = connection.name;
|
|
43299
|
-
return typeof name === "string" && managedOverrides.some((layer) => layer.has(name));
|
|
43300
|
-
}
|
|
43301
|
-
function overrideOf(connection) {
|
|
43302
|
-
const name = connection.name;
|
|
43303
|
-
if (typeof name !== "string")
|
|
43304
|
-
return;
|
|
43305
|
-
for (let i = overrides.length - 1;i >= 0; i--) {
|
|
43306
|
-
const type = overrides[i].get(name);
|
|
43307
|
-
if (type !== undefined)
|
|
43308
|
-
return type;
|
|
43309
|
-
}
|
|
43310
|
-
return;
|
|
43311
|
-
}
|
|
43312
|
-
function recordConnectionType(connection, type, options = {}) {
|
|
43313
|
-
const recordedType = overrideOf(connection) ?? type;
|
|
43314
|
-
if (recordedType)
|
|
43315
|
-
recorded.set(connection, recordedType);
|
|
43316
|
-
if (options.managed === true || managedOverrideOf(connection)) {
|
|
43317
|
-
managed.set(connection, options.schemas ?? MAIN_ONLY);
|
|
43318
|
-
}
|
|
43319
|
-
return connection;
|
|
43320
|
-
}
|
|
43321
|
-
function isManagedConnection(connection) {
|
|
43322
|
-
return !!connection && managed.has(connection);
|
|
43323
|
-
}
|
|
43324
|
-
function managedSchemasOf(connection) {
|
|
43325
|
-
return connection ? managed.get(connection) : undefined;
|
|
43326
|
-
}
|
|
43327
|
-
function resolveManagedConnections(connections) {
|
|
43328
|
-
return [...connections].filter(([, connection]) => managed.has(connection)).map(([name]) => name).sort();
|
|
43329
|
-
}
|
|
43330
|
-
function connectionTypeOf(connection) {
|
|
43331
|
-
return connection ? recorded.get(connection) : undefined;
|
|
43332
|
-
}
|
|
43333
|
-
function resolveConnectionTypes(connections) {
|
|
43334
|
-
const types = {};
|
|
43335
|
-
for (const [name, connection] of connections) {
|
|
43336
|
-
const type = connectionTypeOf(connection);
|
|
43337
|
-
if (type !== undefined)
|
|
43338
|
-
types[name] = type;
|
|
43339
|
-
}
|
|
43340
|
-
return types;
|
|
43341
|
-
}
|
|
43342
|
-
var recorded, managed, MAIN_ONLY, overrides, managedOverrides;
|
|
43343
|
-
var init_connection_type = __esm(() => {
|
|
43344
|
-
recorded = new WeakMap;
|
|
43345
|
-
managed = new WeakMap;
|
|
43346
|
-
MAIN_ONLY = managedSchemas();
|
|
43347
|
-
overrides = [];
|
|
43348
|
-
managedOverrides = [];
|
|
43349
|
-
});
|
|
43350
|
-
|
|
43351
44232
|
// src/service/materialization/plan/refusal_key.ts
|
|
43352
44233
|
function tierOf(storage) {
|
|
43353
44234
|
return storage !== undefined ? "storage" : "database";
|
|
@@ -43382,15 +44263,26 @@ function errorCodeOf(err) {
|
|
|
43382
44263
|
}
|
|
43383
44264
|
return "Error";
|
|
43384
44265
|
}
|
|
43385
|
-
|
|
44266
|
+
function runtimeErrorTextOf(err) {
|
|
44267
|
+
for (const e of causeChain(err)) {
|
|
44268
|
+
const { code } = e;
|
|
44269
|
+
if (typeof code === "number" && RUNTIME_ERROR_NAMES.has(e.name) && typeof e.message === "string" && RUNTIME_TEXT.test(e.message)) {
|
|
44270
|
+
return e.message;
|
|
44271
|
+
}
|
|
44272
|
+
}
|
|
44273
|
+
return;
|
|
44274
|
+
}
|
|
44275
|
+
var CODE_PATTERN, RUNTIME_ERROR_NAMES, RUNTIME_TEXT;
|
|
43386
44276
|
var init_error_code = __esm(() => {
|
|
43387
44277
|
init_driver_errors();
|
|
43388
44278
|
init_errors2();
|
|
43389
44279
|
CODE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$/;
|
|
44280
|
+
RUNTIME_ERROR_NAMES = new Set(["TimeoutError", "AbortError"]);
|
|
44281
|
+
RUNTIME_TEXT = /^[A-Za-z][A-Za-z ,.'-]{0,119}$/;
|
|
43390
44282
|
});
|
|
43391
44283
|
|
|
43392
44284
|
// src/service/materialization/domain/table_name.ts
|
|
43393
|
-
import { createHash as
|
|
44285
|
+
import { createHash as createHash7 } from "crypto";
|
|
43394
44286
|
function leafBudget(dialect, inDestination) {
|
|
43395
44287
|
if (inDestination)
|
|
43396
44288
|
return DESTINATION_LEAF_BUDGET;
|
|
@@ -43494,7 +44386,7 @@ function fitPrefix(prefix, room) {
|
|
|
43494
44386
|
}
|
|
43495
44387
|
function readableTableName(args) {
|
|
43496
44388
|
const { identity } = args;
|
|
43497
|
-
const hash =
|
|
44389
|
+
const hash = createHash7("sha256").update(JSON.stringify([
|
|
43498
44390
|
"publisher-table/1",
|
|
43499
44391
|
identity.environmentName,
|
|
43500
44392
|
identity.packageName,
|
|
@@ -43852,6 +44744,21 @@ var init_persist_annotation_validation = __esm(() => {
|
|
|
43852
44744
|
SAFE_NAME_PATH = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
43853
44745
|
});
|
|
43854
44746
|
|
|
44747
|
+
// src/service/materialization/domain/rollup_grain.ts
|
|
44748
|
+
function pathColumnName(join, field) {
|
|
44749
|
+
return `${join}__${field}`;
|
|
44750
|
+
}
|
|
44751
|
+
function grainPathOf(grain) {
|
|
44752
|
+
const at = grain.indexOf(".");
|
|
44753
|
+
if (at < 0)
|
|
44754
|
+
return;
|
|
44755
|
+
return { join: grain.slice(0, at), field: grain.slice(at + 1) };
|
|
44756
|
+
}
|
|
44757
|
+
function grainColumnOf(grain) {
|
|
44758
|
+
const path = grainPathOf(grain);
|
|
44759
|
+
return path ? pathColumnName(path.join, path.field) : grain;
|
|
44760
|
+
}
|
|
44761
|
+
|
|
43855
44762
|
// src/service/materialization/text/read_text.ts
|
|
43856
44763
|
import * as path11 from "path";
|
|
43857
44764
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
@@ -43949,7 +44856,10 @@ function persistLine(plan) {
|
|
|
43949
44856
|
return "#@ persist";
|
|
43950
44857
|
}
|
|
43951
44858
|
function emitRollupBuildSource(plan) {
|
|
43952
|
-
const grain = plan.grainDimensions.map((g) =>
|
|
44859
|
+
const grain = plan.grainDimensions.map((g) => {
|
|
44860
|
+
const path = grainPathOf(g);
|
|
44861
|
+
return path ? ` ${identifier(grainColumnOf(g))} is ${identifier(path.join)}.${identifier(path.field)}` : ` ${identifier(g)}`;
|
|
44862
|
+
}).join(`
|
|
43953
44863
|
`);
|
|
43954
44864
|
const partials = plan.rollupMeasures.flatMap((m) => m.partials).map((p) => ` ${identifier(p.column)} is ${emitMeasureExpr(p.leaf.expr)}`).join(`
|
|
43955
44865
|
`);
|
|
@@ -45132,7 +46042,7 @@ var init_types2 = __esm(() => {
|
|
|
45132
46042
|
});
|
|
45133
46043
|
|
|
45134
46044
|
// src/retrieval/config.ts
|
|
45135
|
-
function
|
|
46045
|
+
function describe3(value) {
|
|
45136
46046
|
return value === undefined ? "nothing" : JSON.stringify(value);
|
|
45137
46047
|
}
|
|
45138
46048
|
function positiveInt(value, key, fix) {
|
|
@@ -45140,7 +46050,7 @@ function positiveInt(value, key, fix) {
|
|
|
45140
46050
|
return;
|
|
45141
46051
|
const parsed = typeof value === "string" && /^\d+$/.test(value.trim()) ? Number(value.trim()) : value;
|
|
45142
46052
|
if (typeof parsed !== "number" || !Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
45143
|
-
throw new Error(`Invalid ${key}: expected a positive integer, got ${
|
|
46053
|
+
throw new Error(`Invalid ${key}: expected a positive integer, got ${describe3(value)}. Fix: ${fix}`);
|
|
45144
46054
|
}
|
|
45145
46055
|
return parsed;
|
|
45146
46056
|
}
|
|
@@ -45148,7 +46058,7 @@ function nonEmptyString(value, key, fix) {
|
|
|
45148
46058
|
if (value === undefined || value === null)
|
|
45149
46059
|
return;
|
|
45150
46060
|
if (typeof value !== "string" || value.trim() === "") {
|
|
45151
|
-
throw new Error(`Invalid ${key}: expected a non-empty string, got ${
|
|
46061
|
+
throw new Error(`Invalid ${key}: expected a non-empty string, got ${describe3(value)}. Fix: ${fix}`);
|
|
45152
46062
|
}
|
|
45153
46063
|
return value.trim();
|
|
45154
46064
|
}
|
|
@@ -45156,7 +46066,7 @@ function plainString(value, key, fix) {
|
|
|
45156
46066
|
if (value === undefined || value === null)
|
|
45157
46067
|
return;
|
|
45158
46068
|
if (typeof value !== "string") {
|
|
45159
|
-
throw new Error(`Invalid ${key}: expected a string, got ${
|
|
46069
|
+
throw new Error(`Invalid ${key}: expected a string, got ${describe3(value)}. Fix: ${fix}`);
|
|
45160
46070
|
}
|
|
45161
46071
|
return value;
|
|
45162
46072
|
}
|
|
@@ -45167,13 +46077,13 @@ function url(value, key, fix) {
|
|
|
45167
46077
|
try {
|
|
45168
46078
|
new URL(text);
|
|
45169
46079
|
} catch {
|
|
45170
|
-
throw new Error(`Invalid ${key}: expected a URL, got ${
|
|
46080
|
+
throw new Error(`Invalid ${key}: expected a URL, got ${describe3(value)}. Fix: ${fix}`);
|
|
45171
46081
|
}
|
|
45172
46082
|
return text.replace(/\/+$/, "");
|
|
45173
46083
|
}
|
|
45174
46084
|
function block(raw, key, valid, fix) {
|
|
45175
46085
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
45176
|
-
throw new Error(`Invalid ${key}: expected an object, got ${
|
|
46086
|
+
throw new Error(`Invalid ${key}: expected an object, got ${describe3(raw)}. Fix: ${fix}`);
|
|
45177
46087
|
}
|
|
45178
46088
|
const obj = raw;
|
|
45179
46089
|
const unknown = Object.keys(obj).filter((k) => !valid.includes(k));
|
|
@@ -45186,7 +46096,7 @@ function providerName(value, key, allowed, fix) {
|
|
|
45186
46096
|
if (value === undefined || value === null)
|
|
45187
46097
|
return;
|
|
45188
46098
|
if (typeof value !== "string" || !allowed.includes(value)) {
|
|
45189
|
-
throw new Error(`Invalid ${key}: expected one of ${allowed.join(", ")}, got ${
|
|
46099
|
+
throw new Error(`Invalid ${key}: expected one of ${allowed.join(", ")}, got ${describe3(value)}. Fix: ${fix}`);
|
|
45190
46100
|
}
|
|
45191
46101
|
return value;
|
|
45192
46102
|
}
|
|
@@ -45287,20 +46197,20 @@ function parseValueGivens(raw) {
|
|
|
45287
46197
|
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
45288
46198
|
const isValue = (v) => typeof v === "string" || typeof v === "boolean" || typeof v === "number" && Number.isFinite(v);
|
|
45289
46199
|
if (!isObject(raw)) {
|
|
45290
|
-
throw new Error(`Invalid retrieval.dimensionValues.givens: expected an object of packages, got ${
|
|
46200
|
+
throw new Error(`Invalid retrieval.dimensionValues.givens: expected an object of packages, got ${describe3(raw)}. Fix: ${GIVENS_FIX}`);
|
|
45291
46201
|
}
|
|
45292
46202
|
const out = {};
|
|
45293
46203
|
for (const [pkg, givens] of Object.entries(raw)) {
|
|
45294
46204
|
const at = `retrieval.dimensionValues.givens.${pkg}`;
|
|
45295
46205
|
if (!isObject(givens)) {
|
|
45296
|
-
throw new Error(`Invalid ${at}: expected an object of givens, got ${
|
|
46206
|
+
throw new Error(`Invalid ${at}: expected an object of givens, got ${describe3(givens)}. Fix: ${GIVENS_FIX}`);
|
|
45297
46207
|
}
|
|
45298
46208
|
const parsed = {};
|
|
45299
46209
|
let combinations = 1;
|
|
45300
46210
|
for (const [name, value] of Object.entries(givens)) {
|
|
45301
46211
|
const list = Array.isArray(value) ? value : [value];
|
|
45302
46212
|
if (list.length === 0 || !list.every(isValue)) {
|
|
45303
|
-
throw new Error(`Invalid ${at}.${name}: expected a string, number or boolean, or a non-empty list of them, got ${
|
|
46213
|
+
throw new Error(`Invalid ${at}.${name}: expected a string, number or boolean, or a non-empty list of them, got ${describe3(value)}. Fix: ${GIVENS_FIX}`);
|
|
45304
46214
|
}
|
|
45305
46215
|
parsed[name] = [...new Set(list)];
|
|
45306
46216
|
combinations *= parsed[name].length;
|
|
@@ -45317,7 +46227,7 @@ function parseDimensionValues(raw) {
|
|
|
45317
46227
|
const out = {};
|
|
45318
46228
|
if (fields.enabled !== undefined && fields.enabled !== null) {
|
|
45319
46229
|
if (typeof fields.enabled !== "boolean") {
|
|
45320
|
-
throw new Error(`Invalid retrieval.dimensionValues.enabled: expected a boolean, got ${
|
|
46230
|
+
throw new Error(`Invalid retrieval.dimensionValues.enabled: expected a boolean, got ${describe3(fields.enabled)}. Fix: "enabled": false`);
|
|
45321
46231
|
}
|
|
45322
46232
|
out.enabled = fields.enabled;
|
|
45323
46233
|
}
|
|
@@ -46084,7 +46994,7 @@ function isObj2(value) {
|
|
|
46084
46994
|
function holdsRawSqlExpression(def) {
|
|
46085
46995
|
const seen = new Set;
|
|
46086
46996
|
const walk = (node, depth) => {
|
|
46087
|
-
if (depth >
|
|
46997
|
+
if (depth > MAX_DEPTH4)
|
|
46088
46998
|
return true;
|
|
46089
46999
|
if (node === null || typeof node !== "object")
|
|
46090
47000
|
return false;
|
|
@@ -46126,7 +47036,7 @@ function resolveJoinPath(roots, path) {
|
|
|
46126
47036
|
throw new Unknown(`join path ${path.join(".")} did not resolve`);
|
|
46127
47037
|
}
|
|
46128
47038
|
function relationReads(def, out, depth) {
|
|
46129
|
-
if (depth >
|
|
47039
|
+
if (depth > MAX_DEPTH4 || !isObj2(def))
|
|
46130
47040
|
throw new Unknown("unreadable");
|
|
46131
47041
|
switch (def.type) {
|
|
46132
47042
|
case "table":
|
|
@@ -46192,7 +47102,7 @@ function queryTableReads(entry, pipeline) {
|
|
|
46192
47102
|
}
|
|
46193
47103
|
});
|
|
46194
47104
|
}
|
|
46195
|
-
var
|
|
47105
|
+
var MAX_DEPTH4 = 200, Unknown;
|
|
46196
47106
|
var init_source_reads = __esm(() => {
|
|
46197
47107
|
Unknown = class Unknown extends Error {
|
|
46198
47108
|
};
|
|
@@ -47237,7 +48147,7 @@ var init_preaggregation_classifier = __esm(() => {
|
|
|
47237
48147
|
import {
|
|
47238
48148
|
expressionIsAggregate,
|
|
47239
48149
|
expressionIsAnalytic,
|
|
47240
|
-
isJoined as
|
|
48150
|
+
isJoined as isJoined6
|
|
47241
48151
|
} from "@malloydata/malloy";
|
|
47242
48152
|
function isAccessRestricted(f) {
|
|
47243
48153
|
return f.accessModifier != null && f.accessModifier !== "public";
|
|
@@ -47249,7 +48159,7 @@ function isView(f) {
|
|
|
47249
48159
|
return f.type === "turtle";
|
|
47250
48160
|
}
|
|
47251
48161
|
function isFanoutJoin(f) {
|
|
47252
|
-
return
|
|
48162
|
+
return isJoined6(f) && f.join !== "one";
|
|
47253
48163
|
}
|
|
47254
48164
|
function hasFanoutJoin(source) {
|
|
47255
48165
|
return (source.fields ?? []).some((f) => isFanoutJoin(f));
|
|
@@ -47258,7 +48168,7 @@ function isMeasure(f) {
|
|
|
47258
48168
|
return expressionIsAggregate(f.expressionType) && !expressionIsAnalytic(f.expressionType);
|
|
47259
48169
|
}
|
|
47260
48170
|
function isGroupableDimension(f) {
|
|
47261
|
-
if (
|
|
48171
|
+
if (isJoined6(f) || isView(f))
|
|
47262
48172
|
return false;
|
|
47263
48173
|
if (f.expressionType === undefined)
|
|
47264
48174
|
return true;
|
|
@@ -47278,7 +48188,7 @@ function validateGrainDimension(sourceName, measure, source, grainDimension) {
|
|
|
47278
48188
|
if (!field) {
|
|
47279
48189
|
return violation("unknown_grain_dimension", `Measure \`${measure}\` declares \`#@ preaggregate\` at a grain naming \`${grainDimension}\`, but \`${head}\` is not a field of \`${sourceName}\`. Use a dimension that exists on the source; a rollup can only group by the source's own dimensions.`);
|
|
47280
48190
|
}
|
|
47281
|
-
if (
|
|
48191
|
+
if (isJoined6(field)) {
|
|
47282
48192
|
return violation("grain_path_through_join", `Measure \`${measure}\` declares a grain of \`${grainDimension}\`, which reaches through the join \`${head}\`. Pre-aggregating across a join is not supported in this version; copy the value into a dimension on \`${sourceName}\` and group by that instead.`);
|
|
47283
48193
|
}
|
|
47284
48194
|
if (parts.length > 1) {
|
|
@@ -47353,7 +48263,7 @@ function validateSourcePreaggregation(sourceName, source) {
|
|
|
47353
48263
|
}
|
|
47354
48264
|
function fieldViolations(sourceName, source, field, declaration, grains, violations) {
|
|
47355
48265
|
const name = fieldName4(field);
|
|
47356
|
-
if (
|
|
48266
|
+
if (isJoined6(field)) {
|
|
47357
48267
|
violations.push({
|
|
47358
48268
|
code: "misplaced_on_join",
|
|
47359
48269
|
sourceName,
|
|
@@ -48413,7 +49323,7 @@ function rollupLabel(plan) {
|
|
|
48413
49323
|
}
|
|
48414
49324
|
|
|
48415
49325
|
// src/service/materialization/plan/rollup_plan.ts
|
|
48416
|
-
import { createHash as
|
|
49326
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
48417
49327
|
import { Annotations as Annotations8 } from "@malloydata/malloy";
|
|
48418
49328
|
function isRollupRoute(route) {
|
|
48419
49329
|
return route === ROLLUP_ROUTE || route === ROLLUP_ALIAS_ROUTE;
|
|
@@ -48546,7 +49456,7 @@ function byCodepoint2(a, b) {
|
|
|
48546
49456
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
48547
49457
|
}
|
|
48548
49458
|
function digest(parts) {
|
|
48549
|
-
return
|
|
49459
|
+
return createHash8("sha256").update(parts.join("\x00")).digest("hex").slice(0, 8);
|
|
48550
49460
|
}
|
|
48551
49461
|
function rollupName(baseDeclaredName, packageRelativeSourceID, grain, placement) {
|
|
48552
49462
|
const slug = grain.join("_").replace(/[^A-Za-z0-9_]/g, "_");
|
|
@@ -48846,16 +49756,7 @@ function declarationRefusal(decl, facts, ctx) {
|
|
|
48846
49756
|
return "skip";
|
|
48847
49757
|
return unservable("hidden_field", decl, "the measure is not public, and a rollup would publish it");
|
|
48848
49758
|
}
|
|
48849
|
-
const grainProblem = decl.grain
|
|
48850
|
-
const f = byName.get(g);
|
|
48851
|
-
if (g.includes(".")) {
|
|
48852
|
-
return `the grain names \`${g}\`, a path; declare a dimension on the source that reads it, and name that`;
|
|
48853
|
-
}
|
|
48854
|
-
if (!f || !isDimension(f)) {
|
|
48855
|
-
return `the grain names \`${g}\`, which is not a dimension of the source`;
|
|
48856
|
-
}
|
|
48857
|
-
return;
|
|
48858
|
-
}).find((p) => p !== undefined);
|
|
49759
|
+
const grainProblem = grainProblemOf(decl.grain, facts);
|
|
48859
49760
|
if (grainProblem) {
|
|
48860
49761
|
if (decl.v1)
|
|
48861
49762
|
return "skip";
|
|
@@ -48867,7 +49768,7 @@ function declarationRefusal(decl, facts, ctx) {
|
|
|
48867
49768
|
measure: decl.measure
|
|
48868
49769
|
};
|
|
48869
49770
|
}
|
|
48870
|
-
const timeRead = facts.windowed ? "the source's rows read the current time (a `where:` with `now` or a relative time filter such as `f'last 7 days'`, a rolling window)" : timeFields.has(decl.measure) ? "the measure reads the current time (`now`, or a relative time filter)" : decl.grain.filter((g) => timeFields.has(g)).map((g) => `its grain dimension \`${g}\` reads the current time (\`now\`, or a relative time filter)`)[0];
|
|
49771
|
+
const timeRead = facts.windowed ? "the source's rows read the current time (a `where:` with `now` or a relative time filter such as `f'last 7 days'`, a rolling window)" : timeFields.has(decl.measure) ? "the measure reads the current time (`now`, or a relative time filter)" : decl.grain.filter((g) => timeFields.has(g) || pathReadsCurrentTime(g, facts)).map((g) => `its grain dimension \`${g}\` reads the current time (\`now\`, or a relative time filter)`)[0];
|
|
48871
49772
|
if (timeRead) {
|
|
48872
49773
|
return unservable("current_time", decl, `${timeRead}, which a rollup would fix at build time while a live query reads it again at every read`);
|
|
48873
49774
|
}
|
|
@@ -48886,7 +49787,12 @@ function declarationRefusal(decl, facts, ctx) {
|
|
|
48886
49787
|
if (hiddenGrain) {
|
|
48887
49788
|
return unservable("hidden_field", decl, `its grain dimension \`${hiddenGrain}\` is private on a source it extends, declared in another file, which a rollup's build copy cannot lift`);
|
|
48888
49789
|
}
|
|
48889
|
-
const unreadableGrain = decl.storage === undefined ? undefined : unreadableStoredGrain(decl.grain,
|
|
49790
|
+
const unreadableGrain = decl.storage === undefined ? undefined : unreadableStoredGrain(decl.grain, (g) => {
|
|
49791
|
+
if (!g.includes("."))
|
|
49792
|
+
return byName.get(g);
|
|
49793
|
+
const path = pathGrainOf(g, facts);
|
|
49794
|
+
return "problem" in path ? undefined : path.joined;
|
|
49795
|
+
}, facts.dialect);
|
|
48890
49796
|
if (unreadableGrain) {
|
|
48891
49797
|
return unservable("unreadable_grain", decl, `its grain dimension \`${unreadableGrain.name}\` is stored as ${unreadableGrain.storedType}, which no read of a storage destination declares, so its table would cost a build no query reads; leave out storage= to build it in the source's own warehouse, which reads it`);
|
|
48892
49798
|
}
|
|
@@ -48915,11 +49821,142 @@ function declarationRefusal(decl, facts, ctx) {
|
|
|
48915
49821
|
}
|
|
48916
49822
|
return;
|
|
48917
49823
|
}
|
|
48918
|
-
function
|
|
49824
|
+
function grainProblemOf(grain, facts) {
|
|
49825
|
+
const { byName } = facts;
|
|
49826
|
+
const columns = new Map;
|
|
49827
|
+
return grain.map((g) => {
|
|
49828
|
+
const f = byName.get(g);
|
|
49829
|
+
if (g.includes(".")) {
|
|
49830
|
+
const path = pathGrainOf(g, facts);
|
|
49831
|
+
if ("problem" in path)
|
|
49832
|
+
return path.problem;
|
|
49833
|
+
const column = grainColumnOf(g);
|
|
49834
|
+
if (byName.has(column) || columns.has(column)) {
|
|
49835
|
+
return `the grain names \`${g}\`, stored as \`${column}\`, which is already the name of ${byName.has(column) ? "a field of the source" : `\`${columns.get(column)}\``}`;
|
|
49836
|
+
}
|
|
49837
|
+
columns.set(column, g);
|
|
49838
|
+
return;
|
|
49839
|
+
}
|
|
49840
|
+
if (!f || !isDimension(f)) {
|
|
49841
|
+
return `the grain names \`${g}\`, which is not a dimension of the source`;
|
|
49842
|
+
}
|
|
49843
|
+
columns.set(g, g);
|
|
49844
|
+
return;
|
|
49845
|
+
}).find((p) => p !== undefined);
|
|
49846
|
+
}
|
|
49847
|
+
function pathGrainOf(grain, facts) {
|
|
49848
|
+
const [head, second, ...rest] = grain.split(".");
|
|
49849
|
+
const join = facts.joins.get(head);
|
|
49850
|
+
const joinField = facts.byName.get(head);
|
|
49851
|
+
if (!join || !joinField) {
|
|
49852
|
+
return {
|
|
49853
|
+
problem: `the grain names \`${grain}\`, which reads no join of the source; a truncation or a field of a record is named through a dimension on the source that reads it`
|
|
49854
|
+
};
|
|
49855
|
+
}
|
|
49856
|
+
const joinedFields = new Map((joinField.fields ?? []).map((f) => [fieldNameOf2(f), f]));
|
|
49857
|
+
const joined = joinedFields.get(second);
|
|
49858
|
+
if (rest.length > 0) {
|
|
49859
|
+
return {
|
|
49860
|
+
problem: joined?.join !== undefined ? `the grain names \`${grain}\`, a path through more than one join; a grain reads one join, so declare a dimension on \`${head}\`'s source that reads the rest, and name \`${head}.<that dimension>\`` : `the grain names \`${grain}\`, a truncation through a join; declare the truncated dimension on \`${head}\`'s source, and name \`${head}.<that dimension>\``
|
|
49861
|
+
};
|
|
49862
|
+
}
|
|
49863
|
+
if (join.relationship === "cross") {
|
|
49864
|
+
return {
|
|
49865
|
+
problem: `the grain names \`${grain}\`, through \`${head}\`, a join_cross; a path grain reads a join_one or a join_many`
|
|
49866
|
+
};
|
|
49867
|
+
}
|
|
49868
|
+
if (!joined || !isDimension(joined)) {
|
|
49869
|
+
return {
|
|
49870
|
+
problem: `the grain names \`${grain}\`, but \`${second}\` is not a dimension of \`${head}\`'s source`
|
|
49871
|
+
};
|
|
49872
|
+
}
|
|
49873
|
+
if (isHidden(joinField) || isHidden(joined)) {
|
|
49874
|
+
return {
|
|
49875
|
+
problem: `the grain names \`${grain}\`, which is not public (${isHidden(joinField) ? `the join \`${head}\`` : `\`${second}\` on its source`} is not), so a rollup's build cannot read it`
|
|
49876
|
+
};
|
|
49877
|
+
}
|
|
49878
|
+
return {
|
|
49879
|
+
join: head,
|
|
49880
|
+
field: second,
|
|
49881
|
+
joined,
|
|
49882
|
+
relationship: join.relationship
|
|
49883
|
+
};
|
|
49884
|
+
}
|
|
49885
|
+
function pathColumnsOf(grain, facts) {
|
|
49886
|
+
const out = [];
|
|
49887
|
+
const add = (entry, column, join, joined) => {
|
|
49888
|
+
const field = fieldNameOf2(joined);
|
|
49889
|
+
const timeframe = joined.timeframe;
|
|
49890
|
+
out.push({
|
|
49891
|
+
grain: entry,
|
|
49892
|
+
column,
|
|
49893
|
+
join,
|
|
49894
|
+
field,
|
|
49895
|
+
...typeof timeframe === "string" ? { timeframe } : {},
|
|
49896
|
+
...fieldNotes(joined).length > 0 ? { annotated: true } : {}
|
|
49897
|
+
});
|
|
49898
|
+
};
|
|
49899
|
+
for (const g of grain) {
|
|
49900
|
+
if (g.includes(".")) {
|
|
49901
|
+
const path = pathGrainOf(g, facts);
|
|
49902
|
+
if (!("problem" in path))
|
|
49903
|
+
add(g, grainColumnOf(g), path.join, path.joined);
|
|
49904
|
+
continue;
|
|
49905
|
+
}
|
|
49906
|
+
const read = exactPathRead(facts.byName.get(g)?.e);
|
|
49907
|
+
if (!read)
|
|
49908
|
+
continue;
|
|
49909
|
+
const path = pathGrainOf(read.join("."), facts);
|
|
49910
|
+
if ("problem" in path)
|
|
49911
|
+
continue;
|
|
49912
|
+
add(g, g, path.join, path.joined);
|
|
49913
|
+
}
|
|
49914
|
+
return out;
|
|
49915
|
+
}
|
|
49916
|
+
function pathReadsCurrentTime(g, facts) {
|
|
49917
|
+
const path = grainPathOf(g);
|
|
49918
|
+
if (!path || !facts.joins.has(path.join))
|
|
49919
|
+
return false;
|
|
49920
|
+
const joinField = facts.byName.get(path.join);
|
|
49921
|
+
return currentTimeFields(joinField?.fields).has(path.field);
|
|
49922
|
+
}
|
|
49923
|
+
function joinOneGrainOf(grain, facts) {
|
|
49924
|
+
const byJoin = new Map;
|
|
49925
|
+
const add = (join, entry) => {
|
|
49926
|
+
if (facts.joins.get(join)?.relationship !== "one")
|
|
49927
|
+
return;
|
|
49928
|
+
const entries = byJoin.get(join) ?? [];
|
|
49929
|
+
if (!entries.includes(entry))
|
|
49930
|
+
entries.push(entry);
|
|
49931
|
+
byJoin.set(join, entries);
|
|
49932
|
+
};
|
|
49933
|
+
for (const g of grain) {
|
|
49934
|
+
const path = grainPathOf(g);
|
|
49935
|
+
if (path) {
|
|
49936
|
+
add(path.join, g);
|
|
49937
|
+
continue;
|
|
49938
|
+
}
|
|
49939
|
+
for (const j of facts.joinUsage.get(g)?.joins ?? [])
|
|
49940
|
+
add(j, g);
|
|
49941
|
+
}
|
|
49942
|
+
if (byJoin.size === 0)
|
|
49943
|
+
return {};
|
|
49944
|
+
return {
|
|
49945
|
+
joinOneGrain: [...byJoin].sort(([a], [b]) => byCodepoint2(a, b)).map(([join, entries]) => ({ join, grain: entries }))
|
|
49946
|
+
};
|
|
49947
|
+
}
|
|
49948
|
+
function exactPathRead(e) {
|
|
49949
|
+
const n = e;
|
|
49950
|
+
if (n?.node !== "field" || !Array.isArray(n.path) || n.path.length !== 2 || !n.path.every((p) => typeof p === "string")) {
|
|
49951
|
+
return;
|
|
49952
|
+
}
|
|
49953
|
+
return n.path;
|
|
49954
|
+
}
|
|
49955
|
+
function unreadableStoredGrain(grain, fieldOf, dialect) {
|
|
48919
49956
|
if (dialect !== STORAGE_DIALECT)
|
|
48920
49957
|
return;
|
|
48921
49958
|
for (const name of grain) {
|
|
48922
|
-
const f =
|
|
49959
|
+
const f = fieldOf(name);
|
|
48923
49960
|
if (f?.type !== "sql native" || typeof f.rawType !== "string")
|
|
48924
49961
|
continue;
|
|
48925
49962
|
const storedType = f.rawType.toUpperCase();
|
|
@@ -49007,6 +50044,7 @@ function rollupPlanOf({ decl, measures }, node, facts, ctx) {
|
|
|
49007
50044
|
inherited.set(`${at.range.start.line}:${at.range.start.character}`, at);
|
|
49008
50045
|
}
|
|
49009
50046
|
}
|
|
50047
|
+
const pathColumns = pathColumnsOf(decl.grain, facts);
|
|
49010
50048
|
const liftedAncestors = [...inherited.values()].sort((a, b) => a.range.start.line - b.range.start.line || a.range.start.character - b.range.start.character);
|
|
49011
50049
|
return {
|
|
49012
50050
|
variant: true,
|
|
@@ -49032,7 +50070,12 @@ function rollupPlanOf({ decl, measures }, node, facts, ctx) {
|
|
|
49032
50070
|
...liftedAncestors.length > 0 ? { liftedAncestors } : {},
|
|
49033
50071
|
..."terms" in facts.given && facts.given.terms.length > 0 ? { readTimeTerms: facts.given.terms } : {},
|
|
49034
50072
|
...(privateGrain.length > 0 || ("terms" in facts.given) && facts.given.terms.length > 0) && facts.declaration ? { declaration: facts.declaration } : {},
|
|
50073
|
+
...pathColumns.length > 0 ? { pathColumns } : {},
|
|
50074
|
+
...joinOneGrainOf(decl.grain, facts),
|
|
49035
50075
|
fanOutDimensions: decl.grain.filter((g) => {
|
|
50076
|
+
const path = grainPathOf(g);
|
|
50077
|
+
if (path)
|
|
50078
|
+
return joins.get(path.join)?.relationship !== "one";
|
|
49036
50079
|
const usage = joinUsage.get(g);
|
|
49037
50080
|
if (usage === undefined)
|
|
49038
50081
|
return joinUsage.has(g);
|
|
@@ -49203,8 +50246,9 @@ function storedDestinationsOf(map, struct) {
|
|
|
49203
50246
|
}
|
|
49204
50247
|
function rollupKeyCheckQuery(plan) {
|
|
49205
50248
|
const [key, ...rest] = plan.grainDimensions;
|
|
49206
|
-
if (key === undefined || rest.length > 0)
|
|
50249
|
+
if (key === undefined || rest.length > 0 || grainPathOf(key)) {
|
|
49207
50250
|
return;
|
|
50251
|
+
}
|
|
49208
50252
|
return `run: ${keyCheckPipeline("rollup_key", rollupBaseAlias(plan.baseDeclaredName), key)}`;
|
|
49209
50253
|
}
|
|
49210
50254
|
function parentKeyNeedsOf(map) {
|
|
@@ -49346,139 +50390,6 @@ var init_source_connection_type = __esm(() => {
|
|
|
49346
50390
|
];
|
|
49347
50391
|
});
|
|
49348
50392
|
|
|
49349
|
-
// src/service/materialization/domain/same_catalog_build.ts
|
|
49350
|
-
function isSameCatalog(source, destination) {
|
|
49351
|
-
const a = source?.type === "ducklake" ? source.ducklakeConnection : undefined;
|
|
49352
|
-
const b = destination?.type === "ducklake" ? destination.ducklakeConnection : undefined;
|
|
49353
|
-
if (!a || !b)
|
|
49354
|
-
return false;
|
|
49355
|
-
const pa = a.catalog?.postgresConnection;
|
|
49356
|
-
const pb = b.catalog?.postgresConnection;
|
|
49357
|
-
if (!pa || !pb)
|
|
49358
|
-
return false;
|
|
49359
|
-
const path = (url) => (url ?? "").replace(/\/+$/, "");
|
|
49360
|
-
const pathA = path(a.storage?.bucketUrl);
|
|
49361
|
-
const pathB = path(b.storage?.bucketUrl);
|
|
49362
|
-
return !!pa.host && pa.host === pb.host && (pa.port ?? 5432) === (pb.port ?? 5432) && !!pa.databaseName && pa.databaseName === pb.databaseName && (a.catalog.metadataSchema ?? "") === (b.catalog.metadataSchema ?? "") && (pathA === "" || pathB === "" || pathA === pathB);
|
|
49363
|
-
}
|
|
49364
|
-
function carriesAuthorSql(def) {
|
|
49365
|
-
return authorSqlCause(def) !== undefined;
|
|
49366
|
-
}
|
|
49367
|
-
function authorSqlCause(def) {
|
|
49368
|
-
const seen = new Set;
|
|
49369
|
-
const walk = (node, depth, frames) => {
|
|
49370
|
-
if (depth > MAX_DEPTH4)
|
|
49371
|
-
return { found: UNREADABLE3, frames };
|
|
49372
|
-
if (node === null || typeof node !== "object")
|
|
49373
|
-
return;
|
|
49374
|
-
if (seen.has(node))
|
|
49375
|
-
return;
|
|
49376
|
-
seen.add(node);
|
|
49377
|
-
if (Array.isArray(node)) {
|
|
49378
|
-
for (const child of node) {
|
|
49379
|
-
const hit = walk(child, depth + 1, frames);
|
|
49380
|
-
if (hit)
|
|
49381
|
-
return hit;
|
|
49382
|
-
}
|
|
49383
|
-
return;
|
|
49384
|
-
}
|
|
49385
|
-
const record = node;
|
|
49386
|
-
if (typeof record.join === "string") {
|
|
49387
|
-
frames = [
|
|
49388
|
-
...frames,
|
|
49389
|
-
{
|
|
49390
|
-
kind: "join",
|
|
49391
|
-
as: String(record.as ?? record.name ?? ""),
|
|
49392
|
-
source: sourceNameOf(record)
|
|
49393
|
-
}
|
|
49394
|
-
];
|
|
49395
|
-
}
|
|
49396
|
-
if (record.type === "sql_select") {
|
|
49397
|
-
return { found: { kind: "sql_source" }, frames };
|
|
49398
|
-
}
|
|
49399
|
-
if (record.node === "genericSQLExpr") {
|
|
49400
|
-
return { found: { kind: "sql_expression" }, frames };
|
|
49401
|
-
}
|
|
49402
|
-
if (record.type === "table" && typeof record.tablePath === "string" && !CATALOG_TABLE_PATH.test(record.tablePath)) {
|
|
49403
|
-
return {
|
|
49404
|
-
found: { kind: "file_table", path: record.tablePath },
|
|
49405
|
-
frames
|
|
49406
|
-
};
|
|
49407
|
-
}
|
|
49408
|
-
for (const [key, child] of Object.entries(record)) {
|
|
49409
|
-
if (record.node === "function_call" && key === "overload")
|
|
49410
|
-
continue;
|
|
49411
|
-
const hit = key === "fields" && Array.isArray(child) ? walkFields(child, depth + 1, frames) : walk(child, depth + 1, key === "structRef" && child !== null && typeof child === "object" ? [
|
|
49412
|
-
...frames,
|
|
49413
|
-
{
|
|
49414
|
-
kind: "reads",
|
|
49415
|
-
source: sourceNameOf(child)
|
|
49416
|
-
}
|
|
49417
|
-
] : frames);
|
|
49418
|
-
if (hit)
|
|
49419
|
-
return hit;
|
|
49420
|
-
}
|
|
49421
|
-
return;
|
|
49422
|
-
};
|
|
49423
|
-
const walkFields = (fields, depth, frames) => {
|
|
49424
|
-
if (depth > MAX_DEPTH4)
|
|
49425
|
-
return { found: UNREADABLE3, frames };
|
|
49426
|
-
if (seen.has(fields))
|
|
49427
|
-
return;
|
|
49428
|
-
seen.add(fields);
|
|
49429
|
-
for (const field of fields) {
|
|
49430
|
-
const f = field;
|
|
49431
|
-
const named = f !== null && typeof f === "object" && typeof f.name === "string" && typeof f.join !== "string";
|
|
49432
|
-
const hit = walk(field, depth + 1, named ? [...frames, { kind: "field", name: String(f.name) }] : frames);
|
|
49433
|
-
if (hit)
|
|
49434
|
-
return hit;
|
|
49435
|
-
}
|
|
49436
|
-
return;
|
|
49437
|
-
};
|
|
49438
|
-
try {
|
|
49439
|
-
if (def === null || typeof def !== "object")
|
|
49440
|
-
return describe3([], UNREADABLE3);
|
|
49441
|
-
const hit = walk(def, 0, []);
|
|
49442
|
-
return hit ? describe3(hit.frames, hit.found) : undefined;
|
|
49443
|
-
} catch {
|
|
49444
|
-
return describe3([], UNREADABLE3);
|
|
49445
|
-
}
|
|
49446
|
-
}
|
|
49447
|
-
function sourceNameOf(record) {
|
|
49448
|
-
const id = typeof record.sourceID === "string" ? record.sourceID : "";
|
|
49449
|
-
const name = typeof record.name === "string" ? record.name : "";
|
|
49450
|
-
return id.split("@")[0] || (name.startsWith("sql://") ? "" : name);
|
|
49451
|
-
}
|
|
49452
|
-
function describe3(frames, found) {
|
|
49453
|
-
if (found.kind === "unreadable") {
|
|
49454
|
-
return "its definition could not be read to check for SQL its author wrote";
|
|
49455
|
-
}
|
|
49456
|
-
frames = frames.filter((frame, i) => frame.kind !== "reads" || i === frames.length - 1 && found.kind !== "sql_expression");
|
|
49457
|
-
const parts = [];
|
|
49458
|
-
let lead = true;
|
|
49459
|
-
for (const frame of frames) {
|
|
49460
|
-
const possessive = lead ? "its" : "whose";
|
|
49461
|
-
const subject = lead ? "it" : "which";
|
|
49462
|
-
lead = false;
|
|
49463
|
-
if (frame.kind === "join") {
|
|
49464
|
-
parts.push(`${possessive} join '${frame.as}'` + (frame.source ? ` reads source '${frame.source}'` : ""));
|
|
49465
|
-
} else if (frame.kind === "reads") {
|
|
49466
|
-
parts.push(frame.source ? `${subject} reads source '${frame.source}'` : `${subject} reads a source`);
|
|
49467
|
-
} else {
|
|
49468
|
-
parts.push(`${possessive} field '${frame.name}'`);
|
|
49469
|
-
}
|
|
49470
|
-
}
|
|
49471
|
-
const last = frames[frames.length - 1];
|
|
49472
|
-
const subject = frames.length === 0 ? "it" : ", which";
|
|
49473
|
-
const what = found.kind === "sql_source" ? `${subject} is an .sql() source` : found.kind === "file_table" ? `${subject} reads '${found.path.replace(/^'|'$/g, "")}' as a table` : last?.kind === "field" ? " uses a sql_* expression" : `${subject} uses a sql_* expression`;
|
|
49474
|
-
return (parts.join(", ") + what).replace(/^ /, "");
|
|
49475
|
-
}
|
|
49476
|
-
var CATALOG_TABLE_PATH, MAX_DEPTH4 = 200, UNREADABLE3;
|
|
49477
|
-
var init_same_catalog_build = __esm(() => {
|
|
49478
|
-
CATALOG_TABLE_PATH = /^[A-Za-z_][A-Za-z0-9_$]*(\.[A-Za-z_][A-Za-z0-9_$]*)*$/;
|
|
49479
|
-
UNREADABLE3 = { kind: "unreadable" };
|
|
49480
|
-
});
|
|
49481
|
-
|
|
49482
50393
|
// src/service/materialization/plan/materialization_eligibility.ts
|
|
49483
50394
|
function assertMaterializationEligible(persistSource, annotationFields, options = {}) {
|
|
49484
50395
|
const sourceName = persistSource.name;
|
|
@@ -50576,13 +51487,13 @@ var init_pair_reroot = __esm(() => {
|
|
|
50576
51487
|
});
|
|
50577
51488
|
|
|
50578
51489
|
// src/service/materialization/plan/materialize_plan.ts
|
|
50579
|
-
import { createHash as
|
|
51490
|
+
import { createHash as createHash9 } from "crypto";
|
|
50580
51491
|
import { Annotations as Annotations9 } from "@malloydata/malloy";
|
|
50581
51492
|
function materializeTableName(sourceName) {
|
|
50582
51493
|
if (PLAIN_TABLE_NAME.test(sourceName))
|
|
50583
51494
|
return sourceName;
|
|
50584
51495
|
const folded = sourceName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "");
|
|
50585
|
-
const hash =
|
|
51496
|
+
const hash = createHash9("sha256").update(sourceName).digest("hex");
|
|
50586
51497
|
return `${folded || "source"}_${hash.slice(0, 8)}`;
|
|
50587
51498
|
}
|
|
50588
51499
|
function readMaterializeDeclaration(def, contents = {}) {
|
|
@@ -56187,6 +57098,28 @@ var init_access_closure = __esm(() => {
|
|
|
56187
57098
|
]);
|
|
56188
57099
|
});
|
|
56189
57100
|
|
|
57101
|
+
// src/service/materialization/domain/target_containers.ts
|
|
57102
|
+
function targetContainerKey(target) {
|
|
57103
|
+
return JSON.stringify([target.connectionName, target.container]);
|
|
57104
|
+
}
|
|
57105
|
+
function containerOfTableName(name) {
|
|
57106
|
+
const dot = name.lastIndexOf(".");
|
|
57107
|
+
return dot > 0 ? name.slice(0, dot) : undefined;
|
|
57108
|
+
}
|
|
57109
|
+
function missingContainerReason(target, dialect, reading) {
|
|
57110
|
+
const kind = capabilitiesOf(dialect).containerCatalog === "dataset" ? "dataset" : "schema";
|
|
57111
|
+
const where = `its name= places its table in ${kind} "${target.container}"`;
|
|
57112
|
+
if ("otherLocation" in reading) {
|
|
57113
|
+
const { location, expected } = reading.otherLocation;
|
|
57114
|
+
return `${where}, which is in location "${location}", but connection ` + `"${target.connectionName}" runs its queries in "${expected}"; ` + `create the ${kind} in "${expected}", or change name= to a ${kind} ` + `there`;
|
|
57115
|
+
}
|
|
57116
|
+
const project = reading.project ? ` (project "${reading.project}")` : "";
|
|
57117
|
+
return `${where}${project}, which connection "${target.connectionName}" does ` + `not hold, and no build creates one; create the ${kind}, or change ` + `name= to one that exists`;
|
|
57118
|
+
}
|
|
57119
|
+
var init_target_containers = __esm(() => {
|
|
57120
|
+
init_dialect();
|
|
57121
|
+
});
|
|
57122
|
+
|
|
56190
57123
|
// src/service/materialization/domain/package_plan.ts
|
|
56191
57124
|
function countRefusal(counts, reason) {
|
|
56192
57125
|
counts[reason] = (counts[reason] ?? 0) + 1;
|
|
@@ -56716,18 +57649,19 @@ function inDestinationStringReads(args, stored, planned, upstreams) {
|
|
|
56716
57649
|
const run = planned.kind === "query" ? `run: ${quotedIdentifier(planned.queryName)}` : `run: ${quotedIdentifier(planned.sourceName)} -> ${quotedIdentifier(planned.viewName)}`;
|
|
56717
57650
|
return planStringReads(args.stringReads, args.materializer, { run, stored: stored.upstreams.map((u) => u.sourceID) }, planned.storage, upstreams);
|
|
56718
57651
|
}
|
|
56719
|
-
async function chainedStringReads(source, modelDef, materializer, ports, judged) {
|
|
57652
|
+
async function chainedStringReads(source, modelDef, materializer, ports, judged, planned) {
|
|
56720
57653
|
const destination = declaredStorage(source)?.trim();
|
|
56721
57654
|
if (!destination)
|
|
56722
57655
|
return;
|
|
56723
57656
|
const map = SourceMap.of(modelDef);
|
|
56724
57657
|
const def = map.node(source.sourceID)?.def;
|
|
56725
|
-
if (def?.type !== "query_source"
|
|
57658
|
+
if (def?.type !== "query_source")
|
|
56726
57659
|
return;
|
|
56727
|
-
}
|
|
56728
57660
|
const stored = reachedUpstreams(def, modelDef, map).filter((u) => u.storage === destination && u.sourceID !== source.sourceID).map((u) => u.sourceID);
|
|
56729
57661
|
if (stored.length === 0)
|
|
56730
57662
|
return;
|
|
57663
|
+
if (sharesStoredBuild(source, stored, planned))
|
|
57664
|
+
return;
|
|
56731
57665
|
const reads = await planStringReads(ports, materializer, { downstream: source.name, stored }, destination, { modelDef, judged });
|
|
56732
57666
|
if (!("refused" in reads) || !reads.unstored)
|
|
56733
57667
|
return reads;
|
|
@@ -56738,6 +57672,19 @@ async function chainedStringReads(source, modelDef, materializer, ports, judged)
|
|
|
56738
57672
|
unstored: true
|
|
56739
57673
|
} : reads;
|
|
56740
57674
|
}
|
|
57675
|
+
function sharesStoredBuild(source, stored, planned) {
|
|
57676
|
+
const keyOf = (s) => {
|
|
57677
|
+
if (!s)
|
|
57678
|
+
return;
|
|
57679
|
+
try {
|
|
57680
|
+
return compilerBuildId(s);
|
|
57681
|
+
} catch {
|
|
57682
|
+
return;
|
|
57683
|
+
}
|
|
57684
|
+
};
|
|
57685
|
+
const own = keyOf(source);
|
|
57686
|
+
return own !== undefined && stored.some((id) => keyOf(planned.get(id)) === own);
|
|
57687
|
+
}
|
|
56741
57688
|
async function collectGeneratedPersistedViews(parts, args) {
|
|
56742
57689
|
const authorDef = modelDefOf(args.malloyModel);
|
|
56743
57690
|
const { generated, refused, refusedQueries, omitted, failure } = await tryCompilePersistedViewCompanion({
|
|
@@ -56943,13 +57890,14 @@ async function collectGeneratedTables(parts, args) {
|
|
|
56943
57890
|
parts.modelGateLines.nameProblems.push(...persistNameProblems(text, modelPath));
|
|
56944
57891
|
}
|
|
56945
57892
|
}
|
|
57893
|
+
const materializeOn = getMaterializeEnabled();
|
|
56946
57894
|
collectPersistQueryFindings(parts, {
|
|
56947
57895
|
modelPath,
|
|
56948
57896
|
packagePath,
|
|
56949
57897
|
malloyModel,
|
|
56950
|
-
notBuilt: !
|
|
57898
|
+
notBuilt: !materializeOn
|
|
56951
57899
|
});
|
|
56952
|
-
if (!
|
|
57900
|
+
if (!materializeOn) {
|
|
56953
57901
|
collectPersistViewFindingsSwitchedOff(parts, {
|
|
56954
57902
|
modelPath,
|
|
56955
57903
|
packagePath,
|
|
@@ -56957,7 +57905,7 @@ async function collectGeneratedTables(parts, args) {
|
|
|
56957
57905
|
});
|
|
56958
57906
|
}
|
|
56959
57907
|
let materialized;
|
|
56960
|
-
if (
|
|
57908
|
+
if (materializeOn) {
|
|
56961
57909
|
materialized = await collectGeneratedMaterialize(parts, {
|
|
56962
57910
|
modelPath,
|
|
56963
57911
|
packagePath,
|
|
@@ -57074,7 +58022,7 @@ function reportPersistLineFindings(parts, targets, planned, args) {
|
|
|
57074
58022
|
route: "@",
|
|
57075
58023
|
tier: "malformed",
|
|
57076
58024
|
code: "persist-not-materializable",
|
|
57077
|
-
message: `#@ persist source "${name}" is not a source Malloy can ` + `materialize: only a query or aggregate source builds, and a ` + `filtered pass-through, a table with only added fields, or an ` + `unbound parameterized source does not.
|
|
58025
|
+
message: `#@ persist source "${name}" is not a source Malloy can ` + `materialize: only a query or aggregate source builds, and a ` + `filtered pass-through, a table with only added fields, or an ` + `unbound parameterized source does not. ` + (getMaterializeEnabled() ? `Mark a table-shaped source \`#(materialize)\` instead, ` + `which stores a table-shaped source as well as a ` + `query-shaped one; or persist a query source over it, ` : `Persist a query source over it, `) + `invoke a parameterized source with a bound argument, or ` + `remove the annotation`,
|
|
57078
58026
|
subject: name,
|
|
57079
58027
|
model: modelPath
|
|
57080
58028
|
});
|
|
@@ -57083,6 +58031,7 @@ function reportPersistLineFindings(parts, targets, planned, args) {
|
|
|
57083
58031
|
async function planV1PersistSources(parts, planned, args) {
|
|
57084
58032
|
const { modelPath, packagePath, materializer, malloyModel } = args;
|
|
57085
58033
|
let classificationCtx;
|
|
58034
|
+
const plannedByID = new Map(planned.map((s) => [s.sourceID, s]));
|
|
57086
58035
|
for (const source of planned) {
|
|
57087
58036
|
const sourceID = source.sourceID;
|
|
57088
58037
|
try {
|
|
@@ -57112,7 +58061,7 @@ async function planV1PersistSources(parts, planned, args) {
|
|
|
57112
58061
|
modelDef: modelDefOf(malloyModel),
|
|
57113
58062
|
deps: gateDepsFor(malloyModel, modelPath)
|
|
57114
58063
|
};
|
|
57115
|
-
const stringReads = declaringModelPath(sourceIDFileURL(sourceID), packagePath, modelPath) === modelPath ? await chainedStringReads(source, classificationCtx.modelDef, materializer, args.stringReads, parts.stringCapabilityReads) : parts.tables[sourceID]?.stringReads;
|
|
58064
|
+
const stringReads = declaringModelPath(sourceIDFileURL(sourceID), packagePath, modelPath) === modelPath ? await chainedStringReads(source, classificationCtx.modelDef, materializer, args.stringReads, parts.stringCapabilityReads, plannedByID) : parts.tables[sourceID]?.stringReads;
|
|
57116
58065
|
const destination = declaredStorage(source)?.trim();
|
|
57117
58066
|
const map = SourceMap.of(classificationCtx.modelDef);
|
|
57118
58067
|
const query = map.node(sourceID)?.def?.query;
|
|
@@ -57289,7 +58238,7 @@ function finishBuildPlan(parts, ctx) {
|
|
|
57289
58238
|
addresses: planAddresses({ ...plan, tableFolds })
|
|
57290
58239
|
};
|
|
57291
58240
|
const refused = refuseCollidingMaterialize(refuseRewrittenNames(full));
|
|
57292
|
-
const known = refuseUpstreamUnread(refused);
|
|
58241
|
+
const known = refuseMissingContainers(refuseUpstreamUnread(refused), ctx.targetContainers);
|
|
57293
58242
|
return refuseOverMissingUpstreams(refuseUncomparableStrings(refuseAcrossPlacements(ctx.keepIncrementalUnbuildable ? known : refuseIncrementalUnbuildable(known))), full);
|
|
57294
58243
|
}
|
|
57295
58244
|
function refuseAcrossPlacements(compiled) {
|
|
@@ -57409,21 +58358,45 @@ function refuseOverMissingUpstreams(compiled, full = compiled) {
|
|
|
57409
58358
|
return dropped.size === 0 ? compiled : withoutSources(compiled, findings, dropped);
|
|
57410
58359
|
}
|
|
57411
58360
|
async function finishPackagePlan(parts, ctx) {
|
|
57412
|
-
const {
|
|
58361
|
+
const {
|
|
58362
|
+
getMalloyConnection,
|
|
58363
|
+
readUpstreamSchemas,
|
|
58364
|
+
readTargetContainers,
|
|
58365
|
+
...finish
|
|
58366
|
+
} = ctx;
|
|
57413
58367
|
const connections = await resolvePackageConnections({ getMalloyConnection }, parts.builds.map((b) => b.connectionName));
|
|
57414
58368
|
const digestSkipped = [];
|
|
57415
58369
|
const connectionDigests = await resolveConnectionDigests(connections, parts.builds, (name) => digestSkipped.push(name));
|
|
57416
58370
|
const upstreamSchemas = readUpstreamSchemas ? await readUpstreamSchemas(planUpstreamTables(parts.tables)) : undefined;
|
|
58371
|
+
const containers = planTargetContainers(parts.tables);
|
|
58372
|
+
const targetContainers = readTargetContainers && containers.length > 0 ? await readTargetContainers(containers) : undefined;
|
|
57417
58373
|
return {
|
|
57418
58374
|
compiled: finishBuildPlan(parts, {
|
|
57419
58375
|
...finish,
|
|
57420
58376
|
connectionDigests,
|
|
57421
58377
|
...upstreamSchemas ? { upstreamSchemas } : {},
|
|
58378
|
+
...targetContainers ? { targetContainers } : {},
|
|
57422
58379
|
connections
|
|
57423
58380
|
}),
|
|
57424
58381
|
digestSkipped
|
|
57425
58382
|
};
|
|
57426
58383
|
}
|
|
58384
|
+
function targetContainerOf(source) {
|
|
58385
|
+
if (declaredStorage(source) !== undefined)
|
|
58386
|
+
return;
|
|
58387
|
+
const name = deriveAnnotationFields(source).name;
|
|
58388
|
+
const container = name ? containerOfTableName(name) : undefined;
|
|
58389
|
+
return container ? { connectionName: source.connectionName, container } : undefined;
|
|
58390
|
+
}
|
|
58391
|
+
function planTargetContainers(tables) {
|
|
58392
|
+
const out = new Map;
|
|
58393
|
+
for (const { source } of Object.values(tables)) {
|
|
58394
|
+
const target = targetContainerOf(source);
|
|
58395
|
+
if (target)
|
|
58396
|
+
out.set(targetContainerKey(target), target);
|
|
58397
|
+
}
|
|
58398
|
+
return [...out.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, t]) => t);
|
|
58399
|
+
}
|
|
57427
58400
|
function planUpstreamTables(tables) {
|
|
57428
58401
|
const out = new Map;
|
|
57429
58402
|
for (const { source } of Object.values(tables)) {
|
|
@@ -57590,6 +58563,26 @@ function refuseUpstreamUnread(compiled) {
|
|
|
57590
58563
|
}
|
|
57591
58564
|
return withoutSources(compiled, findings, dropped);
|
|
57592
58565
|
}
|
|
58566
|
+
function refuseMissingContainers(compiled, readings) {
|
|
58567
|
+
if (!readings)
|
|
58568
|
+
return compiled;
|
|
58569
|
+
const shared = sharedTables(compiled);
|
|
58570
|
+
const findings = [];
|
|
58571
|
+
const dropped = new Set;
|
|
58572
|
+
for (const [sourceID, { source }] of Object.entries(compiled.tables)) {
|
|
58573
|
+
if (shared.has(sourceID))
|
|
58574
|
+
continue;
|
|
58575
|
+
const target = targetContainerOf(source);
|
|
58576
|
+
if (!target)
|
|
58577
|
+
continue;
|
|
58578
|
+
const reading = readings[targetContainerKey(target)];
|
|
58579
|
+
if (!reading || "found" in reading || "unread" in reading)
|
|
58580
|
+
continue;
|
|
58581
|
+
dropped.add(sourceID);
|
|
58582
|
+
findings.push(notBuiltFinding(compiled, sourceID, "container_not_found", missingContainerReason(target, source.dialectName, reading)));
|
|
58583
|
+
}
|
|
58584
|
+
return withoutSources(compiled, findings, dropped);
|
|
58585
|
+
}
|
|
57593
58586
|
function notBuiltFinding(compiled, sourceID, reason, why) {
|
|
57594
58587
|
const table = compiled.tables[sourceID];
|
|
57595
58588
|
const source = table.source;
|
|
@@ -57794,6 +58787,7 @@ var init_build_plan = __esm(() => {
|
|
|
57794
58787
|
init_persist_source_fields();
|
|
57795
58788
|
init_quoting();
|
|
57796
58789
|
init_addressing();
|
|
58790
|
+
init_target_containers();
|
|
57797
58791
|
init_eligibility_collect();
|
|
57798
58792
|
init_plan_layers();
|
|
57799
58793
|
init_addressing();
|
|
@@ -57810,7 +58804,7 @@ var init_build_plan = __esm(() => {
|
|
|
57810
58804
|
});
|
|
57811
58805
|
|
|
57812
58806
|
// src/package_load/protocol.ts
|
|
57813
|
-
var PACKAGE_LOAD_PROTOCOL_VERSION =
|
|
58807
|
+
var PACKAGE_LOAD_PROTOCOL_VERSION = 9;
|
|
57814
58808
|
|
|
57815
58809
|
// src/package_load/package_load_worker.ts
|
|
57816
58810
|
init_served_copy_serve();
|
|
@@ -57822,6 +58816,16 @@ init_data_styles();
|
|
|
57822
58816
|
init_overlay_key();
|
|
57823
58817
|
init_errors2();
|
|
57824
58818
|
init_error_wire();
|
|
58819
|
+
init_job_files();
|
|
58820
|
+
init_translator_error();
|
|
58821
|
+
init_model_load_checks();
|
|
58822
|
+
init_model_info();
|
|
58823
|
+
init_model_notebook_cell();
|
|
58824
|
+
init_package_revision();
|
|
58825
|
+
init_package_manifest();
|
|
58826
|
+
init_plan();
|
|
58827
|
+
init_package_retrieval_settings();
|
|
58828
|
+
init_utils();
|
|
57825
58829
|
import {
|
|
57826
58830
|
contextOverlay,
|
|
57827
58831
|
MalloyConfig as MalloyConfig4,
|
|
@@ -57830,216 +58834,10 @@ import {
|
|
|
57830
58834
|
import * as fs10 from "fs";
|
|
57831
58835
|
import * as path20 from "path";
|
|
57832
58836
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
57833
|
-
import { createHash as
|
|
58837
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
57834
58838
|
import { parentPort, threadId, workerData as workerData2 } from "node:worker_threads";
|
|
57835
58839
|
import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL17 } from "url";
|
|
57836
58840
|
|
|
57837
|
-
// src/package_load/job_files.ts
|
|
57838
|
-
init_constants();
|
|
57839
|
-
init_data_styles();
|
|
57840
|
-
import {
|
|
57841
|
-
CacheManager,
|
|
57842
|
-
InMemoryModelCache
|
|
57843
|
-
} from "@malloydata/malloy";
|
|
57844
|
-
import * as path6 from "path";
|
|
57845
|
-
import { fileURLToPath as fileURLToPath5, pathToFileURL as pathToFileURL5 } from "url";
|
|
57846
|
-
function jobFiles(inner) {
|
|
57847
|
-
const texts = new Map;
|
|
57848
|
-
const stylesByUrl = new Map;
|
|
57849
|
-
const reads = new Map;
|
|
57850
|
-
const reader = {
|
|
57851
|
-
readURL: (url) => {
|
|
57852
|
-
const key = url.toString();
|
|
57853
|
-
let read = reads.get(key);
|
|
57854
|
-
if (!read) {
|
|
57855
|
-
read = (async () => {
|
|
57856
|
-
const contents = await inner.readURL(url);
|
|
57857
|
-
texts.set(key, contents);
|
|
57858
|
-
stylesByUrl.set(key, await dataStylesForFile(key, contents, inner));
|
|
57859
|
-
return contents;
|
|
57860
|
-
})();
|
|
57861
|
-
reads.set(key, read);
|
|
57862
|
-
read.catch(() => reads.delete(key));
|
|
57863
|
-
}
|
|
57864
|
-
return read;
|
|
57865
|
-
}
|
|
57866
|
-
};
|
|
57867
|
-
return {
|
|
57868
|
-
reader,
|
|
57869
|
-
texts,
|
|
57870
|
-
stylesByUrl,
|
|
57871
|
-
models: new Map,
|
|
57872
|
-
imported: new Set,
|
|
57873
|
-
stats: { stored: 0, reused: 0 }
|
|
57874
|
-
};
|
|
57875
|
-
}
|
|
57876
|
-
function urlKey(url) {
|
|
57877
|
-
try {
|
|
57878
|
-
return new URL(url).href;
|
|
57879
|
-
} catch {
|
|
57880
|
-
return url;
|
|
57881
|
-
}
|
|
57882
|
-
}
|
|
57883
|
-
var sameUrl = (a, b) => a === b || urlKey(a) === urlKey(b);
|
|
57884
|
-
function decodedUrl(url) {
|
|
57885
|
-
try {
|
|
57886
|
-
return decodeURI(url);
|
|
57887
|
-
} catch {
|
|
57888
|
-
return url;
|
|
57889
|
-
}
|
|
57890
|
-
}
|
|
57891
|
-
|
|
57892
|
-
class ModelCacheView extends CacheManager {
|
|
57893
|
-
files;
|
|
57894
|
-
ownUrl;
|
|
57895
|
-
constructor(files, ownUrl) {
|
|
57896
|
-
super(new InMemoryModelCache);
|
|
57897
|
-
this.files = files;
|
|
57898
|
-
this.ownUrl = ownUrl;
|
|
57899
|
-
}
|
|
57900
|
-
async getCachedModelDef(...[, url]) {
|
|
57901
|
-
if (sameUrl(url, this.ownUrl))
|
|
57902
|
-
return;
|
|
57903
|
-
const hit = this.files.models.get(url);
|
|
57904
|
-
if (!hit)
|
|
57905
|
-
return;
|
|
57906
|
-
this.files.stats.reused++;
|
|
57907
|
-
return {
|
|
57908
|
-
modelDef: structuredClone(hit.modelDef),
|
|
57909
|
-
invalidationKeys: { ...hit.invalidationKeys }
|
|
57910
|
-
};
|
|
57911
|
-
}
|
|
57912
|
-
async setCachedModelDef(...[url, cached]) {
|
|
57913
|
-
if (!this.files.imported.has(urlKey(url)))
|
|
57914
|
-
return false;
|
|
57915
|
-
if (sameUrl(url, this.ownUrl) && decodedUrl(url) !== url)
|
|
57916
|
-
return false;
|
|
57917
|
-
this.files.models.set(url, {
|
|
57918
|
-
modelDef: structuredClone(cached.modelDef),
|
|
57919
|
-
invalidationKeys: { ...cached.invalidationKeys }
|
|
57920
|
-
});
|
|
57921
|
-
this.files.stats.stored++;
|
|
57922
|
-
return true;
|
|
57923
|
-
}
|
|
57924
|
-
}
|
|
57925
|
-
function modelFileTexts(files, modelUrl, dependencies) {
|
|
57926
|
-
const byPath = new Map;
|
|
57927
|
-
for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
|
|
57928
|
-
const key = urlKey(url);
|
|
57929
|
-
const text = files.texts.get(key);
|
|
57930
|
-
if (text !== undefined && key.startsWith("file:")) {
|
|
57931
|
-
byPath.set(fileURLToPath5(key), text);
|
|
57932
|
-
}
|
|
57933
|
-
}
|
|
57934
|
-
return byPath;
|
|
57935
|
-
}
|
|
57936
|
-
function dataStylesForModel(files, modelUrl, dependencies) {
|
|
57937
|
-
let styles = {};
|
|
57938
|
-
for (const url of [modelUrl, ...importReadOrder(dependencies)]) {
|
|
57939
|
-
styles = { ...styles, ...files.stylesByUrl.get(urlKey(url)) ?? {} };
|
|
57940
|
-
}
|
|
57941
|
-
return styles;
|
|
57942
|
-
}
|
|
57943
|
-
function importReadOrder(tree) {
|
|
57944
|
-
const order = [];
|
|
57945
|
-
const seen = new Set;
|
|
57946
|
-
const descended = new Set;
|
|
57947
|
-
const visit = (node) => {
|
|
57948
|
-
if (!node || typeof node !== "object")
|
|
57949
|
-
return;
|
|
57950
|
-
const entries = Object.entries(node);
|
|
57951
|
-
for (const [url] of entries) {
|
|
57952
|
-
if (!seen.has(url)) {
|
|
57953
|
-
seen.add(url);
|
|
57954
|
-
order.push(url);
|
|
57955
|
-
}
|
|
57956
|
-
}
|
|
57957
|
-
for (const [url, sub] of entries) {
|
|
57958
|
-
if (descended.has(url))
|
|
57959
|
-
continue;
|
|
57960
|
-
descended.add(url);
|
|
57961
|
-
visit(sub);
|
|
57962
|
-
}
|
|
57963
|
-
};
|
|
57964
|
-
visit(tree);
|
|
57965
|
-
return order;
|
|
57966
|
-
}
|
|
57967
|
-
var IMPORT_RE = /^\s*import\s+(?:\{[^}]*\}\s+from\s+)?(?:"([^"]+)"|'([^']+)')/gim;
|
|
57968
|
-
async function compileOrder(packagePath, modelPaths, reader, imported = new Set) {
|
|
57969
|
-
const malloy = modelPaths.filter((p) => p.endsWith(MODEL_FILE_SUFFIX));
|
|
57970
|
-
const inPackage = new Set(malloy);
|
|
57971
|
-
const imports = new Map;
|
|
57972
|
-
for (const modelPath of malloy) {
|
|
57973
|
-
const url = pathToFileURL5(path6.join(packagePath, modelPath));
|
|
57974
|
-
let text = "";
|
|
57975
|
-
try {
|
|
57976
|
-
text = await reader.readURL(url);
|
|
57977
|
-
} catch {}
|
|
57978
|
-
const deps = [];
|
|
57979
|
-
for (const match of text.matchAll(IMPORT_RE)) {
|
|
57980
|
-
const target = match[1] ?? match[2];
|
|
57981
|
-
if (!target)
|
|
57982
|
-
continue;
|
|
57983
|
-
try {
|
|
57984
|
-
const resolved = new URL(target, url);
|
|
57985
|
-
if (resolved.protocol !== "file:")
|
|
57986
|
-
continue;
|
|
57987
|
-
const rel = path6.relative(packagePath, fileURLToPath5(resolved)).replace(/\\/g, "/");
|
|
57988
|
-
if (inPackage.has(rel)) {
|
|
57989
|
-
deps.push(rel);
|
|
57990
|
-
imported.add(urlKey(resolved.href));
|
|
57991
|
-
}
|
|
57992
|
-
} catch {}
|
|
57993
|
-
}
|
|
57994
|
-
imports.set(modelPath, deps);
|
|
57995
|
-
}
|
|
57996
|
-
const level = new Map;
|
|
57997
|
-
const visiting = new Set;
|
|
57998
|
-
const levelOf = (modelPath) => {
|
|
57999
|
-
const known = level.get(modelPath);
|
|
58000
|
-
if (known !== undefined)
|
|
58001
|
-
return known;
|
|
58002
|
-
if (visiting.has(modelPath))
|
|
58003
|
-
return 0;
|
|
58004
|
-
visiting.add(modelPath);
|
|
58005
|
-
let mine = 0;
|
|
58006
|
-
for (const dep of imports.get(modelPath) ?? []) {
|
|
58007
|
-
mine = Math.max(mine, levelOf(dep) + 1);
|
|
58008
|
-
}
|
|
58009
|
-
visiting.delete(modelPath);
|
|
58010
|
-
level.set(modelPath, mine);
|
|
58011
|
-
return mine;
|
|
58012
|
-
};
|
|
58013
|
-
const levels = [];
|
|
58014
|
-
const waitsOn = new Map;
|
|
58015
|
-
for (const modelPath of malloy) {
|
|
58016
|
-
const mine = levelOf(modelPath);
|
|
58017
|
-
(levels[mine] ??= []).push(modelPath);
|
|
58018
|
-
waitsOn.set(modelPath, (imports.get(modelPath) ?? []).filter((dep) => levelOf(dep) < mine));
|
|
58019
|
-
}
|
|
58020
|
-
const rest = modelPaths.filter((p) => !p.endsWith(MODEL_FILE_SUFFIX));
|
|
58021
|
-
for (const modelPath of rest)
|
|
58022
|
-
waitsOn.set(modelPath, []);
|
|
58023
|
-
return {
|
|
58024
|
-
waitsOn,
|
|
58025
|
-
levels: [
|
|
58026
|
-
...levels.filter((l) => l !== undefined && l.length > 0),
|
|
58027
|
-
...rest.length > 0 ? [rest] : []
|
|
58028
|
-
]
|
|
58029
|
-
};
|
|
58030
|
-
}
|
|
58031
|
-
|
|
58032
|
-
// src/package_load/package_load_worker.ts
|
|
58033
|
-
init_translator_error();
|
|
58034
|
-
init_model_load_checks();
|
|
58035
|
-
init_model_info();
|
|
58036
|
-
init_model_notebook_cell();
|
|
58037
|
-
init_package_revision();
|
|
58038
|
-
init_package_manifest();
|
|
58039
|
-
init_plan();
|
|
58040
|
-
init_package_retrieval_settings();
|
|
58041
|
-
init_utils();
|
|
58042
|
-
|
|
58043
58841
|
// src/package_load/rpc_wait_accountant.ts
|
|
58044
58842
|
class RpcWaitAccountant {
|
|
58045
58843
|
now;
|
|
@@ -58259,7 +59057,7 @@ function callMain(send) {
|
|
|
58259
59057
|
}
|
|
58260
59058
|
var schemaWait = new RpcWaitAccountant;
|
|
58261
59059
|
function dispatchMainResponse(message) {
|
|
58262
|
-
if (message.type === "schema-for-tables-response" || message.type === "schema-for-sql-response" || message.type === "upstream-schemas-response" || message.type === "read-url-response" || message.type === "connection-metadata-response") {
|
|
59060
|
+
if (message.type === "schema-for-tables-response" || message.type === "schema-for-sql-response" || message.type === "upstream-schemas-response" || message.type === "target-containers-response" || message.type === "read-url-response" || message.type === "connection-metadata-response") {
|
|
58263
59061
|
const pending = pendingRpc.get(message.requestId);
|
|
58264
59062
|
if (!pending)
|
|
58265
59063
|
return;
|
|
@@ -58796,7 +59594,7 @@ var REFERENCE_ID = /reference_id = \\"[0-9a-f-]{36}\\"/g;
|
|
|
58796
59594
|
function digestRenderTagResults(results) {
|
|
58797
59595
|
try {
|
|
58798
59596
|
const json = JSON.stringify(results).replace(REFERENCE_ID, "reference_id = \\\"\\\"");
|
|
58799
|
-
return
|
|
59597
|
+
return createHash10("sha256").update(json).digest("hex");
|
|
58800
59598
|
} catch {
|
|
58801
59599
|
return;
|
|
58802
59600
|
}
|
|
@@ -58992,6 +59790,7 @@ async function loadPackage(job) {
|
|
|
58992
59790
|
models,
|
|
58993
59791
|
replacementMatchedExisting,
|
|
58994
59792
|
...refresh ? { refreshedSchemaKeys: [...refresh.refetched] } : {},
|
|
59793
|
+
fileDigests: fileTextDigests(files),
|
|
58995
59794
|
loadDurationMs: loadEnd - loadStart,
|
|
58996
59795
|
timings: {
|
|
58997
59796
|
compileDurationMs: Math.max(0, compileEnd - compileRegionStart - schemaFetchDurationMs),
|
|
@@ -59034,6 +59833,15 @@ async function finishWorkerBuildPlan(malloyConfig, modelPaths, load, materializa
|
|
|
59034
59833
|
tables
|
|
59035
59834
|
};
|
|
59036
59835
|
port.postMessage(req);
|
|
59836
|
+
})).readings,
|
|
59837
|
+
readTargetContainers: async (containers) => (await callMain((requestId) => {
|
|
59838
|
+
const req = {
|
|
59839
|
+
type: "target-containers",
|
|
59840
|
+
requestId,
|
|
59841
|
+
jobId,
|
|
59842
|
+
containers
|
|
59843
|
+
};
|
|
59844
|
+
port.postMessage(req);
|
|
59037
59845
|
})).readings
|
|
59038
59846
|
});
|
|
59039
59847
|
digestSkipped = finished.digestSkipped;
|