@malloydata/malloy 0.0.194-dev241001212731 → 0.0.194
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/malloy.d.ts +4 -6
- package/dist/malloy.js +18 -25
- package/dist/model/malloy_query.d.ts +2 -1
- package/dist/model/malloy_query.js +6 -5
- package/dist/model/malloy_types.d.ts +1 -0
- package/dist/model/materialization/utils.d.ts +1 -1
- package/dist/model/materialization/utils.js +3 -3
- package/package.json +1 -1
package/dist/malloy.d.ts
CHANGED
|
@@ -61,15 +61,13 @@ export declare class Malloy {
|
|
|
61
61
|
* @param model A compiled model to build upon (optional).
|
|
62
62
|
* @return A (promise of a) compiled `Model`.
|
|
63
63
|
*/
|
|
64
|
-
static compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, replaceMaterializedReferences, }: {
|
|
64
|
+
static compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, replaceMaterializedReferences, materializedTablePrefix, }: {
|
|
65
65
|
urlReader: URLReader;
|
|
66
66
|
connections: LookupConnection<InfoConnection>;
|
|
67
67
|
parse: Parse;
|
|
68
68
|
model?: Model;
|
|
69
69
|
} & CompileOptions & PrepareResultOptions): Promise<Model>;
|
|
70
|
-
static compileSQLBlock(partialModel: ModelDef | undefined, toCompile: SQLBlockSource, options?:
|
|
71
|
-
replaceMaterializedReferences?: boolean;
|
|
72
|
-
}): SQLBlock;
|
|
70
|
+
static compileSQLBlock(partialModel: ModelDef | undefined, toCompile: SQLBlockSource, options?: PrepareResultOptions): SQLBlock;
|
|
73
71
|
/**
|
|
74
72
|
* Run a fully-prepared query.
|
|
75
73
|
*
|
|
@@ -892,7 +890,7 @@ declare class FluentState<T> {
|
|
|
892
890
|
*/
|
|
893
891
|
export declare class ModelMaterializer extends FluentState<Model> {
|
|
894
892
|
protected runtime: Runtime;
|
|
895
|
-
private readonly
|
|
893
|
+
private readonly prepareResultOptions;
|
|
896
894
|
constructor(runtime: Runtime, materialize: () => Promise<Model>, options?: PrepareResultOptions);
|
|
897
895
|
/**
|
|
898
896
|
* Load the final (unnamed) Malloy query contained within this loaded `Model`.
|
|
@@ -1026,7 +1024,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
|
|
|
1026
1024
|
*/
|
|
1027
1025
|
export declare class QueryMaterializer extends FluentState<PreparedQuery> {
|
|
1028
1026
|
protected runtime: Runtime;
|
|
1029
|
-
private readonly
|
|
1027
|
+
private readonly prepareResultOptions;
|
|
1030
1028
|
constructor(runtime: Runtime, materialize: () => Promise<PreparedQuery>, options?: PrepareResultOptions);
|
|
1031
1029
|
/**
|
|
1032
1030
|
* Run this loaded `Query`.
|
package/dist/malloy.js
CHANGED
|
@@ -80,7 +80,7 @@ class Malloy {
|
|
|
80
80
|
* @param model A compiled model to build upon (optional).
|
|
81
81
|
* @return A (promise of a) compiled `Model`.
|
|
82
82
|
*/
|
|
83
|
-
static async compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, replaceMaterializedReferences, }) {
|
|
83
|
+
static async compile({ urlReader, connections, parse, model, refreshSchemaCache, noThrowOnError, replaceMaterializedReferences, materializedTablePrefix, }) {
|
|
84
84
|
var _a, _b, _c, _d;
|
|
85
85
|
let refreshTimestamp;
|
|
86
86
|
if (refreshSchemaCache) {
|
|
@@ -177,7 +177,7 @@ class Malloy {
|
|
|
177
177
|
const connectionName = toCompile.connection;
|
|
178
178
|
try {
|
|
179
179
|
const conn = await connections.lookupConnection(connectionName);
|
|
180
|
-
const expanded = Malloy.compileSQLBlock(result.partialModel, toCompile, { replaceMaterializedReferences });
|
|
180
|
+
const expanded = Malloy.compileSQLBlock(result.partialModel, toCompile, { replaceMaterializedReferences, materializedTablePrefix });
|
|
181
181
|
const resolved = await conn.fetchSchemaForSQLBlock(expanded, {
|
|
182
182
|
refreshTimestamp,
|
|
183
183
|
modelAnnotation,
|
|
@@ -1629,6 +1629,7 @@ class Runtime {
|
|
|
1629
1629
|
refreshSchemaCache,
|
|
1630
1630
|
noThrowOnError,
|
|
1631
1631
|
replaceMaterializedReferences: options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences,
|
|
1632
|
+
materializedTablePrefix: options === null || options === void 0 ? void 0 : options.materializedTablePrefix,
|
|
1632
1633
|
});
|
|
1633
1634
|
}, options);
|
|
1634
1635
|
}
|
|
@@ -1842,11 +1843,9 @@ class FluentState {
|
|
|
1842
1843
|
*/
|
|
1843
1844
|
class ModelMaterializer extends FluentState {
|
|
1844
1845
|
constructor(runtime, materialize, options) {
|
|
1845
|
-
var _a;
|
|
1846
1846
|
super(runtime, materialize);
|
|
1847
1847
|
this.runtime = runtime;
|
|
1848
|
-
this.
|
|
1849
|
-
(_a = options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences) !== null && _a !== void 0 ? _a : false;
|
|
1848
|
+
this.prepareResultOptions = options;
|
|
1850
1849
|
}
|
|
1851
1850
|
/**
|
|
1852
1851
|
* Load the final (unnamed) Malloy query contained within this loaded `Model`.
|
|
@@ -1858,7 +1857,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1858
1857
|
return this.makeQueryMaterializer(async () => {
|
|
1859
1858
|
return (await this.materialize()).getPreparedQuery();
|
|
1860
1859
|
}, {
|
|
1861
|
-
|
|
1860
|
+
...this.prepareResultOptions,
|
|
1862
1861
|
...options,
|
|
1863
1862
|
});
|
|
1864
1863
|
}
|
|
@@ -1873,7 +1872,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1873
1872
|
return this.makeQueryMaterializer(async () => {
|
|
1874
1873
|
return (await this.materialize()).getPreparedQueryByIndex(index);
|
|
1875
1874
|
}, {
|
|
1876
|
-
|
|
1875
|
+
...this.prepareResultOptions,
|
|
1877
1876
|
...options,
|
|
1878
1877
|
});
|
|
1879
1878
|
}
|
|
@@ -1888,7 +1887,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1888
1887
|
return this.makeQueryMaterializer(async () => {
|
|
1889
1888
|
return (await this.materialize()).getPreparedQueryByName(name);
|
|
1890
1889
|
}, {
|
|
1891
|
-
|
|
1890
|
+
...this.prepareResultOptions,
|
|
1892
1891
|
...options,
|
|
1893
1892
|
});
|
|
1894
1893
|
}
|
|
@@ -1902,7 +1901,6 @@ class ModelMaterializer extends FluentState {
|
|
|
1902
1901
|
loadQuery(query, options) {
|
|
1903
1902
|
const { refreshSchemaCache, noThrowOnError } = options || {};
|
|
1904
1903
|
return this.makeQueryMaterializer(async () => {
|
|
1905
|
-
var _a;
|
|
1906
1904
|
const urlReader = this.runtime.urlReader;
|
|
1907
1905
|
const connections = this.runtime.connections;
|
|
1908
1906
|
if (this.runtime.isTestRuntime) {
|
|
@@ -1931,7 +1929,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1931
1929
|
model,
|
|
1932
1930
|
refreshSchemaCache,
|
|
1933
1931
|
noThrowOnError,
|
|
1934
|
-
|
|
1932
|
+
...this.prepareResultOptions,
|
|
1935
1933
|
});
|
|
1936
1934
|
return queryModel.preparedQuery;
|
|
1937
1935
|
});
|
|
@@ -1953,7 +1951,6 @@ class ModelMaterializer extends FluentState {
|
|
|
1953
1951
|
}
|
|
1954
1952
|
}
|
|
1955
1953
|
return new ModelMaterializer(this.runtime, async () => {
|
|
1956
|
-
var _a;
|
|
1957
1954
|
const urlReader = this.runtime.urlReader;
|
|
1958
1955
|
const connections = this.runtime.connections;
|
|
1959
1956
|
const parse = query instanceof URL
|
|
@@ -1974,7 +1971,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1974
1971
|
model,
|
|
1975
1972
|
refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
|
|
1976
1973
|
noThrowOnError: options === null || options === void 0 ? void 0 : options.noThrowOnError,
|
|
1977
|
-
|
|
1974
|
+
...this.prepareResultOptions,
|
|
1978
1975
|
});
|
|
1979
1976
|
return queryModel;
|
|
1980
1977
|
}, options);
|
|
@@ -2110,7 +2107,7 @@ class ModelMaterializer extends FluentState {
|
|
|
2110
2107
|
const model = await this.materialize();
|
|
2111
2108
|
return new PreparedQuery(query, model._modelDef, model.problems);
|
|
2112
2109
|
}, {
|
|
2113
|
-
|
|
2110
|
+
...this.prepareResultOptions,
|
|
2114
2111
|
...options,
|
|
2115
2112
|
});
|
|
2116
2113
|
}
|
|
@@ -2124,9 +2121,7 @@ class ModelMaterializer extends FluentState {
|
|
|
2124
2121
|
loadExploreByName(name) {
|
|
2125
2122
|
return this.makeExploreMaterializer(async () => {
|
|
2126
2123
|
return (await this.materialize()).getExploreByName(name);
|
|
2127
|
-
},
|
|
2128
|
-
replaceMaterializedReferences: this.replaceMaterializedReferences,
|
|
2129
|
-
});
|
|
2124
|
+
}, this.prepareResultOptions);
|
|
2130
2125
|
}
|
|
2131
2126
|
/**
|
|
2132
2127
|
* Materialize an explore contained within this loaded `Model` by its name.
|
|
@@ -2154,11 +2149,9 @@ exports.ModelMaterializer = ModelMaterializer;
|
|
|
2154
2149
|
*/
|
|
2155
2150
|
class QueryMaterializer extends FluentState {
|
|
2156
2151
|
constructor(runtime, materialize, options) {
|
|
2157
|
-
var _a;
|
|
2158
2152
|
super(runtime, materialize);
|
|
2159
2153
|
this.runtime = runtime;
|
|
2160
|
-
this.
|
|
2161
|
-
(_a = options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences) !== null && _a !== void 0 ? _a : false;
|
|
2154
|
+
this.prepareResultOptions = options;
|
|
2162
2155
|
}
|
|
2163
2156
|
/**
|
|
2164
2157
|
* Run this loaded `Query`.
|
|
@@ -2168,7 +2161,7 @@ class QueryMaterializer extends FluentState {
|
|
|
2168
2161
|
async run(options) {
|
|
2169
2162
|
const connections = this.runtime.connections;
|
|
2170
2163
|
const preparedResult = await this.getPreparedResult({
|
|
2171
|
-
|
|
2164
|
+
...this.prepareResultOptions,
|
|
2172
2165
|
...options,
|
|
2173
2166
|
});
|
|
2174
2167
|
const finalOptions = runSQLOptionsWithAnnotations(preparedResult, options);
|
|
@@ -2176,7 +2169,7 @@ class QueryMaterializer extends FluentState {
|
|
|
2176
2169
|
}
|
|
2177
2170
|
async *runStream(options) {
|
|
2178
2171
|
const preparedResult = await this.getPreparedResult({
|
|
2179
|
-
|
|
2172
|
+
...this.prepareResultOptions,
|
|
2180
2173
|
...options,
|
|
2181
2174
|
});
|
|
2182
2175
|
const connections = this.runtime.connections;
|
|
@@ -2199,7 +2192,7 @@ class QueryMaterializer extends FluentState {
|
|
|
2199
2192
|
loadPreparedResult(options) {
|
|
2200
2193
|
return this.makePreparedResultMaterializer(async () => {
|
|
2201
2194
|
return (await this.materialize()).getPreparedResult({
|
|
2202
|
-
|
|
2195
|
+
...this.prepareResultOptions,
|
|
2203
2196
|
...options,
|
|
2204
2197
|
});
|
|
2205
2198
|
});
|
|
@@ -2211,7 +2204,7 @@ class QueryMaterializer extends FluentState {
|
|
|
2211
2204
|
*/
|
|
2212
2205
|
getPreparedResult(options) {
|
|
2213
2206
|
return this.loadPreparedResult({
|
|
2214
|
-
|
|
2207
|
+
...this.prepareResultOptions,
|
|
2215
2208
|
...options,
|
|
2216
2209
|
}).getPreparedResult();
|
|
2217
2210
|
}
|
|
@@ -2222,7 +2215,7 @@ class QueryMaterializer extends FluentState {
|
|
|
2222
2215
|
*/
|
|
2223
2216
|
async getSQL(options) {
|
|
2224
2217
|
return (await this.getPreparedResult({
|
|
2225
|
-
|
|
2218
|
+
...this.prepareResultOptions,
|
|
2226
2219
|
...options,
|
|
2227
2220
|
})).sql;
|
|
2228
2221
|
}
|
|
@@ -2242,7 +2235,7 @@ class QueryMaterializer extends FluentState {
|
|
|
2242
2235
|
async estimateQueryCost(options) {
|
|
2243
2236
|
const connections = this.runtime.connections;
|
|
2244
2237
|
const preparedResult = await this.getPreparedResult({
|
|
2245
|
-
|
|
2238
|
+
...this.prepareResultOptions,
|
|
2246
2239
|
...options,
|
|
2247
2240
|
});
|
|
2248
2241
|
return Malloy.estimateQueryCost({ connections, preparedResult });
|
|
@@ -35,7 +35,7 @@ declare class StageWriter {
|
|
|
35
35
|
root(): StageWriter;
|
|
36
36
|
addStage(sql: string): string;
|
|
37
37
|
addUDF(stageWriter: StageWriter, dialect: Dialect, structDef: StructDef): string;
|
|
38
|
-
addMaterializedQuery(fieldName: string, query: Query): string;
|
|
38
|
+
addMaterializedQuery(fieldName: string, query: Query, materializatedTablePrefix?: string): string;
|
|
39
39
|
addPDT(baseName: string, dialect: Dialect): string;
|
|
40
40
|
combineStages(includeLastStage: boolean): {
|
|
41
41
|
sql: string;
|
|
@@ -301,6 +301,7 @@ declare class QueryStruct extends QueryNode {
|
|
|
301
301
|
pathAliasMap: Map<string, string>;
|
|
302
302
|
dialect: Dialect;
|
|
303
303
|
connectionName: string;
|
|
304
|
+
readonly stacki: string;
|
|
304
305
|
constructor(fieldDef: StructDef, sourceArguments: Record<string, Argument> | undefined, parent: ParentQueryStruct | ParentQueryModel, prepareResultOptions?: PrepareResultOptions | undefined);
|
|
305
306
|
resolveParentParameterReferences(param: Parameter): Parameter;
|
|
306
307
|
private _arguments;
|
|
@@ -107,7 +107,7 @@ class StageWriter {
|
|
|
107
107
|
this.root().udfs.push(sql);
|
|
108
108
|
return id;
|
|
109
109
|
}
|
|
110
|
-
addMaterializedQuery(fieldName, query) {
|
|
110
|
+
addMaterializedQuery(fieldName, query, materializatedTablePrefix) {
|
|
111
111
|
var _a;
|
|
112
112
|
const name = query.name;
|
|
113
113
|
if (!name) {
|
|
@@ -118,7 +118,7 @@ class StageWriter {
|
|
|
118
118
|
throw new Error(`Trying to materialize query ${name}, but its path is not set.`);
|
|
119
119
|
}
|
|
120
120
|
// Creating an object that should uniquely identify a query within a Malloy model repo.
|
|
121
|
-
const queryMaterializationSpec = (0, utils_2.buildQueryMaterializationSpec)(path, name);
|
|
121
|
+
const queryMaterializationSpec = (0, utils_2.buildQueryMaterializationSpec)(path, name, materializatedTablePrefix);
|
|
122
122
|
this.root().dependenciesToMaterialize[queryMaterializationSpec.id] =
|
|
123
123
|
queryMaterializationSpec;
|
|
124
124
|
return queryMaterializationSpec.id;
|
|
@@ -2984,6 +2984,7 @@ class QueryStruct extends QueryNode {
|
|
|
2984
2984
|
this.prepareResultOptions = prepareResultOptions;
|
|
2985
2985
|
this.nameMap = new Map();
|
|
2986
2986
|
this._arguments = undefined;
|
|
2987
|
+
this.stacki = new Error('').stack;
|
|
2987
2988
|
this.setParent(parent);
|
|
2988
2989
|
if ('model' in parent) {
|
|
2989
2990
|
this.model = parent.model;
|
|
@@ -3260,7 +3261,7 @@ class QueryStruct extends QueryNode {
|
|
|
3260
3261
|
}
|
|
3261
3262
|
}
|
|
3262
3263
|
structSourceSQL(stageWriter) {
|
|
3263
|
-
var _a;
|
|
3264
|
+
var _a, _b;
|
|
3264
3265
|
switch (this.fieldDef.structSource.type) {
|
|
3265
3266
|
case 'table': {
|
|
3266
3267
|
const tablePath = this.fieldDef.structSource.tablePath;
|
|
@@ -3285,7 +3286,7 @@ class QueryStruct extends QueryNode {
|
|
|
3285
3286
|
// cache derived table.
|
|
3286
3287
|
if (((_a = this.prepareResultOptions) === null || _a === void 0 ? void 0 : _a.replaceMaterializedReferences) &&
|
|
3287
3288
|
(0, utils_2.shouldMaterialize)(this.fieldDef.structSource.query.annotation)) {
|
|
3288
|
-
return stageWriter.addMaterializedQuery((0, malloy_types_1.getIdentifier)(this.fieldDef), this.fieldDef.structSource.query);
|
|
3289
|
+
return stageWriter.addMaterializedQuery((0, malloy_types_1.getIdentifier)(this.fieldDef), this.fieldDef.structSource.query, (_b = this.prepareResultOptions) === null || _b === void 0 ? void 0 : _b.materializedTablePrefix);
|
|
3289
3290
|
}
|
|
3290
3291
|
else {
|
|
3291
3292
|
// returns the stage name.
|
|
@@ -3520,7 +3521,7 @@ class QueryModel {
|
|
|
3520
3521
|
sql: ret.stageWriter.generateSQLStages(),
|
|
3521
3522
|
dependenciesToMaterialize: ret.stageWriter.dependenciesToMaterialize,
|
|
3522
3523
|
materialization: (0, utils_2.shouldMaterialize)(query.annotation)
|
|
3523
|
-
? (0, utils_2.buildQueryMaterializationSpec)((_a = query.location) === null || _a === void 0 ? void 0 : _a.url, query.name)
|
|
3524
|
+
? (0, utils_2.buildQueryMaterializationSpec)((_a = query.location) === null || _a === void 0 ? void 0 : _a.url, query.name, prepareResultOptions === null || prepareResultOptions === void 0 ? void 0 : prepareResultOptions.materializedTablePrefix)
|
|
3524
3525
|
: undefined,
|
|
3525
3526
|
structs: ret.structs,
|
|
3526
3527
|
sourceExplore,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Annotation, QueryToMaterialize } from '../malloy_types';
|
|
2
2
|
export declare function shouldMaterialize(annotation?: Annotation): boolean;
|
|
3
|
-
export declare function buildQueryMaterializationSpec(path?: string, queryName?: string): QueryToMaterialize;
|
|
3
|
+
export declare function buildQueryMaterializationSpec(path?: string, queryName?: string, materializatedTablePrefix?: string): QueryToMaterialize;
|
|
@@ -18,7 +18,7 @@ function shouldMaterialize(annotation) {
|
|
|
18
18
|
return sourceTag.has('materialize');
|
|
19
19
|
}
|
|
20
20
|
exports.shouldMaterialize = shouldMaterialize;
|
|
21
|
-
function buildQueryMaterializationSpec(path, queryName) {
|
|
21
|
+
function buildQueryMaterializationSpec(path, queryName, materializatedTablePrefix) {
|
|
22
22
|
if (!queryName) {
|
|
23
23
|
throw new Error(`Query tagged to materialize, but its name is not specified. ${path}`);
|
|
24
24
|
}
|
|
@@ -31,8 +31,8 @@ function buildQueryMaterializationSpec(path, queryName) {
|
|
|
31
31
|
source: undefined,
|
|
32
32
|
queryName,
|
|
33
33
|
};
|
|
34
|
-
const objectHash = (0, utils_1.generateHash)(JSON.stringify(queryRep));
|
|
35
|
-
const id = `${queryName}
|
|
34
|
+
const objectHash = (0, utils_1.generateHash)(JSON.stringify(queryRep)).replace(/-/g, '_');
|
|
35
|
+
const id = `${materializatedTablePrefix ? `${materializatedTablePrefix}_` : ''}${queryName}_${objectHash}`;
|
|
36
36
|
return {
|
|
37
37
|
...queryRep,
|
|
38
38
|
id,
|