@malloydata/malloy 0.0.119-dev240123183113 → 0.0.119-dev240124170348
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/index.d.ts +2 -2
- package/dist/index.js +1 -3
- package/dist/lang/ast/error-factory.js +3 -3
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +6 -4
- package/dist/lang/ast/expressions/expr-aggregate-function.js +24 -13
- package/dist/lang/ast/expressions/expr-count.js +1 -1
- package/dist/lang/ast/expressions/expr-func.js +4 -4
- package/dist/lang/ast/expressions/expr-id-reference.js +2 -2
- package/dist/lang/ast/field-space/dynamic-space.js +1 -1
- package/dist/lang/ast/field-space/index-field-space.d.ts +5 -3
- package/dist/lang/ast/field-space/index-field-space.js +85 -16
- package/dist/lang/ast/field-space/query-input-space.d.ts +3 -3
- package/dist/lang/ast/field-space/query-spaces.d.ts +15 -12
- package/dist/lang/ast/field-space/query-spaces.js +60 -57
- package/dist/lang/ast/field-space/reference-field.d.ts +0 -5
- package/dist/lang/ast/field-space/reference-field.js +16 -46
- package/dist/lang/ast/query-builders/index-builder.d.ts +2 -2
- package/dist/lang/ast/query-builders/partial-builder.js +28 -1
- package/dist/lang/ast/query-builders/project-builder.d.ts +8 -4
- package/dist/lang/ast/query-builders/project-builder.js +5 -6
- package/dist/lang/ast/query-builders/reduce-builder.d.ts +13 -8
- package/dist/lang/ast/query-builders/reduce-builder.js +12 -9
- package/dist/lang/ast/query-items/field-declaration.d.ts +1 -1
- package/dist/lang/ast/query-items/field-references.d.ts +5 -1
- package/dist/lang/ast/query-items/field-references.js +17 -1
- package/dist/lang/ast/query-properties/qop-desc.d.ts +2 -2
- package/dist/lang/ast/source-properties/joins.js +1 -1
- package/dist/lang/ast/types/field-space.d.ts +2 -2
- package/dist/lang/ast/types/query-builder.d.ts +2 -2
- package/dist/lang/ast/view-elements/qop-desc-view.d.ts +3 -3
- package/dist/lang/ast/view-elements/reference-view.d.ts +3 -3
- package/dist/lang/ast/view-elements/reference-view.js +1 -1
- package/dist/lang/ast/view-elements/refine-utils.js +20 -18
- package/dist/lang/ast/view-elements/view-arrow.d.ts +2 -2
- package/dist/lang/ast/view-elements/view-refine.d.ts +3 -3
- package/dist/lang/ast/view-elements/view.d.ts +4 -4
- package/dist/lang/field-utils.d.ts +3 -3
- package/dist/lang/field-utils.js +9 -8
- package/dist/lang/test/annotation.spec.js +26 -27
- package/dist/lang/test/expressions.spec.js +43 -40
- package/dist/lang/test/field-symbols.spec.js +4 -4
- package/dist/lang/test/locations.spec.js +13 -6
- package/dist/lang/test/query.spec.js +44 -56
- package/dist/lang/test/test-translator.d.ts +3 -2
- package/dist/lang/test/test-translator.js +30 -24
- package/dist/malloy.js +1 -1
- package/dist/model/malloy_query.d.ts +14 -36
- package/dist/model/malloy_query.js +145 -312
- package/dist/model/malloy_types.d.ts +18 -23
- package/dist/model/malloy_types.js +2 -15
- package/dist/tags.js +19 -4
- package/package.json +1 -1
|
@@ -14,9 +14,4 @@ export declare class ReferenceField extends SpaceField {
|
|
|
14
14
|
get referenceTo(): SpaceEntry | undefined;
|
|
15
15
|
getQueryFieldDef(fs: FieldSpace): QueryFieldDef | undefined;
|
|
16
16
|
typeDesc(): TypeDesc;
|
|
17
|
-
/**
|
|
18
|
-
* If the referenced field has any annotations, replace the reference
|
|
19
|
-
* with something which can hold an annotation
|
|
20
|
-
*/
|
|
21
|
-
maybeAnnotate(): QueryFieldDef;
|
|
22
17
|
}
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.ReferenceField = void 0;
|
|
26
|
-
const malloy_types_1 = require("../../../model/malloy_types");
|
|
27
26
|
const space_field_1 = require("../types/space-field");
|
|
28
27
|
class ReferenceField extends space_field_1.SpaceField {
|
|
29
28
|
constructor(fieldRef, inFS) {
|
|
@@ -45,7 +44,22 @@ class ReferenceField extends space_field_1.SpaceField {
|
|
|
45
44
|
if (check.error) {
|
|
46
45
|
this.fieldRef.log(check.error);
|
|
47
46
|
}
|
|
48
|
-
this.queryFieldDef =
|
|
47
|
+
this.queryFieldDef = {
|
|
48
|
+
type: 'fieldref',
|
|
49
|
+
path: this.fieldRef.list.map(f => f.name),
|
|
50
|
+
};
|
|
51
|
+
const refTo = this.referenceTo;
|
|
52
|
+
if (refTo instanceof space_field_1.SpaceField && refTo.haveFieldDef) {
|
|
53
|
+
const origFd = refTo.haveFieldDef;
|
|
54
|
+
const notes = this.fieldRef.note;
|
|
55
|
+
if (origFd.annotation || notes) {
|
|
56
|
+
const annotation = notes || {};
|
|
57
|
+
if (origFd.annotation) {
|
|
58
|
+
annotation.inherits = origFd.annotation;
|
|
59
|
+
}
|
|
60
|
+
this.queryFieldDef.annotation = annotation;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
64
|
return this.queryFieldDef;
|
|
51
65
|
}
|
|
@@ -59,50 +73,6 @@ class ReferenceField extends space_field_1.SpaceField {
|
|
|
59
73
|
}
|
|
60
74
|
return { dataType: 'error', expressionType: 'scalar', evalSpace: 'input' };
|
|
61
75
|
}
|
|
62
|
-
/**
|
|
63
|
-
* If the referenced field has any annotations, replace the reference
|
|
64
|
-
* with something which can hold an annotation
|
|
65
|
-
*/
|
|
66
|
-
maybeAnnotate() {
|
|
67
|
-
const path = this.fieldRef.refString;
|
|
68
|
-
const refTo = this.referenceTo;
|
|
69
|
-
if (refTo instanceof space_field_1.SpaceField &&
|
|
70
|
-
refTo.haveFieldDef &&
|
|
71
|
-
typeof refTo.haveFieldDef !== 'string') {
|
|
72
|
-
const origFd = refTo.haveFieldDef;
|
|
73
|
-
if ((0, malloy_types_1.isFilteredAliasedName)(origFd)) {
|
|
74
|
-
return origFd;
|
|
75
|
-
}
|
|
76
|
-
const notes = this.fieldRef.note;
|
|
77
|
-
if (origFd.annotation || notes) {
|
|
78
|
-
const annotation = notes || {};
|
|
79
|
-
if (origFd.annotation) {
|
|
80
|
-
annotation.inherits = origFd.annotation;
|
|
81
|
-
}
|
|
82
|
-
if (this.fieldRef.list.length > 1) {
|
|
83
|
-
// This is a field inside a join or a record, create an expression
|
|
84
|
-
// and annotate the expression.
|
|
85
|
-
if ((0, malloy_types_1.isAtomicFieldType)(origFd.type)) {
|
|
86
|
-
const newField = {
|
|
87
|
-
name: this.fieldRef.list[this.fieldRef.list.length - 1].refString,
|
|
88
|
-
type: origFd.type,
|
|
89
|
-
e: [{ type: 'field', path }],
|
|
90
|
-
annotation,
|
|
91
|
-
};
|
|
92
|
-
if ((0, malloy_types_1.hasExpression)(origFd)) {
|
|
93
|
-
newField.expressionType = origFd.expressionType;
|
|
94
|
-
}
|
|
95
|
-
return newField;
|
|
96
|
-
}
|
|
97
|
-
// maybe ok, this likely is some field which cannot be referenced
|
|
98
|
-
// in a query and will error, so there would be nothing to annotate
|
|
99
|
-
return path;
|
|
100
|
-
}
|
|
101
|
-
return { ...origFd, annotation };
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return path;
|
|
105
|
-
}
|
|
106
76
|
}
|
|
107
77
|
exports.ReferenceField = ReferenceField;
|
|
108
78
|
//# sourceMappingURL=reference-field.js.map
|
|
@@ -5,7 +5,7 @@ import { IndexFieldSpace } from '../field-space/index-field-space';
|
|
|
5
5
|
import { QueryProperty } from '../types/query-property';
|
|
6
6
|
import { QueryBuilder } from '../types/query-builder';
|
|
7
7
|
import { QueryInputSpace } from '../field-space/query-input-space';
|
|
8
|
-
import {
|
|
8
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
9
9
|
import { MalloyElement } from '../types/malloy-element';
|
|
10
10
|
export declare class IndexBuilder implements QueryBuilder {
|
|
11
11
|
filters: FilterExpression[];
|
|
@@ -15,7 +15,7 @@ export declare class IndexBuilder implements QueryBuilder {
|
|
|
15
15
|
resultFS: IndexFieldSpace;
|
|
16
16
|
inputFS: QueryInputSpace;
|
|
17
17
|
readonly type = "index";
|
|
18
|
-
constructor(inputFS: FieldSpace, refineThis: PipeSegment | undefined, isNestIn:
|
|
18
|
+
constructor(inputFS: FieldSpace, refineThis: PipeSegment | undefined, isNestIn: QueryOperationSpace | undefined, astEl: MalloyElement);
|
|
19
19
|
execute(qp: QueryProperty): void;
|
|
20
20
|
finalize(from: PipeSegment | undefined): PipeSegment;
|
|
21
21
|
}
|
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PartialBuilder = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2023 Google LLC
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
* a copy of this software and associated documentation files
|
|
9
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
10
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
11
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
12
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be
|
|
16
|
+
* included in all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
const model_1 = require("../../../model");
|
|
4
27
|
const reduce_builder_1 = require("./reduce-builder");
|
|
5
28
|
class PartialBuilder extends reduce_builder_1.ReduceBuilder {
|
|
6
29
|
finalize(fromSeg) {
|
|
7
30
|
const seg = super.finalize(fromSeg);
|
|
8
|
-
|
|
31
|
+
if ((0, model_1.isQuerySegment)(seg)) {
|
|
32
|
+
return { ...seg, type: 'partial' };
|
|
33
|
+
}
|
|
34
|
+
// TODO index, raw, ??
|
|
35
|
+
throw new Error(`Partial Builder cannot finalize from ${seg.type}`);
|
|
9
36
|
}
|
|
10
37
|
}
|
|
11
38
|
exports.PartialBuilder = PartialBuilder;
|
|
@@ -2,12 +2,16 @@ import { PipeSegment } from '../../../model/malloy_types';
|
|
|
2
2
|
import { FieldSpace } from '../types/field-space';
|
|
3
3
|
import { ProjectFieldSpace } from '../field-space/project-field-space';
|
|
4
4
|
import { QueryProperty } from '../types/query-property';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { QuerySegmentBuilder } from './reduce-builder';
|
|
6
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
7
7
|
import { MalloyElement } from '../types/malloy-element';
|
|
8
|
-
|
|
8
|
+
import { QueryBuilder } from '../types/query-builder';
|
|
9
|
+
import { QueryInputSpace } from '../field-space/query-input-space';
|
|
10
|
+
export declare class ProjectBuilder extends QuerySegmentBuilder implements QueryBuilder {
|
|
11
|
+
resultFS: ProjectFieldSpace;
|
|
12
|
+
inputFS: QueryInputSpace;
|
|
9
13
|
readonly type = "project";
|
|
10
|
-
|
|
14
|
+
constructor(baseFS: FieldSpace, refineThis: PipeSegment | undefined, isNestIn: QueryOperationSpace | undefined, astEl: MalloyElement);
|
|
11
15
|
execute(qp: QueryProperty): void;
|
|
12
16
|
finalize(fromSeg: PipeSegment | undefined): PipeSegment;
|
|
13
17
|
}
|
|
@@ -28,13 +28,12 @@ const error_factory_1 = require("../error-factory");
|
|
|
28
28
|
const group_by_1 = require("../query-properties/group-by");
|
|
29
29
|
const project_field_space_1 = require("../field-space/project-field-space");
|
|
30
30
|
const reduce_builder_1 = require("./reduce-builder");
|
|
31
|
-
class ProjectBuilder extends reduce_builder_1.
|
|
32
|
-
constructor() {
|
|
33
|
-
super(
|
|
31
|
+
class ProjectBuilder extends reduce_builder_1.QuerySegmentBuilder {
|
|
32
|
+
constructor(baseFS, refineThis, isNestIn, astEl) {
|
|
33
|
+
super();
|
|
34
34
|
this.type = 'project';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return new project_field_space_1.ProjectFieldSpace(fs, refineThis, isNestIn, astEl);
|
|
35
|
+
this.resultFS = new project_field_space_1.ProjectFieldSpace(baseFS, refineThis, isNestIn, astEl);
|
|
36
|
+
this.inputFS = this.resultFS.inputSpace();
|
|
38
37
|
}
|
|
39
38
|
execute(qp) {
|
|
40
39
|
if (qp.elementType === 'having' || qp instanceof group_by_1.GroupBy) {
|
|
@@ -4,19 +4,24 @@ import { Ordering } from '../query-properties/ordering';
|
|
|
4
4
|
import { Top } from '../query-properties/top';
|
|
5
5
|
import { QueryProperty } from '../types/query-property';
|
|
6
6
|
import { QueryBuilder } from '../types/query-builder';
|
|
7
|
-
import {
|
|
7
|
+
import { QueryOperationSpace, ReduceFieldSpace } from '../field-space/query-spaces';
|
|
8
8
|
import { QueryInputSpace } from '../field-space/query-input-space';
|
|
9
9
|
import { MalloyElement } from '../types/malloy-element';
|
|
10
|
-
export declare class
|
|
11
|
-
inputFS: QueryInputSpace;
|
|
12
|
-
resultFS: QuerySpace;
|
|
13
|
-
filters: FilterExpression[];
|
|
10
|
+
export declare abstract class QuerySegmentBuilder implements QueryBuilder {
|
|
14
11
|
order?: Top | Ordering;
|
|
15
12
|
limit?: number;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
abstract inputFS: QueryInputSpace;
|
|
14
|
+
abstract resultFS: QueryOperationSpace;
|
|
15
|
+
abstract readonly type: 'grouping' | 'project';
|
|
16
|
+
filters: FilterExpression[];
|
|
19
17
|
execute(qp: QueryProperty): void;
|
|
18
|
+
abstract finalize(fromSeg: PipeSegment | undefined): PipeSegment;
|
|
20
19
|
refineFrom(from: PipeSegment | undefined, to: QuerySegment): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class ReduceBuilder extends QuerySegmentBuilder implements QueryBuilder {
|
|
22
|
+
inputFS: QueryInputSpace;
|
|
23
|
+
resultFS: ReduceFieldSpace;
|
|
24
|
+
readonly type = "grouping";
|
|
25
|
+
constructor(baseFS: FieldSpace, refineThis: PipeSegment | undefined, isNestIn: QueryOperationSpace | undefined, astEl: MalloyElement);
|
|
21
26
|
finalize(fromSeg: PipeSegment | undefined): PipeSegment;
|
|
22
27
|
}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ReduceBuilder = void 0;
|
|
25
|
+
exports.ReduceBuilder = exports.QuerySegmentBuilder = void 0;
|
|
26
26
|
const malloy_types_1 = require("../../../model/malloy_types");
|
|
27
27
|
const error_factory_1 = require("../error-factory");
|
|
28
28
|
const filters_1 = require("../query-properties/filters");
|
|
@@ -31,15 +31,9 @@ const ordering_1 = require("../query-properties/ordering");
|
|
|
31
31
|
const top_1 = require("../query-properties/top");
|
|
32
32
|
const query_spaces_1 = require("../field-space/query-spaces");
|
|
33
33
|
const definition_list_1 = require("../types/definition-list");
|
|
34
|
-
class
|
|
35
|
-
constructor(
|
|
34
|
+
class QuerySegmentBuilder {
|
|
35
|
+
constructor() {
|
|
36
36
|
this.filters = [];
|
|
37
|
-
this.resultFS = this.getResultSpace(baseFS, refineThis, isNestIn, astEl);
|
|
38
|
-
this.inputFS = this.resultFS.inputSpace();
|
|
39
|
-
this.type = 'grouping';
|
|
40
|
-
}
|
|
41
|
-
getResultSpace(fs, refineThis, isNestIn, astEl) {
|
|
42
|
-
return new query_spaces_1.ReduceFieldSpace(fs, refineThis, isNestIn, astEl);
|
|
43
37
|
}
|
|
44
38
|
execute(qp) {
|
|
45
39
|
if (qp.queryExecute) {
|
|
@@ -120,6 +114,15 @@ class ReduceBuilder {
|
|
|
120
114
|
to.filterList = [...oldFilters, ...this.filters];
|
|
121
115
|
}
|
|
122
116
|
}
|
|
117
|
+
}
|
|
118
|
+
exports.QuerySegmentBuilder = QuerySegmentBuilder;
|
|
119
|
+
class ReduceBuilder extends QuerySegmentBuilder {
|
|
120
|
+
constructor(baseFS, refineThis, isNestIn, astEl) {
|
|
121
|
+
super();
|
|
122
|
+
this.type = 'grouping';
|
|
123
|
+
this.resultFS = new query_spaces_1.ReduceFieldSpace(baseFS, refineThis, isNestIn, astEl);
|
|
124
|
+
this.inputFS = this.resultFS.inputSpace();
|
|
125
|
+
}
|
|
123
126
|
finalize(fromSeg) {
|
|
124
127
|
let from;
|
|
125
128
|
if (fromSeg) {
|
|
@@ -69,7 +69,7 @@ export declare class DefSpace implements FieldSpace {
|
|
|
69
69
|
entries(): [string, SpaceEntry][];
|
|
70
70
|
dialectObj(): Dialect | undefined;
|
|
71
71
|
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
72
|
-
outputSpace(): import("../field-space/query-spaces").
|
|
72
|
+
outputSpace(): import("../field-space/query-spaces").QueryOperationSpace;
|
|
73
73
|
inputSpace(): FieldSpace;
|
|
74
74
|
}
|
|
75
75
|
export declare class FieldDefinitionValue extends SpaceField {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Annotation, FieldDef, TypeDesc } from '../../../model/malloy_types';
|
|
1
|
+
import { Annotation, FieldDef, RefToField, TypeDesc } from '../../../model/malloy_types';
|
|
2
2
|
import { DynamicSpace } from '../field-space/dynamic-space';
|
|
3
3
|
import { DefinitionList } from '../types/definition-list';
|
|
4
4
|
import { FieldName, FieldSpace } from '../types/field-space';
|
|
@@ -13,7 +13,9 @@ export declare abstract class FieldReference extends ListOf<FieldName> implement
|
|
|
13
13
|
extendNote: typeof extendNoteMethod;
|
|
14
14
|
constructor(names: FieldName[]);
|
|
15
15
|
makeEntry(fs: DynamicSpace): void;
|
|
16
|
+
get refToField(): RefToField;
|
|
16
17
|
get refString(): string;
|
|
18
|
+
get path(): string[];
|
|
17
19
|
get outputName(): string;
|
|
18
20
|
get sourceString(): string | undefined;
|
|
19
21
|
get nameString(): string;
|
|
@@ -35,6 +37,8 @@ export declare class CalculateFieldReference extends FieldReference {
|
|
|
35
37
|
export declare class IndexFieldReference extends FieldReference {
|
|
36
38
|
elementType: string;
|
|
37
39
|
typecheck(type: TypeDesc): void;
|
|
40
|
+
static indexOutputName(path: string[]): string;
|
|
41
|
+
get outputName(): string;
|
|
38
42
|
}
|
|
39
43
|
export declare class AggregateFieldReference extends FieldReference {
|
|
40
44
|
elementType: string;
|
|
@@ -45,8 +45,17 @@ class FieldReference extends malloy_element_1.ListOf {
|
|
|
45
45
|
fs.newEntry(refName, this, new reference_field_1.ReferenceField(this, fromFS));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
get refToField() {
|
|
49
|
+
return {
|
|
50
|
+
type: 'fieldref',
|
|
51
|
+
path: this.list.map(n => n.refString),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
48
54
|
get refString() {
|
|
49
|
-
return this.
|
|
55
|
+
return this.path.join('.');
|
|
56
|
+
}
|
|
57
|
+
get path() {
|
|
58
|
+
return this.list.map(n => n.refString);
|
|
50
59
|
}
|
|
51
60
|
get outputName() {
|
|
52
61
|
const last = this.list[this.list.length - 1];
|
|
@@ -114,6 +123,13 @@ class IndexFieldReference extends FieldReference {
|
|
|
114
123
|
typecheck(type) {
|
|
115
124
|
(0, typecheck_utils_1.typecheckIndex)(type, this);
|
|
116
125
|
}
|
|
126
|
+
// Index entries are expected to be unique on path
|
|
127
|
+
static indexOutputName(path) {
|
|
128
|
+
return path.map(pe => encodeURIComponent(pe)).join('/');
|
|
129
|
+
}
|
|
130
|
+
get outputName() {
|
|
131
|
+
return IndexFieldReference.indexOutputName(this.path);
|
|
132
|
+
}
|
|
117
133
|
}
|
|
118
134
|
exports.IndexFieldReference = IndexFieldReference;
|
|
119
135
|
class AggregateFieldReference extends FieldReference {
|
|
@@ -4,7 +4,7 @@ import { ListOf } from '../types/malloy-element';
|
|
|
4
4
|
import { OpDesc } from '../types/op-desc';
|
|
5
5
|
import { QueryProperty } from '../types/query-property';
|
|
6
6
|
import { QueryClass } from '../types/query-property-interface';
|
|
7
|
-
import {
|
|
7
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
8
8
|
export declare class QOpDesc extends ListOf<QueryProperty> {
|
|
9
9
|
elementType: string;
|
|
10
10
|
opClass: QueryClass | undefined;
|
|
@@ -12,5 +12,5 @@ export declare class QOpDesc extends ListOf<QueryProperty> {
|
|
|
12
12
|
protected computeType(): QueryClass | undefined;
|
|
13
13
|
refineFrom(existing: PipeSegment): void;
|
|
14
14
|
private getBuilder;
|
|
15
|
-
getOp(inputFS: FieldSpace, isNestIn:
|
|
15
|
+
getOp(inputFS: FieldSpace, isNestIn: QueryOperationSpace | undefined): OpDesc;
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dialect } from '../../../dialect/dialect';
|
|
2
2
|
import { StructDef } from '../../../model/malloy_types';
|
|
3
|
-
import {
|
|
3
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
4
4
|
import { LookupResult } from './lookup-result';
|
|
5
5
|
import { MalloyElement } from './malloy-element';
|
|
6
6
|
import { SpaceEntry } from './space-entry';
|
|
@@ -19,7 +19,7 @@ export interface FieldSpace {
|
|
|
19
19
|
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
20
20
|
}
|
|
21
21
|
export interface QueryFieldSpace extends FieldSpace {
|
|
22
|
-
outputSpace():
|
|
22
|
+
outputSpace(): QueryOperationSpace;
|
|
23
23
|
inputSpace(): FieldSpace;
|
|
24
24
|
}
|
|
25
25
|
export declare class FieldName extends MalloyElement {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PipeSegment } from '../../../model/malloy_types';
|
|
2
2
|
import { QueryProperty } from './query-property';
|
|
3
3
|
import { QueryInputSpace } from '../field-space/query-input-space';
|
|
4
|
-
import {
|
|
4
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
5
5
|
export interface QueryBuilder {
|
|
6
6
|
type: 'grouping' | 'index' | 'project';
|
|
7
7
|
inputFS: QueryInputSpace;
|
|
8
|
-
resultFS:
|
|
8
|
+
resultFS: QueryOperationSpace;
|
|
9
9
|
execute(qp: QueryProperty): void;
|
|
10
10
|
finalize(refineFrom: PipeSegment | undefined): PipeSegment;
|
|
11
11
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PipeSegment } from '../../../model/malloy_types';
|
|
2
|
-
import {
|
|
2
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
3
3
|
import { QOpDesc } from '../query-properties/qop-desc';
|
|
4
4
|
import { FieldSpace } from '../types/field-space';
|
|
5
5
|
import { PipelineComp } from '../types/pipeline-comp';
|
|
@@ -13,7 +13,7 @@ export declare class QOpDescView extends View {
|
|
|
13
13
|
readonly operation: QOpDesc;
|
|
14
14
|
elementType: string;
|
|
15
15
|
constructor(operation: QOpDesc);
|
|
16
|
-
pipelineComp(fs: FieldSpace, isNestIn?:
|
|
16
|
+
pipelineComp(fs: FieldSpace, isNestIn?: QueryOperationSpace): PipelineComp;
|
|
17
17
|
private getOp;
|
|
18
|
-
refine(inputFS: FieldSpace, _pipeline: PipeSegment[], isNestIn:
|
|
18
|
+
refine(inputFS: FieldSpace, _pipeline: PipeSegment[], isNestIn: QueryOperationSpace | undefined): PipeSegment[];
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PipeSegment } from '../../../model/malloy_types';
|
|
2
|
-
import {
|
|
2
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
3
3
|
import { ViewOrScalarFieldReference } from '../query-items/field-references';
|
|
4
4
|
import { FieldSpace } from '../types/field-space';
|
|
5
5
|
import { PipelineComp } from '../types/pipeline-comp';
|
|
@@ -16,12 +16,12 @@ export declare class ReferenceView extends View {
|
|
|
16
16
|
readonly reference: ViewOrScalarFieldReference;
|
|
17
17
|
elementType: string;
|
|
18
18
|
constructor(reference: ViewOrScalarFieldReference);
|
|
19
|
-
pipelineComp(fs: FieldSpace, _isNestIn:
|
|
19
|
+
pipelineComp(fs: FieldSpace, _isNestIn: QueryOperationSpace): PipelineComp;
|
|
20
20
|
_pipelineComp(fs: FieldSpace, { forRefinement }?: {
|
|
21
21
|
forRefinement: boolean;
|
|
22
22
|
}): PipelineComp & {
|
|
23
23
|
error?: boolean;
|
|
24
24
|
};
|
|
25
25
|
private getRefinementSegment;
|
|
26
|
-
refine(inputFS: FieldSpace, pipeline: PipeSegment[], _isNestIn:
|
|
26
|
+
refine(inputFS: FieldSpace, pipeline: PipeSegment[], _isNestIn: QueryOperationSpace | undefined): PipeSegment[];
|
|
27
27
|
}
|
|
@@ -81,7 +81,7 @@ class ReferenceView extends view_1.View {
|
|
|
81
81
|
}
|
|
82
82
|
const newSegment = {
|
|
83
83
|
type: 'reduce',
|
|
84
|
-
|
|
84
|
+
queryFields: [this.reference.refToField],
|
|
85
85
|
};
|
|
86
86
|
const { dialect, queryTimezone, structRelationship } = fs.structDef();
|
|
87
87
|
const name = this.reference.nameString;
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.refine = void 0;
|
|
26
26
|
const model_1 = require("../../../model");
|
|
27
|
+
const field_utils_1 = require("../../field-utils");
|
|
27
28
|
function refine(logTo, refineTo, refineFrom) {
|
|
28
29
|
var _a, _b;
|
|
29
30
|
// TODO we should probably support this
|
|
@@ -72,30 +73,31 @@ function refine(logTo, refineTo, refineFrom) {
|
|
|
72
73
|
to.filterList !== undefined || from.filterList !== undefined
|
|
73
74
|
? [...((_a = to.filterList) !== null && _a !== void 0 ? _a : []), ...((_b = from.filterList) !== null && _b !== void 0 ? _b : [])]
|
|
74
75
|
: undefined;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
if ((0, model_1.isQuerySegment)(from) && (0, model_1.isQuerySegment)(to)) {
|
|
77
|
+
const overlappingFields = [];
|
|
78
|
+
const nonOverlappingFields = [];
|
|
79
|
+
const existingNames = new Map(to.queryFields.map((f) => [
|
|
80
|
+
(0, field_utils_1.nameFromDef)(f),
|
|
81
|
+
f,
|
|
82
|
+
]));
|
|
83
|
+
for (const field of from.queryFields) {
|
|
84
|
+
if (existingNames.has((0, field_utils_1.nameFromDef)(field))) {
|
|
85
|
+
overlappingFields.push(field);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
nonOverlappingFields.push(field);
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
to.queryFields = [...to.queryFields, ...nonOverlappingFields];
|
|
92
|
+
if (overlappingFields.length > 0) {
|
|
93
|
+
logTo.log(`overlapping fields in refinement: ${overlappingFields.map(field_utils_1.nameFromDef)}`);
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
logTo.log(`overlapping fields in refinement: ${overlappingFields.map(extractName)}`);
|
|
96
|
+
else if (from.type === 'index' && to.type === 'index') {
|
|
97
|
+
to.indexFields = [...from.indexFields, ...to.indexFields];
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
return [to];
|
|
95
101
|
}
|
|
96
102
|
exports.refine = refine;
|
|
97
|
-
function extractName(f1) {
|
|
98
|
-
var _a;
|
|
99
|
-
return typeof f1 === 'string' ? f1 : (_a = f1.as) !== null && _a !== void 0 ? _a : f1.name;
|
|
100
|
-
}
|
|
101
103
|
//# sourceMappingURL=refine-utils.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PipeSegment } from '../../../model/malloy_types';
|
|
2
|
-
import {
|
|
2
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
3
3
|
import { FieldSpace } from '../types/field-space';
|
|
4
4
|
import { PipelineComp } from '../types/pipeline-comp';
|
|
5
5
|
import { View } from './view';
|
|
@@ -15,5 +15,5 @@ export declare class ViewArrow extends View {
|
|
|
15
15
|
elementType: string;
|
|
16
16
|
constructor(base: View, operation: View);
|
|
17
17
|
pipelineComp(fs: FieldSpace): PipelineComp;
|
|
18
|
-
refine(_inputFS: FieldSpace, _pipeline: PipeSegment[], _isNestIn:
|
|
18
|
+
refine(_inputFS: FieldSpace, _pipeline: PipeSegment[], _isNestIn: QueryOperationSpace | undefined): PipeSegment[];
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PipeSegment } from '../../../model';
|
|
2
|
-
import {
|
|
2
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
3
3
|
import { FieldSpace } from '../types/field-space';
|
|
4
4
|
import { PipelineComp } from '../types/pipeline-comp';
|
|
5
5
|
import { View } from './view';
|
|
@@ -14,6 +14,6 @@ export declare class ViewRefine extends View {
|
|
|
14
14
|
readonly refinement: View;
|
|
15
15
|
elementType: string;
|
|
16
16
|
constructor(base: View, refinement: View);
|
|
17
|
-
pipelineComp(fs: FieldSpace, isNestIn?:
|
|
18
|
-
refine(inputFS: FieldSpace, pipeline: PipeSegment[], isNestIn:
|
|
17
|
+
pipelineComp(fs: FieldSpace, isNestIn?: QueryOperationSpace): PipelineComp;
|
|
18
|
+
refine(inputFS: FieldSpace, pipeline: PipeSegment[], isNestIn: QueryOperationSpace | undefined): PipeSegment[];
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PipeSegment } from '../../../model/malloy_types';
|
|
2
|
-
import {
|
|
2
|
+
import { QueryOperationSpace } from '../field-space/query-spaces';
|
|
3
3
|
import { FieldSpace } from '../types/field-space';
|
|
4
4
|
import { MalloyElement } from '../types/malloy-element';
|
|
5
5
|
import { PipelineComp } from '../types/pipeline-comp';
|
|
@@ -19,7 +19,7 @@ import { PipelineComp } from '../types/pipeline-comp';
|
|
|
19
19
|
* e.g. after the arrow in `run: flights -> by_carrier`
|
|
20
20
|
*/
|
|
21
21
|
export declare abstract class View extends MalloyElement {
|
|
22
|
-
abstract pipelineComp(fs: FieldSpace, isNestIn?:
|
|
23
|
-
pipeline(fs: FieldSpace, isNestIn?:
|
|
24
|
-
abstract refine(inputFS: FieldSpace, pipeline: PipeSegment[], isNestIn:
|
|
22
|
+
abstract pipelineComp(fs: FieldSpace, isNestIn?: QueryOperationSpace): PipelineComp;
|
|
23
|
+
pipeline(fs: FieldSpace, isNestIn?: QueryOperationSpace): PipeSegment[];
|
|
24
|
+
abstract refine(inputFS: FieldSpace, pipeline: PipeSegment[], isNestIn: QueryOperationSpace | undefined): PipeSegment[];
|
|
25
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldDef, QueryFieldDef } from '../model/malloy_types';
|
|
2
|
-
type
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function mergeFields<T extends
|
|
2
|
+
type NamedFieldThing = FieldDef | QueryFieldDef;
|
|
3
|
+
export declare function nameFromDef(f1: NamedFieldThing): string;
|
|
4
|
+
export declare function mergeFields<T extends NamedFieldThing>(older: T[] | undefined, newer: T[]): T[];
|
|
5
5
|
export {};
|
package/dist/lang/field-utils.js
CHANGED
|
@@ -22,20 +22,21 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.mergeFields = exports.
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
exports.mergeFields = exports.nameFromDef = void 0;
|
|
26
|
+
function nameFromDef(f1) {
|
|
27
|
+
var _a;
|
|
28
|
+
if (f1.type === 'fieldref') {
|
|
29
|
+
return f1.path[f1.path.length - 1];
|
|
29
30
|
}
|
|
30
|
-
return
|
|
31
|
+
return (_a = f1.as) !== null && _a !== void 0 ? _a : f1.name;
|
|
31
32
|
}
|
|
32
|
-
exports.
|
|
33
|
+
exports.nameFromDef = nameFromDef;
|
|
33
34
|
function mergeFields(older, newer) {
|
|
34
35
|
if (older === undefined) {
|
|
35
36
|
return newer;
|
|
36
37
|
}
|
|
37
|
-
const redefined = new Set(newer.map(f =>
|
|
38
|
-
const merged = older.filter(f => !redefined.has(
|
|
38
|
+
const redefined = new Set(newer.map(f => nameFromDef(f)));
|
|
39
|
+
const merged = older.filter(f => !redefined.has(nameFromDef(f)));
|
|
39
40
|
merged.push(...newer);
|
|
40
41
|
return merged;
|
|
41
42
|
}
|