@malloydata/malloy-query-builder 0.0.240-dev250311202829 → 0.0.240-dev250311213218
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 +4 -4
- package/dist/query-ast.d.ts +53 -23
- package/dist/query-ast.js +178 -80
- package/dist/query-ast.js.map +1 -1
- package/dist/query-ast.spec.js +278 -72
- package/dist/query-ast.spec.js.map +1 -1
- package/flow/query-ast.d.ts +56 -19
- package/package.json +4 -4
- package/src/query-ast.spec.ts +278 -72
- package/src/query-ast.ts +222 -82
package/README.md
CHANGED
|
@@ -325,10 +325,10 @@ run: flights -> { aggregate: flight_count { where: carrier ~ f`WN, AA`} }
|
|
|
325
325
|
|
|
326
326
|
## Specify or remove source parameter value
|
|
327
327
|
|
|
328
|
-
{@link
|
|
328
|
+
{@link ASTReferenceQueryArrowSource.setParameter}
|
|
329
329
|
|
|
330
330
|
```ts
|
|
331
|
-
query.definition.
|
|
331
|
+
query.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource().parameters.setParameter("param", 1)
|
|
332
332
|
```
|
|
333
333
|
```
|
|
334
334
|
run: flights(param is 1) ->
|
|
@@ -336,10 +336,10 @@ run: flights(param is 1) ->
|
|
|
336
336
|
|
|
337
337
|
## List parameters of the source and whether they are required
|
|
338
338
|
|
|
339
|
-
{@link
|
|
339
|
+
{@link ASTReferenceQueryArrowSource.getSourceParameters}
|
|
340
340
|
|
|
341
341
|
```ts
|
|
342
|
-
query.definition.
|
|
342
|
+
query.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource().getSourceParameters();
|
|
343
343
|
```
|
|
344
344
|
|
|
345
345
|
## To a particular field in the query (including nests), add/edit/delete annotation
|
package/dist/query-ast.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ declare abstract class ASTNode<T> {
|
|
|
43
43
|
get as(): {
|
|
44
44
|
Query(): ASTQuery;
|
|
45
45
|
Reference(): ASTReference;
|
|
46
|
-
|
|
46
|
+
ReferenceQueryArrowSource(): ASTReferenceQueryArrowSource;
|
|
47
47
|
ParameterValueList(): ASTParameterValueList;
|
|
48
48
|
Where(): ASTWhere;
|
|
49
49
|
WhereList(): ASTWhereList;
|
|
@@ -72,7 +72,7 @@ declare abstract class ASTNode<T> {
|
|
|
72
72
|
get find(): {
|
|
73
73
|
Query(path: Path): ASTQuery;
|
|
74
74
|
Reference(path: Path): ASTReference;
|
|
75
|
-
|
|
75
|
+
ReferenceQueryArrowSource(path: Path): ASTReferenceQueryArrowSource;
|
|
76
76
|
ParameterValueList(path: Path): ASTParameterValueList;
|
|
77
77
|
Where(path: Path): ASTWhere;
|
|
78
78
|
WhereList(path: Path): ASTWhereList;
|
|
@@ -234,6 +234,7 @@ export declare class ASTQuery extends ASTObjectNode<Malloy.Query, {
|
|
|
234
234
|
removeTagProperty(path: Path, prefix?: string): void;
|
|
235
235
|
setViewToEmptySegment(): ASTSegmentViewDefinition;
|
|
236
236
|
isRunnable(): boolean;
|
|
237
|
+
isEmpty(): boolean;
|
|
237
238
|
/**
|
|
238
239
|
* Gets an {@link ASTSegmentViewDefinition} for the "default" place to add query
|
|
239
240
|
* operations, or creates one if it doesn't exist.
|
|
@@ -328,6 +329,7 @@ export declare class ASTQuery extends ASTObjectNode<Malloy.Query, {
|
|
|
328
329
|
* @param name The name of the view to set as the head of the query pipeline
|
|
329
330
|
*/
|
|
330
331
|
setView(name: string): ASTReferenceViewDefinition;
|
|
332
|
+
private _getInheritedAnnotations;
|
|
331
333
|
getInheritedAnnotations(): Malloy.Annotation[];
|
|
332
334
|
}
|
|
333
335
|
export type RawLiteralValue = number | string | {
|
|
@@ -391,20 +393,6 @@ export declare class ASTFieldReference extends ASTReference {
|
|
|
391
393
|
private getReferenceSchema;
|
|
392
394
|
getFieldInfo(): Malloy.FieldInfo;
|
|
393
395
|
}
|
|
394
|
-
export declare class ASTSourceReference extends ASTReference {
|
|
395
|
-
/**
|
|
396
|
-
* @internal
|
|
397
|
-
*/
|
|
398
|
-
get query(): ASTQuery;
|
|
399
|
-
/**
|
|
400
|
-
* Gets the `Malloy.SourceInfo` for the referenced source
|
|
401
|
-
*
|
|
402
|
-
* @returns The source information for the referenced source
|
|
403
|
-
*/
|
|
404
|
-
getSourceInfo(): Malloy.SourceInfo;
|
|
405
|
-
getSourceParameters(): Malloy.ParameterInfo[];
|
|
406
|
-
areRequiredParametersSet(): boolean;
|
|
407
|
-
}
|
|
408
396
|
export declare class ASTParameterValueList extends ASTListNode<Malloy.ParameterValue, ASTParameterValue> {
|
|
409
397
|
constructor(parameters: Malloy.ParameterValue[]);
|
|
410
398
|
get parameters(): ASTParameterValue[];
|
|
@@ -497,22 +485,27 @@ export interface IASTQueryDefinition extends IASTQueryOrViewDefinition {
|
|
|
497
485
|
reorderFields(names: string[]): void;
|
|
498
486
|
isRunnable(): boolean;
|
|
499
487
|
}
|
|
488
|
+
export type ASTQueryArrowSource = ASTReferenceQueryArrowSource | ASTRefinementQueryDefinition;
|
|
489
|
+
export declare const ASTQueryArrowSource: {
|
|
490
|
+
from(definition: Malloy.QueryArrowSource): ASTReferenceQueryArrowSource | ASTRefinementQueryDefinition;
|
|
491
|
+
};
|
|
500
492
|
export type ASTQueryDefinition = ASTReferenceQueryDefinition | ASTArrowQueryDefinition | ASTRefinementQueryDefinition;
|
|
501
493
|
export declare const ASTQueryDefinition: {
|
|
502
|
-
from
|
|
494
|
+
from(definition: Malloy.QueryDefinition): ASTArrowQueryDefinition | ASTReferenceQueryDefinition | ASTRefinementQueryDefinition;
|
|
503
495
|
};
|
|
504
496
|
export declare class ASTArrowQueryDefinition extends ASTObjectNode<Malloy.QueryDefinitionWithArrow, {
|
|
505
497
|
kind: 'arrow';
|
|
506
|
-
|
|
498
|
+
source: ASTQueryArrowSource;
|
|
507
499
|
view: ASTViewDefinition;
|
|
508
500
|
}> implements IASTQueryDefinition {
|
|
509
501
|
node: Malloy.QueryDefinitionWithArrow;
|
|
510
502
|
constructor(node: Malloy.QueryDefinitionWithArrow);
|
|
511
503
|
get view(): ASTViewDefinition;
|
|
512
504
|
set view(view: ASTViewDefinition);
|
|
513
|
-
get
|
|
505
|
+
get source(): ASTQueryArrowSource;
|
|
506
|
+
set source(source: ASTQueryArrowSource);
|
|
514
507
|
getOrAddDefaultSegment(): ASTSegmentViewDefinition;
|
|
515
|
-
getSourceInfo():
|
|
508
|
+
getSourceInfo(): any;
|
|
516
509
|
getOutputSchema(): Malloy.Schema;
|
|
517
510
|
isRunnable(): boolean;
|
|
518
511
|
/**
|
|
@@ -531,12 +524,12 @@ export declare class ASTArrowQueryDefinition extends ASTObjectNode<Malloy.QueryD
|
|
|
531
524
|
}
|
|
532
525
|
export declare class ASTRefinementQueryDefinition extends ASTObjectNode<Malloy.QueryDefinitionWithRefinement, {
|
|
533
526
|
kind: 'refinement';
|
|
534
|
-
|
|
527
|
+
base: ASTQueryDefinition;
|
|
535
528
|
refinement: ASTViewDefinition;
|
|
536
529
|
}> implements IASTQueryDefinition {
|
|
537
530
|
node: Malloy.QueryDefinitionWithRefinement;
|
|
538
531
|
constructor(node: Malloy.QueryDefinitionWithRefinement);
|
|
539
|
-
get
|
|
532
|
+
get base(): ASTQueryDefinition;
|
|
540
533
|
get refinement(): ASTViewDefinition;
|
|
541
534
|
set refinement(refinement: ASTViewDefinition);
|
|
542
535
|
isRunnable(): boolean;
|
|
@@ -545,7 +538,7 @@ export declare class ASTRefinementQueryDefinition extends ASTObjectNode<Malloy.Q
|
|
|
545
538
|
*/
|
|
546
539
|
get query(): ASTQuery;
|
|
547
540
|
getOrAddDefaultSegment(): ASTSegmentViewDefinition;
|
|
548
|
-
getOutputSchema():
|
|
541
|
+
getOutputSchema(): any;
|
|
549
542
|
/**
|
|
550
543
|
* @internal
|
|
551
544
|
*/
|
|
@@ -555,6 +548,7 @@ export declare class ASTRefinementQueryDefinition extends ASTObjectNode<Malloy.Q
|
|
|
555
548
|
*/
|
|
556
549
|
propagateDown(f: PropagationFunction): void;
|
|
557
550
|
reorderFields(names: string[]): void;
|
|
551
|
+
getSourceInfo(): any;
|
|
558
552
|
}
|
|
559
553
|
export declare class ASTReferenceQueryDefinition extends ASTObjectNode<Malloy.QueryDefinitionWithQueryReference, {
|
|
560
554
|
kind: 'query_reference';
|
|
@@ -583,6 +577,42 @@ export declare class ASTReferenceQueryDefinition extends ASTObjectNode<Malloy.Qu
|
|
|
583
577
|
getOrAddParameters(): any;
|
|
584
578
|
setParameter(name: string, value: RawLiteralValue): void;
|
|
585
579
|
tryGetParameter(name: string): ASTParameterValue | undefined;
|
|
580
|
+
getOutputSchema(): Malloy.Schema;
|
|
581
|
+
getSourceInfo(): Malloy.ModelEntryValue;
|
|
582
|
+
}
|
|
583
|
+
export declare class ASTReferenceQueryArrowSource extends ASTObjectNode<Malloy.QueryArrowSourceWithSourceReference, {
|
|
584
|
+
kind: 'source_reference';
|
|
585
|
+
name: string;
|
|
586
|
+
path?: string[];
|
|
587
|
+
parameters?: ASTParameterValueList;
|
|
588
|
+
}> implements IASTReference {
|
|
589
|
+
node: Malloy.QueryArrowSourceWithSourceReference;
|
|
590
|
+
constructor(node: Malloy.QueryArrowSourceWithSourceReference);
|
|
591
|
+
isRunnable(): boolean;
|
|
592
|
+
get name(): string;
|
|
593
|
+
get arrow(): ASTArrowQueryDefinition;
|
|
594
|
+
get parameters(): ASTParameterValueList | undefined;
|
|
595
|
+
set parameters(parameters: ASTParameterValueList | undefined);
|
|
596
|
+
get path(): string[] | undefined;
|
|
597
|
+
getSourceInfo(): Malloy.ModelEntryValue;
|
|
598
|
+
getOrAddDefaultSegment(): ASTSegmentViewDefinition;
|
|
599
|
+
/**
|
|
600
|
+
* @internal
|
|
601
|
+
*/
|
|
602
|
+
propagateUp(_f: PropagationFunction): void;
|
|
603
|
+
/**
|
|
604
|
+
* @internal
|
|
605
|
+
*/
|
|
606
|
+
propagateDown(_f: PropagationFunction): void;
|
|
607
|
+
getOrAddParameters(): any;
|
|
608
|
+
setParameter(name: string, value: RawLiteralValue): void;
|
|
609
|
+
tryGetParameter(name: string): ASTParameterValue | undefined;
|
|
610
|
+
/**
|
|
611
|
+
* @internal
|
|
612
|
+
*/
|
|
613
|
+
get query(): ASTQuery;
|
|
614
|
+
getSourceParameters(): Malloy.ParameterInfo[];
|
|
615
|
+
areRequiredParametersSet(): boolean;
|
|
586
616
|
}
|
|
587
617
|
export interface IASTViewDefinition extends IASTQueryOrViewDefinition {
|
|
588
618
|
isRunnable(): boolean;
|
package/dist/query-ast.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ASTAnnotation = exports.ASTAnnotationList = exports.ASTLimitViewOperation = exports.ASTView = exports.ASTFilterWithFilterString = exports.ASTFilter = exports.ASTWhereViewOperation = exports.ASTNestViewOperation = exports.ASTFilteredFieldExpression = exports.ASTWhereList = exports.ASTWhere = exports.ASTTimeTruncationExpression = exports.ASTReferenceExpression = exports.ASTExpression = exports.ASTField = exports.ASTAggregateViewOperation = exports.ASTGroupByViewOperation = exports.ASTOrderByViewOperation = exports.ASTViewOperation = exports.ASTViewOperationList = exports.ASTSegmentViewDefinition = exports.ASTRefinementViewDefinition = exports.ASTArrowViewDefinition = exports.ASTReferenceViewDefinition = exports.ASTReferenceQueryDefinition = exports.ASTRefinementQueryDefinition = exports.ASTArrowQueryDefinition = exports.ASTQueryDefinition = exports.ASTUnimplemented = exports.ASTTimestampLiteralValue = exports.ASTDateLiteralValue = exports.ASTBooleanLiteralValue = exports.ASTNumberLiteralValue = exports.ASTNullLiteralValue = exports.ASTStringLiteralValue = exports.LiteralValueAST = exports.ASTParameterValue = exports.ASTParameterValueList = exports.
|
|
26
|
+
exports.ASTAnnotation = exports.ASTAnnotationList = exports.ASTLimitViewOperation = exports.ASTView = exports.ASTFilterWithFilterString = exports.ASTFilter = exports.ASTWhereViewOperation = exports.ASTNestViewOperation = exports.ASTFilteredFieldExpression = exports.ASTWhereList = exports.ASTWhere = exports.ASTTimeTruncationExpression = exports.ASTReferenceExpression = exports.ASTExpression = exports.ASTField = exports.ASTAggregateViewOperation = exports.ASTGroupByViewOperation = exports.ASTOrderByViewOperation = exports.ASTViewOperation = exports.ASTViewOperationList = exports.ASTSegmentViewDefinition = exports.ASTRefinementViewDefinition = exports.ASTArrowViewDefinition = exports.ASTReferenceViewDefinition = exports.ASTReferenceQueryArrowSource = exports.ASTReferenceQueryDefinition = exports.ASTRefinementQueryDefinition = exports.ASTArrowQueryDefinition = exports.ASTQueryDefinition = exports.ASTQueryArrowSource = exports.ASTUnimplemented = exports.ASTTimestampLiteralValue = exports.ASTDateLiteralValue = exports.ASTBooleanLiteralValue = exports.ASTNumberLiteralValue = exports.ASTNullLiteralValue = exports.ASTStringLiteralValue = exports.LiteralValueAST = exports.ASTParameterValue = exports.ASTParameterValueList = exports.ASTFieldReference = exports.ASTReference = exports.ASTQuery = void 0;
|
|
27
27
|
/*
|
|
28
28
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
29
|
*
|
|
@@ -63,10 +63,10 @@ class ASTNode {
|
|
|
63
63
|
return node;
|
|
64
64
|
throw new Error('Not an ASTReference');
|
|
65
65
|
},
|
|
66
|
-
|
|
67
|
-
if (node instanceof
|
|
66
|
+
ReferenceQueryArrowSource() {
|
|
67
|
+
if (node instanceof ASTReferenceQueryArrowSource)
|
|
68
68
|
return node;
|
|
69
|
-
throw new Error('Not an
|
|
69
|
+
throw new Error('Not an ASTReferenceQueryArrowSource');
|
|
70
70
|
},
|
|
71
71
|
ParameterValueList() {
|
|
72
72
|
if (node instanceof ASTParameterValueList)
|
|
@@ -200,8 +200,8 @@ class ASTNode {
|
|
|
200
200
|
Reference(path) {
|
|
201
201
|
return node.findAny(path).as.Reference();
|
|
202
202
|
},
|
|
203
|
-
|
|
204
|
-
return node.findAny(path).as.
|
|
203
|
+
ReferenceQueryArrowSource(path) {
|
|
204
|
+
return node.findAny(path).as.ReferenceQueryArrowSource();
|
|
205
205
|
},
|
|
206
206
|
ParameterValueList(path) {
|
|
207
207
|
return node.findAny(path).as.ParameterValueList();
|
|
@@ -519,8 +519,9 @@ class ASTQuery extends ASTObjectNode {
|
|
|
519
519
|
}
|
|
520
520
|
if (options.query) {
|
|
521
521
|
const definition = options.query.definition;
|
|
522
|
-
if (definition.kind === 'arrow'
|
|
523
|
-
|
|
522
|
+
if (definition.kind === 'arrow' &&
|
|
523
|
+
definition.source.kind === 'source_reference') {
|
|
524
|
+
const name = definition.source.name;
|
|
524
525
|
chosenSource = options.model.entries.find(e => e.name === name);
|
|
525
526
|
if (chosenSource === undefined) {
|
|
526
527
|
throw new Error(`Model does not contain source or query named ${name}`);
|
|
@@ -538,7 +539,8 @@ class ASTQuery extends ASTObjectNode {
|
|
|
538
539
|
const query = (_a = options.query) !== null && _a !== void 0 ? _a : {
|
|
539
540
|
definition: {
|
|
540
541
|
kind: 'arrow',
|
|
541
|
-
|
|
542
|
+
source: {
|
|
543
|
+
kind: 'source_reference',
|
|
542
544
|
name: source.name,
|
|
543
545
|
},
|
|
544
546
|
view: {
|
|
@@ -607,7 +609,7 @@ class ASTQuery extends ASTObjectNode {
|
|
|
607
609
|
}
|
|
608
610
|
this.definition = new ASTArrowQueryDefinition({
|
|
609
611
|
kind: 'arrow',
|
|
610
|
-
|
|
612
|
+
source: this.definition.source.build(),
|
|
611
613
|
view: {
|
|
612
614
|
kind: 'segment',
|
|
613
615
|
operations: [],
|
|
@@ -618,6 +620,11 @@ class ASTQuery extends ASTObjectNode {
|
|
|
618
620
|
isRunnable() {
|
|
619
621
|
return this.definition.isRunnable();
|
|
620
622
|
}
|
|
623
|
+
isEmpty() {
|
|
624
|
+
return (this.definition instanceof ASTArrowQueryDefinition &&
|
|
625
|
+
this.definition.view instanceof ASTSegmentViewDefinition &&
|
|
626
|
+
this.definition.view.operations.length === 0);
|
|
627
|
+
}
|
|
621
628
|
/**
|
|
622
629
|
* Gets an {@link ASTSegmentViewDefinition} for the "default" place to add query
|
|
623
630
|
* operations, or creates one if it doesn't exist.
|
|
@@ -660,7 +667,8 @@ class ASTQuery extends ASTObjectNode {
|
|
|
660
667
|
*/
|
|
661
668
|
setSource(name) {
|
|
662
669
|
if (this.definition instanceof ASTArrowQueryDefinition) {
|
|
663
|
-
if (this.definition.
|
|
670
|
+
if (this.definition.source instanceof ASTReferenceQueryArrowSource &&
|
|
671
|
+
this.definition.source.name === name) {
|
|
664
672
|
return;
|
|
665
673
|
}
|
|
666
674
|
}
|
|
@@ -670,7 +678,10 @@ class ASTQuery extends ASTObjectNode {
|
|
|
670
678
|
}
|
|
671
679
|
this.definition = new ASTArrowQueryDefinition({
|
|
672
680
|
kind: 'arrow',
|
|
673
|
-
|
|
681
|
+
source: {
|
|
682
|
+
kind: 'source_reference',
|
|
683
|
+
name,
|
|
684
|
+
},
|
|
674
685
|
view: this.definition instanceof ASTArrowQueryDefinition
|
|
675
686
|
? this.definition.view.build()
|
|
676
687
|
: {
|
|
@@ -761,7 +772,7 @@ class ASTQuery extends ASTObjectNode {
|
|
|
761
772
|
}
|
|
762
773
|
this.definition = new ASTArrowQueryDefinition({
|
|
763
774
|
kind: 'arrow',
|
|
764
|
-
|
|
775
|
+
source: this.definition.source.build(),
|
|
765
776
|
view: {
|
|
766
777
|
kind: 'view_reference',
|
|
767
778
|
name,
|
|
@@ -769,21 +780,23 @@ class ASTQuery extends ASTObjectNode {
|
|
|
769
780
|
});
|
|
770
781
|
return this.definition.view.as.ReferenceViewDefinition();
|
|
771
782
|
}
|
|
772
|
-
|
|
773
|
-
var _a
|
|
774
|
-
if (
|
|
775
|
-
const query = this.getQueryInfo(
|
|
783
|
+
_getInheritedAnnotations(definition) {
|
|
784
|
+
var _a;
|
|
785
|
+
if (definition instanceof ASTReferenceQueryDefinition) {
|
|
786
|
+
const query = this.getQueryInfo(definition.name);
|
|
776
787
|
return (_a = query.annotations) !== null && _a !== void 0 ? _a : [];
|
|
777
788
|
}
|
|
778
|
-
else if (
|
|
779
|
-
|
|
780
|
-
return (_b = query.annotations) !== null && _b !== void 0 ? _b : [];
|
|
789
|
+
else if (definition instanceof ASTRefinementQueryDefinition) {
|
|
790
|
+
return this._getInheritedAnnotations(definition.base);
|
|
781
791
|
}
|
|
782
|
-
else if (
|
|
783
|
-
return
|
|
792
|
+
else if (definition instanceof ASTArrowQueryDefinition) {
|
|
793
|
+
return definition.view.getInheritedAnnotations();
|
|
784
794
|
}
|
|
785
795
|
return [];
|
|
786
796
|
}
|
|
797
|
+
getInheritedAnnotations() {
|
|
798
|
+
return this._getInheritedAnnotations(this.definition);
|
|
799
|
+
}
|
|
787
800
|
}
|
|
788
801
|
exports.ASTQuery = ASTQuery;
|
|
789
802
|
class ASTReference extends ASTObjectNode {
|
|
@@ -888,43 +901,6 @@ class ASTFieldReference extends ASTReference {
|
|
|
888
901
|
}
|
|
889
902
|
}
|
|
890
903
|
exports.ASTFieldReference = ASTFieldReference;
|
|
891
|
-
class ASTSourceReference extends ASTReference {
|
|
892
|
-
/**
|
|
893
|
-
* @internal
|
|
894
|
-
*/
|
|
895
|
-
get query() {
|
|
896
|
-
return this.parent.parent.as.Query();
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* Gets the `Malloy.SourceInfo` for the referenced source
|
|
900
|
-
*
|
|
901
|
-
* @returns The source information for the referenced source
|
|
902
|
-
*/
|
|
903
|
-
getSourceInfo() {
|
|
904
|
-
const info = this.query.model.entries.find(e => e.name === this.name);
|
|
905
|
-
if (info === undefined) {
|
|
906
|
-
throw new Error('No source info found');
|
|
907
|
-
}
|
|
908
|
-
return info;
|
|
909
|
-
}
|
|
910
|
-
getSourceParameters() {
|
|
911
|
-
var _a;
|
|
912
|
-
return (_a = this.getSourceInfo().parameters) !== null && _a !== void 0 ? _a : [];
|
|
913
|
-
}
|
|
914
|
-
areRequiredParametersSet() {
|
|
915
|
-
const sourceParameters = this.getSourceParameters();
|
|
916
|
-
for (const parameterInfo of sourceParameters) {
|
|
917
|
-
if (parameterInfo.default_value !== undefined)
|
|
918
|
-
continue;
|
|
919
|
-
const parameter = this.tryGetParameter(parameterInfo.name);
|
|
920
|
-
if (parameter === undefined) {
|
|
921
|
-
return false;
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
return true;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
exports.ASTSourceReference = ASTSourceReference;
|
|
928
904
|
class ASTParameterValueList extends ASTListNode {
|
|
929
905
|
constructor(parameters) {
|
|
930
906
|
super(parameters, parameters.map(p => new ASTParameterValue(p)));
|
|
@@ -1097,8 +1073,18 @@ class ASTUnimplemented extends ASTNode {
|
|
|
1097
1073
|
}
|
|
1098
1074
|
}
|
|
1099
1075
|
exports.ASTUnimplemented = ASTUnimplemented;
|
|
1076
|
+
exports.ASTQueryArrowSource = {
|
|
1077
|
+
from(definition) {
|
|
1078
|
+
switch (definition.kind) {
|
|
1079
|
+
case 'refinement':
|
|
1080
|
+
return new ASTRefinementQueryDefinition(definition);
|
|
1081
|
+
case 'source_reference':
|
|
1082
|
+
return new ASTReferenceQueryArrowSource(definition);
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
};
|
|
1100
1086
|
exports.ASTQueryDefinition = {
|
|
1101
|
-
from
|
|
1087
|
+
from(definition) {
|
|
1102
1088
|
switch (definition.kind) {
|
|
1103
1089
|
case 'arrow':
|
|
1104
1090
|
return new ASTArrowQueryDefinition(definition);
|
|
@@ -1113,7 +1099,7 @@ class ASTArrowQueryDefinition extends ASTObjectNode {
|
|
|
1113
1099
|
constructor(node) {
|
|
1114
1100
|
super(node, {
|
|
1115
1101
|
kind: 'arrow',
|
|
1116
|
-
|
|
1102
|
+
source: exports.ASTQueryArrowSource.from(node.source),
|
|
1117
1103
|
view: ASTViewDefinition.from(node.view),
|
|
1118
1104
|
});
|
|
1119
1105
|
this.node = node;
|
|
@@ -1126,20 +1112,24 @@ class ASTArrowQueryDefinition extends ASTObjectNode {
|
|
|
1126
1112
|
this.children.view = view;
|
|
1127
1113
|
view.parent = this;
|
|
1128
1114
|
}
|
|
1129
|
-
get
|
|
1130
|
-
return this.children.
|
|
1115
|
+
get source() {
|
|
1116
|
+
return this.children.source;
|
|
1117
|
+
}
|
|
1118
|
+
set source(source) {
|
|
1119
|
+
this.edit();
|
|
1120
|
+
this.children.source = source;
|
|
1131
1121
|
}
|
|
1132
1122
|
getOrAddDefaultSegment() {
|
|
1133
1123
|
return this.view.getOrAddDefaultSegment();
|
|
1134
1124
|
}
|
|
1135
1125
|
getSourceInfo() {
|
|
1136
|
-
return this.
|
|
1126
|
+
return this.source.getSourceInfo();
|
|
1137
1127
|
}
|
|
1138
1128
|
getOutputSchema() {
|
|
1139
1129
|
return this.view.getRefinementSchema();
|
|
1140
1130
|
}
|
|
1141
1131
|
isRunnable() {
|
|
1142
|
-
return
|
|
1132
|
+
return this.view.isRunnable() && this.source.isRunnable();
|
|
1143
1133
|
}
|
|
1144
1134
|
/**
|
|
1145
1135
|
* @internal
|
|
@@ -1174,13 +1164,13 @@ class ASTRefinementQueryDefinition extends ASTObjectNode {
|
|
|
1174
1164
|
constructor(node) {
|
|
1175
1165
|
super(node, {
|
|
1176
1166
|
kind: 'refinement',
|
|
1177
|
-
|
|
1167
|
+
base: exports.ASTQueryDefinition.from(node.base),
|
|
1178
1168
|
refinement: ASTViewDefinition.from(node.refinement),
|
|
1179
1169
|
});
|
|
1180
1170
|
this.node = node;
|
|
1181
1171
|
}
|
|
1182
|
-
get
|
|
1183
|
-
return this.children.
|
|
1172
|
+
get base() {
|
|
1173
|
+
return this.children.base;
|
|
1184
1174
|
}
|
|
1185
1175
|
get refinement() {
|
|
1186
1176
|
return this.children.refinement;
|
|
@@ -1203,12 +1193,7 @@ class ASTRefinementQueryDefinition extends ASTObjectNode {
|
|
|
1203
1193
|
return this.refinement.getOrAddDefaultSegment();
|
|
1204
1194
|
}
|
|
1205
1195
|
getOutputSchema() {
|
|
1206
|
-
const
|
|
1207
|
-
const query = model.entries.find(e => e.name === this.queryReference.name);
|
|
1208
|
-
if (query === undefined) {
|
|
1209
|
-
throw new Error(`Query not found with name ${this.queryReference.name}`);
|
|
1210
|
-
}
|
|
1211
|
-
const base = query.schema;
|
|
1196
|
+
const base = this.base.getOutputSchema();
|
|
1212
1197
|
const refinement = this.refinement.getRefinementSchema();
|
|
1213
1198
|
return ASTQuery.schemaMerge(base, refinement);
|
|
1214
1199
|
}
|
|
@@ -1228,6 +1213,9 @@ class ASTRefinementQueryDefinition extends ASTObjectNode {
|
|
|
1228
1213
|
reorderFields(names) {
|
|
1229
1214
|
this.query.getOrAddAnnotations().setTagProperty(['field_order'], names);
|
|
1230
1215
|
}
|
|
1216
|
+
getSourceInfo() {
|
|
1217
|
+
return this.base.getSourceInfo();
|
|
1218
|
+
}
|
|
1231
1219
|
}
|
|
1232
1220
|
exports.ASTRefinementQueryDefinition = ASTRefinementQueryDefinition;
|
|
1233
1221
|
class ASTReferenceQueryDefinition extends ASTObjectNode {
|
|
@@ -1260,14 +1248,9 @@ class ASTReferenceQueryDefinition extends ASTObjectNode {
|
|
|
1260
1248
|
return this.children.path;
|
|
1261
1249
|
}
|
|
1262
1250
|
getOrAddDefaultSegment() {
|
|
1263
|
-
var _a;
|
|
1264
1251
|
const newQuery = new ASTRefinementQueryDefinition({
|
|
1265
1252
|
kind: 'refinement',
|
|
1266
|
-
|
|
1267
|
-
name: this.name,
|
|
1268
|
-
path: this.path,
|
|
1269
|
-
parameters: (_a = this.parameters) === null || _a === void 0 ? void 0 : _a.build(),
|
|
1270
|
-
},
|
|
1253
|
+
base: this.build(),
|
|
1271
1254
|
refinement: {
|
|
1272
1255
|
kind: 'segment',
|
|
1273
1256
|
operations: [],
|
|
@@ -1300,8 +1283,123 @@ class ASTReferenceQueryDefinition extends ASTObjectNode {
|
|
|
1300
1283
|
tryGetParameter(name) {
|
|
1301
1284
|
return ASTReference.tryGetParameter(this, name);
|
|
1302
1285
|
}
|
|
1286
|
+
getOutputSchema() {
|
|
1287
|
+
return this.getSourceInfo().schema;
|
|
1288
|
+
}
|
|
1289
|
+
getSourceInfo() {
|
|
1290
|
+
const model = this.query.model;
|
|
1291
|
+
const query = model.entries.find(e => e.name === this.name);
|
|
1292
|
+
if (query === undefined) {
|
|
1293
|
+
throw new Error(`Query not found with name ${this.name}`);
|
|
1294
|
+
}
|
|
1295
|
+
return query;
|
|
1296
|
+
}
|
|
1303
1297
|
}
|
|
1304
1298
|
exports.ASTReferenceQueryDefinition = ASTReferenceQueryDefinition;
|
|
1299
|
+
class ASTReferenceQueryArrowSource extends ASTObjectNode {
|
|
1300
|
+
constructor(node) {
|
|
1301
|
+
super(node, {
|
|
1302
|
+
kind: 'source_reference',
|
|
1303
|
+
name: node.name,
|
|
1304
|
+
path: node.path,
|
|
1305
|
+
parameters: node.parameters && new ASTParameterValueList(node.parameters),
|
|
1306
|
+
});
|
|
1307
|
+
this.node = node;
|
|
1308
|
+
}
|
|
1309
|
+
isRunnable() {
|
|
1310
|
+
return this.areRequiredParametersSet();
|
|
1311
|
+
}
|
|
1312
|
+
get name() {
|
|
1313
|
+
return this.children.name;
|
|
1314
|
+
}
|
|
1315
|
+
get arrow() {
|
|
1316
|
+
return this.parent.as.ArrowQueryDefinition();
|
|
1317
|
+
}
|
|
1318
|
+
get parameters() {
|
|
1319
|
+
return this.children.parameters;
|
|
1320
|
+
}
|
|
1321
|
+
set parameters(parameters) {
|
|
1322
|
+
this.edit();
|
|
1323
|
+
this.children.parameters = parameters;
|
|
1324
|
+
}
|
|
1325
|
+
get path() {
|
|
1326
|
+
return this.children.path;
|
|
1327
|
+
}
|
|
1328
|
+
getSourceInfo() {
|
|
1329
|
+
const entry = this.arrow.query.model.entries.find(entry => entry.name === this.name);
|
|
1330
|
+
if (entry === undefined) {
|
|
1331
|
+
throw new Error(`No query or source named ${this.name}`);
|
|
1332
|
+
}
|
|
1333
|
+
return entry;
|
|
1334
|
+
}
|
|
1335
|
+
getOrAddDefaultSegment() {
|
|
1336
|
+
const entry = this.getSourceInfo();
|
|
1337
|
+
if (entry.kind !== 'query') {
|
|
1338
|
+
throw new Error(`Cannot refine source ${this.name}`);
|
|
1339
|
+
}
|
|
1340
|
+
const newQuery = new ASTRefinementQueryDefinition({
|
|
1341
|
+
kind: 'refinement',
|
|
1342
|
+
base: {
|
|
1343
|
+
...this.build(),
|
|
1344
|
+
kind: 'query_reference',
|
|
1345
|
+
},
|
|
1346
|
+
refinement: {
|
|
1347
|
+
kind: 'segment',
|
|
1348
|
+
operations: [],
|
|
1349
|
+
},
|
|
1350
|
+
});
|
|
1351
|
+
this.arrow.source = newQuery;
|
|
1352
|
+
return newQuery.refinement.as.SegmentViewDefinition();
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* @internal
|
|
1356
|
+
*/
|
|
1357
|
+
propagateUp(_f) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* @internal
|
|
1362
|
+
*/
|
|
1363
|
+
propagateDown(_f) {
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
getOrAddParameters() {
|
|
1367
|
+
return ASTReference.getOrAddParameters(this);
|
|
1368
|
+
}
|
|
1369
|
+
setParameter(name, value) {
|
|
1370
|
+
return ASTReference.setParameter(this, name, value);
|
|
1371
|
+
}
|
|
1372
|
+
tryGetParameter(name) {
|
|
1373
|
+
return ASTReference.tryGetParameter(this, name);
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* @internal
|
|
1377
|
+
*/
|
|
1378
|
+
get query() {
|
|
1379
|
+
return this.parent.parent.as.Query();
|
|
1380
|
+
}
|
|
1381
|
+
getSourceParameters() {
|
|
1382
|
+
var _a;
|
|
1383
|
+
const sourceInfo = this.getSourceInfo();
|
|
1384
|
+
if (sourceInfo.kind === 'query') {
|
|
1385
|
+
return [];
|
|
1386
|
+
}
|
|
1387
|
+
return (_a = sourceInfo.parameters) !== null && _a !== void 0 ? _a : [];
|
|
1388
|
+
}
|
|
1389
|
+
areRequiredParametersSet() {
|
|
1390
|
+
const sourceParameters = this.getSourceParameters();
|
|
1391
|
+
for (const parameterInfo of sourceParameters) {
|
|
1392
|
+
if (parameterInfo.default_value !== undefined)
|
|
1393
|
+
continue;
|
|
1394
|
+
const parameter = this.tryGetParameter(parameterInfo.name);
|
|
1395
|
+
if (parameter === undefined) {
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return true;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
exports.ASTReferenceQueryArrowSource = ASTReferenceQueryArrowSource;
|
|
1305
1403
|
const ASTViewDefinition = {
|
|
1306
1404
|
from(definition) {
|
|
1307
1405
|
switch (definition.kind) {
|