@malloydata/malloy 0.0.192-dev240927231204 → 0.0.192-dev241001142343
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.
|
@@ -27,7 +27,7 @@ const dialect_1 = require("../dialect");
|
|
|
27
27
|
const standardsql_1 = require("../dialect/standardsql/standardsql");
|
|
28
28
|
const malloy_types_1 = require("./malloy_types");
|
|
29
29
|
const utils_1 = require("./utils");
|
|
30
|
-
const
|
|
30
|
+
const utils_2 = require("./materialization/utils");
|
|
31
31
|
function pathToCol(path) {
|
|
32
32
|
return path.map(el => encodeURIComponent(el)).join('/');
|
|
33
33
|
}
|
|
@@ -117,18 +117,10 @@ class StageWriter {
|
|
|
117
117
|
throw new Error(`Trying to materialize query ${name}, but its path is not set.`);
|
|
118
118
|
}
|
|
119
119
|
// Creating an object that should uniquely identify a query within a Malloy model repo.
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
const id = (0, utils_1.generateHash)(JSON.stringify(queryRep));
|
|
126
|
-
const uniqueName = `${name}-${id}`;
|
|
127
|
-
this.root().dependenciesToMaterialize[uniqueName] = {
|
|
128
|
-
...queryRep,
|
|
129
|
-
id,
|
|
130
|
-
};
|
|
131
|
-
return uniqueName;
|
|
120
|
+
const queryMaterializationSpec = (0, utils_2.buildQueryMaterializationSpec)(path, name);
|
|
121
|
+
this.root().dependenciesToMaterialize[queryMaterializationSpec.id] =
|
|
122
|
+
queryMaterializationSpec;
|
|
123
|
+
return queryMaterializationSpec.id;
|
|
132
124
|
}
|
|
133
125
|
addPDT(baseName, dialect) {
|
|
134
126
|
const sql = this.combineStages(false).sql + this.withs[this.withs.length - 1];
|
|
@@ -3286,13 +3278,8 @@ class QueryStruct extends QueryNode {
|
|
|
3286
3278
|
return '';
|
|
3287
3279
|
case 'query': {
|
|
3288
3280
|
// cache derived table.
|
|
3289
|
-
const clonedAnnotation = structuredClone(this.fieldDef.structSource.query.annotation);
|
|
3290
|
-
if (clonedAnnotation) {
|
|
3291
|
-
clonedAnnotation.inherits = undefined;
|
|
3292
|
-
}
|
|
3293
|
-
const sourceTag = tags_1.Tag.annotationToTag(clonedAnnotation).tag;
|
|
3294
3281
|
if (((_a = this.prepareResultOptions) === null || _a === void 0 ? void 0 : _a.replaceMaterializedReferences) &&
|
|
3295
|
-
|
|
3282
|
+
(0, utils_2.shouldMaterialize)(this.fieldDef.structSource.query.annotation)) {
|
|
3296
3283
|
return stageWriter.addMaterializedQuery((0, malloy_types_1.getIdentifier)(this.fieldDef), this.fieldDef.structSource.query);
|
|
3297
3284
|
}
|
|
3298
3285
|
else {
|
|
@@ -3502,6 +3489,7 @@ class QueryModel {
|
|
|
3502
3489
|
};
|
|
3503
3490
|
}
|
|
3504
3491
|
compileQuery(query, prepareResultOptions, finalize = true) {
|
|
3492
|
+
var _a;
|
|
3505
3493
|
let newModel;
|
|
3506
3494
|
const m = newModel || this;
|
|
3507
3495
|
const ret = m.loadQuery(query, undefined, prepareResultOptions, finalize, false);
|
|
@@ -3523,6 +3511,9 @@ class QueryModel {
|
|
|
3523
3511
|
malloy: ret.malloy,
|
|
3524
3512
|
sql: ret.stageWriter.generateSQLStages(),
|
|
3525
3513
|
dependenciesToMaterialize: ret.stageWriter.dependenciesToMaterialize,
|
|
3514
|
+
materialization: (0, utils_2.shouldMaterialize)(query.annotation)
|
|
3515
|
+
? (0, utils_2.buildQueryMaterializationSpec)((_a = query.location) === null || _a === void 0 ? void 0 : _a.url, query.name)
|
|
3516
|
+
: undefined,
|
|
3526
3517
|
structs: ret.structs,
|
|
3527
3518
|
sourceExplore,
|
|
3528
3519
|
sourceFilters: query.filterList,
|
|
@@ -735,6 +735,7 @@ export interface CompiledQuery extends DrillSource {
|
|
|
735
735
|
queryTimezone?: string;
|
|
736
736
|
annotation?: Annotation;
|
|
737
737
|
dependenciesToMaterialize?: Record<string, QueryToMaterialize>;
|
|
738
|
+
materialization?: QueryToMaterialize;
|
|
738
739
|
}
|
|
739
740
|
/** Result type for running a Malloy query. */
|
|
740
741
|
export interface QueryResult extends CompiledQuery {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.buildQueryMaterializationSpec = exports.shouldMaterialize = void 0;
|
|
10
|
+
const tags_1 = require("../../tags");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
function shouldMaterialize(annotation) {
|
|
13
|
+
const clonedAnnotation = structuredClone(annotation);
|
|
14
|
+
if (clonedAnnotation) {
|
|
15
|
+
clonedAnnotation.inherits = undefined;
|
|
16
|
+
}
|
|
17
|
+
const sourceTag = tags_1.Tag.annotationToTag(clonedAnnotation).tag;
|
|
18
|
+
return sourceTag.has('materialize');
|
|
19
|
+
}
|
|
20
|
+
exports.shouldMaterialize = shouldMaterialize;
|
|
21
|
+
function buildQueryMaterializationSpec(path, queryName) {
|
|
22
|
+
if (!queryName) {
|
|
23
|
+
throw new Error(`Query tagged to materialize, but its name is not specified. ${path}`);
|
|
24
|
+
}
|
|
25
|
+
if (!path) {
|
|
26
|
+
throw new Error(`Query tagged to materialize, but its path is not specified: ${queryName}`);
|
|
27
|
+
}
|
|
28
|
+
// Creating an object that should uniquely identify a query within a Malloy model repo.
|
|
29
|
+
const queryRep = {
|
|
30
|
+
path: path,
|
|
31
|
+
source: undefined,
|
|
32
|
+
queryName,
|
|
33
|
+
};
|
|
34
|
+
const objectHash = (0, utils_1.generateHash)(JSON.stringify(queryRep));
|
|
35
|
+
const id = `${queryName}-${objectHash}`;
|
|
36
|
+
return {
|
|
37
|
+
...queryRep,
|
|
38
|
+
id,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.buildQueryMaterializationSpec = buildQueryMaterializationSpec;
|
|
42
|
+
//# sourceMappingURL=utils.js.map
|