@malloydata/malloy 0.0.1 → 0.0.3
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/README.md +12 -11
- package/dist/dialect/dialect.d.ts +1 -1
- package/dist/dialect/dialect.js +13 -0
- package/dist/dialect/duckdb.d.ts +1 -1
- package/dist/dialect/duckdb.js +35 -37
- package/dist/dialect/postgres.d.ts +1 -1
- package/dist/dialect/postgres.js +15 -8
- package/dist/dialect/standardsql.js +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/lang/ast/apply-expr.d.ts +2 -2
- package/dist/lang/ast/apply-expr.js +19 -3
- package/dist/lang/ast/ast-expr.d.ts +37 -37
- package/dist/lang/ast/ast-expr.js +24 -39
- package/dist/lang/ast/ast-main.d.ts +14 -14
- package/dist/lang/ast/ast-main.js +36 -45
- package/dist/lang/ast/ast-time-expr.d.ts +19 -19
- package/dist/lang/ast/ast-time-expr.js +6 -7
- package/dist/lang/ast/time-utils.d.ts +1 -0
- package/dist/lang/ast/time-utils.js +12 -1
- package/dist/lang/field-space.d.ts +43 -41
- package/dist/lang/field-space.js +115 -135
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +108 -106
- package/dist/lang/lib/Malloy/MalloyLexer.js +1019 -1006
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +581 -590
- package/dist/lang/lib/Malloy/MalloyParser.js +1141 -1202
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2015 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1269 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
- package/dist/lang/parse-to-ast.d.ts +3 -4
- package/dist/lang/parse-to-ast.js +1 -1
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +2 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +2 -2
- package/dist/lang/space-field.d.ts +10 -7
- package/dist/lang/space-field.js +11 -4
- package/dist/lang/test/field-symbols.spec.js +2 -2
- package/dist/lang/test/parse.spec.js +16 -1
- package/dist/lang/test/test-translator.js +1 -1
- package/dist/malloy.d.ts +1 -1
- package/dist/malloy.js +11 -5
- package/dist/md5.d.ts +1 -0
- package/dist/md5.js +30 -0
- package/dist/model/malloy_query.js +10 -6
- package/dist/model/malloy_types.d.ts +15 -2
- package/package.json +9 -13
- package/dist/dialect/dialect-map.d.ts +0 -3
- package/dist/dialect/dialect-map.js +0 -33
- package/dist/model/malloy-query.d.ts +0 -313
- package/dist/model/malloy-query.js +0 -2603
- package/dist/model/malloy-types.d.ts +0 -404
- package/dist/model/malloy-types.js +0 -242
- package/dist/model/sql-block.d.ts +0 -11
- package/dist/model/sql-block.js +0 -38
- package/dist/runtime-types.d.ts +0 -116
- package/dist/runtime-types.js +0 -40
|
@@ -20,7 +20,7 @@ export interface FieldSpace {
|
|
|
20
20
|
structDef(): model.StructDef;
|
|
21
21
|
emptyStructDef(): model.StructDef;
|
|
22
22
|
lookup(symbol: FieldName[]): LookupResult;
|
|
23
|
-
|
|
23
|
+
dialectObj(): Dialect | undefined;
|
|
24
24
|
whenComplete: (step: () => void) => void;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -32,7 +32,7 @@ export declare class StaticSpace implements FieldSpace {
|
|
|
32
32
|
protected fromStruct: model.StructDef;
|
|
33
33
|
constructor(sourceStructDef: model.StructDef);
|
|
34
34
|
whenComplete(step: () => void): void;
|
|
35
|
-
|
|
35
|
+
dialectObj(): Dialect | undefined;
|
|
36
36
|
fromFieldDef(from: model.FieldDef): SpaceField;
|
|
37
37
|
private get map();
|
|
38
38
|
protected dropEntries(): void;
|
|
@@ -48,10 +48,10 @@ export declare type SourceSpec = model.StructDef | FieldSpace;
|
|
|
48
48
|
/**
|
|
49
49
|
* Based on how things are constructed, the starting field space
|
|
50
50
|
* can either be another field space or an existing structdef.
|
|
51
|
-
* Using a
|
|
51
|
+
* Using a SpaceSeed allows a class to accept either one
|
|
52
52
|
* and use either version at some future time.
|
|
53
53
|
*/
|
|
54
|
-
declare class
|
|
54
|
+
declare class SpaceSeed {
|
|
55
55
|
readonly sourceSpec: SourceSpec;
|
|
56
56
|
private spaceSpec;
|
|
57
57
|
private asFS?;
|
|
@@ -65,7 +65,7 @@ declare class SourceSpace {
|
|
|
65
65
|
*/
|
|
66
66
|
export declare class DynamicSpace extends StaticSpace {
|
|
67
67
|
protected final: model.StructDef | undefined;
|
|
68
|
-
protected source:
|
|
68
|
+
protected source: SpaceSeed;
|
|
69
69
|
outputFS?: QuerySpace;
|
|
70
70
|
completions: (() => void)[];
|
|
71
71
|
private complete;
|
|
@@ -85,50 +85,57 @@ export declare class DynamicSpace extends StaticSpace {
|
|
|
85
85
|
addFieldDef(fd: model.FieldDef): void;
|
|
86
86
|
structDef(): model.StructDef;
|
|
87
87
|
}
|
|
88
|
-
declare type QuerySegType = "reduce" | "project" | "index";
|
|
89
88
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
89
|
+
* Unlike a source, which is a refinement of a namespace, a query
|
|
90
|
+
* is creating a new unrelated namespace. The query starts with a
|
|
91
|
+
* source, which it might modify. This set of fields used to resolve
|
|
92
|
+
* expressions in the query is called the "input space". There is a
|
|
93
|
+
* specialized QuerySpace for each type of query operation.
|
|
94
|
+
*
|
|
95
|
+
* The query output is managed by an instance of ResultSpace.
|
|
92
96
|
*/
|
|
93
|
-
export declare
|
|
94
|
-
|
|
95
|
-
astEl?: MalloyElement | undefined;
|
|
96
|
-
readonly queryInput: SourceSpace;
|
|
97
|
+
export declare class QuerySpace extends DynamicSpace {
|
|
98
|
+
readonly result: ResultSpace;
|
|
97
99
|
nestParent?: QuerySpace;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
extendList: string[];
|
|
101
|
+
constructor(input: SourceSpec, result: ResultSpace);
|
|
102
|
+
extendSource(extendField: Join | FieldDeclaration): void;
|
|
103
|
+
}
|
|
104
|
+
export declare abstract class ResultSpace extends DynamicSpace {
|
|
105
|
+
readonly queryInputSpace: FieldSpace;
|
|
106
|
+
readonly exprSpace: QuerySpace;
|
|
107
|
+
astEl?: MalloyElement | undefined;
|
|
108
|
+
abstract readonly segmentType: "reduce" | "project" | "index";
|
|
109
|
+
constructor(queryInputSpace: FieldSpace);
|
|
110
|
+
log(s: string): void;
|
|
102
111
|
addMembers(members: FieldCollectionMember[]): void;
|
|
103
112
|
addReference(ref: FieldReference): void;
|
|
104
113
|
addWild(wild: WildcardFieldReference): void;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
extendedInput?: DynamicSpace;
|
|
112
|
-
extendedFields: string[];
|
|
113
|
-
extendSource(extendField: Join | FieldDeclaration): void;
|
|
114
|
-
inputFS(): FieldSpace;
|
|
115
|
-
qfs(): FSPair;
|
|
114
|
+
/**
|
|
115
|
+
* Check for the definition of an ungrouping reference in the result space,
|
|
116
|
+
* or in the case of an exclude reference, if this query is nested
|
|
117
|
+
* in another query, in the result space of a query that this query
|
|
118
|
+
* is nested inside of.
|
|
119
|
+
*/
|
|
116
120
|
checkUngroup(fn: FieldName, isExclude: boolean): void;
|
|
117
|
-
private extendInto;
|
|
118
|
-
getPipeSegment(refineFrom: model.QuerySegment | undefined): model.QuerySegment;
|
|
119
121
|
addQueryItems(...qiList: QueryItem[]): void;
|
|
120
122
|
canContain(_qd: model.QueryFieldDef): boolean;
|
|
121
123
|
protected queryFieldDefs(): model.QueryFieldDef[];
|
|
124
|
+
getQuerySegment(rf: model.QuerySegment | undefined): model.QuerySegment;
|
|
125
|
+
getPipeSegment(refineFrom: model.QuerySegment | undefined): model.PipeSegment;
|
|
122
126
|
}
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Reduce and project queries use a "QuerySpace"
|
|
129
|
+
*/
|
|
130
|
+
export declare class ReduceFieldSpace extends ResultSpace {
|
|
131
|
+
readonly segmentType = "reduce";
|
|
125
132
|
}
|
|
126
|
-
export declare class ProjectFieldSpace extends
|
|
127
|
-
|
|
133
|
+
export declare class ProjectFieldSpace extends ResultSpace {
|
|
134
|
+
readonly segmentType = "project";
|
|
128
135
|
canContain(qd: model.QueryFieldDef): boolean;
|
|
129
136
|
}
|
|
130
|
-
export declare class IndexFieldSpace extends
|
|
131
|
-
|
|
137
|
+
export declare class IndexFieldSpace extends ResultSpace {
|
|
138
|
+
readonly segmentType = "index";
|
|
132
139
|
fieldList: Set<string>;
|
|
133
140
|
addReference(ref: FieldReference): void;
|
|
134
141
|
addWild(wild: WildcardFieldReference): void;
|
|
@@ -146,12 +153,7 @@ export declare class DefSpace implements FieldSpace {
|
|
|
146
153
|
structDef(): model.StructDef;
|
|
147
154
|
emptyStructDef(): model.StructDef;
|
|
148
155
|
lookup(symbol: FieldName[]): LookupResult;
|
|
149
|
-
|
|
156
|
+
dialectObj(): Dialect | undefined;
|
|
150
157
|
whenComplete(step: () => void): void;
|
|
151
158
|
}
|
|
152
|
-
export interface FSPair {
|
|
153
|
-
in: FieldSpace;
|
|
154
|
-
out: FieldSpace;
|
|
155
|
-
}
|
|
156
|
-
export declare function fsPair(inFS: FieldSpace, outFS?: FieldSpace): FSPair;
|
|
157
159
|
export {};
|
package/dist/lang/field-space.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
35
35
|
return result;
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
38
|
+
exports.DefSpace = exports.IndexFieldSpace = exports.ProjectFieldSpace = exports.ReduceFieldSpace = exports.ResultSpace = exports.QuerySpace = exports.DynamicSpace = exports.StaticSpace = void 0;
|
|
39
39
|
/* eslint-disable no-useless-constructor */
|
|
40
40
|
const lodash_1 = require("lodash");
|
|
41
41
|
const dialect_1 = require("../dialect");
|
|
@@ -54,8 +54,13 @@ class StaticSpace {
|
|
|
54
54
|
whenComplete(step) {
|
|
55
55
|
step();
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
dialectObj() {
|
|
58
|
+
try {
|
|
59
|
+
return (0, dialect_1.getDialect)(this.fromStruct.dialect);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
65
|
fromFieldDef(from) {
|
|
61
66
|
if (from.type === "struct") {
|
|
@@ -116,6 +121,8 @@ class StaticSpace {
|
|
|
116
121
|
}
|
|
117
122
|
if (found instanceof space_field_1.SpaceField) {
|
|
118
123
|
/*
|
|
124
|
+
* TODO cache defs, post the addReference call to whenComplete
|
|
125
|
+
*
|
|
119
126
|
* In the cleanup phase of query space construction, it may check
|
|
120
127
|
* the output space for ungrouping variables. However if an
|
|
121
128
|
* ungrouping variable is a measure, the field expression value
|
|
@@ -129,18 +136,7 @@ class StaticSpace {
|
|
|
129
136
|
* ... or this check would look at the finalized output of
|
|
130
137
|
* the namespace and not re-compile ...
|
|
131
138
|
*/
|
|
132
|
-
|
|
133
|
-
if (this instanceof QuerySpace) {
|
|
134
|
-
const qfd = found.getQueryFieldDef(this.qfs());
|
|
135
|
-
if (qfd &&
|
|
136
|
-
typeof qfd != "string" &&
|
|
137
|
-
!model.isFilteredAliasedName(qfd)) {
|
|
138
|
-
definition = qfd;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
definition = found.fieldDef();
|
|
143
|
-
}
|
|
139
|
+
const definition = found.fieldDef();
|
|
144
140
|
if (definition) {
|
|
145
141
|
head.addReference({
|
|
146
142
|
type: found instanceof space_field_1.StructSpaceField
|
|
@@ -171,10 +167,10 @@ function isFieldSpace(x) {
|
|
|
171
167
|
/**
|
|
172
168
|
* Based on how things are constructed, the starting field space
|
|
173
169
|
* can either be another field space or an existing structdef.
|
|
174
|
-
* Using a
|
|
170
|
+
* Using a SpaceSeed allows a class to accept either one
|
|
175
171
|
* and use either version at some future time.
|
|
176
172
|
*/
|
|
177
|
-
class
|
|
173
|
+
class SpaceSeed {
|
|
178
174
|
constructor(sourceSpec) {
|
|
179
175
|
this.sourceSpec = sourceSpec;
|
|
180
176
|
this.spaceSpec = sourceSpec;
|
|
@@ -203,7 +199,7 @@ class SourceSpace {
|
|
|
203
199
|
*/
|
|
204
200
|
class DynamicSpace extends StaticSpace {
|
|
205
201
|
constructor(extending) {
|
|
206
|
-
const source = new
|
|
202
|
+
const source = new SpaceSeed(extending);
|
|
207
203
|
super((0, lodash_1.cloneDeep)(source.structDef));
|
|
208
204
|
this.completions = [];
|
|
209
205
|
this.complete = false;
|
|
@@ -285,7 +281,7 @@ class DynamicSpace extends StaticSpace {
|
|
|
285
281
|
def.log("Can't rename field to itself");
|
|
286
282
|
continue;
|
|
287
283
|
}
|
|
288
|
-
const oldValue = def.oldName.getField(
|
|
284
|
+
const oldValue = def.oldName.getField(this);
|
|
289
285
|
if (oldValue.found) {
|
|
290
286
|
if (oldValue.found instanceof space_field_1.SpaceField) {
|
|
291
287
|
this.setEntry(def.newName, new space_field_1.RenameSpaceField(oldValue.found, def.newName, def.location));
|
|
@@ -360,7 +356,7 @@ class DynamicSpace extends StaticSpace {
|
|
|
360
356
|
}
|
|
361
357
|
// If we have join expressions, we need to now go back and fill them in
|
|
362
358
|
for (const [join, missingOn] of fixupJoins) {
|
|
363
|
-
join.fixupJoinOn(
|
|
359
|
+
join.fixupJoinOn(this, missingOn);
|
|
364
360
|
}
|
|
365
361
|
}
|
|
366
362
|
this.isComplete();
|
|
@@ -369,26 +365,42 @@ class DynamicSpace extends StaticSpace {
|
|
|
369
365
|
}
|
|
370
366
|
exports.DynamicSpace = DynamicSpace;
|
|
371
367
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
368
|
+
* Unlike a source, which is a refinement of a namespace, a query
|
|
369
|
+
* is creating a new unrelated namespace. The query starts with a
|
|
370
|
+
* source, which it might modify. This set of fields used to resolve
|
|
371
|
+
* expressions in the query is called the "input space". There is a
|
|
372
|
+
* specialized QuerySpace for each type of query operation.
|
|
373
|
+
*
|
|
374
|
+
* The query output is managed by an instance of ResultSpace.
|
|
374
375
|
*/
|
|
375
|
-
class
|
|
376
|
-
constructor(input) {
|
|
377
|
-
const inputSpace = new
|
|
378
|
-
super(
|
|
379
|
-
this.
|
|
376
|
+
class QuerySpace extends DynamicSpace {
|
|
377
|
+
constructor(input, result) {
|
|
378
|
+
const inputSpace = new SpaceSeed(input);
|
|
379
|
+
super(inputSpace.structDef);
|
|
380
|
+
this.result = result;
|
|
381
|
+
this.extendList = [];
|
|
380
382
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
+
extendSource(extendField) {
|
|
384
|
+
this.addField(extendField);
|
|
385
|
+
if (extendField instanceof ast_1.Join) {
|
|
386
|
+
this.extendList.push(extendField.name.refString);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
this.extendList.push(extendField.defineName);
|
|
390
|
+
}
|
|
383
391
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
}
|
|
393
|
+
exports.QuerySpace = QuerySpace;
|
|
394
|
+
class ResultSpace extends DynamicSpace {
|
|
395
|
+
constructor(queryInputSpace) {
|
|
396
|
+
super(queryInputSpace.emptyStructDef());
|
|
397
|
+
this.queryInputSpace = queryInputSpace;
|
|
398
|
+
this.exprSpace = new QuerySpace(queryInputSpace, this);
|
|
399
|
+
}
|
|
400
|
+
log(s) {
|
|
401
|
+
if (this.astEl) {
|
|
402
|
+
this.astEl.log(s);
|
|
403
|
+
}
|
|
392
404
|
}
|
|
393
405
|
addMembers(members) {
|
|
394
406
|
for (const member of members) {
|
|
@@ -415,45 +427,18 @@ class QueryOperationSpace extends DynamicSpace {
|
|
|
415
427
|
addWild(wild) {
|
|
416
428
|
this.setEntry(wild.refString, new space_field_1.WildSpaceField(wild.refString));
|
|
417
429
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
exports.QueryOperationSpace = QueryOperationSpace;
|
|
425
|
-
/**
|
|
426
|
-
* Reduce and project queries use a "QuerySpace"
|
|
427
|
-
*/
|
|
428
|
-
class QuerySpace extends QueryOperationSpace {
|
|
429
|
-
constructor() {
|
|
430
|
-
super(...arguments);
|
|
431
|
-
this.extendedFields = [];
|
|
432
|
-
}
|
|
433
|
-
extendSource(extendField) {
|
|
434
|
-
this.extendedFields.push(extendField instanceof ast_1.Join
|
|
435
|
-
? extendField.name.refString
|
|
436
|
-
: extendField.defineName);
|
|
437
|
-
this.extendInto().addField(extendField);
|
|
438
|
-
}
|
|
439
|
-
inputFS() {
|
|
440
|
-
if (this.extendedInput) {
|
|
441
|
-
return this.extendedInput;
|
|
442
|
-
}
|
|
443
|
-
return this.queryInput.fieldSpace;
|
|
444
|
-
}
|
|
445
|
-
qfs() {
|
|
446
|
-
return {
|
|
447
|
-
in: this.inputFS(),
|
|
448
|
-
out: this,
|
|
449
|
-
};
|
|
450
|
-
}
|
|
430
|
+
/**
|
|
431
|
+
* Check for the definition of an ungrouping reference in the result space,
|
|
432
|
+
* or in the case of an exclude reference, if this query is nested
|
|
433
|
+
* in another query, in the result space of a query that this query
|
|
434
|
+
* is nested inside of.
|
|
435
|
+
*/
|
|
451
436
|
checkUngroup(fn, isExclude) {
|
|
452
|
-
if (this.
|
|
453
|
-
if (isExclude && this.nestParent) {
|
|
454
|
-
const parent = this.nestParent;
|
|
437
|
+
if (!this.entry(fn.refString)) {
|
|
438
|
+
if (isExclude && this.exprSpace.nestParent) {
|
|
439
|
+
const parent = this.exprSpace.nestParent;
|
|
455
440
|
parent.whenComplete(() => {
|
|
456
|
-
parent.checkUngroup(fn, isExclude);
|
|
441
|
+
parent.result.checkUngroup(fn, isExclude);
|
|
457
442
|
});
|
|
458
443
|
}
|
|
459
444
|
else {
|
|
@@ -462,46 +447,6 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
462
447
|
}
|
|
463
448
|
}
|
|
464
449
|
}
|
|
465
|
-
extendInto() {
|
|
466
|
-
if (!this.extendedInput) {
|
|
467
|
-
this.extendedInput = new DynamicSpace(this.queryInput.sourceSpec);
|
|
468
|
-
}
|
|
469
|
-
return this.extendedInput;
|
|
470
|
-
}
|
|
471
|
-
getPipeSegment(refineFrom) {
|
|
472
|
-
const reduceOrProject = this.segType;
|
|
473
|
-
if (reduceOrProject === "index") {
|
|
474
|
-
throw new Error("IndexSegment getPipeSegment should not call super");
|
|
475
|
-
}
|
|
476
|
-
if (refineFrom === null || refineFrom === void 0 ? void 0 : refineFrom.extendSource) {
|
|
477
|
-
for (const xField of refineFrom.extendSource) {
|
|
478
|
-
this.extendInto().addFieldDef(xField);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
const segment = {
|
|
482
|
-
type: reduceOrProject,
|
|
483
|
-
fields: this.queryFieldDefs(),
|
|
484
|
-
};
|
|
485
|
-
segment.fields = (0, field_utils_1.mergeFields)(refineFrom === null || refineFrom === void 0 ? void 0 : refineFrom.fields, segment.fields);
|
|
486
|
-
if (refineFrom === null || refineFrom === void 0 ? void 0 : refineFrom.extendSource) {
|
|
487
|
-
segment.extendSource = refineFrom.extendSource;
|
|
488
|
-
}
|
|
489
|
-
if (this.extendedInput) {
|
|
490
|
-
const newExtends = [];
|
|
491
|
-
// have to get the whole structdef because we need all the join
|
|
492
|
-
// resolution to happen and that only happens at the completion
|
|
493
|
-
// of the structdef generation.
|
|
494
|
-
const extendedStruct = this.extendedInput.structDef();
|
|
495
|
-
for (const extendName of this.extendedFields) {
|
|
496
|
-
const extendEnt = extendedStruct.fields.find((f) => (0, field_utils_1.nameOf)(f) == extendName);
|
|
497
|
-
if (extendEnt) {
|
|
498
|
-
newExtends.push(extendEnt);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
segment.extendSource = (0, field_utils_1.mergeFields)(segment.extendSource, newExtends);
|
|
502
|
-
}
|
|
503
|
-
return segment;
|
|
504
|
-
}
|
|
505
450
|
addQueryItems(...qiList) {
|
|
506
451
|
for (const qi of qiList) {
|
|
507
452
|
if (qi instanceof ast_1.FieldReference || qi instanceof ast_1.NestReference) {
|
|
@@ -511,8 +456,8 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
511
456
|
this.addField(qi);
|
|
512
457
|
}
|
|
513
458
|
else if ((0, ast_1.isNestedQuery)(qi)) {
|
|
514
|
-
const qf = new space_field_1.QueryFieldAST(this
|
|
515
|
-
qf.nestParent = this;
|
|
459
|
+
const qf = new space_field_1.QueryFieldAST(this, qi, qi.name);
|
|
460
|
+
qf.nestParent = this.exprSpace;
|
|
516
461
|
this.setEntry(qi.name, qf);
|
|
517
462
|
}
|
|
518
463
|
else {
|
|
@@ -528,13 +473,13 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
528
473
|
const fields = [];
|
|
529
474
|
for (const [name, field] of this.entries()) {
|
|
530
475
|
if (field instanceof space_field_1.SpaceField) {
|
|
531
|
-
const fieldQueryDef = field.getQueryFieldDef(this.
|
|
476
|
+
const fieldQueryDef = field.getQueryFieldDef(this.exprSpace);
|
|
532
477
|
if (fieldQueryDef) {
|
|
533
478
|
if (this.canContain(fieldQueryDef)) {
|
|
534
479
|
fields.push(fieldQueryDef);
|
|
535
480
|
}
|
|
536
481
|
else {
|
|
537
|
-
this.log(`'${name}' not legal in ${this.
|
|
482
|
+
this.log(`'${name}' not legal in ${this.segmentType}`);
|
|
538
483
|
}
|
|
539
484
|
}
|
|
540
485
|
else {
|
|
@@ -545,19 +490,61 @@ class QuerySpace extends QueryOperationSpace {
|
|
|
545
490
|
this.isComplete();
|
|
546
491
|
return fields;
|
|
547
492
|
}
|
|
493
|
+
getQuerySegment(rf) {
|
|
494
|
+
const p = this.getPipeSegment(rf);
|
|
495
|
+
if (model.isQuerySegment(p)) {
|
|
496
|
+
return p;
|
|
497
|
+
}
|
|
498
|
+
throw new Error("TODO NOT POSSIBLE");
|
|
499
|
+
}
|
|
500
|
+
getPipeSegment(refineFrom) {
|
|
501
|
+
if (this.segmentType == "index") {
|
|
502
|
+
// TODO ... should make this go away
|
|
503
|
+
throw new Error("INDEX FIELD PIPE SEGMENT MIS HANDLED");
|
|
504
|
+
}
|
|
505
|
+
if (refineFrom === null || refineFrom === void 0 ? void 0 : refineFrom.extendSource) {
|
|
506
|
+
for (const xField of refineFrom.extendSource) {
|
|
507
|
+
this.exprSpace.addFieldDef(xField);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const segment = {
|
|
511
|
+
type: this.segmentType,
|
|
512
|
+
fields: this.queryFieldDefs(),
|
|
513
|
+
};
|
|
514
|
+
segment.fields = (0, field_utils_1.mergeFields)(refineFrom === null || refineFrom === void 0 ? void 0 : refineFrom.fields, segment.fields);
|
|
515
|
+
if (refineFrom === null || refineFrom === void 0 ? void 0 : refineFrom.extendSource) {
|
|
516
|
+
segment.extendSource = refineFrom.extendSource;
|
|
517
|
+
}
|
|
518
|
+
if (this.exprSpace.extendList.length > 0) {
|
|
519
|
+
const newExtends = [];
|
|
520
|
+
const extendedStruct = this.exprSpace.structDef();
|
|
521
|
+
for (const extendName of this.exprSpace.extendList) {
|
|
522
|
+
const extendEnt = extendedStruct.fields.find((f) => (0, field_utils_1.nameOf)(f) == extendName);
|
|
523
|
+
if (extendEnt) {
|
|
524
|
+
newExtends.push(extendEnt);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
segment.extendSource = (0, field_utils_1.mergeFields)(segment.extendSource, newExtends);
|
|
528
|
+
}
|
|
529
|
+
this.isComplete();
|
|
530
|
+
return segment;
|
|
531
|
+
}
|
|
548
532
|
}
|
|
549
|
-
exports.
|
|
550
|
-
|
|
533
|
+
exports.ResultSpace = ResultSpace;
|
|
534
|
+
/**
|
|
535
|
+
* Reduce and project queries use a "QuerySpace"
|
|
536
|
+
*/
|
|
537
|
+
class ReduceFieldSpace extends ResultSpace {
|
|
551
538
|
constructor() {
|
|
552
539
|
super(...arguments);
|
|
553
|
-
this.
|
|
540
|
+
this.segmentType = "reduce";
|
|
554
541
|
}
|
|
555
542
|
}
|
|
556
543
|
exports.ReduceFieldSpace = ReduceFieldSpace;
|
|
557
|
-
class ProjectFieldSpace extends
|
|
544
|
+
class ProjectFieldSpace extends ResultSpace {
|
|
558
545
|
constructor() {
|
|
559
546
|
super(...arguments);
|
|
560
|
-
this.
|
|
547
|
+
this.segmentType = "project";
|
|
561
548
|
}
|
|
562
549
|
canContain(qd) {
|
|
563
550
|
if (typeof qd !== "string") {
|
|
@@ -577,14 +564,14 @@ class ProjectFieldSpace extends QuerySpace {
|
|
|
577
564
|
}
|
|
578
565
|
}
|
|
579
566
|
exports.ProjectFieldSpace = ProjectFieldSpace;
|
|
580
|
-
class IndexFieldSpace extends
|
|
567
|
+
class IndexFieldSpace extends ResultSpace {
|
|
581
568
|
constructor() {
|
|
582
569
|
super(...arguments);
|
|
583
|
-
this.
|
|
570
|
+
this.segmentType = "index";
|
|
584
571
|
this.fieldList = new Set();
|
|
585
572
|
}
|
|
586
573
|
addReference(ref) {
|
|
587
|
-
if (ref.getField(this.
|
|
574
|
+
if (ref.getField(this.exprSpace).found) {
|
|
588
575
|
this.fieldList.add(ref.refString);
|
|
589
576
|
}
|
|
590
577
|
}
|
|
@@ -633,19 +620,12 @@ class DefSpace {
|
|
|
633
620
|
}
|
|
634
621
|
return this.realFS.lookup(symbol);
|
|
635
622
|
}
|
|
636
|
-
|
|
637
|
-
return this.realFS.
|
|
623
|
+
dialectObj() {
|
|
624
|
+
return this.realFS.dialectObj();
|
|
638
625
|
}
|
|
639
626
|
whenComplete(step) {
|
|
640
627
|
this.realFS.whenComplete(step);
|
|
641
628
|
}
|
|
642
629
|
}
|
|
643
630
|
exports.DefSpace = DefSpace;
|
|
644
|
-
function fsPair(inFS, outFS) {
|
|
645
|
-
return {
|
|
646
|
-
in: inFS,
|
|
647
|
-
out: outFS || inFS,
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
exports.fsPair = fsPair;
|
|
651
631
|
//# sourceMappingURL=field-space.js.map
|