@malloydata/malloy 0.0.88-dev231002231014 → 0.0.88-dev231002235732

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.
Files changed (50) hide show
  1. package/dist/lang/ast/elements/define-query.d.ts +3 -3
  2. package/dist/lang/ast/elements/define-query.js +9 -4
  3. package/dist/lang/ast/elements/define-source.d.ts +3 -3
  4. package/dist/lang/ast/elements/define-source.js +12 -4
  5. package/dist/lang/ast/elements/pipeline-desc.d.ts +1 -0
  6. package/dist/lang/ast/elements/pipeline-desc.js +3 -0
  7. package/dist/lang/ast/elements/source-query-nodes.d.ts +72 -0
  8. package/dist/lang/ast/elements/source-query-nodes.js +368 -0
  9. package/dist/lang/ast/elements/source-query.d.ts +11 -0
  10. package/dist/lang/ast/{query-elements/run-query.js → elements/source-query.js} +32 -21
  11. package/dist/lang/ast/index.d.ts +2 -2
  12. package/dist/lang/ast/index.js +2 -2
  13. package/dist/lang/ast/query-elements/anonymous-query.d.ts +3 -3
  14. package/dist/lang/ast/query-elements/anonymous-query.js +15 -8
  15. package/dist/lang/ast/query-elements/existing-query.js +1 -1
  16. package/dist/lang/ast/query-items/field-references.d.ts +4 -0
  17. package/dist/lang/ast/query-items/field-references.js +11 -1
  18. package/dist/lang/ast/query-items/typecheck_utils.js +5 -5
  19. package/dist/lang/ast/query-properties/joins.d.ts +7 -5
  20. package/dist/lang/ast/query-properties/joins.js +22 -8
  21. package/dist/lang/ast/sources/sql-source.js +5 -0
  22. package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
  23. package/dist/lang/ast/sql-elements/sql-string.js +19 -9
  24. package/dist/lang/ast/types/malloy-element.d.ts +3 -1
  25. package/dist/lang/ast/types/malloy-element.js +16 -5
  26. package/dist/lang/lib/Malloy/MalloyParser.d.ts +179 -184
  27. package/dist/lang/lib/Malloy/MalloyParser.js +3141 -2928
  28. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +147 -199
  29. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +88 -120
  30. package/dist/lang/malloy-to-ast.d.ts +16 -15
  31. package/dist/lang/malloy-to-ast.js +147 -141
  32. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +1 -1
  33. package/dist/lang/parse-utils.js +2 -2
  34. package/dist/lang/test/annotation.spec.js +35 -46
  35. package/dist/lang/test/document-symbol-walker.spec.js +2 -2
  36. package/dist/lang/test/expressions.spec.js +16 -16
  37. package/dist/lang/test/imports.spec.js +10 -8
  38. package/dist/lang/test/literals.spec.js +4 -4
  39. package/dist/lang/test/locations.spec.js +82 -80
  40. package/dist/lang/test/parse-expects.js +5 -1
  41. package/dist/lang/test/parse.spec.js +173 -117
  42. package/dist/lang/test/query.spec.js +199 -203
  43. package/dist/lang/test/source.spec.js +54 -45
  44. package/dist/lang/test/sql-block.spec.js +19 -12
  45. package/dist/lang/test/test-translator.js +8 -5
  46. package/dist/malloy.js +2 -2
  47. package/package.json +1 -2
  48. package/dist/lang/ast/query-elements/run-query.d.ts +0 -13
  49. package/dist/lang/ast/sources/named-source-or-query.d.ts +0 -10
  50. package/dist/lang/ast/sources/named-source-or-query.js +0 -71
@@ -1,12 +1,12 @@
1
1
  import { Annotation } from '../../../model/malloy_types';
2
2
  import { DocStatement, Document, MalloyElement, DocStatementList } from '../types/malloy-element';
3
- import { QueryElement } from '../types/query-element';
4
3
  import { Noteable, extendNoteMethod } from '../types/noteable';
4
+ import { SourceQueryNode } from './source-query';
5
5
  export declare class DefineQuery extends MalloyElement implements DocStatement, Noteable {
6
6
  readonly name: string;
7
- readonly queryDetails: QueryElement;
7
+ readonly queryExpr: SourceQueryNode;
8
8
  elementType: string;
9
- constructor(name: string, queryDetails: QueryElement);
9
+ constructor(name: string, queryExpr: SourceQueryNode);
10
10
  readonly isNoteableObj = true;
11
11
  extendNote: typeof extendNoteMethod;
12
12
  note?: Annotation;
@@ -26,10 +26,10 @@ exports.DefineQueryList = exports.DefineQuery = void 0;
26
26
  const malloy_element_1 = require("../types/malloy-element");
27
27
  const noteable_1 = require("../types/noteable");
28
28
  class DefineQuery extends malloy_element_1.MalloyElement {
29
- constructor(name, queryDetails) {
30
- super({ queryDetails: queryDetails });
29
+ constructor(name, queryExpr) {
30
+ super({ queryExpr });
31
31
  this.name = name;
32
- this.queryDetails = queryDetails;
32
+ this.queryExpr = queryExpr;
33
33
  this.elementType = 'defineQuery';
34
34
  this.isNoteableObj = true;
35
35
  this.extendNote = noteable_1.extendNoteMethod;
@@ -40,8 +40,13 @@ class DefineQuery extends malloy_element_1.MalloyElement {
40
40
  this.log(`'${this.name}' is already defined, cannot redefine`);
41
41
  return;
42
42
  }
43
+ const queryEl = this.queryExpr.getQuery();
44
+ if (!queryEl) {
45
+ this.queryExpr.sqLog('Cannot define a query from this expression');
46
+ return;
47
+ }
43
48
  const entry = {
44
- ...this.queryDetails.query(),
49
+ ...queryEl.query(),
45
50
  type: 'query',
46
51
  name: this.name,
47
52
  location: this.location,
@@ -2,14 +2,14 @@ import { Annotation } from '../../../model/malloy_types';
2
2
  import { HasParameter } from '../parameters/has-parameter';
3
3
  import { DocStatement, Document, MalloyElement, DocStatementList } from '../types/malloy-element';
4
4
  import { Noteable, extendNoteMethod } from '../types/noteable';
5
- import { Source } from './source';
5
+ import { SourceQueryNode } from './source-query';
6
6
  export declare class DefineSource extends MalloyElement implements DocStatement, Noteable {
7
7
  readonly name: string;
8
- readonly theSource: Source;
8
+ readonly sourceExpr: SourceQueryNode | undefined;
9
9
  readonly exported: boolean;
10
10
  elementType: string;
11
11
  readonly parameters?: HasParameter[];
12
- constructor(name: string, theSource: Source, exported: boolean, params?: MalloyElement[]);
12
+ constructor(name: string, sourceExpr: SourceQueryNode | undefined, exported: boolean, params?: MalloyElement[]);
13
13
  readonly isNoteableObj = true;
14
14
  extendNote: typeof extendNoteMethod;
15
15
  note?: Annotation;
@@ -28,14 +28,17 @@ const has_parameter_1 = require("../parameters/has-parameter");
28
28
  const malloy_element_1 = require("../types/malloy-element");
29
29
  const noteable_1 = require("../types/noteable");
30
30
  class DefineSource extends malloy_element_1.MalloyElement {
31
- constructor(name, theSource, exported, params) {
32
- super({ explore: theSource });
31
+ constructor(name, sourceExpr, exported, params) {
32
+ super();
33
33
  this.name = name;
34
- this.theSource = theSource;
34
+ this.sourceExpr = sourceExpr;
35
35
  this.exported = exported;
36
36
  this.elementType = 'defineSource';
37
37
  this.isNoteableObj = true;
38
38
  this.extendNote = noteable_1.extendNoteMethod;
39
+ if (sourceExpr) {
40
+ this.has({ sourceExpr });
41
+ }
39
42
  if (params) {
40
43
  this.parameters = [];
41
44
  for (const el of params) {
@@ -50,11 +53,16 @@ class DefineSource extends malloy_element_1.MalloyElement {
50
53
  }
51
54
  }
52
55
  execute(doc) {
56
+ var _a;
53
57
  if (doc.modelEntry(this.name)) {
54
58
  this.log(`Cannot redefine '${this.name}'`);
55
59
  }
56
60
  else {
57
- const structDef = this.theSource.withParameters(this.parameters);
61
+ const theSource = (_a = this.sourceExpr) === null || _a === void 0 ? void 0 : _a.getSource();
62
+ if (theSource === undefined) {
63
+ return;
64
+ }
65
+ const structDef = theSource.withParameters(this.parameters);
58
66
  if (error_factory_1.ErrorFactory.isErrorStructDef(structDef)) {
59
67
  return;
60
68
  }
@@ -16,6 +16,7 @@ export declare abstract class PipelineDesc extends MalloyElement {
16
16
  protected withRefinement?: QOPDesc;
17
17
  protected qops: QOPDesc[];
18
18
  nestedInQuerySpace?: QueryInputSpace;
19
+ alreadyRefined(): boolean;
19
20
  refineWith(refinement: QOPDesc): void;
20
21
  addSegments(...segDesc: QOPDesc[]): void;
21
22
  protected appendOps(pipelineOutput: FieldSpace, modelPipe: PipeSegment[]): AppendResult;
@@ -38,6 +38,9 @@ class PipelineDesc extends malloy_element_1.MalloyElement {
38
38
  super(...arguments);
39
39
  this.qops = [];
40
40
  }
41
+ alreadyRefined() {
42
+ return this.withRefinement !== undefined;
43
+ }
41
44
  refineWith(refinement) {
42
45
  this.withRefinement = refinement;
43
46
  this.has({ withRefinement: refinement });
@@ -0,0 +1,72 @@
1
+ import { RefinedSource } from './refined-source';
2
+ import { MalloyElement, ModelEntryReference } from '../types/malloy-element';
3
+ import { Source } from './source';
4
+ import { SourceQueryNode } from './source-query';
5
+ import { QueryElement } from '../types/query-element';
6
+ import { QuerySource } from '../sources/query-source';
7
+ import { SourceDesc } from '../types/source-desc';
8
+ import { QOPDesc } from '../query-properties/qop-desc';
9
+ import { FullQuery } from '../query-elements/full-query';
10
+ import { ViewFieldReference } from '../query-items/field-references';
11
+ export declare class SQReference extends SourceQueryNode {
12
+ readonly ref: ModelEntryReference;
13
+ elementType: string;
14
+ asSource?: Source;
15
+ constructor(ref: ModelEntryReference);
16
+ getQuery(): QueryElement | undefined;
17
+ isSource(): boolean;
18
+ getSource(): Source | undefined;
19
+ }
20
+ export declare class SQLegacyModify extends SourceQueryNode {
21
+ readonly sourceQuery: SourceQueryNode;
22
+ readonly plus: MalloyElement[];
23
+ readonly hasPlus: boolean;
24
+ readonly m4Warnings: boolean;
25
+ elementType: string;
26
+ constructor(sourceQuery: SourceQueryNode, plus: MalloyElement[], hasPlus: boolean, m4Warnings: boolean);
27
+ getQuery(): QueryElement | undefined;
28
+ getSource(): Source | undefined;
29
+ isSource(): boolean;
30
+ }
31
+ export declare class SQExtendedSource extends SourceQueryNode {
32
+ readonly sqSrc: SourceQueryNode;
33
+ readonly extend: SourceDesc;
34
+ elementType: string;
35
+ asSource?: RefinedSource;
36
+ constructor(sqSrc: SourceQueryNode, extend: SourceDesc);
37
+ getSource(): RefinedSource | undefined;
38
+ isSource(): boolean;
39
+ }
40
+ export type ArrowViewComponent = ViewFieldReference | QOPDesc;
41
+ export declare class SQAppendView extends SourceQueryNode {
42
+ readonly applyTo: SourceQueryNode;
43
+ readonly viewList: ArrowViewComponent[];
44
+ elementType: string;
45
+ constructor(applyTo: SourceQueryNode, viewList: ArrowViewComponent[]);
46
+ getQuery(): QueryElement | undefined;
47
+ getSource(): Source | undefined;
48
+ }
49
+ export declare class SQRefinedQuery extends SourceQueryNode {
50
+ readonly toRefine: SourceQueryNode;
51
+ readonly refine: QOPDesc;
52
+ elementType: string;
53
+ constructor(toRefine: SourceQueryNode, refine: QOPDesc);
54
+ getQuery(): QueryElement | undefined;
55
+ getSource(): QuerySource | undefined;
56
+ }
57
+ export declare class SQFrom extends SourceQueryNode {
58
+ readonly from: SourceQueryNode;
59
+ elementType: string;
60
+ constructor(from: SourceQueryNode);
61
+ getSource(): Source | undefined;
62
+ getQuery(): QueryElement | undefined;
63
+ isSource(): boolean;
64
+ }
65
+ export declare class SQSourceWrapper extends SourceQueryNode {
66
+ readonly theSource: Source;
67
+ elementType: string;
68
+ constructor(theSource: Source);
69
+ isSource(): boolean;
70
+ getSource(): Source;
71
+ getQuery(): FullQuery | undefined;
72
+ }
@@ -0,0 +1,368 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.SQSourceWrapper = exports.SQFrom = exports.SQRefinedQuery = exports.SQAppendView = exports.SQExtendedSource = exports.SQLegacyModify = exports.SQReference = void 0;
26
+ const refined_source_1 = require("./refined-source");
27
+ const source_query_1 = require("./source-query");
28
+ const existing_query_1 = require("../query-elements/existing-query");
29
+ const query_source_1 = require("../sources/query-source");
30
+ const named_source_1 = require("../sources/named-source");
31
+ const source_desc_1 = require("../types/source-desc");
32
+ const qop_desc_1 = require("../query-properties/qop-desc");
33
+ const full_query_1 = require("../query-elements/full-query");
34
+ const field_references_1 = require("../query-items/field-references");
35
+ const query_property_1 = require("../types/query-property");
36
+ const source_property_1 = require("../types/source-property");
37
+ const sql_source_1 = require("../sources/sql-source");
38
+ class SQReference extends source_query_1.SourceQueryNode {
39
+ constructor(ref) {
40
+ super({ ref });
41
+ this.ref = ref;
42
+ this.elementType = 'sqReference';
43
+ }
44
+ getQuery() {
45
+ const entry = this.ref.getNamed();
46
+ if (entry) {
47
+ if (entry.type === 'query') {
48
+ const query = new existing_query_1.ExistingQuery();
49
+ query.head = this.ref.name;
50
+ this.has({ query });
51
+ return query;
52
+ }
53
+ else {
54
+ this.sqLog(`Illegal reference to '${entry.as || entry.name}', query expected`);
55
+ }
56
+ }
57
+ else {
58
+ this.ref.log(`Reference to undefined object '${this.ref.refString}'`);
59
+ this.errored = true;
60
+ }
61
+ return;
62
+ }
63
+ isSource() {
64
+ var _a;
65
+ return ((_a = this.ref.getNamed()) === null || _a === void 0 ? void 0 : _a.type) === 'struct';
66
+ }
67
+ getSource() {
68
+ if (this.asSource) {
69
+ return this.asSource;
70
+ }
71
+ const entry = this.ref.getNamed();
72
+ if (!entry) {
73
+ this.ref.log(`Reference to undefined object '${this.ref.refString}'`);
74
+ this.errored = true;
75
+ return;
76
+ }
77
+ if (entry.type === 'query') {
78
+ const existingQuery = new existing_query_1.ExistingQuery();
79
+ existingQuery.head = this.ref.name;
80
+ this.asSource = new query_source_1.QuerySource(existingQuery);
81
+ }
82
+ else if (entry.type === 'struct') {
83
+ this.asSource = new named_source_1.NamedSource(this.ref);
84
+ }
85
+ else {
86
+ this.sqLog(`Expected '${this.ref.refString}' to be of type query or source, not '${entry.type}'`);
87
+ return;
88
+ }
89
+ this.has({ asSource: this.asSource });
90
+ return this.asSource;
91
+ }
92
+ }
93
+ exports.SQReference = SQReference;
94
+ class SQLegacyModify extends source_query_1.SourceQueryNode {
95
+ constructor(sourceQuery, plus, hasPlus, m4Warnings) {
96
+ super({ sourceQuery, plus });
97
+ this.sourceQuery = sourceQuery;
98
+ this.plus = plus;
99
+ this.hasPlus = hasPlus;
100
+ this.m4Warnings = m4Warnings;
101
+ this.elementType = 'sqLogacyModify';
102
+ }
103
+ getQuery() {
104
+ const asQuery = this.sourceQuery.getQuery();
105
+ if (!asQuery) {
106
+ return;
107
+ }
108
+ if (!this.hasPlus && this.m4Warnings) {
109
+ this.log('Implicit query refinement is deprecated, use the `+` operator', 'warn');
110
+ }
111
+ const stmts = [];
112
+ for (const stmt of this.plus) {
113
+ if ((0, query_property_1.isQueryProperty)(stmt)) {
114
+ stmts.push(stmt);
115
+ }
116
+ else {
117
+ // just for typing, should never happen because this is an ambiguous modification
118
+ stmt.log('Unable to add this refinement to query');
119
+ }
120
+ }
121
+ asQuery.refineWith(new qop_desc_1.QOPDesc(stmts));
122
+ this.has({ asQuery });
123
+ return asQuery;
124
+ }
125
+ getSource() {
126
+ let asSource = this.sourceQuery.getSource();
127
+ if (!asSource) {
128
+ return;
129
+ }
130
+ if (this.m4Warnings) {
131
+ if (this.hasPlus) {
132
+ this.log('Source extension with "+" is deprecated, use the "extend" operator', 'warn');
133
+ }
134
+ else {
135
+ this.log('Implicit source extension is deprecated, use the `extend` operator.', 'warn');
136
+ }
137
+ }
138
+ const stmts = [];
139
+ for (const stmt of this.plus) {
140
+ if ((0, source_property_1.isSourceProperty)(stmt)) {
141
+ stmts.push(stmt);
142
+ }
143
+ else {
144
+ // just for typing, should never happen because this is an ambiguous modification
145
+ stmt.log('Unable to add this extension to source');
146
+ }
147
+ }
148
+ const extend = new source_desc_1.SourceDesc(stmts);
149
+ asSource = new refined_source_1.RefinedSource(asSource, extend);
150
+ this.has({ asSource });
151
+ return asSource;
152
+ }
153
+ isSource() {
154
+ return this.sourceQuery.isSource();
155
+ }
156
+ }
157
+ exports.SQLegacyModify = SQLegacyModify;
158
+ class SQExtendedSource extends source_query_1.SourceQueryNode {
159
+ constructor(sqSrc, extend) {
160
+ super({ sqSrc, extend });
161
+ this.sqSrc = sqSrc;
162
+ this.extend = extend;
163
+ this.elementType = 'sqExtendedSource';
164
+ }
165
+ getSource() {
166
+ if (this.asSource) {
167
+ return this.asSource;
168
+ }
169
+ const src = this.sqSrc.getSource();
170
+ if (src) {
171
+ this.asSource = new refined_source_1.RefinedSource(src, this.extend);
172
+ this.has({ asSource: this.asSource });
173
+ return this.asSource;
174
+ }
175
+ this.sqLog('Could not compute source to extend');
176
+ }
177
+ isSource() {
178
+ return true;
179
+ }
180
+ }
181
+ exports.SQExtendedSource = SQExtendedSource;
182
+ class SQAppendView extends source_query_1.SourceQueryNode {
183
+ constructor(applyTo, viewList) {
184
+ super({ applyTo, viewList });
185
+ this.applyTo = applyTo;
186
+ this.viewList = viewList;
187
+ this.elementType = 'sqAppendView';
188
+ }
189
+ /*
190
+
191
+ if the thing we are applying a view to as a query ... just add a segment
192
+ if the view is a segment
193
+
194
+ if it is a source then the first segment is allowed to be a string
195
+
196
+ all the rest of the segments are refinements to the first segment
197
+
198
+ which are usually illegal ... so patterns
199
+
200
+ src -> turtle // ok
201
+ src -> turtle + qop // ok second thing is a refinement
202
+ src -> qop // ok
203
+ query -> qop // ok
204
+
205
+ the grammar allows for a list of views and refinements ... these are not translated yet
206
+
207
+
208
+ */
209
+ getQuery() {
210
+ let theQuery;
211
+ const views = [...this.viewList];
212
+ if (this.applyTo.isSource()) {
213
+ const querySrc = this.applyTo.getSource();
214
+ if (!querySrc) {
215
+ this.sqLog('Could not get source for query');
216
+ return;
217
+ }
218
+ this.has({ querySrc });
219
+ theQuery = new full_query_1.FullQuery(querySrc);
220
+ this.has({ theQuery });
221
+ const head = views[0];
222
+ if (head instanceof field_references_1.ViewFieldReference) {
223
+ theQuery.turtleName = head.list[0];
224
+ if (views.length === 1) {
225
+ return theQuery;
226
+ }
227
+ if (views.length === 2) {
228
+ if (views[1] instanceof qop_desc_1.QOPDesc) {
229
+ theQuery.refineWith(views[1]);
230
+ return theQuery;
231
+ }
232
+ else {
233
+ this.sqLog('Cannot refine with a named view');
234
+ return;
235
+ }
236
+ }
237
+ else {
238
+ this.sqLog('Cannot have multiple refinements');
239
+ }
240
+ }
241
+ else if (views.length === 1) {
242
+ if (head instanceof qop_desc_1.QOPDesc) {
243
+ theQuery.addSegments(head);
244
+ return theQuery;
245
+ }
246
+ }
247
+ if (views.length > 0) {
248
+ this.sqLog('Cannot have multiple refinements');
249
+ return;
250
+ }
251
+ return theQuery;
252
+ }
253
+ const found = this.applyTo.getQuery();
254
+ if (!found) {
255
+ this.sqLog('Could not create query to extend');
256
+ return;
257
+ }
258
+ theQuery = found;
259
+ this.has({ theQuery });
260
+ const head = views[0];
261
+ if (views.length === 1) {
262
+ if (head instanceof qop_desc_1.QOPDesc) {
263
+ theQuery.addSegments(head);
264
+ views.shift();
265
+ }
266
+ else {
267
+ this.sqLog(`Cannot reference view '${head}' in output of query`);
268
+ return;
269
+ }
270
+ }
271
+ else {
272
+ this.sqLog('query definition by combining not yet supported');
273
+ return;
274
+ }
275
+ return theQuery;
276
+ }
277
+ getSource() {
278
+ const query = this.getQuery();
279
+ if (!query) {
280
+ this.sqLog("Couldn't comprehend query well enough to make a source");
281
+ return;
282
+ }
283
+ const asSource = new query_source_1.QuerySource(query);
284
+ this.has({ asSource });
285
+ return asSource;
286
+ }
287
+ }
288
+ exports.SQAppendView = SQAppendView;
289
+ class SQRefinedQuery extends source_query_1.SourceQueryNode {
290
+ constructor(toRefine, refine) {
291
+ super({ toRefine, refine });
292
+ this.toRefine = toRefine;
293
+ this.refine = refine;
294
+ this.elementType = 'sqRefinedQuery';
295
+ }
296
+ getQuery() {
297
+ if (this.toRefine.isSource()) {
298
+ if (this.toRefine instanceof SQReference) {
299
+ this.sqLog(`Cannot add view refinements to '${this.toRefine.ref.refString}' because it is a source`);
300
+ }
301
+ else {
302
+ this.sqLog('Cannot add view refinements to a source');
303
+ }
304
+ return;
305
+ }
306
+ const refinedQuery = this.toRefine.getQuery();
307
+ if (refinedQuery) {
308
+ if (refinedQuery.alreadyRefined()) {
309
+ this.sqLog('Cannot refine a refined query');
310
+ return;
311
+ }
312
+ refinedQuery.refineWith(this.refine);
313
+ this.has({ query: refinedQuery });
314
+ return refinedQuery;
315
+ }
316
+ }
317
+ getSource() {
318
+ const query = this.getQuery();
319
+ if (query) {
320
+ const queryAsSource = new query_source_1.QuerySource(query);
321
+ this.has({ queryAsSource });
322
+ return queryAsSource;
323
+ }
324
+ }
325
+ }
326
+ exports.SQRefinedQuery = SQRefinedQuery;
327
+ class SQFrom extends source_query_1.SourceQueryNode {
328
+ constructor(from) {
329
+ super({ from });
330
+ this.from = from;
331
+ this.elementType = 'sqFrom';
332
+ }
333
+ getSource() {
334
+ return this.from.getSource();
335
+ }
336
+ getQuery() {
337
+ return this.from.getQuery();
338
+ }
339
+ isSource() {
340
+ return true;
341
+ }
342
+ }
343
+ exports.SQFrom = SQFrom;
344
+ class SQSourceWrapper extends source_query_1.SourceQueryNode {
345
+ constructor(theSource) {
346
+ super({ theSource });
347
+ this.theSource = theSource;
348
+ this.elementType = 'SQtable';
349
+ }
350
+ isSource() {
351
+ return true;
352
+ }
353
+ getSource() {
354
+ return this.theSource;
355
+ }
356
+ getQuery() {
357
+ if (this.theSource instanceof sql_source_1.SQLSource) {
358
+ const queryObj = new full_query_1.FullQuery(this.theSource);
359
+ this.has({ sqlAsQUery: queryObj });
360
+ return queryObj;
361
+ }
362
+ if (this.theSource instanceof named_source_1.NamedSource) {
363
+ this.sqLog(`Illegal reference to '${this.theSource.refName}', query expected`);
364
+ }
365
+ }
366
+ }
367
+ exports.SQSourceWrapper = SQSourceWrapper;
368
+ //# sourceMappingURL=source-query-nodes.js.map
@@ -0,0 +1,11 @@
1
+ import { QueryElement } from '../types/query-element';
2
+ import { MalloyElement } from '../types/malloy-element';
3
+ import { Source } from './source';
4
+ export declare abstract class SourceQueryNode extends MalloyElement {
5
+ errored: boolean;
6
+ getSource(): Source | undefined;
7
+ getQuery(): QueryElement | undefined;
8
+ isSource(): boolean;
9
+ sqLog(message: string): void;
10
+ isErrorFree(): boolean;
11
+ }
@@ -22,30 +22,41 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.RunQuery = void 0;
25
+ exports.SourceQueryNode = void 0;
26
26
  const malloy_element_1 = require("../types/malloy-element");
27
- const noteable_1 = require("../types/noteable");
28
- class RunQuery extends malloy_element_1.MalloyElement {
29
- constructor(theQuery) {
30
- super();
31
- this.theQuery = theQuery;
32
- this.elementType = 'runQuery';
33
- this.isNoteableObj = true;
34
- this.extendNote = noteable_1.extendNoteMethod;
35
- this.has({ query: theQuery });
27
+ class SourceQueryNode extends malloy_element_1.MalloyElement {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.errored = false;
36
31
  }
37
- execute(doc) {
38
- let modelQuery = this.theQuery.query();
39
- const annotation = this.note || {};
40
- if (modelQuery.annotation) {
41
- annotation.inherits = modelQuery.annotation;
32
+ getSource() {
33
+ return;
34
+ }
35
+ getQuery() {
36
+ return;
37
+ }
38
+ isSource() {
39
+ return false;
40
+ }
41
+ sqLog(message) {
42
+ if (this.isErrorFree()) {
43
+ this.log(message);
44
+ }
45
+ this.errored = true;
46
+ }
47
+ isErrorFree() {
48
+ if (this.errored) {
49
+ return false;
42
50
  }
43
- if (annotation.notes || annotation.blockNotes || annotation.inherits) {
44
- modelQuery = { ...modelQuery, annotation };
51
+ let clean = true;
52
+ for (const child of this.walk()) {
53
+ if (child instanceof SourceQueryNode && child.errored) {
54
+ clean = false;
55
+ break;
56
+ }
45
57
  }
46
- doc.queryList.push(modelQuery);
47
- return undefined;
58
+ return clean;
48
59
  }
49
60
  }
50
- exports.RunQuery = RunQuery;
51
- //# sourceMappingURL=run-query.js.map
61
+ exports.SourceQueryNode = SourceQueryNode;
62
+ //# sourceMappingURL=source-query.js.map
@@ -3,6 +3,8 @@ export * from './elements/define-source';
3
3
  export * from './elements/define-query';
4
4
  export * from './elements/source';
5
5
  export * from './elements/refined-source';
6
+ export * from './elements/source-query';
7
+ export * from './elements/source-query-nodes';
6
8
  export * from './source-properties/field-list-edit';
7
9
  export * from './source-properties/primary-key';
8
10
  export * from './source-properties/renames';
@@ -53,7 +55,6 @@ export * from './elements/import-statement';
53
55
  export * from './query-properties/extend';
54
56
  export * from './parameters/has-parameter';
55
57
  export * from './query-elements/anonymous-query';
56
- export * from './query-elements/run-query';
57
58
  export * from './query-elements/existing-query';
58
59
  export * from './query-elements/full-query';
59
60
  export * from './query-items/field-declaration';
@@ -77,7 +78,6 @@ export * from './query-properties/qop-desc';
77
78
  export * from './query-properties/sampling';
78
79
  export * from './query-properties/top';
79
80
  export * from './sources/named-source';
80
- export * from './sources/named-source-or-query';
81
81
  export * from './sources/query-source';
82
82
  export * from './sources/from-sql-source';
83
83
  export * from './sources/sql-source';