@holistics/cli-core 2.5.18 → 2.5.19
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/commands.js +437 -254
- package/package.json +1 -1
package/dist/commands.js
CHANGED
|
@@ -24097,7 +24097,7 @@ __export(exports_aml_es, {
|
|
|
24097
24097
|
uniqDiagnostics: () => yi
|
|
24098
24098
|
});
|
|
24099
24099
|
// package.json
|
|
24100
|
-
var version = "2.5.
|
|
24100
|
+
var version = "2.5.19";
|
|
24101
24101
|
|
|
24102
24102
|
// ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
|
|
24103
24103
|
class CommanderError extends Error {
|
|
@@ -89018,12 +89018,15 @@ class Or3 {
|
|
|
89018
89018
|
const c = Sr4(o);
|
|
89019
89019
|
this.otelSpan.setAttributes(c);
|
|
89020
89020
|
}
|
|
89021
|
+
setError(o) {
|
|
89022
|
+
const r = typeof o == "string" ? new Error(o) : o;
|
|
89023
|
+
this.otelSpan.recordException(r), this.otelSpan.setStatus({
|
|
89024
|
+
code: cu3.ERROR,
|
|
89025
|
+
message: r.message
|
|
89026
|
+
});
|
|
89027
|
+
}
|
|
89021
89028
|
end(o) {
|
|
89022
|
-
|
|
89023
|
-
let r = o;
|
|
89024
|
-
typeof o == "string" && (r = new Error(o)), this.otelSpan.recordException(r), this.otelSpan.setStatus({ code: cu3.ERROR });
|
|
89025
|
-
}
|
|
89026
|
-
this.otelSpan.end();
|
|
89029
|
+
o && this.setError(o), this.otelSpan.end();
|
|
89027
89030
|
}
|
|
89028
89031
|
updateName(o) {
|
|
89029
89032
|
this.otelSpan.updateName(o);
|
|
@@ -107048,6 +107051,14 @@ function modelFieldRefKey(e, t) {
|
|
|
107048
107051
|
function modelFieldRefAsKey(e) {
|
|
107049
107052
|
return import_lodash2.isEmpty(e.modelName) ? e.fieldName : `${e.modelName}->${e.fieldName}`;
|
|
107050
107053
|
}
|
|
107054
|
+
function transitiveDependencies(e, t) {
|
|
107055
|
+
let n = /* @__PURE__ */ new Set, r = [...e.get(t) ?? []];
|
|
107056
|
+
for (;r.length > 0; ) {
|
|
107057
|
+
let t = r.pop();
|
|
107058
|
+
n.has(t) || (n.add(t), r.push(...e.get(t) ?? []));
|
|
107059
|
+
}
|
|
107060
|
+
return n;
|
|
107061
|
+
}
|
|
107051
107062
|
function parseModelFieldReferenceKey(e) {
|
|
107052
107063
|
let t = e.split("->");
|
|
107053
107064
|
return t.length === 1 ? createModelFieldReference("", t[0]) : createModelFieldReference(t[0], t.slice(1).join("->"));
|
|
@@ -115419,6 +115430,9 @@ function transformDynamicExplore(e, t) {
|
|
|
115419
115430
|
r ? (r.origin && !isSubtimeField(r.origin) && !r.isCompiledAqlField && r.syntax !== "aql" && r.type === SqlType.DATETIME && !r.typeCast && e.store.dataSource.dbtype === DbType.BIGQUERY ? a.push({
|
|
115420
115431
|
...r,
|
|
115421
115432
|
typeCast: SqlType.DATETIME
|
|
115433
|
+
}) : (L.length > 1 || i) && !mi && getFieldResultType(r) === SqlType.UNKNOWN ? a.push({
|
|
115434
|
+
...r,
|
|
115435
|
+
typeCast: getFieldResultType(r)
|
|
115422
115436
|
}) : a.push(r), oi.has(t) && l++, pi.has(t) && c++, pe.has(t) && s.push({
|
|
115423
115437
|
name: rollupMarkerFieldName(t),
|
|
115424
115438
|
sql: "0",
|
|
@@ -120565,7 +120579,7 @@ function bodyTrace(e) {
|
|
|
120565
120579
|
udfName: n.name,
|
|
120566
120580
|
source: e,
|
|
120567
120581
|
syntax: "aql"
|
|
120568
|
-
}) : n.kind !== "param" && t.push({
|
|
120582
|
+
}) : n.kind !== "param" && n.kind !== "query" && t.push({
|
|
120569
120583
|
type: n.kind,
|
|
120570
120584
|
field: n.modelName ? `${n.modelName}.${n.name}` : n.name,
|
|
120571
120585
|
source: e,
|
|
@@ -120675,6 +120689,16 @@ function declKey(e, t, n) {
|
|
|
120675
120689
|
return e;
|
|
120676
120690
|
}
|
|
120677
120691
|
}
|
|
120692
|
+
var QUERY_DECL_KEY = "query:";
|
|
120693
|
+
function refOfDeclKey(e) {
|
|
120694
|
+
let t = e.indexOf(":"), n = t < 0 ? "dimension" : e.slice(0, t), r = e.slice(t + 1);
|
|
120695
|
+
if (n === "metric")
|
|
120696
|
+
return createModelFieldReference("", r);
|
|
120697
|
+
if (n !== "dimension" && n !== "measure" && n !== "param")
|
|
120698
|
+
return;
|
|
120699
|
+
let i = r.lastIndexOf(".");
|
|
120700
|
+
return createModelFieldReference(r.slice(0, i), r.slice(i + 1));
|
|
120701
|
+
}
|
|
120678
120702
|
function isPrefixed(e) {
|
|
120679
120703
|
return e.includes(":");
|
|
120680
120704
|
}
|
|
@@ -120744,6 +120768,9 @@ function filterRefKeys(e) {
|
|
|
120744
120768
|
return false;
|
|
120745
120769
|
}), [...t];
|
|
120746
120770
|
}
|
|
120771
|
+
function declClosure(e, t) {
|
|
120772
|
+
return transitiveDependencies(e.declDeps, t);
|
|
120773
|
+
}
|
|
120747
120774
|
function dependsOn(e, t, n) {
|
|
120748
120775
|
let r = e.declDeps, i = /* @__PURE__ */ new Set, a = [...r.get(t) ?? []];
|
|
120749
120776
|
for (;a.length > 0; ) {
|
|
@@ -122106,7 +122133,8 @@ function nameInlined(e, t, n, r, i, a) {
|
|
|
122106
122133
|
ty: c,
|
|
122107
122134
|
name: synthIdent(e, t, [], c, r),
|
|
122108
122135
|
expr: n,
|
|
122109
|
-
synthetic: true
|
|
122136
|
+
synthetic: true,
|
|
122137
|
+
...a ? { inlinedField: a } : {}
|
|
122110
122138
|
};
|
|
122111
122139
|
}
|
|
122112
122140
|
function checkNamedLiterals(e, t, n, r) {
|
|
@@ -122427,6 +122455,25 @@ function grainMatches(e, t, n, r) {
|
|
|
122427
122455
|
let i = e.ty;
|
|
122428
122456
|
return isTableType(i) && i.name ? n && r ? relatedToModel(r, t, i.name) : t.modelName === i.name : isFieldType(i) && i.origin ? refEq(t, i.origin) || n && isSubtimeFieldOf(t, i.origin) : false;
|
|
122429
122457
|
}
|
|
122458
|
+
function scanRootOf(e) {
|
|
122459
|
+
let t = e;
|
|
122460
|
+
for (;; ) {
|
|
122461
|
+
if (t.kind === "expand_model")
|
|
122462
|
+
return t.model;
|
|
122463
|
+
if (t.kind === Kind.IDENTIFIER)
|
|
122464
|
+
return isTableType(t.ty) ? t.name : undefined;
|
|
122465
|
+
if (t.kind === "reduce" || t.kind === "select" || t.kind === "filter" || t.kind === "sort" || t.kind === "pivot" || t.kind === "union")
|
|
122466
|
+
t = t.input;
|
|
122467
|
+
else
|
|
122468
|
+
return;
|
|
122469
|
+
}
|
|
122470
|
+
}
|
|
122471
|
+
function isSliceable(e, t, n) {
|
|
122472
|
+
return n === "H.calendar" || e.canReach(t, n, {
|
|
122473
|
+
allowFanout: true,
|
|
122474
|
+
respectFilterDirection: true
|
|
122475
|
+
});
|
|
122476
|
+
}
|
|
122430
122477
|
var BIZ_CAL_SAFE_FNS = /* @__PURE__ */ new Set([
|
|
122431
122478
|
"date_trunc",
|
|
122432
122479
|
"year",
|
|
@@ -127970,10 +128017,10 @@ function orderWrapperName(e) {
|
|
|
127970
128017
|
return e.kind === Kind.FUNCTION_CALL && (e.name.name.startsWith("asc") || e.name.name.startsWith("desc")) ? e.name.name : undefined;
|
|
127971
128018
|
}
|
|
127972
128019
|
var GraphContext = class {
|
|
127973
|
-
|
|
128020
|
+
resolver;
|
|
127974
128021
|
graphs = [];
|
|
127975
128022
|
constructor(e) {
|
|
127976
|
-
this.
|
|
128023
|
+
this.resolver = e;
|
|
127977
128024
|
}
|
|
127978
128025
|
fingerprint() {
|
|
127979
128026
|
return this.graphs.map(objectId).join(",") || "-";
|
|
@@ -127982,10 +128029,10 @@ var GraphContext = class {
|
|
|
127982
128029
|
return this.graphs[this.graphs.length - 1] ?? this.baseGraph();
|
|
127983
128030
|
}
|
|
127984
128031
|
baseGraph() {
|
|
127985
|
-
return baseGraph(this.
|
|
128032
|
+
return baseGraph(this.resolver);
|
|
127986
128033
|
}
|
|
127987
128034
|
rlpGraph() {
|
|
127988
|
-
return rlpGraph(this.
|
|
128035
|
+
return rlpGraph(this.resolver);
|
|
127989
128036
|
}
|
|
127990
128037
|
graphFor(e) {
|
|
127991
128038
|
return e.role === "rlp" ? this.rlpGraph() : this.currentGraph();
|
|
@@ -127997,7 +128044,7 @@ var GraphContext = class {
|
|
|
127997
128044
|
if (e.code !== ErrorCode.RELATIONSHIP_NOT_FOUND_0)
|
|
127998
128045
|
throw e;
|
|
127999
128046
|
let n = e.args;
|
|
128000
|
-
this.
|
|
128047
|
+
this.resolver.dataset.diagnostics.push(createError(ErrorCode.RELATIONSHIP_NOT_FOUND_0, t, undefined, n?.[0]));
|
|
128001
128048
|
return;
|
|
128002
128049
|
}
|
|
128003
128050
|
}
|
|
@@ -128081,7 +128128,7 @@ var GrainFold = class e extends HirFold {
|
|
|
128081
128128
|
window = new Window(this);
|
|
128082
128129
|
timeSpine = new TimeSpine(this);
|
|
128083
128130
|
explore = new Explore(this);
|
|
128084
|
-
graphContext
|
|
128131
|
+
graphContext;
|
|
128085
128132
|
scope = ScopeChain.root();
|
|
128086
128133
|
auditSeen = /* @__PURE__ */ new Map;
|
|
128087
128134
|
inScope(e, t, n) {
|
|
@@ -128155,7 +128202,7 @@ var GrainFold = class e extends HirFold {
|
|
|
128155
128202
|
}
|
|
128156
128203
|
}
|
|
128157
128204
|
constructor(e) {
|
|
128158
|
-
super(), this.resolver = e, this.memo = new FoldMemo(e);
|
|
128205
|
+
super(), this.resolver = e, this.memo = new FoldMemo(e), this.graphContext = new GraphContext(e);
|
|
128159
128206
|
}
|
|
128160
128207
|
foldRelationshipKeyDims() {
|
|
128161
128208
|
for (let e of this.resolver.dataset.graph.relationships)
|
|
@@ -128535,18 +128582,15 @@ var GrainFold = class e extends HirFold {
|
|
|
128535
128582
|
return;
|
|
128536
128583
|
let n = this.graphContext.currentGraph(), r = t.model, i = this.timeSpine.graphWithCalendar(n), a = this.period.withExactRange(e, () => effectiveFiltersForModel(this, r));
|
|
128537
128584
|
a = [...a, ...this.period.dayRoundtripFilters(this.period.rawKeys(this.currentIteration().inheritedGroups).map((e) => e.expr))], a = this.applicableRlp(r, a), a = this.applicableFilters(i, r, a), a = this.semiJoinOnReachableSubjects(i, r, a);
|
|
128538
|
-
let s = narrowToReachableRows(this.resolver, i, r, normalizeConditions(this.resolver, a, i, r)), c = /* @__PURE__ */ new Set, { droppable: l = [] } = this.currentIteration(), u = (e) => e
|
|
128539
|
-
|
|
128540
|
-
|
|
128541
|
-
|
|
128542
|
-
t = addJoins(this.resolver, i, t, m, "grainKey", s, c), t.kind === "expand_model" && (t = applyFilters(this.resolver, i, t, s, c));
|
|
128543
|
-
let _ = s.filter((e) => !c.has(e)), v = this.resolver.dataset.spans.get(e.id) ?? locStub(), S = _.flatMap((e) => e.predicate.kind === "in_table_condition" ? e.predicate.row.map((e) => e.expr) : []);
|
|
128544
|
-
S.length > 0 && (t = addJoins(this.resolver, n, t, leafFields(this.resolver, S))), f.length > 0 && t.kind === "expand_model" && (t = {
|
|
128585
|
+
let s = narrowToReachableRows(this.resolver, i, r, normalizeConditions(this.resolver, a, i, r)), c = /* @__PURE__ */ new Set, { droppable: l = [] } = this.currentIteration(), u = l.filter((e) => !exprModels(e.expr).every((e) => isSliceable(n, r, e))), f = this.currentIteration().inheritedGroups.filter((e) => !u.includes(e));
|
|
128586
|
+
t = addJoins(this.resolver, i, t, f, "grainKey", s, c), t.kind === "expand_model" && (t = applyFilters(this.resolver, i, t, s, c));
|
|
128587
|
+
let m = s.filter((e) => !c.has(e)), _ = this.resolver.dataset.spans.get(e.id) ?? locStub(), v = m.flatMap((e) => e.predicate.kind === "in_table_condition" ? e.predicate.row.map((e) => e.expr) : []);
|
|
128588
|
+
v.length > 0 && (t = addJoins(this.resolver, n, t, leafFields(this.resolver, v))), u.length > 0 && t.kind === "expand_model" && (t = {
|
|
128545
128589
|
...t,
|
|
128546
|
-
unsliced:
|
|
128547
|
-
}),
|
|
128548
|
-
let
|
|
128549
|
-
return
|
|
128590
|
+
unsliced: u
|
|
128591
|
+
}), m.length > 0 && (t = this.filterInput(t, _, m));
|
|
128592
|
+
let S = this.period.strictBounds(bareLeafKeys(this.resolver, f, materialisedOrigins(t)).map((e) => e.expr), _);
|
|
128593
|
+
return S.length > 0 ? this.filterInput(t, _, S) : t;
|
|
128550
128594
|
}
|
|
128551
128595
|
diagnoseGroupFanout(e, t, n) {
|
|
128552
128596
|
let r = /* @__PURE__ */ new Set;
|
|
@@ -128770,19 +128814,6 @@ function unslicedOf(e) {
|
|
|
128770
128814
|
scanRoot: t.model
|
|
128771
128815
|
} : t.kind === "reduce" ? { keys: t.unsliced ?? [] } : { keys: [] };
|
|
128772
128816
|
}
|
|
128773
|
-
function scanRootOf(e) {
|
|
128774
|
-
let t = e;
|
|
128775
|
-
for (;; ) {
|
|
128776
|
-
if (t.kind === "expand_model")
|
|
128777
|
-
return t.model;
|
|
128778
|
-
if (t.kind === Kind.IDENTIFIER)
|
|
128779
|
-
return isTableType(t.ty) ? t.name : undefined;
|
|
128780
|
-
if (t.kind === "reduce" || t.kind === "select" || t.kind === "filter" || t.kind === "sort" || t.kind === "pivot" || t.kind === "union")
|
|
128781
|
-
t = t.input;
|
|
128782
|
-
else
|
|
128783
|
-
return;
|
|
128784
|
-
}
|
|
128785
|
-
}
|
|
128786
128817
|
function appendPartGrains(e, t, n) {
|
|
128787
128818
|
let r = (t) => extendDef(e.dataset, t), i = /* @__PURE__ */ new Set;
|
|
128788
128819
|
walkTree(t, (e) => i.add(e.model)), n && t.extend !== undefined && walkTree(r(t.extend).base, (e) => i.add(e.model));
|
|
@@ -130789,7 +130820,7 @@ function createResolver(e, t, n = false, r = DEFAULT_DATETIME_CONTEXT, i = true,
|
|
|
130789
130820
|
};
|
|
130790
130821
|
return l.dataset.declarationsMap = l.declarationsMap, l;
|
|
130791
130822
|
}
|
|
130792
|
-
function
|
|
130823
|
+
function startResolve(e) {
|
|
130793
130824
|
let t = e.datetime, n = {
|
|
130794
130825
|
...DEFAULT_DATETIME_CONTEXT,
|
|
130795
130826
|
...t?.timezoneRegion === undefined ? {} : { timezoneRegion: t.timezoneRegion },
|
|
@@ -130802,23 +130833,29 @@ function resolve(e) {
|
|
|
130802
130833
|
}, r = createResolver(e.store, e.modelContext, ((e.checkFlags ?? CheckFlags.Normal) & CheckFlags.EnableWarningCheck) !== 0, n, e.strictUserPermissionCheck ?? true, e.sqlGenerationFlags ?? createDefaultSqlGenerationFlags(), e.recordSpanTypes ?? false, e.typeCheckOnly ?? false);
|
|
130803
130834
|
for (let t of e.userAttributes ?? [])
|
|
130804
130835
|
r.userAttributes.set(t.name, t);
|
|
130805
|
-
buildGlobals(r), ((e.checkFlags ?? CheckFlags.Normal) & CheckFlags.SkipCheckingRelationshipKey) === 0 && validateRelationships(r);
|
|
130806
|
-
|
|
130807
|
-
|
|
130808
|
-
let
|
|
130836
|
+
return buildGlobals(r), ((e.checkFlags ?? CheckFlags.Normal) & CheckFlags.SkipCheckingRelationshipKey) === 0 && validateRelationships(r), r;
|
|
130837
|
+
}
|
|
130838
|
+
function resolve(e) {
|
|
130839
|
+
let t = startResolve(e), n = e.modelContext ? resolveModel(t, e.modelContext) : undefined, r = makeScope(undefined, e.modelContext ? undefined : n);
|
|
130840
|
+
e.rowLevelPermissions && e.rowLevelPermissions.length > 0 && resolveRowLevelPermissions(t, e.rowLevelPermissions, r);
|
|
130841
|
+
let i = e.adhocFields && e.adhocFields.length > 0 ? {
|
|
130809
130842
|
...e.program,
|
|
130810
130843
|
exprs: [...e.adhocFields, ...e.program.exprs]
|
|
130811
130844
|
} : e.program;
|
|
130812
|
-
if (
|
|
130813
|
-
|
|
130814
|
-
|
|
130815
|
-
|
|
130816
|
-
|
|
130817
|
-
|
|
130818
|
-
|
|
130845
|
+
if (t.dataset.program = withBody(t, {
|
|
130846
|
+
kind: "query",
|
|
130847
|
+
name: "",
|
|
130848
|
+
key: QUERY_DECL_KEY
|
|
130849
|
+
}, () => e.modelContext ? resolveAsDimensionBody(t, e.modelContext, i, r) : resolveProgram(t, i, r)), logger.stage("resolved", t.dataset), t.spanTypes && (t.dataset.spanTypes = SpanIndex.build(t.spanTypes)), e.programKind === "condition")
|
|
130850
|
+
return t.dataset.conditionKind = checkCondition(t, t.dataset.program, i), t.dataset;
|
|
130851
|
+
t.dataset.program = castTablesToJson(t, t.dataset.program), logger.stage("table-json", t.dataset), t.dataset.program = wireGrains(t, t.dataset.program), logger.stage("grains", t.dataset), t.dataset.program = wireExtends(t, t.dataset.program), logger.stage("extends", t.dataset), t.dataset.program = wireTransitions(t, t.dataset.program), logger.stage("transitions", t.dataset), t.dataset.program = wireWindows(t, t.dataset.program), logger.stage("windows", t.dataset);
|
|
130852
|
+
let { program: a } = t.dataset;
|
|
130853
|
+
a?.resultMeta && a.result.kind !== "reduce" && (a.result.annotation ?? []).length === 0 && (a.result = {
|
|
130854
|
+
...a.result,
|
|
130855
|
+
annotation: [...a.result.annotation ?? [], { meta: a.resultMeta }]
|
|
130819
130856
|
});
|
|
130820
|
-
let
|
|
130821
|
-
return
|
|
130857
|
+
let s = t.dataset.diagnostics.some((e) => e.severity !== "warning"), c = a && !s && (e.programKind ?? "query") === "query" ? topLevelResultError(a.result) : undefined;
|
|
130858
|
+
return c && t.dataset.diagnostics.push(createError(ErrorCode.INVALID_EXPRESSION_0, i.exprs[i.exprs.length - 1]?.loc, "", c)), t.dataset.diagnostics = filterEnclosingDiags(t.dataset.diagnostics), t.dataset;
|
|
130822
130859
|
}
|
|
130823
130860
|
function topLevelResultError(e) {
|
|
130824
130861
|
if (!isTableType(e.ty))
|
|
@@ -130841,6 +130878,62 @@ function isModelScan(e) {
|
|
|
130841
130878
|
return false;
|
|
130842
130879
|
}
|
|
130843
130880
|
}
|
|
130881
|
+
function createSliceCheck(e) {
|
|
130882
|
+
let t = startResolve({
|
|
130883
|
+
...e,
|
|
130884
|
+
typeCheckOnly: true
|
|
130885
|
+
}), n = resolveProgram(t, createProgram([...e.adhocFields ?? []]), makeScope(undefined, undefined)), r = makeScope(makeScope(undefined, undefined), n), i = /* @__PURE__ */ new Map, a = /* @__PURE__ */ new Map;
|
|
130886
|
+
return (e) => {
|
|
130887
|
+
let n = modelFieldRefAsKey(e), s = a.get(n);
|
|
130888
|
+
if (s === undefined) {
|
|
130889
|
+
let c = t.dataset.diagnostics.length, l = t.resolveExpr(referenceTo(e), r), u = t.dataset.diagnostics.slice(c);
|
|
130890
|
+
s = u.length > 0 ? u : unsliceableModels(t, l, i), a.set(n, s);
|
|
130891
|
+
}
|
|
130892
|
+
return s;
|
|
130893
|
+
};
|
|
130894
|
+
}
|
|
130895
|
+
function referenceTo(e) {
|
|
130896
|
+
if (!e.modelName)
|
|
130897
|
+
return createIdentifier(e.fieldName);
|
|
130898
|
+
let [t, ...n] = e.modelName.split(".");
|
|
130899
|
+
return createDotExpression(n.reduce((e, t) => createDotExpression(e, createIdentifier(t)), createIdentifier(t)), createIdentifier(e.fieldName));
|
|
130900
|
+
}
|
|
130901
|
+
function unsliceableModels(e, t, n) {
|
|
130902
|
+
let r = new SliceCheckFold(e, n);
|
|
130903
|
+
return r.foldExpr(t), r.models;
|
|
130904
|
+
}
|
|
130905
|
+
var SliceCheckFold = class e extends HirFold {
|
|
130906
|
+
resolver;
|
|
130907
|
+
memo;
|
|
130908
|
+
models = /* @__PURE__ */ new Set;
|
|
130909
|
+
graphContext;
|
|
130910
|
+
constructor(e, t) {
|
|
130911
|
+
super(), this.resolver = e, this.memo = t, this.graphContext = new GraphContext(e);
|
|
130912
|
+
}
|
|
130913
|
+
foldNamedExpression(t) {
|
|
130914
|
+
if (!t.inlinedField)
|
|
130915
|
+
return super.foldNamedExpression(t);
|
|
130916
|
+
let n = this.graphContext.currentGraph(), r = `${modelFieldRefAsKey(t.inlinedField)}:${n.hash()}`, i = this.memo.get(r);
|
|
130917
|
+
if (!i) {
|
|
130918
|
+
let a = new e(this.resolver, this.memo);
|
|
130919
|
+
a.graphContext.withGraph(n, () => a.foldExpr(t.expr)), i = a.models, this.memo.set(r, i);
|
|
130920
|
+
}
|
|
130921
|
+
return i.forEach((e) => this.models.add(e)), t;
|
|
130922
|
+
}
|
|
130923
|
+
foldWithRelationships(e) {
|
|
130924
|
+
let t = this.graphContext.newGraph(e, this.resolver.dataset.spans.get(e.id) ?? locStub());
|
|
130925
|
+
return t ? this.graphContext.withGraph(t, () => super.foldWithRelationships(e)) : e;
|
|
130926
|
+
}
|
|
130927
|
+
foldComputedRef(e) {
|
|
130928
|
+
let t = scanRootOf(e.reduce.input);
|
|
130929
|
+
if (t) {
|
|
130930
|
+
let e = this.graphContext.currentGraph();
|
|
130931
|
+
for (let n of e.models)
|
|
130932
|
+
isSliceable(e, t, n) || this.models.add(n);
|
|
130933
|
+
}
|
|
130934
|
+
return super.foldComputedRef(e);
|
|
130935
|
+
}
|
|
130936
|
+
};
|
|
130844
130937
|
function normalizeFieldForAql(e, t, n) {
|
|
130845
130938
|
let r;
|
|
130846
130939
|
t === "measure" && (r = import_lodash2.get(e, "aggregationType") ?? e.aggregation_type ?? AggregationType.CUSTOM);
|
|
@@ -130999,183 +131092,247 @@ function listDatasetAqlNamespace(e) {
|
|
|
130999
131092
|
function sqlTypeOfCheckedExpression(e) {
|
|
131000
131093
|
return e === undefined ? SqlType.UNKNOWN : isScalarLikeType(e) ? getScalarType(e).sqlType : isTableType(e) ? SqlType.JSON : SqlType.UNKNOWN;
|
|
131001
131094
|
}
|
|
131095
|
+
function declaredFieldRef(e) {
|
|
131096
|
+
let { name: t, path: n } = flattenName(e.name);
|
|
131097
|
+
return createModelFieldReference(n.join("."), t);
|
|
131098
|
+
}
|
|
131002
131099
|
function prepareCheck(e) {
|
|
131003
|
-
let { dataset: t, adhocMetrics: n, adhocDimensions: r, aqlType: i, fieldName: a, modelUname: s, allowAmbiguousPaths: c = false } = e,
|
|
131100
|
+
let { dataset: t, adhocMetrics: n, adhocDimensions: r, aqlType: i, fieldName: a, modelUname: s, allowAmbiguousPaths: c = false, userAttributes: l = [], checkFlags: u = CheckFlags.SkipCheckingRelationshipKey, useV2Compiler: f = false } = e, m = new DatasetStore(normalizeDatasetToAqlDataset(import_lodash2.cloneDeep(t)), {
|
|
131004
131101
|
name: "dummy",
|
|
131005
131102
|
dbtype: DbType.POSTGRESQL
|
|
131006
|
-
}, { allowAmbiguousPaths: c }),
|
|
131103
|
+
}, { allowAmbiguousPaths: c }), _ = n.filter((e) => i !== "metric" || e.name !== a).map((e) => ({
|
|
131104
|
+
ref: createModelFieldReference("", e.name),
|
|
131105
|
+
aql: `metric ${e.name} = ${e.sql}`
|
|
131106
|
+
})), v = r.filter((e) => e.model?.id && import_lodash2.isString(e.model?.id)).filter((e) => i !== "dimension" || e.name !== a || e.model?.id !== s).map((e) => ({
|
|
131107
|
+
ref: createModelFieldReference(getFqn(e.model.id), e.name),
|
|
131108
|
+
aql: `dimension ${getFqn(e.model.id)}.${e.name} = ${e.sql}`
|
|
131109
|
+
})), S = /* @__PURE__ */ new Set;
|
|
131007
131110
|
return {
|
|
131008
|
-
|
|
131009
|
-
|
|
131111
|
+
engine: {
|
|
131112
|
+
store: m,
|
|
131113
|
+
adhocFields: import_lodash2.compact([..._, ...v].map(({ ref: e, aql: t }) => {
|
|
131114
|
+
try {
|
|
131115
|
+
let e = parse(t).exprs[0];
|
|
131116
|
+
if (isFieldDeclaration(e))
|
|
131117
|
+
return e;
|
|
131118
|
+
} catch {}
|
|
131119
|
+
S.add(modelFieldRefAsKey(e));
|
|
131120
|
+
})),
|
|
131121
|
+
userAttributes: l,
|
|
131122
|
+
checkFlags: u,
|
|
131123
|
+
useV2Compiler: f
|
|
131124
|
+
},
|
|
131125
|
+
unparsedAdhocFields: S
|
|
131126
|
+
};
|
|
131127
|
+
}
|
|
131128
|
+
function resolveV2ForCheck(e, t, n) {
|
|
131129
|
+
return resolve({
|
|
131130
|
+
store: e.store,
|
|
131131
|
+
program: t,
|
|
131132
|
+
adhocFields: e.adhocFields,
|
|
131133
|
+
userAttributes: e.userAttributes,
|
|
131134
|
+
checkFlags: e.checkFlags,
|
|
131135
|
+
typeCheckOnly: true,
|
|
131136
|
+
...n
|
|
131137
|
+
});
|
|
131138
|
+
}
|
|
131139
|
+
function createV1Checker(e) {
|
|
131140
|
+
return createTypeChecker(e.store, e.userAttributes ?? [], e.adhocFields ?? [], [], e.checkFlags);
|
|
131141
|
+
}
|
|
131142
|
+
function checkedProgram(e, t, n) {
|
|
131143
|
+
return {
|
|
131144
|
+
program: e,
|
|
131145
|
+
diagnostics: t,
|
|
131146
|
+
typeOf: n,
|
|
131147
|
+
sqlTypeOf: (e) => sqlTypeOfCheckedExpression(n(e))
|
|
131148
|
+
};
|
|
131149
|
+
}
|
|
131150
|
+
function checkProgram(e, t, { modelContext: n, programKind: r = "definition" } = {}) {
|
|
131151
|
+
if (e.useV2Compiler) {
|
|
131152
|
+
let { diagnostics: i, spanTypes: a } = resolveV2ForCheck(e, t, {
|
|
131153
|
+
modelContext: n,
|
|
131154
|
+
programKind: r,
|
|
131155
|
+
recordSpanTypes: true
|
|
131156
|
+
});
|
|
131157
|
+
return checkedProgram(t, i, (e) => a?.at(e.loc));
|
|
131158
|
+
}
|
|
131159
|
+
let i = createV1Checker(e);
|
|
131160
|
+
return checkedProgram(t, i.getDiagnostics(t, n), (e) => {
|
|
131161
|
+
if (e.id !== undefined)
|
|
131010
131162
|
try {
|
|
131011
|
-
|
|
131012
|
-
return isFieldDeclaration(t) ? t : undefined;
|
|
131163
|
+
return i.getTypeFromNodeId(e.id);
|
|
131013
131164
|
} catch {
|
|
131014
131165
|
return;
|
|
131015
131166
|
}
|
|
131016
|
-
|
|
131017
|
-
|
|
131167
|
+
});
|
|
131168
|
+
}
|
|
131169
|
+
var DEPENDENCY_ROOT = "__field_dependencies_root__";
|
|
131170
|
+
function getProgramDependencies(e, t) {
|
|
131171
|
+
let n;
|
|
131172
|
+
if (e.useV2Compiler) {
|
|
131173
|
+
let r = resolveV2ForCheck(e, t, { programKind: "definition" });
|
|
131174
|
+
n = import_lodash2.compact([...declClosure(r, QUERY_DECL_KEY)].map(refOfDeclKey));
|
|
131175
|
+
} else {
|
|
131176
|
+
let r = import_lodash2.last(t.exprs);
|
|
131177
|
+
if (r === undefined)
|
|
131178
|
+
return [];
|
|
131179
|
+
let i = createIdentifier(DEPENDENCY_ROOT), a = createV1Checker(e);
|
|
131180
|
+
a.getDiagnostics(createProgram([
|
|
131181
|
+
...t.exprs.slice(0, -1),
|
|
131182
|
+
createFieldDeclaration(FieldDeclarationType.METRIC, i, r),
|
|
131183
|
+
i
|
|
131184
|
+
])), n = [...transitiveDependencies(a.fields.getFieldDependencyGraph(), DEPENDENCY_ROOT)].map(parseModelFieldReferenceKey);
|
|
131185
|
+
}
|
|
131186
|
+
let r = new Set((e.adhocFields ?? []).map((e) => modelFieldRefAsKey(declaredFieldRef(e))));
|
|
131187
|
+
return n.filter((t) => r.has(modelFieldRefAsKey(t)) || (import_lodash2.isEmpty(t.modelName) ? !!e.store.getMayBeMetric(t.fieldName) : !!e.store.getMayBeModelField(t)));
|
|
131018
131188
|
}
|
|
131019
131189
|
function checkAql(e) {
|
|
131020
|
-
let {
|
|
131190
|
+
let { aql: t, aqlType: n, modelUname: r, useV2Compiler: i = false, allowAdhocSqlPassthroughFunctions: a = true } = e, s;
|
|
131021
131191
|
try {
|
|
131022
|
-
|
|
131192
|
+
s = parse(t);
|
|
131023
131193
|
} catch (e) {
|
|
131024
131194
|
return [e];
|
|
131025
131195
|
}
|
|
131026
|
-
if (!
|
|
131027
|
-
let e = checkAdhocSqlPassthrough([
|
|
131196
|
+
if (!a) {
|
|
131197
|
+
let e = checkAdhocSqlPassthrough([s]);
|
|
131028
131198
|
if (e.length > 0)
|
|
131029
131199
|
return e;
|
|
131030
131200
|
}
|
|
131031
|
-
let
|
|
131032
|
-
|
|
131033
|
-
|
|
131034
|
-
|
|
131035
|
-
|
|
131036
|
-
|
|
131037
|
-
|
|
131038
|
-
|
|
131039
|
-
checkFlags: u,
|
|
131040
|
-
recordSpanTypes: true,
|
|
131041
|
-
typeCheckOnly: true,
|
|
131042
|
-
programKind: "definition"
|
|
131043
|
-
});
|
|
131044
|
-
if (e.diagnostics.length > 0)
|
|
131045
|
-
return e.diagnostics;
|
|
131046
|
-
let t = import_lodash2.last(E.exprs);
|
|
131047
|
-
return t === undefined ? SqlType.UNKNOWN : sqlTypeOfCheckedExpression(e.spanTypes?.at(t.loc));
|
|
131048
|
-
}
|
|
131049
|
-
let N = createTypeChecker(v, l, S, [], u), P;
|
|
131050
|
-
if (a === "condition" && (P = N.getDiagnosticsForCondition(E)), P = N.getDiagnostics(E, j), P.length > 0)
|
|
131051
|
-
return P;
|
|
131052
|
-
let I = import_lodash2.last(E.exprs)?.id;
|
|
131053
|
-
return I === undefined ? SqlType.UNKNOWN : sqlTypeOfCheckedExpression(N.getTypeFromNodeId(I));
|
|
131201
|
+
let c = n === "dimension" && r ? getFqn(r) : undefined, l = n === "condition", { engine: u } = prepareCheck({
|
|
131202
|
+
...e,
|
|
131203
|
+
useV2Compiler: i && !l
|
|
131204
|
+
}), f = checkProgram(u, s, { modelContext: c });
|
|
131205
|
+
if (f.diagnostics.length > 0)
|
|
131206
|
+
return f.diagnostics;
|
|
131207
|
+
let m = import_lodash2.last(s.exprs);
|
|
131208
|
+
return m === undefined ? SqlType.UNKNOWN : f.sqlTypeOf(m);
|
|
131054
131209
|
}
|
|
131055
131210
|
function checkAqlCondition(e) {
|
|
131056
|
-
let {
|
|
131211
|
+
let { allowAdhocSqlPassthroughFunctions: t = true } = e, n;
|
|
131057
131212
|
try {
|
|
131058
|
-
|
|
131213
|
+
n = parse(e.aql);
|
|
131059
131214
|
} catch (e) {
|
|
131060
131215
|
return {
|
|
131061
131216
|
diagnostics: [e],
|
|
131062
131217
|
conditionType: "normal"
|
|
131063
131218
|
};
|
|
131064
131219
|
}
|
|
131065
|
-
if (!
|
|
131066
|
-
let e = checkAdhocSqlPassthrough([
|
|
131220
|
+
if (!t) {
|
|
131221
|
+
let e = checkAdhocSqlPassthrough([n]);
|
|
131067
131222
|
if (e.length > 0)
|
|
131068
131223
|
return {
|
|
131069
131224
|
diagnostics: e,
|
|
131070
131225
|
conditionType: "normal"
|
|
131071
131226
|
};
|
|
131072
131227
|
}
|
|
131073
|
-
let {
|
|
131074
|
-
if (r) {
|
|
131075
|
-
let e =
|
|
131076
|
-
store: s,
|
|
131077
|
-
program: a,
|
|
131078
|
-
adhocFields: c,
|
|
131079
|
-
userAttributes: t,
|
|
131080
|
-
checkFlags: n,
|
|
131081
|
-
typeCheckOnly: true,
|
|
131082
|
-
programKind: "condition"
|
|
131083
|
-
});
|
|
131228
|
+
let { engine: r } = prepareCheck(e);
|
|
131229
|
+
if (r.useV2Compiler) {
|
|
131230
|
+
let e = resolveV2ForCheck(r, n, { programKind: "condition" });
|
|
131084
131231
|
return {
|
|
131085
131232
|
diagnostics: e.diagnostics,
|
|
131086
131233
|
conditionType: e.conditionKind ?? "normal"
|
|
131087
131234
|
};
|
|
131088
131235
|
}
|
|
131089
|
-
let
|
|
131090
|
-
return
|
|
131091
|
-
diagnostics:
|
|
131236
|
+
let i = createV1Checker(r), a = i.getDiagnosticsForCondition(n);
|
|
131237
|
+
return a.length > 0 ? {
|
|
131238
|
+
diagnostics: a,
|
|
131092
131239
|
conditionType: "normal"
|
|
131093
131240
|
} : {
|
|
131094
|
-
diagnostics:
|
|
131095
|
-
conditionType:
|
|
131241
|
+
diagnostics: a,
|
|
131242
|
+
conditionType: i.measure_conditions.getMeasureCondition(n.exprs[0]) ? "measure" : "normal"
|
|
131096
131243
|
};
|
|
131097
131244
|
}
|
|
131245
|
+
function tryParse(e) {
|
|
131246
|
+
try {
|
|
131247
|
+
return parse(e);
|
|
131248
|
+
} catch (e) {
|
|
131249
|
+
return e;
|
|
131250
|
+
}
|
|
131251
|
+
}
|
|
131252
|
+
function analyze(e, t) {
|
|
131253
|
+
let n = tryParse(e.aql);
|
|
131254
|
+
return n instanceof Error ? checkedProgram(createProgram([]), [n], () => {
|
|
131255
|
+
return;
|
|
131256
|
+
}) : checkProgram(prepareCheck(e).engine, n, { programKind: t });
|
|
131257
|
+
}
|
|
131258
|
+
function analyzeAql(e) {
|
|
131259
|
+
return analyze(e, "query");
|
|
131260
|
+
}
|
|
131261
|
+
function tableTypeOf(e) {
|
|
131262
|
+
let t = e && isFieldType(e) ? e.tableToCastToJSON : e;
|
|
131263
|
+
return t && isTableType(t) ? t : undefined;
|
|
131264
|
+
}
|
|
131265
|
+
function getTableFields(e) {
|
|
131266
|
+
let { program: t, diagnostics: n, typeOf: r } = analyze(e, "definition"), i = import_lodash2.last(t.exprs);
|
|
131267
|
+
return n.length > 0 || i === undefined ? [] : import_lodash2.compact(tableTypeOf(r(i))?.rowType.columns.map((e) => e.origin));
|
|
131268
|
+
}
|
|
131269
|
+
function getFieldDependencies(e) {
|
|
131270
|
+
let t = tryParse(e.aql);
|
|
131271
|
+
return t instanceof Error ? [] : getProgramDependencies(prepareCheck(e).engine, t);
|
|
131272
|
+
}
|
|
131273
|
+
function createMetricReachability(e) {
|
|
131274
|
+
if (!e.useV2Compiler) {
|
|
131275
|
+
let t = createV1Checker(e);
|
|
131276
|
+
return (e) => t.getMetricReachableModels(e);
|
|
131277
|
+
}
|
|
131278
|
+
return createSliceCheck(e);
|
|
131279
|
+
}
|
|
131098
131280
|
function createFieldRelationshipChecker(e) {
|
|
131099
|
-
let {
|
|
131100
|
-
|
|
131101
|
-
|
|
131102
|
-
},
|
|
131103
|
-
key: modelFieldRefAsKey(createModelFieldReference("", e.name)),
|
|
131104
|
-
aql: `metric ${e.name} = ${e.sql}`
|
|
131105
|
-
})), u = r.filter((e) => e.model?.id && import_lodash2.isString(e.model?.id)).map((e) => ({
|
|
131106
|
-
key: modelFieldRefAsKey(createModelFieldReference(getFqn(e.model.id), e.name)),
|
|
131107
|
-
aql: `dimension ${getFqn(e.model.id)}.${e.name} = ${e.sql}`
|
|
131108
|
-
})), f = createTypeChecker(s, i, import_lodash2.compact([...l, ...u].map(({ key: e, aql: t }) => {
|
|
131109
|
-
try {
|
|
131110
|
-
let n = parse(t).exprs[0];
|
|
131111
|
-
if (isFieldDeclaration(n))
|
|
131112
|
-
return n;
|
|
131113
|
-
c.add(e);
|
|
131114
|
-
return;
|
|
131115
|
-
} catch {
|
|
131116
|
-
c.add(e);
|
|
131117
|
-
return;
|
|
131118
|
-
}
|
|
131119
|
-
})), [], a), m = (e) => c.has(modelFieldRefAsKey(e)), _ = (e) => {
|
|
131281
|
+
let { engine: t, unparsedAdhocFields: n } = prepareCheck({
|
|
131282
|
+
...e,
|
|
131283
|
+
allowAmbiguousPaths: true
|
|
131284
|
+
}), r = t.store, i = createMetricReachability(t), a = r.modelGraph, s = (e) => n.has(modelFieldRefAsKey(e)), c = (e) => {
|
|
131120
131285
|
if (import_lodash2.isEmpty(e.modelName))
|
|
131121
131286
|
return true;
|
|
131122
|
-
let t =
|
|
131287
|
+
let t = r.getMayBeModelField(e);
|
|
131123
131288
|
return !t || !!t.aggregationType;
|
|
131124
|
-
},
|
|
131289
|
+
}, l = (e, t) => e.every((e) => a.canReach(e.modelName, t, { respectFilterDirection: false })), u = (e, t) => {
|
|
131125
131290
|
for (let n of e) {
|
|
131126
|
-
if (
|
|
131127
|
-
if (!
|
|
131291
|
+
if (r.getMayBeModelField(n)?.syntax === "sql") {
|
|
131292
|
+
if (!a.canReach(n.modelName, t))
|
|
131128
131293
|
return false;
|
|
131129
131294
|
continue;
|
|
131130
131295
|
}
|
|
131131
|
-
let e =
|
|
131296
|
+
let e = i(n);
|
|
131132
131297
|
if (!import_lodash2.isArray(e) && e.has(t))
|
|
131133
131298
|
return false;
|
|
131134
131299
|
}
|
|
131135
131300
|
return true;
|
|
131136
|
-
},
|
|
131301
|
+
}, f = (e) => {
|
|
131137
131302
|
if (import_lodash2.isEmpty(e.modelName))
|
|
131138
131303
|
return false;
|
|
131139
|
-
let t =
|
|
131304
|
+
let t = r.getMayBeModelField(e);
|
|
131140
131305
|
return !!t && !t.aggregationType;
|
|
131141
|
-
},
|
|
131306
|
+
}, m = (e) => {
|
|
131142
131307
|
if (import_lodash2.isEmpty(e.modelName))
|
|
131143
131308
|
return false;
|
|
131144
|
-
let t =
|
|
131309
|
+
let t = r.getMayBeModelField(e);
|
|
131145
131310
|
return !!t && !!t.aggregationType && t.syntax === "sql";
|
|
131146
131311
|
};
|
|
131147
131312
|
return { areCompatible(e, t) {
|
|
131148
|
-
let n = e.filter((e) => !
|
|
131149
|
-
if (
|
|
131313
|
+
let n = e.filter((e) => !s(e)), [r, _] = import_lodash2.partition(n, c);
|
|
131314
|
+
if (f(t)) {
|
|
131150
131315
|
let e = t.modelName;
|
|
131151
|
-
return
|
|
131316
|
+
return l(_, e) && u(r, e);
|
|
131152
131317
|
}
|
|
131153
|
-
if (
|
|
131318
|
+
if (m(t)) {
|
|
131154
131319
|
let e = t.modelName;
|
|
131155
|
-
return
|
|
131320
|
+
return _.every((t) => a.canReach(e, t.modelName));
|
|
131156
131321
|
}
|
|
131157
|
-
let
|
|
131158
|
-
return !import_lodash2.isArray(
|
|
131322
|
+
let v = i(t);
|
|
131323
|
+
return !import_lodash2.isArray(v) && _.every((e) => !v.has(e.modelName));
|
|
131159
131324
|
} };
|
|
131160
131325
|
}
|
|
131161
|
-
function
|
|
131162
|
-
|
|
131163
|
-
|
|
131164
|
-
|
|
131165
|
-
}
|
|
131166
|
-
return createTypeChecker(i, [], import_lodash2.compact([...a, ...s].map((e) => {
|
|
131167
|
-
try {
|
|
131168
|
-
let t = parse(e).exprs[0];
|
|
131169
|
-
return isFieldDeclaration(t) ? t : undefined;
|
|
131170
|
-
} catch {
|
|
131171
|
-
return;
|
|
131172
|
-
}
|
|
131173
|
-
})), [], CheckFlags.SkipCheckingRelationshipKey);
|
|
131326
|
+
function checkCalculationProgram(e, t) {
|
|
131327
|
+
return checkProgram(prepareCheck({
|
|
131328
|
+
...e,
|
|
131329
|
+
allowAmbiguousPaths: true
|
|
131330
|
+
}).engine, t);
|
|
131174
131331
|
}
|
|
131175
131332
|
function getTypeFromExpression(e, t) {
|
|
131176
|
-
let n = import_lodash2.cloneDeep(t), r =
|
|
131177
|
-
if (!(r.
|
|
131178
|
-
return r.
|
|
131333
|
+
let n = import_lodash2.cloneDeep(t), r = checkCalculationProgram(e, { exprs: [n] });
|
|
131334
|
+
if (!(r.diagnostics.length > 0))
|
|
131335
|
+
return r.typeOf(n);
|
|
131179
131336
|
}
|
|
131180
131337
|
function getTypeFromAql(e, t) {
|
|
131181
131338
|
let n;
|
|
@@ -131184,12 +131341,12 @@ function getTypeFromAql(e, t) {
|
|
|
131184
131341
|
} catch {
|
|
131185
131342
|
return;
|
|
131186
131343
|
}
|
|
131187
|
-
let r =
|
|
131188
|
-
if (r.
|
|
131344
|
+
let r = checkCalculationProgram(e, n);
|
|
131345
|
+
if (r.diagnostics.length > 0)
|
|
131189
131346
|
return;
|
|
131190
|
-
let i = import_lodash2.last(n.exprs)
|
|
131347
|
+
let i = import_lodash2.last(n.exprs);
|
|
131191
131348
|
if (i !== undefined)
|
|
131192
|
-
return r.
|
|
131349
|
+
return r.typeOf(i);
|
|
131193
131350
|
}
|
|
131194
131351
|
function createCalculationHelper(e) {
|
|
131195
131352
|
return {
|
|
@@ -134348,6 +134505,14 @@ function windowKeyToPlan(e, t) {
|
|
|
134348
134505
|
}), r = t.tryResolve(e);
|
|
134349
134506
|
return r == null ? scalarToPlan(e, t) : n(r);
|
|
134350
134507
|
}
|
|
134508
|
+
var ORDER_WRAPPERS = /* @__PURE__ */ new Set([
|
|
134509
|
+
"asc",
|
|
134510
|
+
"asc_nulls_first",
|
|
134511
|
+
"asc_nulls_last",
|
|
134512
|
+
"desc",
|
|
134513
|
+
"desc_nulls_first",
|
|
134514
|
+
"desc_nulls_last"
|
|
134515
|
+
]);
|
|
134351
134516
|
function windowOrderDir(e) {
|
|
134352
134517
|
return e ? `${e.startsWith("desc") ? "DESC" : "ASC"} ${e.includes("nulls_first") ? "NULLS FIRST" : "NULLS LAST"}` : "ASC NULLS LAST";
|
|
134353
134518
|
}
|
|
@@ -134569,49 +134734,51 @@ function scalarToPlan(e, t, n) {
|
|
|
134569
134734
|
}]
|
|
134570
134735
|
};
|
|
134571
134736
|
case Kind.FUNCTION_CALL: {
|
|
134572
|
-
let
|
|
134573
|
-
if (
|
|
134574
|
-
return caseToIf(
|
|
134575
|
-
if (
|
|
134576
|
-
|
|
134737
|
+
let i = e, a = i.name.name;
|
|
134738
|
+
if (a === "case")
|
|
134739
|
+
return caseToIf(i.args, r, t);
|
|
134740
|
+
if (ORDER_WRAPPERS.has(a) && i.args.length === 1)
|
|
134741
|
+
return scalarToPlan(i.args[0], t, n);
|
|
134742
|
+
if (isTableToJson(a) && i.args.length === 1) {
|
|
134743
|
+
let e = i.args[0];
|
|
134577
134744
|
if (e.kind === Kind.TABLE_LITERAL) {
|
|
134578
134745
|
let n = e.rows.map((e) => e[0]);
|
|
134579
134746
|
return {
|
|
134580
134747
|
kind: "call_variadic",
|
|
134581
|
-
func:
|
|
134748
|
+
func: a === "private__table_to_json_string" ? "table_literal_to_json_string" : "table_literal_to_json",
|
|
134582
134749
|
type: r,
|
|
134583
134750
|
exprs: n.map((e) => scalarToPlan(e, t))
|
|
134584
134751
|
};
|
|
134585
134752
|
}
|
|
134586
134753
|
}
|
|
134587
|
-
if (WINDOW_NAV[
|
|
134588
|
-
return windowNavToPlan(
|
|
134589
|
-
if (WINDOW_AGG[
|
|
134590
|
-
return windowAggToPlan(
|
|
134591
|
-
if (
|
|
134592
|
-
return regexpToPlan(
|
|
134593
|
-
if (
|
|
134594
|
-
return matchToPlan(
|
|
134595
|
-
if ((
|
|
134596
|
-
let e = dateRangeToPlan(
|
|
134754
|
+
if (WINDOW_NAV[a])
|
|
134755
|
+
return windowNavToPlan(a, i, t, r);
|
|
134756
|
+
if (WINDOW_AGG[a])
|
|
134757
|
+
return windowAggToPlan(a, i, t, r);
|
|
134758
|
+
if (a === "regexp_extract" || a === "regexp_like" || a === "regexp_replace")
|
|
134759
|
+
return regexpToPlan(a, i.args, t, r);
|
|
134760
|
+
if (a === "match" || a === "matches")
|
|
134761
|
+
return matchToPlan(i.args, t);
|
|
134762
|
+
if ((a === "is" || a === "is_not") && i.args.length === 2 && i.args[1].kind === Kind.DATETIME_LITERAL) {
|
|
134763
|
+
let e = dateRangeToPlan(i.args[1], t, sqlTypeOf(i.args[0].ty) === SqlType.DATE);
|
|
134597
134764
|
if (e) {
|
|
134598
|
-
let
|
|
134765
|
+
let n = scalarToPlan(i.args[0], t), r = {
|
|
134599
134766
|
kind: "call_binary",
|
|
134600
134767
|
func: ">=",
|
|
134601
|
-
expr1:
|
|
134768
|
+
expr1: n,
|
|
134602
134769
|
expr2: e.start,
|
|
134603
134770
|
type: SqlType.TRUEFALSE
|
|
134604
134771
|
}, s = {
|
|
134605
134772
|
kind: "call_binary",
|
|
134606
134773
|
func: "<",
|
|
134607
|
-
expr1:
|
|
134774
|
+
expr1: n,
|
|
134608
134775
|
expr2: e.end,
|
|
134609
134776
|
type: SqlType.TRUEFALSE
|
|
134610
134777
|
};
|
|
134611
|
-
return
|
|
134778
|
+
return a === "is" ? {
|
|
134612
134779
|
kind: "call_binary",
|
|
134613
134780
|
func: "and",
|
|
134614
|
-
expr1:
|
|
134781
|
+
expr1: r,
|
|
134615
134782
|
expr2: s,
|
|
134616
134783
|
type: SqlType.TRUEFALSE
|
|
134617
134784
|
} : {
|
|
@@ -134620,14 +134787,14 @@ function scalarToPlan(e, t, n) {
|
|
|
134620
134787
|
expr1: {
|
|
134621
134788
|
kind: "call_binary",
|
|
134622
134789
|
func: "<",
|
|
134623
|
-
expr1:
|
|
134790
|
+
expr1: n,
|
|
134624
134791
|
expr2: e.start,
|
|
134625
134792
|
type: SqlType.TRUEFALSE
|
|
134626
134793
|
},
|
|
134627
134794
|
expr2: {
|
|
134628
134795
|
kind: "call_binary",
|
|
134629
134796
|
func: ">=",
|
|
134630
|
-
expr1:
|
|
134797
|
+
expr1: n,
|
|
134631
134798
|
expr2: e.end,
|
|
134632
134799
|
type: SqlType.TRUEFALSE
|
|
134633
134800
|
},
|
|
@@ -134635,67 +134802,67 @@ function scalarToPlan(e, t, n) {
|
|
|
134635
134802
|
};
|
|
134636
134803
|
}
|
|
134637
134804
|
}
|
|
134638
|
-
if (
|
|
134805
|
+
if (a === "is" && i.args.length === 2 && i.args.some(isEmptyUserAttr))
|
|
134639
134806
|
return boolLit(false);
|
|
134640
|
-
if (
|
|
134641
|
-
let e = (e) => sqlTypeOf(e.ty) === SqlType.DATETIME && e.kind !== Kind.DATETIME_LITERAL, [
|
|
134642
|
-
return s = e(
|
|
134807
|
+
if (a === "date_diff" && i.args.length === 3) {
|
|
134808
|
+
let e = (e) => sqlTypeOf(e.ty) === SqlType.DATETIME && e.kind !== Kind.DATETIME_LITERAL, [n, a] = [i.args[1], i.args[2]], s;
|
|
134809
|
+
return s = e(n) || e(a) ? SqlType.DATETIME : sqlTypeOf(n.ty) === SqlType.DATE || sqlTypeOf(a.ty) === SqlType.DATE ? SqlType.DATE : SqlType.DATETIME, {
|
|
134643
134810
|
kind: "call_variadic",
|
|
134644
134811
|
func: "date_diff",
|
|
134645
134812
|
type: r,
|
|
134646
134813
|
exprs: [
|
|
134647
|
-
scalarToPlan(
|
|
134648
|
-
scalarToPlan(
|
|
134814
|
+
scalarToPlan(i.args[0], t),
|
|
134815
|
+
scalarToPlan(n, t, s),
|
|
134649
134816
|
scalarToPlan(a, t, s)
|
|
134650
134817
|
]
|
|
134651
134818
|
};
|
|
134652
134819
|
}
|
|
134653
|
-
if (
|
|
134654
|
-
let e =
|
|
134655
|
-
return (
|
|
134820
|
+
if (a === "in" && i.args.length >= 2) {
|
|
134821
|
+
let e = i.args.slice(1), n = sqlTypeOf(i.args[0].ty);
|
|
134822
|
+
return (n === SqlType.DATE || n === SqlType.DATETIME) && e.length === 1 && isUserAttributeType(e[0].ty) ? datetimeUaToPlan(i.args[0], e[0], t) : e.length === 1 && e[0].kind === Kind.TABLE_LITERAL && !isUserAttributeType(e[0].ty) ? inArrayToPlan(i.args[0], e[0], t) : e.length === 1 && e[0].kind === Kind.RANGE_LITERAL ? rangeToPlan(i.args[0], e[0], false, t) : membershipToPlan(i.args[0], e, false, t, !!i.synthetic);
|
|
134656
134823
|
}
|
|
134657
|
-
if (
|
|
134658
|
-
let e =
|
|
134824
|
+
if (a === "not" && i.args.length === 1 && i.args[0].kind === Kind.FUNCTION_CALL) {
|
|
134825
|
+
let e = i.args[0];
|
|
134659
134826
|
if (e.name.name === "in" && e.args.length >= 2) {
|
|
134660
134827
|
let n = e.args.slice(1);
|
|
134661
134828
|
return n.length === 1 && n[0].kind === Kind.RANGE_LITERAL ? rangeToPlan(e.args[0], n[0], true, t) : n.length === 1 && n[0].kind === Kind.TABLE_LITERAL && !isUserAttributeType(n[0].ty) ? inArrayToPlan(e.args[0], n[0], t, true) : membershipToPlan(e.args[0], n, true, t, !!e.synthetic);
|
|
134662
134829
|
}
|
|
134663
134830
|
}
|
|
134664
|
-
if ((
|
|
134665
|
-
let e =
|
|
134831
|
+
if ((a === "+" || a === "-") && i.args.length === 2) {
|
|
134832
|
+
let e = i.args.findIndex((e) => e.kind === Kind.INTERVAL);
|
|
134666
134833
|
if (e >= 0) {
|
|
134667
|
-
let
|
|
134834
|
+
let n = i.args[e];
|
|
134668
134835
|
return {
|
|
134669
|
-
...shiftDateByInterval(scalarToPlan(
|
|
134836
|
+
...shiftDateByInterval(scalarToPlan(i.args[1 - e], t), n, a === "-", t),
|
|
134670
134837
|
type: r
|
|
134671
134838
|
};
|
|
134672
134839
|
}
|
|
134673
134840
|
}
|
|
134674
|
-
let
|
|
134675
|
-
if (CMP_FNS.has(
|
|
134676
|
-
return sqlTypeOf(
|
|
134677
|
-
},
|
|
134678
|
-
if (BINARY_FNS.has(
|
|
134841
|
+
let s = a === "coalesce" || a === "nullif" ? r : undefined, c = (e) => {
|
|
134842
|
+
if (CMP_FNS.has(a) && i.args.length === 2 && i.args[e].kind === Kind.DATETIME_LITERAL)
|
|
134843
|
+
return sqlTypeOf(i.args[1 - e].ty) === SqlType.DATE ? SqlType.DATE : undefined;
|
|
134844
|
+
}, l = i.args.map((e, n) => scalarToPlan(e, t, s ?? c(n)));
|
|
134845
|
+
if (BINARY_FNS.has(a) && l.length === 2)
|
|
134679
134846
|
return {
|
|
134680
134847
|
kind: "call_binary",
|
|
134681
|
-
func:
|
|
134682
|
-
expr1:
|
|
134683
|
-
expr2:
|
|
134848
|
+
func: a,
|
|
134849
|
+
expr1: l[0],
|
|
134850
|
+
expr2: l[1],
|
|
134684
134851
|
type: r
|
|
134685
134852
|
};
|
|
134686
|
-
if (PERIOD_FNS.has(
|
|
134853
|
+
if (PERIOD_FNS.has(a) && l.length === 1)
|
|
134687
134854
|
return {
|
|
134688
134855
|
kind: "call_variadic",
|
|
134689
134856
|
func: "date_trunc",
|
|
134690
134857
|
type: r,
|
|
134691
|
-
exprs: [
|
|
134858
|
+
exprs: [l[0], {
|
|
134692
134859
|
kind: "literal",
|
|
134693
134860
|
literal: "text",
|
|
134694
|
-
value:
|
|
134861
|
+
value: a,
|
|
134695
134862
|
type: SqlType.TEXT
|
|
134696
134863
|
}]
|
|
134697
134864
|
};
|
|
134698
|
-
if (PERIOD_NUM_FNS.has(
|
|
134865
|
+
if (PERIOD_NUM_FNS.has(a) && l.length === 1)
|
|
134699
134866
|
return {
|
|
134700
134867
|
kind: "call_variadic",
|
|
134701
134868
|
func: "date_part",
|
|
@@ -134703,17 +134870,17 @@ function scalarToPlan(e, t, n) {
|
|
|
134703
134870
|
exprs: [{
|
|
134704
134871
|
kind: "literal",
|
|
134705
134872
|
literal: "text",
|
|
134706
|
-
value:
|
|
134873
|
+
value: a === "dayofweek_num" || a === "dow_num" ? "dow" : a.replace("_num", ""),
|
|
134707
134874
|
type: SqlType.TEXT
|
|
134708
|
-
},
|
|
134875
|
+
}, l[0]]
|
|
134709
134876
|
};
|
|
134710
|
-
let
|
|
134877
|
+
let u = i.args.map((e) => e.kind === Kind.NAMED_EXPRESSION ? e.name.name : undefined);
|
|
134711
134878
|
return {
|
|
134712
134879
|
kind: "call_variadic",
|
|
134713
|
-
func:
|
|
134714
|
-
exprs:
|
|
134880
|
+
func: a,
|
|
134881
|
+
exprs: l,
|
|
134715
134882
|
type: r,
|
|
134716
|
-
...
|
|
134883
|
+
...u.some((e) => e !== undefined) ? { argNames: u } : {}
|
|
134717
134884
|
};
|
|
134718
134885
|
}
|
|
134719
134886
|
default:
|
|
@@ -139609,10 +139776,10 @@ function isBitValue(e) {
|
|
|
139609
139776
|
return typeof t == "string" ? false : t.operator === OperationType.FIELD || t.operator === OperationType.CAST && t.operands[1] === SqlType.TRUEFALSE;
|
|
139610
139777
|
}
|
|
139611
139778
|
function asBooleanPredicate(e, t) {
|
|
139612
|
-
return
|
|
139779
|
+
return dbHasNoNativeBoolean(t.dataSource.dbtype) && isBitValue(e) ? castBitToTruefalse(e) : e;
|
|
139613
139780
|
}
|
|
139614
139781
|
function truefalseToBit(e, t) {
|
|
139615
|
-
return t.dbtype === DbType.SQLSERVER ? createOperation(OperationType.UNSAFE_SQL, [
|
|
139782
|
+
return t.dataSource.dbtype === DbType.SQLSERVER ? createOperation(OperationType.UNSAFE_SQL, [
|
|
139616
139783
|
"IIF(",
|
|
139617
139784
|
e,
|
|
139618
139785
|
", 1, 0)"
|
|
@@ -139727,7 +139894,7 @@ function scalarToOp(e, t, n) {
|
|
|
139727
139894
|
return createOperation(CMP_OPS[r], [e, s]);
|
|
139728
139895
|
}
|
|
139729
139896
|
if (r === "null_safe_eq") {
|
|
139730
|
-
let e = operandOp(i, t, n), r = operandOp(a, t, n), s =
|
|
139897
|
+
let e = operandOp(i, t, n), r = operandOp(a, t, n), s = dbHasNoNativeBoolean(n.dataSource.dbtype), c = (e) => {
|
|
139731
139898
|
let t = createOperation(OperationType.IS_NULL, [e]);
|
|
139732
139899
|
return s ? truefalseToBit(t, n) : createOperation(OperationType.EXPRESSION, [
|
|
139733
139900
|
"(",
|
|
@@ -139746,14 +139913,14 @@ function scalarToOp(e, t, n) {
|
|
|
139746
139913
|
if (LOGIC_OPS[r])
|
|
139747
139914
|
return flattenLogic(LOGIC_OPS[r], i, t, n);
|
|
139748
139915
|
if (r === "table_literal_to_json" || r === "table_literal_to_json_string") {
|
|
139749
|
-
let e = n.
|
|
139916
|
+
let { dbtype: e } = n.dataSource, a = jsonArrayLiteral(e, commaSeparated(i.map((e) => scalarToOp(e, t, n))));
|
|
139750
139917
|
return r === "table_literal_to_json_string" ? jsonStringOf(e, a) : a;
|
|
139751
139918
|
}
|
|
139752
139919
|
if (VARIADIC_OPS[r])
|
|
139753
139920
|
return createOperation(VARIADIC_OPS[r], i.map((e) => operandOp(e, t, n)));
|
|
139754
139921
|
if (r === "cast" && i.length === 2) {
|
|
139755
139922
|
let e = literalText(i[1]);
|
|
139756
|
-
return e === "int" || e === "integer" ? createOperation(OperationType.CAST_DB_TYPE, [operandOp(i[0], t, n), DB_INTEGER_TYPE[n.dbtype
|
|
139923
|
+
return e === "int" || e === "integer" ? createOperation(OperationType.CAST_DB_TYPE, [operandOp(i[0], t, n), DB_INTEGER_TYPE[n.dataSource.dbtype]]) : e === SqlType.DATE && i[0].type === SqlType.DATETIME ? createOperation(OperationType.CAST_DATETIME_TO_DATE, [
|
|
139757
139924
|
operandOp(i[0], t, n),
|
|
139758
139925
|
n.timezoneRegion,
|
|
139759
139926
|
n.databaseTimezone
|
|
@@ -139941,15 +140108,15 @@ function scalarToOp(e, t, n) {
|
|
|
139941
140108
|
if (r === "epoch")
|
|
139942
140109
|
return createOperation(OperationType.EXTRACT, [...i.map((e) => operandOp(e, t, n)), "epoch"]);
|
|
139943
140110
|
if (r === "safe_divide" && i.length === 2)
|
|
139944
|
-
return createOperation(OperationType.SAFE_DIVIDE, [normalizeDividend(n.dbtype, operandOp(i[0], t, n)), operandOp(i[1], t, n)]);
|
|
140111
|
+
return createOperation(OperationType.SAFE_DIVIDE, [normalizeDividend(n.dataSource.dbtype, operandOp(i[0], t, n)), operandOp(i[1], t, n)]);
|
|
139945
140112
|
if (SIMPLE_OPS[r])
|
|
139946
140113
|
return createOperation(SIMPLE_OPS[r], i.map((e) => operandOp(e, t, n)));
|
|
139947
140114
|
if (REGEXP_OPS[r])
|
|
139948
140115
|
return createOperation(REGEXP_OPS[r], i.map((e) => e.kind === "literal" && e.literal === "text" && e.value === "" ? "" : operandOp(e, t, n)));
|
|
139949
140116
|
if (AI_FUNCS.has(r)) {
|
|
139950
|
-
if (n.dbtype !== DbType.DATABRICKS && n.dbtype !== DbType.SNOWFLAKE)
|
|
140117
|
+
if (n.dataSource.dbtype !== DbType.DATABRICKS && n.dataSource.dbtype !== DbType.SNOWFLAKE)
|
|
139951
140118
|
throw createError(ErrorCode.UNSUPPORTED_BEHAVIOR_0, undefined, undefined, `${r} is only supported on Databricks and Snowflake databases`);
|
|
139952
|
-
let e = n.dbtype === DbType.DATABRICKS, a = i.map((e) => operandOp(e, t, n)), s = (...e) => createOperation(OperationType.UNSAFE_SQL, e);
|
|
140119
|
+
let e = n.dataSource.dbtype === DbType.DATABRICKS, a = i.map((e) => operandOp(e, t, n)), s = (...e) => createOperation(OperationType.UNSAFE_SQL, e);
|
|
139953
140120
|
switch (r) {
|
|
139954
140121
|
case "ai_complete":
|
|
139955
140122
|
return s(e ? "AI_QUERY(" : "AI_COMPLETE(", a[0], ", ", a[1], ")");
|
|
@@ -140024,7 +140191,7 @@ function normalizeDividend(e, t) {
|
|
|
140024
140191
|
}
|
|
140025
140192
|
}
|
|
140026
140193
|
function operandOp(e, t, n) {
|
|
140027
|
-
let r =
|
|
140194
|
+
let r = dbHasNoNativeBoolean(n.dataSource.dbtype);
|
|
140028
140195
|
if (e.kind === "literal")
|
|
140029
140196
|
return r && e.literal === "truefalse" ? e.value === "true" ? "1" : "0" : literalOp(e, n);
|
|
140030
140197
|
if (e.kind === "call_variadic" && e.func === "interval")
|
|
@@ -140090,7 +140257,7 @@ function sentinelLiteral(e) {
|
|
|
140090
140257
|
}
|
|
140091
140258
|
}
|
|
140092
140259
|
function literalOp(e, t) {
|
|
140093
|
-
return e.literal === "null" ? e.type && e.type !== SqlType.UNKNOWN && !e.bare ? createOperation(OperationType.CAST, ["NULL", e.type]) : "NULL" : e.castDbType ? createOperation(OperationType.CAST_DB_TYPE, [e.value ?? "", e.castDbType]) : e.cast && e.cast !== SqlType.UNKNOWN ? createOperation(OperationType.CAST, [e.value ?? "", e.cast]) : e.literal === "text" ? createOperation(OperationType.QUOTE_STRING, [e.value ?? ""]) : e.literal === "date" ? createOperation(OperationType.NORMALIZE_VALUE, [e.value ?? "", SqlType.DATE]) : e.literal === "datetime" ? createOperation(OperationType.NORMALIZE_VALUE, [e.value ?? "", SqlType.DATETIME]) : e.literal === "truefalse" ?
|
|
140260
|
+
return e.literal === "null" ? e.type && e.type !== SqlType.UNKNOWN && !e.bare ? createOperation(OperationType.CAST, ["NULL", e.type]) : "NULL" : e.castDbType ? createOperation(OperationType.CAST_DB_TYPE, [e.value ?? "", e.castDbType]) : e.cast && e.cast !== SqlType.UNKNOWN ? createOperation(OperationType.CAST, [e.value ?? "", e.cast]) : e.literal === "text" ? createOperation(OperationType.QUOTE_STRING, [e.value ?? ""]) : e.literal === "date" ? createOperation(OperationType.NORMALIZE_VALUE, [e.value ?? "", SqlType.DATE]) : e.literal === "datetime" ? createOperation(OperationType.NORMALIZE_VALUE, [e.value ?? "", SqlType.DATETIME]) : e.literal === "truefalse" ? dbHasNoNativeBoolean(t.dataSource.dbtype) ? createOperation(OperationType.EXPRESSION, [e.value === "true" ? "1 = 1" : "1 = 0"]) : createOperation(OperationType.NORMALIZE_TRUEFALSE_VALUE, [e.value ?? "false"]) : e.value ?? "";
|
|
140094
140261
|
}
|
|
140095
140262
|
function literalText(e) {
|
|
140096
140263
|
return (e.kind !== "literal" || e.literal !== "text") && unsupported("expected text literal"), e.value ?? "";
|
|
@@ -140203,9 +140370,9 @@ function approxSketchOp(e, t, n) {
|
|
|
140203
140370
|
let r = e.func === APPROX_SKETCH_FN;
|
|
140204
140371
|
if (!r && e.func !== "private__approx_count_distinct_merge")
|
|
140205
140372
|
return;
|
|
140206
|
-
let i = APPROX_HLL_SQL[n.dbtype
|
|
140373
|
+
let i = APPROX_HLL_SQL[n.dataSource.dbtype];
|
|
140207
140374
|
if (!i)
|
|
140208
|
-
return unsupported(`approx_count_distinct running total on ${n.dbtype}`);
|
|
140375
|
+
return unsupported(`approx_count_distinct running total on ${n.dataSource.dbtype}`);
|
|
140209
140376
|
let [a, s] = r ? i.sketch : i.merge;
|
|
140210
140377
|
return createOperation(OperationType.CUSTOM_AGG, [createOperation(OperationType.UNSAFE_SQL, [
|
|
140211
140378
|
a,
|
|
@@ -140547,6 +140714,10 @@ var Impl = class {
|
|
|
140547
140714
|
maybeSealShared(e, t) {
|
|
140548
140715
|
return e.kind === "get" || t.node.kind !== "select" || this.scanBoundInputs.has(e) && !t.clauses.has(2) ? t : (this.refCounts.get(e) ?? 0) >= 2 ? this.seal(t) : t;
|
|
140549
140716
|
}
|
|
140717
|
+
castUnknownUnionColumn(e, t) {
|
|
140718
|
+
let { dataSource: n, sqlGenerationFlags: r } = this.opts;
|
|
140719
|
+
return t !== SqlType.UNKNOWN || shouldUseImplicitPlaceholderDataType(n, !!r?.shouldUseImplicitPlaceholderDataType) ? e : createOperation(OperationType.CAST, [e, SqlType.UNKNOWN]);
|
|
140720
|
+
}
|
|
140550
140721
|
run(e) {
|
|
140551
140722
|
let t = e.outputs.map((e) => e.name);
|
|
140552
140723
|
if (e.relation.kind === "union") {
|
|
@@ -140557,7 +140728,16 @@ var Impl = class {
|
|
|
140557
140728
|
return {
|
|
140558
140729
|
kind: "union",
|
|
140559
140730
|
distinct: false,
|
|
140560
|
-
branches: n.map((t, n) =>
|
|
140731
|
+
branches: n.map((t, n) => {
|
|
140732
|
+
let r = this.runRelation(t, e.outputs, [], i?.[n]);
|
|
140733
|
+
return {
|
|
140734
|
+
...r,
|
|
140735
|
+
fields: r.fields.map((e) => ({
|
|
140736
|
+
...e,
|
|
140737
|
+
expr: this.castUnknownUnionColumn(e.expr, e.type)
|
|
140738
|
+
}))
|
|
140739
|
+
};
|
|
140740
|
+
})
|
|
140561
140741
|
};
|
|
140562
140742
|
}
|
|
140563
140743
|
return this.countRefs(e.relation), this.pushNameHints(e.relation, t, /* @__PURE__ */ new Set), this.runRelation(e.relation, e.outputs, e.orderBy ?? [], e.annotation);
|
|
@@ -140619,30 +140799,30 @@ var Impl = class {
|
|
|
140619
140799
|
}
|
|
140620
140800
|
}
|
|
140621
140801
|
visitUnion(e) {
|
|
140622
|
-
let t = [e.base, ...e.inputs], n = this.dispatch(e.base).cols, r = anonColNames(n), i = t.map((t,
|
|
140623
|
-
let
|
|
140624
|
-
expr:
|
|
140802
|
+
let t = [e.base, ...e.inputs], n = this.dispatch(e.base).cols, r = anonColNames(n), i = t.map((t, i) => {
|
|
140803
|
+
let a = this.dispatch(t), s = a.cols.map((e, t) => ({
|
|
140804
|
+
expr: this.castUnknownUnionColumn(a.context.field(t), n[t]?.type),
|
|
140625
140805
|
name: r[t],
|
|
140626
140806
|
origin: e.origin,
|
|
140627
140807
|
type: e.type,
|
|
140628
140808
|
aggregationType: e.aggregationType
|
|
140629
|
-
})),
|
|
140630
|
-
...
|
|
140631
|
-
fields:
|
|
140809
|
+
})), c = this.commentLines(e.branchAnnotations?.[i], a), l = a.node.kind === "select" ? {
|
|
140810
|
+
...a.node,
|
|
140811
|
+
fields: s
|
|
140632
140812
|
} : {
|
|
140633
140813
|
kind: "select",
|
|
140634
140814
|
distinct: false,
|
|
140635
|
-
fields:
|
|
140636
|
-
from:
|
|
140815
|
+
fields: s,
|
|
140816
|
+
from: a.node,
|
|
140637
140817
|
where: [],
|
|
140638
140818
|
groupBy: [],
|
|
140639
140819
|
having: [],
|
|
140640
140820
|
orderBy: []
|
|
140641
140821
|
};
|
|
140642
|
-
return
|
|
140643
|
-
...
|
|
140644
|
-
comments:
|
|
140645
|
-
} :
|
|
140822
|
+
return c ? {
|
|
140823
|
+
...l,
|
|
140824
|
+
comments: c
|
|
140825
|
+
} : l;
|
|
140646
140826
|
}), a = `aql__t${allocId(this.reg)}`, s = n.map((e, t) => ({
|
|
140647
140827
|
name: r[t],
|
|
140648
140828
|
origin: e.origin,
|
|
@@ -140776,7 +140956,7 @@ var Impl = class {
|
|
|
140776
140956
|
visitMap(e) {
|
|
140777
140957
|
let t = this.visitInput(e.input), n = e.scalars.some(scalarHasWindow);
|
|
140778
140958
|
n && (t.hasWindow || isCoalesceMergeGrouping(e.input)) && (t = this.seal(t));
|
|
140779
|
-
let r = t.clauses.has(2) &&
|
|
140959
|
+
let r = t.clauses.has(2) && this.opts.dataSource.dbtype === DbType.BIGQUERY ? groupedInlineContext(t.context, t.cols) : aggInlineContext(t.context, t.cols), i = [];
|
|
140780
140960
|
for (let t of e.scalars)
|
|
140781
140961
|
i.push(scalarToOp(t, mapContext(r, [...i]), this.opts));
|
|
140782
140962
|
let a = this.mapNameHints.get(e), s = e.scalars.map((n, r) => ({
|
|
@@ -140927,7 +141107,7 @@ var Impl = class {
|
|
|
140927
141107
|
let t = this.visitInput(e.input, 2);
|
|
140928
141108
|
t.hasWindow && (t = this.seal(t));
|
|
140929
141109
|
let n;
|
|
140930
|
-
if (ROW_LIMIT_JSON_BACKENDS.has(this.opts.dbtype
|
|
141110
|
+
if (ROW_LIMIT_JSON_BACKENDS.has(this.opts.dataSource.dbtype) && e.aggregates.some((e) => isTableToJson(e.func))) {
|
|
140931
141111
|
let r = e.aggregates.find((e) => isTableToJson(e.func)), i = e.groupKey.map((e) => t.context.field(e)), a = scalarToOp(r.args[0], t.context, this.opts), s = raw("ROW_NUMBER() OVER (", ...i.length === 0 ? [] : [
|
|
140932
141112
|
"PARTITION BY ",
|
|
140933
141113
|
...i.flatMap((e, t) => t === 0 ? [e] : [", ", e]),
|
|
@@ -140974,8 +141154,8 @@ var Impl = class {
|
|
|
140974
141154
|
name: s,
|
|
140975
141155
|
type: a?.type ?? n.type
|
|
140976
141156
|
};
|
|
140977
|
-
}), i = tableToJsonSql(this.opts.dbtype
|
|
140978
|
-
return e.func === "private__table_to_json_string" ? jsonStringOf(this.opts.dbtype
|
|
141157
|
+
}), i = tableToJsonSql(this.opts.dataSource.dbtype, n);
|
|
141158
|
+
return e.func === "private__table_to_json_string" ? jsonStringOf(this.opts.dataSource.dbtype, i) : i;
|
|
140979
141159
|
}), l = uniquifyColNames([...a, ...s]), u = [...i, ...c], f = l.map((e, t) => ({
|
|
140980
141160
|
expr: u[t],
|
|
140981
141161
|
name: e.name,
|
|
@@ -141219,7 +141399,7 @@ function sqlToExplore(e, t, n, r, i) {
|
|
|
141219
141399
|
s ?? (s = statementToExplore(e.select, t, n, r, e.alias).id, e.cte ? a.set(e.cte, s) : i.set(e.select, s)), l.set(e.alias, s);
|
|
141220
141400
|
}
|
|
141221
141401
|
});
|
|
141222
|
-
let u = /* @__PURE__ */ new Set, f = collectJoins(e.from, [], u), m = e.fields.map((e) => toFieldFragment(e, n, t)), _ = e.where.map((e) => createCondition(s, asPredicate(e))), v = e.having.map((e) => createCondition(s, asPredicate(e))), S = [...e.groupBy.map((e) => m[e]), ...(e.groupOnly ?? []).map((e) => toFieldFragment(e, n, t))], E = n.
|
|
141402
|
+
let u = /* @__PURE__ */ new Set, f = collectJoins(e.from, [], u), m = e.fields.map((e) => toFieldFragment(e, n, t)), _ = e.where.map((e) => createCondition(s, asPredicate(e))), v = e.having.map((e) => createCondition(s, asPredicate(e))), S = [...e.groupBy.map((e) => m[e]), ...(e.groupOnly ?? []).map((e) => toFieldFragment(e, n, t))], { dbtype: E } = n.dataSource, j = e.orderBy.map((e) => {
|
|
141223
141403
|
let t = m[e.field];
|
|
141224
141404
|
return {
|
|
141225
141405
|
field: E === DbType.CLICKHOUSE ? {
|
|
@@ -141275,7 +141455,7 @@ function isNullValue(e) {
|
|
|
141275
141455
|
return e === "NULL" || typeof e != "string" && e.operator === OperationType.CAST && e.operands[0] === "NULL";
|
|
141276
141456
|
}
|
|
141277
141457
|
function toFieldFragment(e, t, n) {
|
|
141278
|
-
let r = t.
|
|
141458
|
+
let { dbtype: r } = t.dataSource, i = typeof e.expr != "string" && e.expr.operator === OperationType.FIELD;
|
|
141279
141459
|
if (e.type === SqlType.TRUEFALSE && dbHasNoNativeBoolean(r) && !i) {
|
|
141280
141460
|
let r = truefalseLiteralBit(e.expr), i;
|
|
141281
141461
|
return i = r ?? (isNullValue(e.expr) ? e.expr : truefalseToBit(e.expr, t)), {
|
|
@@ -141391,7 +141571,7 @@ function collectFieldRefs(e, t) {
|
|
|
141391
141571
|
function planToExplore(e, t, n = DEFAULT_LOWER_OPTIONS, r = newRegistry()) {
|
|
141392
141572
|
let i = {
|
|
141393
141573
|
...n,
|
|
141394
|
-
|
|
141574
|
+
dataSource: t.dataSource,
|
|
141395
141575
|
sqlGenerationFlags: n.sqlGenerationFlags ?? t.sqlGenerationFlags
|
|
141396
141576
|
};
|
|
141397
141577
|
return statementToExplore(pruneUnusedColumns(buildSelect(e, i, r)), t, i, r);
|
|
@@ -142902,12 +143082,15 @@ function parseAdhocFields(e) {
|
|
|
142902
143082
|
throw unexpectedError("01J3C7VEYA9BE4534AGHDH6EH5");
|
|
142903
143083
|
});
|
|
142904
143084
|
}
|
|
142905
|
-
function getDiagnosticsV2(e, { store: t, userAttributes: n = [], checkFlags: r = CheckFlags.Normal }) {
|
|
143085
|
+
function getDiagnosticsV2(e, { store: t, userAttributes: n = [], checkFlags: r = CheckFlags.Normal, modelContext: i, adhocFields: a, programKind: s }) {
|
|
142906
143086
|
return resolve({
|
|
142907
143087
|
program: e,
|
|
142908
143088
|
store: t,
|
|
142909
143089
|
userAttributes: n,
|
|
142910
143090
|
checkFlags: r,
|
|
143091
|
+
modelContext: i,
|
|
143092
|
+
adhocFields: a,
|
|
143093
|
+
programKind: s,
|
|
142911
143094
|
typeCheckOnly: true
|
|
142912
143095
|
}).diagnostics;
|
|
142913
143096
|
}
|