@malloydata/malloy 0.0.51-dev230629171920 → 0.0.51-dev230705184641

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 (36) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/lang/ast/elements/define-query.d.ts +3 -5
  3. package/dist/lang/ast/elements/define-query.js +1 -4
  4. package/dist/lang/ast/elements/define-source.d.ts +3 -5
  5. package/dist/lang/ast/elements/define-source.js +1 -4
  6. package/dist/lang/ast/elements/import-statement.d.ts +2 -1
  7. package/dist/lang/ast/elements/import-statement.js +12 -5
  8. package/dist/lang/ast/index.d.ts +1 -0
  9. package/dist/lang/ast/index.js +1 -0
  10. package/dist/lang/ast/query-elements/anonymous-query.d.ts +1 -2
  11. package/dist/lang/ast/query-elements/anonymous-query.js +0 -1
  12. package/dist/lang/ast/query-elements/run-query.d.ts +3 -4
  13. package/dist/lang/ast/sources/from-sql-source.d.ts +7 -0
  14. package/dist/lang/ast/sources/from-sql-source.js +68 -0
  15. package/dist/lang/ast/sources/sql-source.d.ts +15 -4
  16. package/dist/lang/ast/sources/sql-source.js +79 -27
  17. package/dist/lang/ast/sql-elements/sql-statement.d.ts +3 -1
  18. package/dist/lang/ast/sql-elements/sql-statement.js +21 -10
  19. package/dist/lang/ast/sql-elements/sql-string.d.ts +1 -0
  20. package/dist/lang/ast/sql-elements/sql-string.js +8 -0
  21. package/dist/lang/ast/types/malloy-element.d.ts +9 -6
  22. package/dist/lang/ast/types/malloy-element.js +42 -14
  23. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +73 -72
  24. package/dist/lang/lib/Malloy/MalloyLexer.js +1078 -1072
  25. package/dist/lang/lib/Malloy/MalloyParser.d.ts +86 -73
  26. package/dist/lang/lib/Malloy/MalloyParser.js +1198 -1135
  27. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +13 -0
  28. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +8 -0
  29. package/dist/lang/malloy-to-ast.d.ts +3 -2
  30. package/dist/lang/malloy-to-ast.js +17 -3
  31. package/dist/lang/parse-malloy.js +3 -3
  32. package/dist/lang/test/parse.spec.js +88 -1
  33. package/dist/lang/zone.d.ts +1 -1
  34. package/dist/malloy.js +1 -1
  35. package/dist/tags.d.ts +1 -1
  36. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -8,4 +8,4 @@ export type { RunSQLOptions } from './run_sql_options';
8
8
  export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from './runtime_types';
9
9
  export type { Loggable } from './malloy';
10
10
  export { toAsyncGenerator } from './connection_utils';
11
- export { Tags, type MalloyTags } from './tags';
11
+ export { Tags, type MalloyTags, type MalloyTagProperties } from './tags';
@@ -1,6 +1,5 @@
1
1
  import { Annotation } from '../../../model/malloy_types';
2
- import { ModelDataRequest } from '../../translate-response';
3
- import { DocStatement, Document, MalloyElement, RunList } from '../types/malloy-element';
2
+ import { DocStatement, Document, MalloyElement, DocStatementList } from '../types/malloy-element';
4
3
  import { QueryElement } from '../types/query-element';
5
4
  import { Noteable, extendNoteMethod } from '../types/noteable';
6
5
  export declare class DefineQuery extends MalloyElement implements DocStatement, Noteable {
@@ -11,10 +10,9 @@ export declare class DefineQuery extends MalloyElement implements DocStatement,
11
10
  readonly isNoteableObj = true;
12
11
  extendNote: typeof extendNoteMethod;
13
12
  note?: Annotation;
14
- execute(doc: Document): ModelDataRequest;
13
+ execute(doc: Document): void;
15
14
  }
16
- export declare class DefineQueryList extends RunList implements DocStatement {
15
+ export declare class DefineQueryList extends DocStatementList {
17
16
  elementType: string;
18
17
  constructor(queryList: DefineQuery[]);
19
- execute(doc: Document): ModelDataRequest;
20
18
  }
@@ -55,14 +55,11 @@ class DefineQuery extends malloy_element_1.MalloyElement {
55
55
  }
56
56
  }
57
57
  exports.DefineQuery = DefineQuery;
58
- class DefineQueryList extends malloy_element_1.RunList {
58
+ class DefineQueryList extends malloy_element_1.DocStatementList {
59
59
  constructor(queryList) {
60
60
  super(queryList);
61
61
  this.elementType = 'defineQueries';
62
62
  }
63
- execute(doc) {
64
- return this.executeList(doc);
65
- }
66
63
  }
67
64
  exports.DefineQueryList = DefineQueryList;
68
65
  //# sourceMappingURL=define-query.js.map
@@ -1,7 +1,6 @@
1
1
  import { Annotation } from '../../../model/malloy_types';
2
- import { ModelDataRequest } from '../../translate-response';
3
2
  import { HasParameter } from '../parameters/has-parameter';
4
- import { DocStatement, Document, MalloyElement, RunList } from '../types/malloy-element';
3
+ import { DocStatement, Document, MalloyElement, DocStatementList } from '../types/malloy-element';
5
4
  import { Noteable, extendNoteMethod } from '../types/noteable';
6
5
  import { Source } from './source';
7
6
  export declare class DefineSource extends MalloyElement implements DocStatement, Noteable {
@@ -14,10 +13,9 @@ export declare class DefineSource extends MalloyElement implements DocStatement,
14
13
  readonly isNoteableObj = true;
15
14
  extendNote: typeof extendNoteMethod;
16
15
  note?: Annotation;
17
- execute(doc: Document): ModelDataRequest;
16
+ execute(doc: Document): void;
18
17
  }
19
- export declare class DefineSourceList extends RunList implements DocStatement {
18
+ export declare class DefineSourceList extends DocStatementList {
20
19
  elementType: string;
21
20
  constructor(sourceList: DefineSource[]);
22
- execute(doc: Document): ModelDataRequest;
23
21
  }
@@ -73,14 +73,11 @@ class DefineSource extends malloy_element_1.MalloyElement {
73
73
  }
74
74
  }
75
75
  exports.DefineSource = DefineSource;
76
- class DefineSourceList extends malloy_element_1.RunList {
76
+ class DefineSourceList extends malloy_element_1.DocStatementList {
77
77
  constructor(sourceList) {
78
78
  super(sourceList);
79
79
  this.elementType = 'defineSources';
80
80
  }
81
- execute(doc) {
82
- return this.executeList(doc);
83
- }
84
81
  }
85
82
  exports.DefineSourceList = DefineSourceList;
86
83
  //# sourceMappingURL=define-source.js.map
@@ -5,5 +5,6 @@ export declare class ImportStatement extends MalloyElement implements DocStateme
5
5
  elementType: string;
6
6
  fullURL?: string;
7
7
  constructor(url: string, baseURL: string);
8
- execute(doc: Document): ModelDataRequest;
8
+ needs(): ModelDataRequest;
9
+ execute(doc: Document): void;
9
10
  }
@@ -44,6 +44,18 @@ class ImportStatement extends malloy_element_1.MalloyElement {
44
44
  this.log('Invalid URI in import statement');
45
45
  }
46
46
  }
47
+ needs() {
48
+ const trans = this.translator();
49
+ if (trans && this.fullURL) {
50
+ const src = trans.root.importZone.getEntry(this.fullURL);
51
+ if (src.status === 'present') {
52
+ const childNeeds = trans.childRequest(this.fullURL);
53
+ if (childNeeds)
54
+ return childNeeds;
55
+ }
56
+ }
57
+ return undefined;
58
+ }
47
59
  execute(doc) {
48
60
  const trans = this.translator();
49
61
  if (!trans) {
@@ -52,10 +64,6 @@ class ImportStatement extends malloy_element_1.MalloyElement {
52
64
  else if (this.fullURL) {
53
65
  const src = trans.root.importZone.getEntry(this.fullURL);
54
66
  if (src.status === 'present') {
55
- const childNeeds = trans.childRequest(this.fullURL);
56
- if (childNeeds) {
57
- return childNeeds;
58
- }
59
67
  for (const [importing, entry] of Object.entries(trans.getChildExports(this.fullURL))) {
60
68
  if (doc.getEntry(importing)) {
61
69
  this.log(`Cannot redefine '${importing}'`);
@@ -72,7 +80,6 @@ class ImportStatement extends malloy_element_1.MalloyElement {
72
80
  this.log(`import failed with status: '${src.status}'`);
73
81
  }
74
82
  }
75
- return undefined;
76
83
  }
77
84
  }
78
85
  exports.ImportStatement = ImportStatement;
@@ -77,6 +77,7 @@ export * from './query-properties/sampling';
77
77
  export * from './query-properties/top';
78
78
  export * from './sources/named-source';
79
79
  export * from './sources/query-source';
80
+ export * from './sources/from-sql-source';
80
81
  export * from './sources/sql-source';
81
82
  export * from './sources/table-source';
82
83
  export * from './sql-elements/sql-statement';
@@ -115,6 +115,7 @@ __exportStar(require("./query-properties/sampling"), exports);
115
115
  __exportStar(require("./query-properties/top"), exports);
116
116
  __exportStar(require("./sources/named-source"), exports);
117
117
  __exportStar(require("./sources/query-source"), exports);
118
+ __exportStar(require("./sources/from-sql-source"), exports);
118
119
  __exportStar(require("./sources/sql-source"), exports);
119
120
  __exportStar(require("./sources/table-source"), exports);
120
121
  __exportStar(require("./sql-elements/sql-statement"), exports);
@@ -1,5 +1,4 @@
1
1
  import { Annotation } from '../../../model';
2
- import { ModelDataRequest } from '../../translate-response';
3
2
  import { DocStatement, Document, MalloyElement } from '../types/malloy-element';
4
3
  import { QueryElement } from '../types/query-element';
5
4
  import { Noteable, extendNoteMethod } from '../types/noteable';
@@ -10,5 +9,5 @@ export declare class AnonymousQuery extends MalloyElement implements DocStatemen
10
9
  readonly isNoteableObj = true;
11
10
  extendNote: typeof extendNoteMethod;
12
11
  note?: Annotation;
13
- execute(doc: Document): ModelDataRequest;
12
+ execute(doc: Document): void;
14
13
  }
@@ -42,7 +42,6 @@ class AnonymousQuery extends malloy_element_1.MalloyElement {
42
42
  : this.note;
43
43
  }
44
44
  doc.queryList.push(modelQuery);
45
- return undefined;
46
45
  }
47
46
  }
48
47
  exports.AnonymousQuery = AnonymousQuery;
@@ -1,11 +1,10 @@
1
1
  import { Annotation } from '../../../model';
2
- import { ModelDataRequest } from '../../translate-response';
3
2
  import { DocStatement, Document, MalloyElement, ModelEntryReference } from '../types/malloy-element';
4
3
  import { Noteable, extendNoteMethod } from '../types/noteable';
5
4
  import { QueryElement } from '../types/query-element';
6
5
  declare abstract class RunQuery extends MalloyElement implements DocStatement {
7
6
  elementType: string;
8
- abstract execute(doc: Document): ModelDataRequest;
7
+ abstract execute(doc: Document): void;
9
8
  }
10
9
  export declare class RunQueryDef extends RunQuery implements Noteable {
11
10
  readonly theQuery: QueryElement;
@@ -13,11 +12,11 @@ export declare class RunQueryDef extends RunQuery implements Noteable {
13
12
  readonly isNoteableObj = true;
14
13
  extendNote: typeof extendNoteMethod;
15
14
  constructor(theQuery: QueryElement);
16
- execute(doc: Document): ModelDataRequest;
15
+ execute(doc: Document): void;
17
16
  }
18
17
  export declare class RunQueryRef extends RunQuery {
19
18
  readonly queryName: ModelEntryReference;
20
19
  constructor(queryName: ModelEntryReference);
21
- execute(doc: Document): ModelDataRequest;
20
+ execute(doc: Document): void;
22
21
  }
23
22
  export {};
@@ -0,0 +1,7 @@
1
+ import { StructDef, StructRef } from '../../../model/malloy_types';
2
+ import { NamedSource } from './named-source';
3
+ export declare class FromSQLSource extends NamedSource {
4
+ elementType: string;
5
+ structRef(): StructRef;
6
+ modelStruct(): StructDef | undefined;
7
+ }
@@ -0,0 +1,68 @@
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.FromSQLSource = void 0;
26
+ const malloy_types_1 = require("../../../model/malloy_types");
27
+ const named_source_1 = require("./named-source");
28
+ class FromSQLSource extends named_source_1.NamedSource {
29
+ constructor() {
30
+ super(...arguments);
31
+ this.elementType = 'fromSQLSource';
32
+ }
33
+ structRef() {
34
+ return this.structDef();
35
+ }
36
+ modelStruct() {
37
+ const modelEnt = this.modelEntry(this.ref);
38
+ const entry = modelEnt === null || modelEnt === void 0 ? void 0 : modelEnt.entry;
39
+ if (!entry) {
40
+ this.log(`Undefined from_sql source '${this.refName}'`);
41
+ return;
42
+ }
43
+ if (entry.type === 'function') {
44
+ this.log(`Cannot construct a source from a function '${this.refName}'`);
45
+ return;
46
+ }
47
+ else if (entry.type === 'query') {
48
+ this.log(`Cannot use 'from_sql()' with a query '${this.refName}'`);
49
+ return;
50
+ }
51
+ else if (entry.type === 'connection') {
52
+ this.log(`Cannot use 'from_sql()' with a connection '${this.refName}'`);
53
+ return;
54
+ }
55
+ else if ((0, malloy_types_1.isSQLBlockStruct)(entry) && entry.declaredSQLBlock) {
56
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
+ const { declaredSQLBlock, ...newEntry } = entry;
58
+ return newEntry;
59
+ }
60
+ else if (!(0, malloy_types_1.isSQLBlockStruct)(entry)) {
61
+ this.log(`Cannot use 'from_sql()' to reference '${this.refName}'`);
62
+ return;
63
+ }
64
+ this.log(`Cannot use 'from_sql()' to reference '${this.refName}'`);
65
+ }
66
+ }
67
+ exports.FromSQLSource = FromSQLSource;
68
+ //# sourceMappingURL=from-sql-source.js.map
@@ -1,7 +1,18 @@
1
- import { StructDef, StructRef } from '../../../model/malloy_types';
2
- import { NamedSource } from './named-source';
3
- export declare class SQLSource extends NamedSource {
1
+ import { StructDef, StructRef, SQLBlockSource } from '../../../model/malloy_types';
2
+ import { NeedCompileSQL } from '../../translate-response';
3
+ import { Source } from '../elements/source';
4
+ import { SQLString } from '../sql-elements/sql-string';
5
+ import { ModelEntryReference, Document } from '../types/malloy-element';
6
+ export declare class SQLSource extends Source {
7
+ readonly connectionName: ModelEntryReference;
8
+ readonly select: SQLString;
4
9
  elementType: string;
10
+ requestBlock?: SQLBlockSource;
11
+ private connectionNameInvalid;
12
+ constructor(connectionName: ModelEntryReference, select: SQLString);
13
+ sqlBlock(): SQLBlockSource;
5
14
  structRef(): StructRef;
6
- modelStruct(): StructDef | undefined;
15
+ validateConnectionName(): boolean;
16
+ needs(doc: Document): NeedCompileSQL | undefined;
17
+ structDef(): StructDef;
7
18
  }
@@ -23,45 +23,97 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.SQLSource = void 0;
26
- const malloy_types_1 = require("../../../model/malloy_types");
27
- const named_source_1 = require("./named-source");
28
- class SQLSource extends named_source_1.NamedSource {
29
- constructor() {
30
- super(...arguments);
26
+ const sql_block_1 = require("../../../model/sql_block");
27
+ const source_1 = require("../elements/source");
28
+ const error_factory_1 = require("../error-factory");
29
+ class SQLSource extends source_1.Source {
30
+ constructor(connectionName, select) {
31
+ super();
32
+ this.connectionName = connectionName;
33
+ this.select = select;
31
34
  this.elementType = 'sqlSource';
35
+ this.connectionNameInvalid = false;
36
+ this.has({ connectionName, select });
37
+ }
38
+ sqlBlock() {
39
+ if (!this.requestBlock) {
40
+ this.requestBlock = (0, sql_block_1.makeSQLBlock)(this.select.sqlPhrases(), this.connectionName.refString);
41
+ }
42
+ return this.requestBlock;
32
43
  }
33
44
  structRef() {
34
45
  return this.structDef();
35
46
  }
36
- modelStruct() {
37
- const modelEnt = this.modelEntry(this.ref);
38
- const entry = modelEnt === null || modelEnt === void 0 ? void 0 : modelEnt.entry;
39
- if (!entry) {
40
- this.log(`Undefined from_sql source '${this.refName}'`);
41
- return;
47
+ validateConnectionName() {
48
+ var _a;
49
+ const connection = this.modelEntry(this.connectionName);
50
+ const name = this.connectionName.refString;
51
+ if (this.connectionNameInvalid)
52
+ return false;
53
+ if (connection === undefined) {
54
+ (_a = this.namespace()) === null || _a === void 0 ? void 0 : _a.setEntry(name, { entry: { type: 'connection', name }, exported: true }, true);
42
55
  }
43
- if (entry.type === 'function') {
44
- this.log(`Cannot construct a source from a function '${this.refName}'`);
45
- return;
56
+ else if (connection.entry.type !== 'connection') {
57
+ this.connectionName.log(`${this.connectionName.refString} is not a connection`);
58
+ this.connectionNameInvalid = true;
59
+ return false;
46
60
  }
47
- else if (entry.type === 'query') {
48
- this.log(`Cannot use 'from_sql()' with a query '${this.refName}'`);
49
- return;
61
+ return true;
62
+ }
63
+ needs(doc) {
64
+ var _a;
65
+ if (!this.validateConnectionName()) {
66
+ return undefined;
50
67
  }
51
- else if (entry.type === 'connection') {
52
- this.log(`Cannot use 'from_sql()' with a connection '${this.refName}'`);
68
+ const childNeeds = super.needs(doc);
69
+ if (childNeeds)
70
+ return childNeeds;
71
+ const sql = this.sqlBlock();
72
+ const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
73
+ if (!sqlDefEntry) {
74
+ this.log("Cant't look up schema for sql block");
53
75
  return;
54
76
  }
55
- else if ((0, malloy_types_1.isSQLBlockStruct)(entry) && entry.declaredSQLBlock) {
56
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
- const { declaredSQLBlock, ...newEntry } = entry;
58
- return newEntry;
77
+ sqlDefEntry.reference(sql.name, this.location);
78
+ const lookup = sqlDefEntry.getEntry(sql.name);
79
+ if (lookup.status === 'reference') {
80
+ return {
81
+ compileSQL: sql,
82
+ partialModel: this.select.containsQueries ? doc.modelDef() : undefined,
83
+ };
59
84
  }
60
- else if (!(0, malloy_types_1.isSQLBlockStruct)(entry)) {
61
- this.log(`Cannot use 'from_sql()' to reference '${this.refName}'`);
62
- return;
85
+ }
86
+ structDef() {
87
+ var _a;
88
+ if (!this.validateConnectionName()) {
89
+ return error_factory_1.ErrorFactory.structDef;
90
+ }
91
+ const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
92
+ if (!sqlDefEntry) {
93
+ this.log("Cant't look up schema for sql block");
94
+ return error_factory_1.ErrorFactory.structDef;
95
+ }
96
+ const sql = this.sqlBlock();
97
+ sqlDefEntry.reference(sql.name, this.location);
98
+ const lookup = sqlDefEntry.getEntry(sql.name);
99
+ if (lookup.status === 'error') {
100
+ const msgLines = lookup.message.split(/\r?\n/);
101
+ this.select.log('Invalid SQL, ' + msgLines.join('\n '));
102
+ return error_factory_1.ErrorFactory.structDef;
103
+ }
104
+ else if (lookup.status === 'present') {
105
+ const location = this.select.location;
106
+ const locStruct = {
107
+ ...lookup.value,
108
+ fields: lookup.value.fields.map(f => ({ ...f, location })),
109
+ location: this.location,
110
+ };
111
+ return locStruct;
112
+ }
113
+ else {
114
+ this.log('`connection_name.sql(...)` can currently only be used in top level source/query definitions');
115
+ return error_factory_1.ErrorFactory.structDef;
63
116
  }
64
- this.log(`Cannot use 'from_sql()' to reference '${this.refName}'`);
65
117
  }
66
118
  }
67
119
  exports.SQLSource = SQLSource;
@@ -10,10 +10,12 @@ export declare class SQLStatement extends MalloyElement implements DocStatement
10
10
  requestBlock?: SQLBlockSource;
11
11
  constructor(select: SQLString);
12
12
  sqlBlock(): SQLBlockSource;
13
+ private lookupCompiledSQL;
14
+ needs(doc: Document): ModelDataRequest;
13
15
  /**
14
16
  * This is the one statement which pauses execution. First time through
15
17
  * it will generate a schema request, next time through it will either
16
18
  * record the error or record the schema.
17
19
  */
18
- execute(doc: Document): ModelDataRequest;
20
+ execute(doc: Document): void;
19
21
  }
@@ -38,21 +38,36 @@ class SQLStatement extends malloy_element_1.MalloyElement {
38
38
  }
39
39
  return this.requestBlock;
40
40
  }
41
+ lookupCompiledSQL(sql) {
42
+ var _a;
43
+ const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
44
+ if (!sqlDefEntry)
45
+ return;
46
+ sqlDefEntry.reference(sql.name, this.location);
47
+ return sqlDefEntry.getEntry(sql.name);
48
+ }
49
+ needs(doc) {
50
+ const sql = this.sqlBlock();
51
+ const lookup = this.lookupCompiledSQL(sql);
52
+ if ((lookup === null || lookup === void 0 ? void 0 : lookup.status) === 'reference') {
53
+ return {
54
+ compileSQL: sql,
55
+ partialModel: this.select.containsQueries ? doc.modelDef() : undefined,
56
+ };
57
+ }
58
+ }
41
59
  /**
42
60
  * This is the one statement which pauses execution. First time through
43
61
  * it will generate a schema request, next time through it will either
44
62
  * record the error or record the schema.
45
63
  */
46
64
  execute(doc) {
47
- var _a;
48
- const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
49
- if (!sqlDefEntry) {
65
+ const sql = this.sqlBlock();
66
+ const lookup = this.lookupCompiledSQL(sql);
67
+ if (!lookup) {
50
68
  this.log("Cant't look up schema for sql block");
51
69
  return;
52
70
  }
53
- const sql = this.sqlBlock();
54
- sqlDefEntry.reference(sql.name, this.location);
55
- const lookup = sqlDefEntry.getEntry(sql.name);
56
71
  if (lookup.status === 'error') {
57
72
  const msgLines = lookup.message.split(/\r?\n/);
58
73
  this.select.log('Invalid SQL, ' + msgLines.join('\n '));
@@ -70,10 +85,6 @@ class SQLStatement extends malloy_element_1.MalloyElement {
70
85
  }
71
86
  return undefined;
72
87
  }
73
- return {
74
- compileSQL: sql,
75
- partialModel: this.select.containsQueries ? doc.modelDef() : undefined,
76
- };
77
88
  }
78
89
  }
79
90
  exports.SQLStatement = SQLStatement;
@@ -6,6 +6,7 @@ export declare class SQLString extends MalloyElement {
6
6
  elementType: string;
7
7
  elements: SQLStringSegment[];
8
8
  containsQueries: boolean;
9
+ complete(): void;
9
10
  push(el: string | MalloyElement): void;
10
11
  sqlPhrases(): SQLPhrase[];
11
12
  }
@@ -32,6 +32,11 @@ class SQLString extends malloy_element_1.MalloyElement {
32
32
  this.elements = [];
33
33
  this.containsQueries = false;
34
34
  }
35
+ complete() {
36
+ this.has({
37
+ queries: this.elements.filter(isMalloyElement),
38
+ });
39
+ }
35
40
  push(el) {
36
41
  if (typeof el === 'string') {
37
42
  if (el.length > 0) {
@@ -57,4 +62,7 @@ class SQLString extends malloy_element_1.MalloyElement {
57
62
  }
58
63
  }
59
64
  exports.SQLString = SQLString;
65
+ function isMalloyElement(x) {
66
+ return typeof x !== 'string' && (0, query_element_1.isQueryElement)(x);
67
+ }
60
68
  //# sourceMappingURL=sql-string.js.map
@@ -42,9 +42,10 @@ export declare abstract class MalloyElement {
42
42
  */
43
43
  toString(): string;
44
44
  private stringify;
45
- walk(callBack: (node: MalloyElement) => void): void;
45
+ walk(): Generator<MalloyElement>;
46
46
  private varInfo;
47
47
  protected internalError(msg: string): Error;
48
+ needs(doc: Document): ModelDataRequest | undefined;
48
49
  }
49
50
  export declare class Unimplemented extends MalloyElement {
50
51
  elementType: string;
@@ -60,9 +61,10 @@ export declare class ModelEntryReference extends MalloyElement {
60
61
  toString(): string;
61
62
  }
62
63
  export interface DocStatement extends MalloyElement {
63
- execute(doc: Document): ModelDataRequest;
64
+ execute(doc: Document): void;
64
65
  }
65
66
  export declare function isDocStatement(e: MalloyElement): e is DocStatement;
67
+ export declare function isDocStatementOrDocStatementList(el: MalloyElement): el is DocStatement | DocStatementList;
66
68
  export declare abstract class ListOf<ET extends MalloyElement> extends MalloyElement {
67
69
  protected elements: ET[];
68
70
  constructor(elements: ET[]);
@@ -71,8 +73,9 @@ export declare abstract class ListOf<ET extends MalloyElement> extends MalloyEle
71
73
  empty(): boolean;
72
74
  notEmpty(): boolean;
73
75
  push(...el: ET[]): ET[];
76
+ needs(doc: Document): ModelDataRequest | undefined;
74
77
  }
75
- export declare class RunList extends ListOf<DocStatement> implements Noteable {
78
+ export declare class DocStatementList extends ListOf<DocStatement | DocStatementList> implements Noteable {
76
79
  elementType: string;
77
80
  execCursor: number;
78
81
  readonly isNoteableObj = true;
@@ -100,10 +103,10 @@ export declare class Document extends MalloyElement implements NameSpace {
100
103
  documentModel: Record<string, ModelEntry>;
101
104
  queryList: Query[];
102
105
  sqlBlocks: SQLBlockStructDef[];
103
- statements: RunList;
106
+ statements: DocStatementList;
104
107
  didInitModel: boolean;
105
108
  notes: string[];
106
- constructor(statements: DocStatement[]);
109
+ constructor(statements: (DocStatement | DocStatementList)[]);
107
110
  initModelDef(extendingModelDef: ModelDef | undefined): void;
108
111
  compile(): DocumentCompileResult;
109
112
  modelDef(): ModelDef;
@@ -118,6 +121,6 @@ export declare class ObjectAnnotation extends MalloyElement {
118
121
  }
119
122
  export declare class ModelAnnotation extends ObjectAnnotation implements DocStatement {
120
123
  elementType: string;
121
- execute(doc: Document): ModelDataRequest;
124
+ execute(doc: Document): void;
122
125
  }
123
126
  export {};