@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.
- package/dist/index.d.ts +1 -1
- package/dist/lang/ast/elements/define-query.d.ts +3 -5
- package/dist/lang/ast/elements/define-query.js +1 -4
- package/dist/lang/ast/elements/define-source.d.ts +3 -5
- package/dist/lang/ast/elements/define-source.js +1 -4
- package/dist/lang/ast/elements/import-statement.d.ts +2 -1
- package/dist/lang/ast/elements/import-statement.js +12 -5
- package/dist/lang/ast/index.d.ts +1 -0
- package/dist/lang/ast/index.js +1 -0
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +1 -2
- package/dist/lang/ast/query-elements/anonymous-query.js +0 -1
- package/dist/lang/ast/query-elements/run-query.d.ts +3 -4
- package/dist/lang/ast/sources/from-sql-source.d.ts +7 -0
- package/dist/lang/ast/sources/from-sql-source.js +68 -0
- package/dist/lang/ast/sources/sql-source.d.ts +15 -4
- package/dist/lang/ast/sources/sql-source.js +79 -27
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +3 -1
- package/dist/lang/ast/sql-elements/sql-statement.js +21 -10
- package/dist/lang/ast/sql-elements/sql-string.d.ts +1 -0
- package/dist/lang/ast/sql-elements/sql-string.js +8 -0
- package/dist/lang/ast/types/malloy-element.d.ts +9 -6
- package/dist/lang/ast/types/malloy-element.js +42 -14
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +73 -72
- package/dist/lang/lib/Malloy/MalloyLexer.js +1078 -1072
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +86 -73
- package/dist/lang/lib/Malloy/MalloyParser.js +1198 -1135
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +13 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +8 -0
- package/dist/lang/malloy-to-ast.d.ts +3 -2
- package/dist/lang/malloy-to-ast.js +17 -3
- package/dist/lang/parse-malloy.js +3 -3
- package/dist/lang/test/parse.spec.js +88 -1
- package/dist/lang/zone.d.ts +1 -1
- package/dist/malloy.js +1 -1
- package/dist/tags.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { NamedSourceContext } from "./MalloyParser";
|
|
|
5
5
|
import { TableSourceContext } from "./MalloyParser";
|
|
6
6
|
import { QuerySourceContext } from "./MalloyParser";
|
|
7
7
|
import { SQLSourceNameContext } from "./MalloyParser";
|
|
8
|
+
import { SQLSourceContext } from "./MalloyParser";
|
|
8
9
|
import { LiteralTimestampContext } from "./MalloyParser";
|
|
9
10
|
import { LiteralHourContext } from "./MalloyParser";
|
|
10
11
|
import { LiteralDayContext } from "./MalloyParser";
|
|
@@ -271,6 +272,18 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
271
272
|
* @param ctx the parse tree
|
|
272
273
|
*/
|
|
273
274
|
exitSQLSourceName?: (ctx: SQLSourceNameContext) => void;
|
|
275
|
+
/**
|
|
276
|
+
* Enter a parse tree produced by the `SQLSource`
|
|
277
|
+
* labeled alternative in `MalloyParser.exploreSource`.
|
|
278
|
+
* @param ctx the parse tree
|
|
279
|
+
*/
|
|
280
|
+
enterSQLSource?: (ctx: SQLSourceContext) => void;
|
|
281
|
+
/**
|
|
282
|
+
* Exit a parse tree produced by the `SQLSource`
|
|
283
|
+
* labeled alternative in `MalloyParser.exploreSource`.
|
|
284
|
+
* @param ctx the parse tree
|
|
285
|
+
*/
|
|
286
|
+
exitSQLSource?: (ctx: SQLSourceContext) => void;
|
|
274
287
|
/**
|
|
275
288
|
* Enter a parse tree produced by the `literalTimestamp`
|
|
276
289
|
* labeled alternative in `MalloyParser.dateLiteral`.
|
|
@@ -5,6 +5,7 @@ import { NamedSourceContext } from "./MalloyParser";
|
|
|
5
5
|
import { TableSourceContext } from "./MalloyParser";
|
|
6
6
|
import { QuerySourceContext } from "./MalloyParser";
|
|
7
7
|
import { SQLSourceNameContext } from "./MalloyParser";
|
|
8
|
+
import { SQLSourceContext } from "./MalloyParser";
|
|
8
9
|
import { LiteralTimestampContext } from "./MalloyParser";
|
|
9
10
|
import { LiteralHourContext } from "./MalloyParser";
|
|
10
11
|
import { LiteralDayContext } from "./MalloyParser";
|
|
@@ -244,6 +245,13 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
|
244
245
|
* @return the visitor result
|
|
245
246
|
*/
|
|
246
247
|
visitSQLSourceName?: (ctx: SQLSourceNameContext) => Result;
|
|
248
|
+
/**
|
|
249
|
+
* Visit a parse tree produced by the `SQLSource`
|
|
250
|
+
* labeled alternative in `MalloyParser.exploreSource`.
|
|
251
|
+
* @param ctx the parse tree
|
|
252
|
+
* @return the visitor result
|
|
253
|
+
*/
|
|
254
|
+
visitSQLSource?: (ctx: SQLSourceContext) => Result;
|
|
247
255
|
/**
|
|
248
256
|
* Visit a parse tree produced by the `literalTimestamp`
|
|
249
257
|
* labeled alternative in `MalloyParser.dateLiteral`.
|
|
@@ -68,7 +68,8 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
68
68
|
visitTableFunction(pcx: parse.TableFunctionContext): ast.TableSource;
|
|
69
69
|
visitTableMethod(pcx: parse.TableMethodContext): ast.TableSource;
|
|
70
70
|
visitTableSource(pcx: parse.TableSourceContext): ast.TableSource;
|
|
71
|
-
visitSQLSourceName(pcx: parse.SQLSourceNameContext): ast.
|
|
71
|
+
visitSQLSourceName(pcx: parse.SQLSourceNameContext): ast.FromSQLSource;
|
|
72
|
+
visitSQLSource(pcx: parse.SQLSourceContext): ast.SQLSource;
|
|
72
73
|
visitQuerySource(pcx: parse.QuerySourceContext): ast.Source;
|
|
73
74
|
visitDefJoinMany(pcx: parse.DefJoinManyContext): ast.Joins;
|
|
74
75
|
visitDefJoinOne(pcx: parse.DefJoinOneContext): ast.Joins;
|
|
@@ -122,7 +123,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
122
123
|
protected buildPipelineFromName(pipe: ast.TurtleHeadedPipe, pipeCx: parse.PipelineFromNameContext): void;
|
|
123
124
|
visitExploreArrowQuery(pcx: parse.ExploreArrowQueryContext): ast.FullQuery;
|
|
124
125
|
visitArrowQuery(pcx: parse.ArrowQueryContext): ast.ExistingQuery;
|
|
125
|
-
visitTopLevelQueryDefs(pcx: parse.TopLevelQueryDefsContext): ast.
|
|
126
|
+
visitTopLevelQueryDefs(pcx: parse.TopLevelQueryDefsContext): ast.DefineQueryList;
|
|
126
127
|
visitTopLevelQueryDef(pcx: parse.TopLevelQueryDefContext): ast.DefineQuery;
|
|
127
128
|
visitAnonymousQuery(pcx: parse.AnonymousQueryContext): ast.AnonymousQuery;
|
|
128
129
|
visitRunStatementDef(pcx: parse.RunStatementDefContext): ast.RunQueryDef;
|
|
@@ -213,6 +213,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
213
213
|
}
|
|
214
214
|
const lastChars = (_a = pcx.SQL_END()) === null || _a === void 0 ? void 0 : _a.text.slice(0, -3);
|
|
215
215
|
sqlStr.push(lastChars || '');
|
|
216
|
+
sqlStr.complete();
|
|
216
217
|
this.astAt(sqlStr, pcx);
|
|
217
218
|
}
|
|
218
219
|
/**
|
|
@@ -229,7 +230,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
229
230
|
return this.astAt(def, pcx);
|
|
230
231
|
}
|
|
231
232
|
visitMalloyDocument(pcx) {
|
|
232
|
-
const stmts = this.only(pcx.malloyStatement().map(scx => this.visit(scx)), x => ast.
|
|
233
|
+
const stmts = this.only(pcx.malloyStatement().map(scx => this.visit(scx)), x => ast.isDocStatementOrDocStatementList(x) && x, 'statement');
|
|
233
234
|
return new ast.Document(stmts);
|
|
234
235
|
}
|
|
235
236
|
visitDefineSourceStatement(pcx) {
|
|
@@ -286,7 +287,16 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
286
287
|
}
|
|
287
288
|
visitSQLSourceName(pcx) {
|
|
288
289
|
const name = this.getModelEntryName(pcx.sqlExploreNameRef());
|
|
289
|
-
return this.astAt(new ast.
|
|
290
|
+
return this.astAt(new ast.FromSQLSource(name), pcx);
|
|
291
|
+
}
|
|
292
|
+
visitSQLSource(pcx) {
|
|
293
|
+
const connId = pcx.connectionId();
|
|
294
|
+
const connectionName = this.astAt(this.getModelEntryName(connId), connId);
|
|
295
|
+
const sqlStr = new ast.SQLString();
|
|
296
|
+
const selCx = pcx.sqlString();
|
|
297
|
+
this.makeSqlString(selCx, sqlStr);
|
|
298
|
+
const expr = new ast.SQLSource(connectionName, sqlStr);
|
|
299
|
+
return this.astAt(expr, pcx);
|
|
290
300
|
}
|
|
291
301
|
visitQuerySource(pcx) {
|
|
292
302
|
const query = this.visit(pcx.query());
|
|
@@ -1111,7 +1121,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1111
1121
|
stmt.connection = connectionName;
|
|
1112
1122
|
}
|
|
1113
1123
|
stmt.is = blockName;
|
|
1114
|
-
|
|
1124
|
+
const result = this.astAt(stmt, pcx);
|
|
1125
|
+
if (ENABLE_M4_WARNINGS) {
|
|
1126
|
+
this.astError(result, '`sql:` statement is deprecated, use `connection_name.sql(...)` instead', 'warn');
|
|
1127
|
+
}
|
|
1128
|
+
return result;
|
|
1115
1129
|
}
|
|
1116
1130
|
visitSampleStatement(pcx) {
|
|
1117
1131
|
const rowCx = pcx.sampleSpec().INTEGER_LITERAL();
|
|
@@ -301,8 +301,8 @@ class ASTStep {
|
|
|
301
301
|
// instead of in the parse step. Note to myself, do that someday.
|
|
302
302
|
const sqlExplores = {};
|
|
303
303
|
if (!this.walked) {
|
|
304
|
-
newAst.walk(
|
|
305
|
-
if (walkedTo instanceof ast.
|
|
304
|
+
for (const walkedTo of newAst.walk()) {
|
|
305
|
+
if (walkedTo instanceof ast.FromSQLSource) {
|
|
306
306
|
if (!sqlExplores[walkedTo.refName]) {
|
|
307
307
|
sqlExplores[walkedTo.refName] = {};
|
|
308
308
|
}
|
|
@@ -317,7 +317,7 @@ class ASTStep {
|
|
|
317
317
|
else if (walkedTo instanceof ast.Unimplemented) {
|
|
318
318
|
walkedTo.log('INTERNAL COMPILER ERROR: Untranslated parse node');
|
|
319
319
|
}
|
|
320
|
-
}
|
|
320
|
+
}
|
|
321
321
|
this.walked = true;
|
|
322
322
|
}
|
|
323
323
|
// If there is a partial ast ...
|
|
@@ -1695,7 +1695,7 @@ function getSelectOneStruct(sqlBlock) {
|
|
|
1695
1695
|
return {
|
|
1696
1696
|
type: 'struct',
|
|
1697
1697
|
name: sqlBlock.name,
|
|
1698
|
-
dialect: '
|
|
1698
|
+
dialect: 'standardsql',
|
|
1699
1699
|
structSource: {
|
|
1700
1700
|
type: 'sql',
|
|
1701
1701
|
method: 'subquery',
|
|
@@ -2770,4 +2770,91 @@ describe('raw function call with type specified', () => {
|
|
|
2770
2770
|
expect('timestamp_seconds!timestamp(0)').toReturnType('timestamp');
|
|
2771
2771
|
});
|
|
2772
2772
|
});
|
|
2773
|
+
describe('sql expressions', () => {
|
|
2774
|
+
test('reference to sql expression in unextended source', () => {
|
|
2775
|
+
const m = (0, test_translator_1.model) `
|
|
2776
|
+
source: na is bigquery.sql("""SELECT 1 as one""")
|
|
2777
|
+
`;
|
|
2778
|
+
expect(m).toParse();
|
|
2779
|
+
const compileSql = m.translator.translate().compileSQL;
|
|
2780
|
+
expect(compileSql).toBeDefined();
|
|
2781
|
+
if (compileSql) {
|
|
2782
|
+
m.translator.update({
|
|
2783
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
2784
|
+
});
|
|
2785
|
+
expect(m).toTranslate();
|
|
2786
|
+
}
|
|
2787
|
+
});
|
|
2788
|
+
test('reference to sql expression in extended source', () => {
|
|
2789
|
+
const m = (0, test_translator_1.model) `
|
|
2790
|
+
source: na is bigquery.sql("""SELECT 1 as one""") {
|
|
2791
|
+
dimension: two is one + one
|
|
2792
|
+
}
|
|
2793
|
+
`;
|
|
2794
|
+
const compileSql = m.translator.translate().compileSQL;
|
|
2795
|
+
expect(compileSql).toBeDefined();
|
|
2796
|
+
if (compileSql) {
|
|
2797
|
+
m.translator.update({
|
|
2798
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
2799
|
+
});
|
|
2800
|
+
expect(m).toTranslate();
|
|
2801
|
+
}
|
|
2802
|
+
});
|
|
2803
|
+
test('reference to sql expression in named query', () => {
|
|
2804
|
+
const m = new test_translator_1.TestTranslator(`
|
|
2805
|
+
query: nq is bigquery.sql("""SELECT 1 as one""") -> { project: * }
|
|
2806
|
+
`);
|
|
2807
|
+
expect(m).toParse();
|
|
2808
|
+
const compileSql = m.translate().compileSQL;
|
|
2809
|
+
expect(compileSql).toBeDefined();
|
|
2810
|
+
if (compileSql) {
|
|
2811
|
+
m.update({
|
|
2812
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
2813
|
+
});
|
|
2814
|
+
expect(m).toTranslate();
|
|
2815
|
+
}
|
|
2816
|
+
});
|
|
2817
|
+
test('reference to sql expression in unnamed query', () => {
|
|
2818
|
+
const m = new test_translator_1.TestTranslator(`
|
|
2819
|
+
query: bigquery.sql("""SELECT 1 as one""") -> { project: * }
|
|
2820
|
+
`);
|
|
2821
|
+
expect(m).toParse();
|
|
2822
|
+
const compileSql = m.translate().compileSQL;
|
|
2823
|
+
expect(compileSql).toBeDefined();
|
|
2824
|
+
if (compileSql) {
|
|
2825
|
+
m.update({
|
|
2826
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
2827
|
+
});
|
|
2828
|
+
expect(m).toTranslate();
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2831
|
+
test('reference to sql expression in join', () => {
|
|
2832
|
+
const m = (0, test_translator_1.model) `
|
|
2833
|
+
source: quux is a {
|
|
2834
|
+
join_one: xyzzy is
|
|
2835
|
+
duckdb.sql("""SELECT 1 as one""")
|
|
2836
|
+
on ai = xyzzy.one
|
|
2837
|
+
}
|
|
2838
|
+
`;
|
|
2839
|
+
const compileSql = m.translator.translate().compileSQL;
|
|
2840
|
+
expect(compileSql).toBeDefined();
|
|
2841
|
+
if (compileSql) {
|
|
2842
|
+
m.translator.update({
|
|
2843
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
2844
|
+
});
|
|
2845
|
+
expect(m).toTranslate();
|
|
2846
|
+
}
|
|
2847
|
+
});
|
|
2848
|
+
// TODO unskip when ENABLE_M4_WARNINGS is turned into an annotation
|
|
2849
|
+
test.skip('sql statement deprecation warning', () => {
|
|
2850
|
+
const m = new test_translator_1.TestTranslator('sql: bad_sql is {select: """SELECT 1 as one"""}');
|
|
2851
|
+
const req = m.translate().compileSQL;
|
|
2852
|
+
if (req) {
|
|
2853
|
+
m.update({
|
|
2854
|
+
compileSQL: { [req.name]: getSelectOneStruct(req) },
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2857
|
+
expect(m).toTranslateWithWarnings('`sql:` statement is deprecated, use `connection_name.sql(...)` instead');
|
|
2858
|
+
});
|
|
2859
|
+
});
|
|
2773
2860
|
//# sourceMappingURL=parse.spec.js.map
|
package/dist/lang/zone.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ interface EntryErrored extends AllEntries {
|
|
|
17
17
|
status: 'error';
|
|
18
18
|
message: string;
|
|
19
19
|
}
|
|
20
|
-
declare type ZoneEntry<T> = EntryPresent<T> | ReferenceEntry | EntryErrored;
|
|
20
|
+
export declare type ZoneEntry<T> = EntryPresent<T> | ReferenceEntry | EntryErrored;
|
|
21
21
|
/**
|
|
22
22
|
* A Zone is a symbol table which may contain references to symbols
|
|
23
23
|
* which are not yet defined. This is used by the parser to track
|
package/dist/malloy.js
CHANGED
package/dist/tags.d.ts
CHANGED