@malloydata/malloy 0.0.194-dev241001154534 → 0.0.194-dev241001212731
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 +5 -0
- package/dist/malloy.js +8 -0
- package/dist/model/malloy_query.d.ts +3 -2
- package/dist/model/malloy_query.js +27 -19
- package/dist/model/malloy_types.d.ts +1 -0
- package/package.json +1 -1
package/dist/malloy.d.ts
CHANGED
|
@@ -621,6 +621,11 @@ export declare class AtomicField extends Entity implements Taggable {
|
|
|
621
621
|
isCalculation(): boolean;
|
|
622
622
|
get sourceField(): Field;
|
|
623
623
|
get sourceClasses(): string[];
|
|
624
|
+
/**
|
|
625
|
+
* A unique ID of this field within the context of a result; undefined
|
|
626
|
+
* for fields that are not derived from a Result.
|
|
627
|
+
*/
|
|
628
|
+
get referenceId(): string | undefined;
|
|
624
629
|
sourceWasMeasure(): boolean;
|
|
625
630
|
sourceWasMeasureLike(): boolean;
|
|
626
631
|
sourceWasDimension(): boolean;
|
package/dist/malloy.js
CHANGED
|
@@ -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;
|
|
@@ -63,7 +63,8 @@ declare abstract class QueryNode {
|
|
|
63
63
|
declare class QueryField extends QueryNode {
|
|
64
64
|
fieldDef: FieldDef;
|
|
65
65
|
parent: QueryStruct;
|
|
66
|
-
|
|
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;
|
|
@@ -324,7 +325,7 @@ declare class QueryStruct extends QueryNode {
|
|
|
324
325
|
getModel(): QueryModel;
|
|
325
326
|
setParent(parent: ParentQueryStruct | ParentQueryModel): void;
|
|
326
327
|
/** makes a new queryable field object from a fieldDef */
|
|
327
|
-
makeQueryField(field: FieldDef): QueryField;
|
|
328
|
+
makeQueryField(field: FieldDef, referenceId?: string): QueryField;
|
|
328
329
|
structSourceSQL(stageWriter: StageWriter): string;
|
|
329
330
|
root(): QueryStruct;
|
|
330
331
|
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
|
-
|
|
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");
|
|
@@ -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
|
-
|
|
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
|
-
|
|
1838
|
-
sourceExpression,
|
|
1844
|
+
...base,
|
|
1839
1845
|
filterList,
|
|
1840
|
-
sourceClasses,
|
|
1841
1846
|
fieldKind: 'dimension',
|
|
1842
1847
|
};
|
|
1843
1848
|
}
|
|
@@ -3229,27 +3234,27 @@ class QueryStruct extends QueryNode {
|
|
|
3229
3234
|
}
|
|
3230
3235
|
}
|
|
3231
3236
|
/** makes a new queryable field object from a fieldDef */
|
|
3232
|
-
makeQueryField(field) {
|
|
3237
|
+
makeQueryField(field, referenceId) {
|
|
3233
3238
|
switch (field.type) {
|
|
3234
3239
|
case 'string':
|
|
3235
|
-
return new QueryFieldString(field, this);
|
|
3240
|
+
return new QueryFieldString(field, this, referenceId);
|
|
3236
3241
|
case 'date':
|
|
3237
|
-
return new QueryFieldDate(field, this);
|
|
3242
|
+
return new QueryFieldDate(field, this, referenceId);
|
|
3238
3243
|
case 'timestamp':
|
|
3239
|
-
return new QueryFieldTimestamp(field, this);
|
|
3244
|
+
return new QueryFieldTimestamp(field, this, referenceId);
|
|
3240
3245
|
case 'number':
|
|
3241
|
-
return new QueryFieldNumber(field, this);
|
|
3246
|
+
return new QueryFieldNumber(field, this, referenceId);
|
|
3242
3247
|
case 'boolean':
|
|
3243
|
-
return new QueryFieldBoolean(field, this);
|
|
3248
|
+
return new QueryFieldBoolean(field, this, referenceId);
|
|
3244
3249
|
case 'json':
|
|
3245
|
-
return new QueryFieldJSON(field, this);
|
|
3250
|
+
return new QueryFieldJSON(field, this, referenceId);
|
|
3246
3251
|
case 'sql native':
|
|
3247
|
-
return new QueryFieldUnsupported(field, this);
|
|
3252
|
+
return new QueryFieldUnsupported(field, this, referenceId);
|
|
3248
3253
|
// case "reduce":
|
|
3249
3254
|
// case "project":
|
|
3250
3255
|
// case "index":
|
|
3251
3256
|
case 'turtle':
|
|
3252
|
-
return new QueryTurtle(field, this);
|
|
3257
|
+
return new QueryTurtle(field, this, referenceId);
|
|
3253
3258
|
default:
|
|
3254
3259
|
throw new Error(`unknown field definition ${JSON.stringify(field)}`);
|
|
3255
3260
|
}
|
|
@@ -3339,10 +3344,13 @@ class QueryStruct extends QueryNode {
|
|
|
3339
3344
|
if (field.parent === undefined) {
|
|
3340
3345
|
throw new Error('Expected field to have a parent');
|
|
3341
3346
|
}
|
|
3347
|
+
if (!(field instanceof QueryField)) {
|
|
3348
|
+
throw new Error('Expected fieldref to reference a QueryField');
|
|
3349
|
+
}
|
|
3342
3350
|
return field.parent.makeQueryField({
|
|
3343
3351
|
...field.fieldDef,
|
|
3344
3352
|
annotation: refAnnoatation,
|
|
3345
|
-
});
|
|
3353
|
+
}, field.referenceId);
|
|
3346
3354
|
}
|
|
3347
3355
|
return field;
|
|
3348
3356
|
}
|
|
@@ -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;
|