@malloydata/malloy 0.0.194-dev241001154534 → 0.0.194-dev241001231135

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 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
  *
@@ -621,6 +619,11 @@ export declare class AtomicField extends Entity implements Taggable {
621
619
  isCalculation(): boolean;
622
620
  get sourceField(): Field;
623
621
  get sourceClasses(): string[];
622
+ /**
623
+ * A unique ID of this field within the context of a result; undefined
624
+ * for fields that are not derived from a Result.
625
+ */
626
+ get referenceId(): string | undefined;
624
627
  sourceWasMeasure(): boolean;
625
628
  sourceWasMeasureLike(): boolean;
626
629
  sourceWasDimension(): boolean;
@@ -887,7 +890,7 @@ declare class FluentState<T> {
887
890
  */
888
891
  export declare class ModelMaterializer extends FluentState<Model> {
889
892
  protected runtime: Runtime;
890
- private readonly replaceMaterializedReferences;
893
+ private readonly prepareResultOptions;
891
894
  constructor(runtime: Runtime, materialize: () => Promise<Model>, options?: PrepareResultOptions);
892
895
  /**
893
896
  * Load the final (unnamed) Malloy query contained within this loaded `Model`.
@@ -1021,7 +1024,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
1021
1024
  */
1022
1025
  export declare class QueryMaterializer extends FluentState<PreparedQuery> {
1023
1026
  protected runtime: Runtime;
1024
- private readonly replaceMaterializedReferences;
1027
+ private readonly prepareResultOptions;
1025
1028
  constructor(runtime: Runtime, materialize: () => Promise<PreparedQuery>, options?: PrepareResultOptions);
1026
1029
  /**
1027
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,
@@ -1268,6 +1268,14 @@ class AtomicField extends Entity {
1268
1268
  const sourceField = this.fieldTypeDef.name || this.fieldTypeDef.as;
1269
1269
  return sourceField ? [sourceField] : [];
1270
1270
  }
1271
+ /**
1272
+ * A unique ID of this field within the context of a result; undefined
1273
+ * for fields that are not derived from a Result.
1274
+ */
1275
+ get referenceId() {
1276
+ var _a;
1277
+ return (_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.referenceId;
1278
+ }
1271
1279
  // was the field generated from a measure in the previous query
1272
1280
  sourceWasMeasure() {
1273
1281
  var _a;
@@ -1621,6 +1629,7 @@ class Runtime {
1621
1629
  refreshSchemaCache,
1622
1630
  noThrowOnError,
1623
1631
  replaceMaterializedReferences: options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences,
1632
+ materializedTablePrefix: options === null || options === void 0 ? void 0 : options.materializedTablePrefix,
1624
1633
  });
1625
1634
  }, options);
1626
1635
  }
@@ -1834,11 +1843,9 @@ class FluentState {
1834
1843
  */
1835
1844
  class ModelMaterializer extends FluentState {
1836
1845
  constructor(runtime, materialize, options) {
1837
- var _a;
1838
1846
  super(runtime, materialize);
1839
1847
  this.runtime = runtime;
1840
- this.replaceMaterializedReferences =
1841
- (_a = options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences) !== null && _a !== void 0 ? _a : false;
1848
+ this.prepareResultOptions = options;
1842
1849
  }
1843
1850
  /**
1844
1851
  * Load the final (unnamed) Malloy query contained within this loaded `Model`.
@@ -1850,7 +1857,7 @@ class ModelMaterializer extends FluentState {
1850
1857
  return this.makeQueryMaterializer(async () => {
1851
1858
  return (await this.materialize()).getPreparedQuery();
1852
1859
  }, {
1853
- replaceMaterializedReferences: this.replaceMaterializedReferences,
1860
+ ...this.prepareResultOptions,
1854
1861
  ...options,
1855
1862
  });
1856
1863
  }
@@ -1865,7 +1872,7 @@ class ModelMaterializer extends FluentState {
1865
1872
  return this.makeQueryMaterializer(async () => {
1866
1873
  return (await this.materialize()).getPreparedQueryByIndex(index);
1867
1874
  }, {
1868
- replaceMaterializedReferences: this.replaceMaterializedReferences,
1875
+ ...this.prepareResultOptions,
1869
1876
  ...options,
1870
1877
  });
1871
1878
  }
@@ -1880,7 +1887,7 @@ class ModelMaterializer extends FluentState {
1880
1887
  return this.makeQueryMaterializer(async () => {
1881
1888
  return (await this.materialize()).getPreparedQueryByName(name);
1882
1889
  }, {
1883
- replaceMaterializedReferences: this.replaceMaterializedReferences,
1890
+ ...this.prepareResultOptions,
1884
1891
  ...options,
1885
1892
  });
1886
1893
  }
@@ -1894,7 +1901,6 @@ class ModelMaterializer extends FluentState {
1894
1901
  loadQuery(query, options) {
1895
1902
  const { refreshSchemaCache, noThrowOnError } = options || {};
1896
1903
  return this.makeQueryMaterializer(async () => {
1897
- var _a;
1898
1904
  const urlReader = this.runtime.urlReader;
1899
1905
  const connections = this.runtime.connections;
1900
1906
  if (this.runtime.isTestRuntime) {
@@ -1923,7 +1929,7 @@ class ModelMaterializer extends FluentState {
1923
1929
  model,
1924
1930
  refreshSchemaCache,
1925
1931
  noThrowOnError,
1926
- replaceMaterializedReferences: (_a = options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences) !== null && _a !== void 0 ? _a : this.replaceMaterializedReferences,
1932
+ ...this.prepareResultOptions,
1927
1933
  });
1928
1934
  return queryModel.preparedQuery;
1929
1935
  });
@@ -1945,7 +1951,6 @@ class ModelMaterializer extends FluentState {
1945
1951
  }
1946
1952
  }
1947
1953
  return new ModelMaterializer(this.runtime, async () => {
1948
- var _a;
1949
1954
  const urlReader = this.runtime.urlReader;
1950
1955
  const connections = this.runtime.connections;
1951
1956
  const parse = query instanceof URL
@@ -1966,7 +1971,7 @@ class ModelMaterializer extends FluentState {
1966
1971
  model,
1967
1972
  refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
1968
1973
  noThrowOnError: options === null || options === void 0 ? void 0 : options.noThrowOnError,
1969
- replaceMaterializedReferences: (_a = options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences) !== null && _a !== void 0 ? _a : this.replaceMaterializedReferences,
1974
+ ...this.prepareResultOptions,
1970
1975
  });
1971
1976
  return queryModel;
1972
1977
  }, options);
@@ -2102,7 +2107,7 @@ class ModelMaterializer extends FluentState {
2102
2107
  const model = await this.materialize();
2103
2108
  return new PreparedQuery(query, model._modelDef, model.problems);
2104
2109
  }, {
2105
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2110
+ ...this.prepareResultOptions,
2106
2111
  ...options,
2107
2112
  });
2108
2113
  }
@@ -2116,9 +2121,7 @@ class ModelMaterializer extends FluentState {
2116
2121
  loadExploreByName(name) {
2117
2122
  return this.makeExploreMaterializer(async () => {
2118
2123
  return (await this.materialize()).getExploreByName(name);
2119
- }, {
2120
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2121
- });
2124
+ }, this.prepareResultOptions);
2122
2125
  }
2123
2126
  /**
2124
2127
  * Materialize an explore contained within this loaded `Model` by its name.
@@ -2146,11 +2149,9 @@ exports.ModelMaterializer = ModelMaterializer;
2146
2149
  */
2147
2150
  class QueryMaterializer extends FluentState {
2148
2151
  constructor(runtime, materialize, options) {
2149
- var _a;
2150
2152
  super(runtime, materialize);
2151
2153
  this.runtime = runtime;
2152
- this.replaceMaterializedReferences =
2153
- (_a = options === null || options === void 0 ? void 0 : options.replaceMaterializedReferences) !== null && _a !== void 0 ? _a : false;
2154
+ this.prepareResultOptions = options;
2154
2155
  }
2155
2156
  /**
2156
2157
  * Run this loaded `Query`.
@@ -2160,7 +2161,7 @@ class QueryMaterializer extends FluentState {
2160
2161
  async run(options) {
2161
2162
  const connections = this.runtime.connections;
2162
2163
  const preparedResult = await this.getPreparedResult({
2163
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2164
+ ...this.prepareResultOptions,
2164
2165
  ...options,
2165
2166
  });
2166
2167
  const finalOptions = runSQLOptionsWithAnnotations(preparedResult, options);
@@ -2168,7 +2169,7 @@ class QueryMaterializer extends FluentState {
2168
2169
  }
2169
2170
  async *runStream(options) {
2170
2171
  const preparedResult = await this.getPreparedResult({
2171
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2172
+ ...this.prepareResultOptions,
2172
2173
  ...options,
2173
2174
  });
2174
2175
  const connections = this.runtime.connections;
@@ -2191,7 +2192,7 @@ class QueryMaterializer extends FluentState {
2191
2192
  loadPreparedResult(options) {
2192
2193
  return this.makePreparedResultMaterializer(async () => {
2193
2194
  return (await this.materialize()).getPreparedResult({
2194
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2195
+ ...this.prepareResultOptions,
2195
2196
  ...options,
2196
2197
  });
2197
2198
  });
@@ -2203,7 +2204,7 @@ class QueryMaterializer extends FluentState {
2203
2204
  */
2204
2205
  getPreparedResult(options) {
2205
2206
  return this.loadPreparedResult({
2206
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2207
+ ...this.prepareResultOptions,
2207
2208
  ...options,
2208
2209
  }).getPreparedResult();
2209
2210
  }
@@ -2214,7 +2215,7 @@ class QueryMaterializer extends FluentState {
2214
2215
  */
2215
2216
  async getSQL(options) {
2216
2217
  return (await this.getPreparedResult({
2217
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2218
+ ...this.prepareResultOptions,
2218
2219
  ...options,
2219
2220
  })).sql;
2220
2221
  }
@@ -2234,7 +2235,7 @@ class QueryMaterializer extends FluentState {
2234
2235
  async estimateQueryCost(options) {
2235
2236
  const connections = this.runtime.connections;
2236
2237
  const preparedResult = await this.getPreparedResult({
2237
- replaceMaterializedReferences: this.replaceMaterializedReferences,
2238
+ ...this.prepareResultOptions,
2238
2239
  ...options,
2239
2240
  });
2240
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;
@@ -63,7 +63,8 @@ declare abstract class QueryNode {
63
63
  declare class QueryField extends QueryNode {
64
64
  fieldDef: FieldDef;
65
65
  parent: QueryStruct;
66
- constructor(fieldDef: FieldDef, parent: QueryStruct);
66
+ readonly referenceId: string;
67
+ constructor(fieldDef: FieldDef, parent: QueryStruct, referenceId?: string);
67
68
  uniqueKeyPossibleUse(): UniqueKeyPossibleUse | undefined;
68
69
  getJoinableParent(): QueryStruct;
69
70
  caseGroup(groupSets: number[], s: string): string;
@@ -300,6 +301,7 @@ declare class QueryStruct extends QueryNode {
300
301
  pathAliasMap: Map<string, string>;
301
302
  dialect: Dialect;
302
303
  connectionName: string;
304
+ readonly stacki: string;
303
305
  constructor(fieldDef: StructDef, sourceArguments: Record<string, Argument> | undefined, parent: ParentQueryStruct | ParentQueryModel, prepareResultOptions?: PrepareResultOptions | undefined);
304
306
  resolveParentParameterReferences(param: Parameter): Parameter;
305
307
  private _arguments;
@@ -324,7 +326,7 @@ declare class QueryStruct extends QueryNode {
324
326
  getModel(): QueryModel;
325
327
  setParent(parent: ParentQueryStruct | ParentQueryModel): void;
326
328
  /** makes a new queryable field object from a fieldDef */
327
- makeQueryField(field: FieldDef): QueryField;
329
+ makeQueryField(field: FieldDef, referenceId?: string): QueryField;
328
330
  structSourceSQL(stageWriter: StageWriter): string;
329
331
  root(): QueryStruct;
330
332
  primaryKey(): QueryAtomicField | undefined;
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryModel = exports.Segment = void 0;
2
4
  /*
3
5
  * Copyright 2023 Google LLC
4
6
  *
@@ -21,8 +23,7 @@
21
23
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
24
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
25
  */
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.QueryModel = exports.Segment = void 0;
26
+ const uuid_1 = require("uuid");
26
27
  const dialect_1 = require("../dialect");
27
28
  const standardsql_1 = require("../dialect/standardsql/standardsql");
28
29
  const malloy_types_1 = require("./malloy_types");
@@ -106,7 +107,7 @@ class StageWriter {
106
107
  this.root().udfs.push(sql);
107
108
  return id;
108
109
  }
109
- addMaterializedQuery(fieldName, query) {
110
+ addMaterializedQuery(fieldName, query, materializatedTablePrefix) {
110
111
  var _a;
111
112
  const name = query.name;
112
113
  if (!name) {
@@ -117,7 +118,7 @@ class StageWriter {
117
118
  throw new Error(`Trying to materialize query ${name}, but its path is not set.`);
118
119
  }
119
120
  // Creating an object that should uniquely identify a query within a Malloy model repo.
120
- const queryMaterializationSpec = (0, utils_2.buildQueryMaterializationSpec)(path, name);
121
+ const queryMaterializationSpec = (0, utils_2.buildQueryMaterializationSpec)(path, name, materializatedTablePrefix);
121
122
  this.root().dependenciesToMaterialize[queryMaterializationSpec.id] =
122
123
  queryMaterializationSpec;
123
124
  return queryMaterializationSpec.id;
@@ -215,10 +216,11 @@ class QueryNode {
215
216
  }
216
217
  }
217
218
  class QueryField extends QueryNode {
218
- constructor(fieldDef, parent) {
219
+ constructor(fieldDef, parent, referenceId) {
219
220
  super(fieldDef);
220
221
  this.parent = parent;
221
222
  this.fieldDef = fieldDef;
223
+ this.referenceId = referenceId !== null && referenceId !== void 0 ? referenceId : (0, uuid_1.v4)();
222
224
  }
223
225
  uniqueKeyPossibleUse() {
224
226
  return undefined;
@@ -1822,22 +1824,25 @@ class QueryQuery extends QueryField {
1822
1824
  (fieldDef.name || fieldDef.as || 'undefined');
1823
1825
  const sourceExpression = fieldDef.code;
1824
1826
  const sourceClasses = [sourceField];
1827
+ const referenceId = fi.f.referenceId;
1828
+ const base = {
1829
+ sourceField,
1830
+ sourceExpression,
1831
+ sourceClasses,
1832
+ referenceId,
1833
+ };
1825
1834
  if (isCalculatedField(fi.f)) {
1826
1835
  filterList = fi.f.getFilterList();
1827
1836
  return {
1828
- sourceField,
1829
- sourceExpression,
1837
+ ...base,
1830
1838
  filterList,
1831
- sourceClasses,
1832
1839
  fieldKind: 'measure',
1833
1840
  };
1834
1841
  }
1835
1842
  if (isScalarField(fi.f)) {
1836
1843
  return {
1837
- sourceField,
1838
- sourceExpression,
1844
+ ...base,
1839
1845
  filterList,
1840
- sourceClasses,
1841
1846
  fieldKind: 'dimension',
1842
1847
  };
1843
1848
  }
@@ -2979,6 +2984,7 @@ class QueryStruct extends QueryNode {
2979
2984
  this.prepareResultOptions = prepareResultOptions;
2980
2985
  this.nameMap = new Map();
2981
2986
  this._arguments = undefined;
2987
+ this.stacki = new Error('').stack;
2982
2988
  this.setParent(parent);
2983
2989
  if ('model' in parent) {
2984
2990
  this.model = parent.model;
@@ -3229,33 +3235,33 @@ class QueryStruct extends QueryNode {
3229
3235
  }
3230
3236
  }
3231
3237
  /** makes a new queryable field object from a fieldDef */
3232
- makeQueryField(field) {
3238
+ makeQueryField(field, referenceId) {
3233
3239
  switch (field.type) {
3234
3240
  case 'string':
3235
- return new QueryFieldString(field, this);
3241
+ return new QueryFieldString(field, this, referenceId);
3236
3242
  case 'date':
3237
- return new QueryFieldDate(field, this);
3243
+ return new QueryFieldDate(field, this, referenceId);
3238
3244
  case 'timestamp':
3239
- return new QueryFieldTimestamp(field, this);
3245
+ return new QueryFieldTimestamp(field, this, referenceId);
3240
3246
  case 'number':
3241
- return new QueryFieldNumber(field, this);
3247
+ return new QueryFieldNumber(field, this, referenceId);
3242
3248
  case 'boolean':
3243
- return new QueryFieldBoolean(field, this);
3249
+ return new QueryFieldBoolean(field, this, referenceId);
3244
3250
  case 'json':
3245
- return new QueryFieldJSON(field, this);
3251
+ return new QueryFieldJSON(field, this, referenceId);
3246
3252
  case 'sql native':
3247
- return new QueryFieldUnsupported(field, this);
3253
+ return new QueryFieldUnsupported(field, this, referenceId);
3248
3254
  // case "reduce":
3249
3255
  // case "project":
3250
3256
  // case "index":
3251
3257
  case 'turtle':
3252
- return new QueryTurtle(field, this);
3258
+ return new QueryTurtle(field, this, referenceId);
3253
3259
  default:
3254
3260
  throw new Error(`unknown field definition ${JSON.stringify(field)}`);
3255
3261
  }
3256
3262
  }
3257
3263
  structSourceSQL(stageWriter) {
3258
- var _a;
3264
+ var _a, _b;
3259
3265
  switch (this.fieldDef.structSource.type) {
3260
3266
  case 'table': {
3261
3267
  const tablePath = this.fieldDef.structSource.tablePath;
@@ -3280,7 +3286,7 @@ class QueryStruct extends QueryNode {
3280
3286
  // cache derived table.
3281
3287
  if (((_a = this.prepareResultOptions) === null || _a === void 0 ? void 0 : _a.replaceMaterializedReferences) &&
3282
3288
  (0, utils_2.shouldMaterialize)(this.fieldDef.structSource.query.annotation)) {
3283
- 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);
3284
3290
  }
3285
3291
  else {
3286
3292
  // returns the stage name.
@@ -3339,10 +3345,13 @@ class QueryStruct extends QueryNode {
3339
3345
  if (field.parent === undefined) {
3340
3346
  throw new Error('Expected field to have a parent');
3341
3347
  }
3348
+ if (!(field instanceof QueryField)) {
3349
+ throw new Error('Expected fieldref to reference a QueryField');
3350
+ }
3342
3351
  return field.parent.makeQueryField({
3343
3352
  ...field.fieldDef,
3344
3353
  annotation: refAnnoatation,
3345
- });
3354
+ }, field.referenceId);
3346
3355
  }
3347
3356
  return field;
3348
3357
  }
@@ -3512,7 +3521,7 @@ class QueryModel {
3512
3521
  sql: ret.stageWriter.generateSQLStages(),
3513
3522
  dependenciesToMaterialize: ret.stageWriter.dependenciesToMaterialize,
3514
3523
  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)
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)
3516
3525
  : undefined,
3517
3526
  structs: ret.structs,
3518
3527
  sourceExplore,
@@ -285,6 +285,7 @@ export interface ResultMetadataDef {
285
285
  sourceClasses: string[];
286
286
  filterList?: FilterCondition[];
287
287
  fieldKind: 'measure' | 'dimension' | 'struct';
288
+ referenceId?: string;
288
289
  }
289
290
  export interface ResultStructMetadataDef extends ResultMetadataDef {
290
291
  limit?: number;
@@ -783,5 +784,6 @@ export interface SearchValueMapResult {
783
784
  }
784
785
  export interface PrepareResultOptions {
785
786
  replaceMaterializedReferences?: boolean;
787
+ materializedTablePrefix?: string;
786
788
  }
787
789
  export {};
@@ -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}-${objectHash}`;
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.194-dev241001154534",
3
+ "version": "0.0.194-dev241001231135",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",