@malloydata/malloy 0.0.132-dev240315233415 → 0.0.132-dev240318200933
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -4
- package/dist/lang/ast/index.d.ts +0 -2
- package/dist/lang/ast/index.js +0 -2
- package/dist/lang/index.d.ts +0 -2
- package/dist/lang/index.js +1 -3
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +125 -127
- package/dist/lang/lib/Malloy/MalloyLexer.js +1000 -1017
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +245 -287
- package/dist/lang/lib/Malloy/MalloyParser.js +1808 -2072
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +0 -33
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +0 -21
- package/dist/lang/malloy-to-ast.d.ts +0 -2
- package/dist/lang/malloy-to-ast.js +0 -35
- package/dist/lang/parse-malloy.js +5 -41
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +0 -10
- package/dist/lang/test/locations.spec.js +0 -23
- package/dist/lang/test/parse.spec.js +0 -11
- package/dist/lang/test/sql-block.spec.js +2 -81
- package/dist/lang/translate-response.d.ts +0 -2
- package/dist/malloy.d.ts +1 -29
- package/dist/malloy.js +1 -37
- package/package.json +1 -1
- package/dist/lang/ast/source-elements/from-sql-source.d.ts +0 -7
- package/dist/lang/ast/source-elements/from-sql-source.js +0 -68
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +0 -21
- package/dist/lang/ast/sql-elements/sql-statement.js +0 -91
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +0 -83
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +0 -388
|
@@ -84,9 +84,6 @@ import { TopLevelAnonQueryDefContext } from "./MalloyParser";
|
|
|
84
84
|
import { TagsContext } from "./MalloyParser";
|
|
85
85
|
import { IsDefineContext } from "./MalloyParser";
|
|
86
86
|
import { RunStatementContext } from "./MalloyParser";
|
|
87
|
-
import { DefineSQLStatementContext } from "./MalloyParser";
|
|
88
|
-
import { SqlBlockContext } from "./MalloyParser";
|
|
89
|
-
import { BlockSQLDefContext } from "./MalloyParser";
|
|
90
87
|
import { SqlStringContext } from "./MalloyParser";
|
|
91
88
|
import { SqlInterpolationContext } from "./MalloyParser";
|
|
92
89
|
import { ImportStatementContext } from "./MalloyParser";
|
|
@@ -1216,36 +1213,6 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
1216
1213
|
* @param ctx the parse tree
|
|
1217
1214
|
*/
|
|
1218
1215
|
exitRunStatement?: (ctx: RunStatementContext) => void;
|
|
1219
|
-
/**
|
|
1220
|
-
* Enter a parse tree produced by `MalloyParser.defineSQLStatement`.
|
|
1221
|
-
* @param ctx the parse tree
|
|
1222
|
-
*/
|
|
1223
|
-
enterDefineSQLStatement?: (ctx: DefineSQLStatementContext) => void;
|
|
1224
|
-
/**
|
|
1225
|
-
* Exit a parse tree produced by `MalloyParser.defineSQLStatement`.
|
|
1226
|
-
* @param ctx the parse tree
|
|
1227
|
-
*/
|
|
1228
|
-
exitDefineSQLStatement?: (ctx: DefineSQLStatementContext) => void;
|
|
1229
|
-
/**
|
|
1230
|
-
* Enter a parse tree produced by `MalloyParser.sqlBlock`.
|
|
1231
|
-
* @param ctx the parse tree
|
|
1232
|
-
*/
|
|
1233
|
-
enterSqlBlock?: (ctx: SqlBlockContext) => void;
|
|
1234
|
-
/**
|
|
1235
|
-
* Exit a parse tree produced by `MalloyParser.sqlBlock`.
|
|
1236
|
-
* @param ctx the parse tree
|
|
1237
|
-
*/
|
|
1238
|
-
exitSqlBlock?: (ctx: SqlBlockContext) => void;
|
|
1239
|
-
/**
|
|
1240
|
-
* Enter a parse tree produced by `MalloyParser.blockSQLDef`.
|
|
1241
|
-
* @param ctx the parse tree
|
|
1242
|
-
*/
|
|
1243
|
-
enterBlockSQLDef?: (ctx: BlockSQLDefContext) => void;
|
|
1244
|
-
/**
|
|
1245
|
-
* Exit a parse tree produced by `MalloyParser.blockSQLDef`.
|
|
1246
|
-
* @param ctx the parse tree
|
|
1247
|
-
*/
|
|
1248
|
-
exitBlockSQLDef?: (ctx: BlockSQLDefContext) => void;
|
|
1249
1216
|
/**
|
|
1250
1217
|
* Enter a parse tree produced by `MalloyParser.sqlString`.
|
|
1251
1218
|
* @param ctx the parse tree
|
|
@@ -84,9 +84,6 @@ import { TopLevelAnonQueryDefContext } from "./MalloyParser";
|
|
|
84
84
|
import { TagsContext } from "./MalloyParser";
|
|
85
85
|
import { IsDefineContext } from "./MalloyParser";
|
|
86
86
|
import { RunStatementContext } from "./MalloyParser";
|
|
87
|
-
import { DefineSQLStatementContext } from "./MalloyParser";
|
|
88
|
-
import { SqlBlockContext } from "./MalloyParser";
|
|
89
|
-
import { BlockSQLDefContext } from "./MalloyParser";
|
|
90
87
|
import { SqlStringContext } from "./MalloyParser";
|
|
91
88
|
import { SqlInterpolationContext } from "./MalloyParser";
|
|
92
89
|
import { ImportStatementContext } from "./MalloyParser";
|
|
@@ -802,24 +799,6 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
|
802
799
|
* @return the visitor result
|
|
803
800
|
*/
|
|
804
801
|
visitRunStatement?: (ctx: RunStatementContext) => Result;
|
|
805
|
-
/**
|
|
806
|
-
* Visit a parse tree produced by `MalloyParser.defineSQLStatement`.
|
|
807
|
-
* @param ctx the parse tree
|
|
808
|
-
* @return the visitor result
|
|
809
|
-
*/
|
|
810
|
-
visitDefineSQLStatement?: (ctx: DefineSQLStatementContext) => Result;
|
|
811
|
-
/**
|
|
812
|
-
* Visit a parse tree produced by `MalloyParser.sqlBlock`.
|
|
813
|
-
* @param ctx the parse tree
|
|
814
|
-
* @return the visitor result
|
|
815
|
-
*/
|
|
816
|
-
visitSqlBlock?: (ctx: SqlBlockContext) => Result;
|
|
817
|
-
/**
|
|
818
|
-
* Visit a parse tree produced by `MalloyParser.blockSQLDef`.
|
|
819
|
-
* @param ctx the parse tree
|
|
820
|
-
* @return the visitor result
|
|
821
|
-
*/
|
|
822
|
-
visitBlockSQLDef?: (ctx: BlockSQLDefContext) => Result;
|
|
823
802
|
/**
|
|
824
803
|
* Visit a parse tree produced by `MalloyParser.sqlString`.
|
|
825
804
|
* @param ctx the parse tree
|
|
@@ -84,7 +84,6 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
84
84
|
visitExploreProperties(pcx: parse.ExplorePropertiesContext): ast.SourceDesc;
|
|
85
85
|
visitTableFunction(pcx: parse.TableFunctionContext): ast.TableSource;
|
|
86
86
|
visitTableMethod(pcx: parse.TableMethodContext): ast.TableSource;
|
|
87
|
-
protected getLegacySQLSouce(pcx: parse.SqlExploreNameRefContext): ast.FromSQLSource;
|
|
88
87
|
visitSqlSource(pcx: parse.SqlSourceContext): ast.SQLSource;
|
|
89
88
|
visitDefJoinMany(pcx: parse.DefJoinManyContext): ast.Joins;
|
|
90
89
|
visitDefJoinOne(pcx: parse.DefJoinOneContext): ast.Joins;
|
|
@@ -197,7 +196,6 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
197
196
|
visitLiteralYear(pcx: parse.LiteralYearContext): ast.ExpressionDef;
|
|
198
197
|
visitImportStatement(pcx: parse.ImportStatementContext): ast.ImportStatement;
|
|
199
198
|
visitJustExpr(pcx: parse.JustExprContext): ast.ExpressionDef;
|
|
200
|
-
visitDefineSQLStatement(pcx: parse.DefineSQLStatementContext): ast.SQLStatement;
|
|
201
199
|
visitSampleStatement(pcx: parse.SampleStatementContext): ast.SampleProperty;
|
|
202
200
|
visitDocAnnotations(pcx: parse.DocAnnotationsContext): ast.ModelAnnotation;
|
|
203
201
|
visitIgnoredObjectAnnotations(pcx: parse.IgnoredObjectAnnotationsContext): IgnoredElement;
|
|
@@ -313,11 +313,6 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
313
313
|
const tablePath = this.getPlainString(pcx.tablePath());
|
|
314
314
|
return this.astAt(new ast.TableMethodSource(connectionName, tablePath), pcx);
|
|
315
315
|
}
|
|
316
|
-
getLegacySQLSouce(pcx) {
|
|
317
|
-
const name = this.getModelEntryName(pcx);
|
|
318
|
-
const res = this.astAt(new ast.FromSQLSource(name), pcx);
|
|
319
|
-
return res;
|
|
320
|
-
}
|
|
321
316
|
visitSqlSource(pcx) {
|
|
322
317
|
const connId = pcx.connectionId();
|
|
323
318
|
const connectionName = this.astAt(this.getModelEntryName(connId), connId);
|
|
@@ -1168,36 +1163,6 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1168
1163
|
visitJustExpr(pcx) {
|
|
1169
1164
|
return this.getFieldExpr(pcx.fieldExpr());
|
|
1170
1165
|
}
|
|
1171
|
-
visitDefineSQLStatement(pcx) {
|
|
1172
|
-
var _a;
|
|
1173
|
-
const blockName = (_a = pcx.nameSQLBlock()) === null || _a === void 0 ? void 0 : _a.text;
|
|
1174
|
-
const blockParts = pcx.sqlBlock().blockSQLDef();
|
|
1175
|
-
const sqlStr = new ast.SQLString();
|
|
1176
|
-
let connectionName;
|
|
1177
|
-
for (const blockEnt of blockParts) {
|
|
1178
|
-
const nmCx = blockEnt.connectionName();
|
|
1179
|
-
if (nmCx) {
|
|
1180
|
-
if (connectionName) {
|
|
1181
|
-
this.contextError(nmCx, 'Cannot redefine connection');
|
|
1182
|
-
}
|
|
1183
|
-
else {
|
|
1184
|
-
connectionName = this.getPlainString(nmCx);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
const selCx = blockEnt.sqlString();
|
|
1188
|
-
if (selCx) {
|
|
1189
|
-
this.makeSqlString(selCx, sqlStr);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
const stmt = new ast.SQLStatement(sqlStr);
|
|
1193
|
-
if (connectionName !== undefined) {
|
|
1194
|
-
stmt.connection = connectionName;
|
|
1195
|
-
}
|
|
1196
|
-
stmt.is = blockName;
|
|
1197
|
-
const result = this.astAt(stmt, pcx);
|
|
1198
|
-
this.m4advisory(pcx, '`sql:` statement is deprecated, use `connection_name.sql(...)` instead');
|
|
1199
|
-
return result;
|
|
1200
|
-
}
|
|
1201
1166
|
visitSampleStatement(pcx) {
|
|
1202
1167
|
const rowCx = pcx.sampleSpec().INTEGER_LITERAL();
|
|
1203
1168
|
if (rowCx) {
|
|
@@ -55,7 +55,6 @@ const parse_log_1 = require("./parse-log");
|
|
|
55
55
|
const find_external_references_1 = require("./parse-tree-walkers/find-external-references");
|
|
56
56
|
const zone_1 = require("./zone");
|
|
57
57
|
const document_symbol_walker_1 = require("./parse-tree-walkers/document-symbol-walker");
|
|
58
|
-
const document_highlight_walker_1 = require("./parse-tree-walkers/document-highlight-walker");
|
|
59
58
|
const document_completion_walker_1 = require("./parse-tree-walkers/document-completion-walker");
|
|
60
59
|
const document_help_context_walker_1 = require("./parse-tree-walkers/document-help-context-walker");
|
|
61
60
|
const reference_list_1 = require("./reference-list");
|
|
@@ -299,48 +298,24 @@ class ASTStep {
|
|
|
299
298
|
const secondPass = new malloy_to_ast_1.MalloyToAST(parse, that.root.logger, that.compilerFlags);
|
|
300
299
|
const newAst = secondPass.visit(parse.root);
|
|
301
300
|
that.compilerFlags = secondPass.compilerFlags;
|
|
302
|
-
if (that.root.logger.hasErrors()) {
|
|
303
|
-
this.response = that.fatalResponse();
|
|
304
|
-
return this.response;
|
|
305
|
-
}
|
|
306
301
|
if (newAst.elementType === 'unimplemented') {
|
|
307
|
-
|
|
302
|
+
newAst.log('INTERNAL COMPILER ERROR: Untranslated parse node');
|
|
308
303
|
}
|
|
309
|
-
// I kind of think table refs should probably also be collected here
|
|
310
|
-
// instead of in the parse step. Note to myself, do that someday.
|
|
311
|
-
const sqlExplores = {};
|
|
312
304
|
if (!this.walked) {
|
|
305
|
+
// The DocumentStatement.needs method has largely replaced the need to walk
|
|
306
|
+
// the AST once it has been translated, this one check remains, though
|
|
307
|
+
// it should probably never be hit
|
|
313
308
|
for (const walkedTo of newAst.walk()) {
|
|
314
|
-
if (walkedTo instanceof ast.
|
|
315
|
-
if (!sqlExplores[walkedTo.refName]) {
|
|
316
|
-
sqlExplores[walkedTo.refName] = {};
|
|
317
|
-
}
|
|
318
|
-
sqlExplores[walkedTo.refName].ref = walkedTo;
|
|
319
|
-
}
|
|
320
|
-
else if (walkedTo instanceof ast.SQLStatement && walkedTo.is) {
|
|
321
|
-
if (!sqlExplores[walkedTo.is]) {
|
|
322
|
-
sqlExplores[walkedTo.is] = {};
|
|
323
|
-
}
|
|
324
|
-
sqlExplores[walkedTo.is].def = walkedTo;
|
|
325
|
-
}
|
|
326
|
-
else if (walkedTo instanceof ast.Unimplemented) {
|
|
309
|
+
if (walkedTo instanceof ast.Unimplemented) {
|
|
327
310
|
walkedTo.log('INTERNAL COMPILER ERROR: Untranslated parse node');
|
|
328
311
|
}
|
|
329
312
|
}
|
|
330
313
|
this.walked = true;
|
|
331
314
|
}
|
|
332
|
-
// If there is a partial ast ...
|
|
333
315
|
if (that.root.logger.hasErrors()) {
|
|
334
316
|
this.response = that.fatalResponse();
|
|
335
317
|
return this.response;
|
|
336
318
|
}
|
|
337
|
-
/*
|
|
338
|
-
TODO we used to scna the AST for SQL blocks here, don't need to do that
|
|
339
|
-
becausae that happens at the translate step, but the code I need to
|
|
340
|
-
understand is how a root translate can return the need of a chiold
|
|
341
|
-
which has an SQL block ...
|
|
342
|
-
|
|
343
|
-
*/
|
|
344
319
|
// Now make sure that every child has fully translated itself
|
|
345
320
|
// before this tree is ready to also translate ...
|
|
346
321
|
for (const child of that.childTranslators.values()) {
|
|
@@ -380,19 +355,8 @@ class MetadataStep {
|
|
|
380
355
|
catch {
|
|
381
356
|
// Do nothing, symbols already `undefined`
|
|
382
357
|
}
|
|
383
|
-
let walkHighlights;
|
|
384
|
-
try {
|
|
385
|
-
walkHighlights = (0, document_highlight_walker_1.walkForDocumentHighlights)(tryParse.parse.tokenStream, tryParse.parse.root);
|
|
386
|
-
}
|
|
387
|
-
catch {
|
|
388
|
-
walkHighlights = [];
|
|
389
|
-
}
|
|
390
358
|
this.response = {
|
|
391
359
|
symbols,
|
|
392
|
-
highlights: (0, document_highlight_walker_1.sortHighlights)([
|
|
393
|
-
...(0, document_highlight_walker_1.passForHighlights)(tryParse.parse.tokenStream),
|
|
394
|
-
...walkHighlights,
|
|
395
|
-
]),
|
|
396
360
|
final: true,
|
|
397
361
|
};
|
|
398
362
|
}
|
|
@@ -241,16 +241,6 @@ class DocumentSymbolWalker {
|
|
|
241
241
|
parent.children.push(symbol);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
enterDefineSQLStatement(pcx) {
|
|
245
|
-
const name = pcx.nameSQLBlock().text;
|
|
246
|
-
const symbol = {
|
|
247
|
-
range: this.translator.rangeFromContext(pcx),
|
|
248
|
-
name,
|
|
249
|
-
type: 'sql',
|
|
250
|
-
children: [],
|
|
251
|
-
};
|
|
252
|
-
this.symbols.push(symbol);
|
|
253
|
-
}
|
|
254
244
|
enterImportStatement(pcx) {
|
|
255
245
|
const name = (0, parse_utils_1.getStringIfShort)(pcx.importURL());
|
|
256
246
|
if (name) {
|
|
@@ -154,21 +154,6 @@ describe('source locations', () => {
|
|
|
154
154
|
expect(a.location).toMatchObject(source.locations[0]);
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
-
test('pre m4 location of named SQL block', () => {
|
|
158
|
-
const source = (0, test_translator_1.markSource) `##! -m4warnings\n${'sql: s is { select: """SELECT 1 as one""" }'}`;
|
|
159
|
-
const m = new test_translator_1.TestTranslator(source.code);
|
|
160
|
-
expect(m).toParse();
|
|
161
|
-
const compileSql = m.translate().compileSQL;
|
|
162
|
-
expect(compileSql).toBeDefined();
|
|
163
|
-
if (compileSql) {
|
|
164
|
-
m.update({
|
|
165
|
-
compileSQL: { [compileSql.name]: (0, test_translator_1.getSelectOneStruct)(compileSql) },
|
|
166
|
-
});
|
|
167
|
-
expect(m).toTranslate();
|
|
168
|
-
const s = m.sqlBlocks[0];
|
|
169
|
-
expect(s.location).isLocationIn(source.locations[0], source.code);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
157
|
test('location of renamed field', () => {
|
|
173
158
|
const source = (0, test_translator_1.markSource) `
|
|
174
159
|
source: na is a extend {
|
|
@@ -221,14 +206,6 @@ describe('source locations', () => {
|
|
|
221
206
|
const y = (0, test_translator_1.getFieldDef)(x, 'y');
|
|
222
207
|
expect(y.location).toMatchObject(source.locations[0]);
|
|
223
208
|
});
|
|
224
|
-
// Since """ strings are not single tokens, I don't know how to do this.
|
|
225
|
-
// test("multi line sql block token span is correct", () => {
|
|
226
|
-
// const sqlSource = `sql: { select: """// line 0\n//line 1\n// line 2""" }`;
|
|
227
|
-
// const m = new TestTranslator(sqlSource);
|
|
228
|
-
// expect(m).not.toParse();
|
|
229
|
-
// const errList = m.errors().errors;
|
|
230
|
-
// expect(errList[0].at?.range.end).toEqual({ line: 2, character: 11 });
|
|
231
|
-
// });
|
|
232
209
|
test('undefined query location', () => {
|
|
233
210
|
expect((0, test_translator_1.model) `run: ${'xyz'}`).translationToFailWith("Reference to undefined object 'xyz'");
|
|
234
211
|
});
|
|
@@ -571,17 +571,6 @@ describe('sql expressions', () => {
|
|
|
571
571
|
expect(m).toTranslate();
|
|
572
572
|
}
|
|
573
573
|
});
|
|
574
|
-
test('sql statement deprecation warning', () => {
|
|
575
|
-
const m = new test_translator_1.TestTranslator(`##! m4warnings=warn
|
|
576
|
-
sql: bad_sql is {select: """SELECT 1 as one"""}`);
|
|
577
|
-
const req = m.translate().compileSQL;
|
|
578
|
-
if (req) {
|
|
579
|
-
m.update({
|
|
580
|
-
compileSQL: { [req.name]: (0, test_translator_1.getSelectOneStruct)(req) },
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
expect(m).toTranslateWithWarnings('`sql:` statement is deprecated, use `connection_name.sql(...)` instead');
|
|
584
|
-
});
|
|
585
574
|
test('reference to sql expression in run', () => {
|
|
586
575
|
const m = new test_translator_1.TestTranslator(`
|
|
587
576
|
run: bigquery.sql("""select 1 as one""")
|
|
@@ -28,17 +28,7 @@ const sql_block_1 = require("../../model/sql_block");
|
|
|
28
28
|
const test_translator_1 = require("./test-translator");
|
|
29
29
|
require("./parse-expects");
|
|
30
30
|
const parse_malloy_1 = require("../parse-malloy");
|
|
31
|
-
|
|
32
|
-
const ret = { ...sd };
|
|
33
|
-
ret.fields = sd.fields.map(f => {
|
|
34
|
-
const nf = { ...f };
|
|
35
|
-
delete nf.location;
|
|
36
|
-
return nf;
|
|
37
|
-
});
|
|
38
|
-
delete ret.location;
|
|
39
|
-
return ret;
|
|
40
|
-
}
|
|
41
|
-
describe('sql:', () => {
|
|
31
|
+
describe('sql blocks in malloy', () => {
|
|
42
32
|
const selStmt = 'SELECT * FROM aTable';
|
|
43
33
|
function makeSchemaResponse(sql) {
|
|
44
34
|
const cname = sql.connection || 'bigquery';
|
|
@@ -59,37 +49,6 @@ describe('sql:', () => {
|
|
|
59
49
|
fields: test_translator_1.aTableDef.fields,
|
|
60
50
|
};
|
|
61
51
|
}
|
|
62
|
-
test('definition', () => {
|
|
63
|
-
const model = new test_translator_1.TestTranslator(`
|
|
64
|
-
##! -m4warnings
|
|
65
|
-
sql: users IS {
|
|
66
|
-
select: """${selStmt}"""
|
|
67
|
-
connection: "aConnection"
|
|
68
|
-
}
|
|
69
|
-
`);
|
|
70
|
-
const needReq = model.translate();
|
|
71
|
-
expect(model).toParse();
|
|
72
|
-
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
73
|
-
expect(needs).toBeDefined();
|
|
74
|
-
if (needs) {
|
|
75
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
76
|
-
expect(needs).toMatchObject(sql);
|
|
77
|
-
const refKey = needs.name;
|
|
78
|
-
expect(refKey).toBeDefined();
|
|
79
|
-
if (refKey) {
|
|
80
|
-
const sr = makeSchemaResponse(sql);
|
|
81
|
-
model.update({ compileSQL: { [refKey]: sr } });
|
|
82
|
-
expect(model).toTranslate();
|
|
83
|
-
const expectThis = unlocatedStructDef({ ...sr, as: 'users' });
|
|
84
|
-
if ((0, model_1.isSQLBlockStruct)(expectThis)) {
|
|
85
|
-
expectThis.declaredSQLBlock = true;
|
|
86
|
-
}
|
|
87
|
-
const got = unlocatedStructDef(model.sqlBlocks[0]);
|
|
88
|
-
delete got.modelAnnotation;
|
|
89
|
-
expect(got).toEqual(expectThis);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
52
|
test('source from sql', () => {
|
|
94
53
|
const model = new test_translator_1.TestTranslator(`
|
|
95
54
|
source: users is aConnection.sql("""${selStmt}""")
|
|
@@ -132,29 +91,7 @@ describe('sql:', () => {
|
|
|
132
91
|
});
|
|
133
92
|
it('simple turducken', () => {
|
|
134
93
|
const m = new test_translator_1.TestTranslator(`
|
|
135
|
-
|
|
136
|
-
sql: someSql is {
|
|
137
|
-
select: """SELECT * FROM %{ a -> { group_by: astr } } WHERE 1=1"""
|
|
138
|
-
}
|
|
139
|
-
`);
|
|
140
|
-
expect(m).toParse();
|
|
141
|
-
const compileSql = m.translate().compileSQL;
|
|
142
|
-
expect(compileSql).toBeDefined();
|
|
143
|
-
if (compileSql) {
|
|
144
|
-
const select = compileSql.select[0];
|
|
145
|
-
const star = compileSql.select[1];
|
|
146
|
-
const where = compileSql.select[2];
|
|
147
|
-
expect(select).toEqual({ sql: 'SELECT * FROM ' });
|
|
148
|
-
expect((0, model_1.isSQLFragment)(star)).toBeFalsy();
|
|
149
|
-
expect(where).toEqual({ sql: ' WHERE 1=1' });
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
it('old style ', () => {
|
|
153
|
-
const m = new test_translator_1.TestTranslator(`
|
|
154
|
-
##! -m4warnings
|
|
155
|
-
sql: someSql is {
|
|
156
|
-
select: """SELECT * FROM %{ a -> { group_by: astr } } WHERE 1=1"""
|
|
157
|
-
}
|
|
94
|
+
source: someSql is _db_.sql("""SELECT * FROM %{ a -> { group_by: astr } } WHERE 1=1""")
|
|
158
95
|
`);
|
|
159
96
|
expect(m).toParse();
|
|
160
97
|
const compileSql = m.translate().compileSQL;
|
|
@@ -200,22 +137,6 @@ describe('sql:', () => {
|
|
|
200
137
|
`);
|
|
201
138
|
expect(m).toParse();
|
|
202
139
|
});
|
|
203
|
-
it('model preserved', () => {
|
|
204
|
-
const shouldBeOK = `
|
|
205
|
-
##! -m4warnings
|
|
206
|
-
source: newa is a
|
|
207
|
-
sql: someSql is { select: """${selStmt}""" }
|
|
208
|
-
source: newaa is newa
|
|
209
|
-
`;
|
|
210
|
-
const model = new test_translator_1.TestTranslator(shouldBeOK);
|
|
211
|
-
expect(model).toParse();
|
|
212
|
-
const needReq = model.translate();
|
|
213
|
-
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
214
|
-
expect(needs).toBeDefined();
|
|
215
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
216
|
-
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
217
|
-
expect(model).toTranslate();
|
|
218
|
-
});
|
|
219
140
|
test('source from extended sql-based-source', () => {
|
|
220
141
|
var _a, _b;
|
|
221
142
|
const model = new test_translator_1.TestTranslator(`
|
|
@@ -2,7 +2,6 @@ import { Annotation, ModelDef, Query, SQLBlockSource, SQLBlockStructDef } from '
|
|
|
2
2
|
import { MalloyElement } from './ast';
|
|
3
3
|
import { LogMessage } from './parse-log';
|
|
4
4
|
import { DocumentSymbol } from './parse-tree-walkers/document-symbol-walker';
|
|
5
|
-
import { DocumentHighlight } from './parse-tree-walkers/document-highlight-walker';
|
|
6
5
|
import { DocumentCompletion } from './parse-tree-walkers/document-completion-walker';
|
|
7
6
|
import { DocumentHelpContext } from './parse-tree-walkers/document-help-context-walker';
|
|
8
7
|
/**
|
|
@@ -40,7 +39,6 @@ interface ASTData extends ProblemResponse, NeededData, FinalResponse {
|
|
|
40
39
|
export type ASTResponse = Partial<ASTData>;
|
|
41
40
|
interface Metadata extends NeededData, ProblemResponse, FinalResponse {
|
|
42
41
|
symbols: DocumentSymbol[];
|
|
43
|
-
highlights: DocumentHighlight[];
|
|
44
42
|
}
|
|
45
43
|
export type MetadataResponse = Partial<Metadata>;
|
|
46
44
|
interface ModelAnnotationData extends NeededData, ProblemResponse, FinalResponse {
|
package/dist/malloy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { RunSQLOptions } from './run_sql_options';
|
|
3
|
-
import { DocumentCompletion as DocumentCompletionDefinition,
|
|
3
|
+
import { DocumentCompletion as DocumentCompletionDefinition, DocumentSymbol as DocumentSymbolDefinition, LogMessage, MalloyTranslator } from './lang';
|
|
4
4
|
import { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-context-walker';
|
|
5
5
|
import { CompiledQuery, DocumentLocation, DocumentReference, FieldBooleanDef, FieldDateDef, FieldJSONDef, FieldNumberDef, FieldStringDef, FieldTimestampDef, FieldTypeDef, FilterExpression, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SQLBlock, SQLBlockSource, SQLBlockStructDef, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, FieldUnsupportedDef, QueryRunStats, ImportLocation, Annotation } from './model';
|
|
6
6
|
import { Connection, InfoConnection, LookupConnection, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
|
|
@@ -267,15 +267,6 @@ export declare class PreparedQuery implements Taggable {
|
|
|
267
267
|
export declare class Parse {
|
|
268
268
|
private translator;
|
|
269
269
|
constructor(translator: MalloyTranslator);
|
|
270
|
-
/**
|
|
271
|
-
* Retrieve the document highlights for the parsed document.
|
|
272
|
-
*
|
|
273
|
-
* These highlights represent the parsed tokens contained in the document,
|
|
274
|
-
* and may be used for syntax highlighting in an IDE, for example.
|
|
275
|
-
*
|
|
276
|
-
* @return An array of document highlights.
|
|
277
|
-
*/
|
|
278
|
-
get highlights(): DocumentHighlight[];
|
|
279
270
|
/**
|
|
280
271
|
* Retrieve the symbols defined in the parsed document.
|
|
281
272
|
*
|
|
@@ -295,25 +286,6 @@ export declare class Parse {
|
|
|
295
286
|
character: number;
|
|
296
287
|
}): DocumentHelpContext | undefined;
|
|
297
288
|
}
|
|
298
|
-
/**
|
|
299
|
-
* A document highlight.
|
|
300
|
-
*
|
|
301
|
-
* Represents a parsed token contained in a Malloy document
|
|
302
|
-
* and may be used for syntax highlighting in an IDE, for example.
|
|
303
|
-
*/
|
|
304
|
-
export declare class DocumentHighlight {
|
|
305
|
-
private _range;
|
|
306
|
-
private _type;
|
|
307
|
-
constructor(documentHighlight: DocumentHighlightDefinition);
|
|
308
|
-
/**
|
|
309
|
-
* @return The range of characters this highlight spans within its source document.
|
|
310
|
-
*/
|
|
311
|
-
get range(): DocumentRange;
|
|
312
|
-
/**
|
|
313
|
-
* @return The type of highlight, which may be any `HighlightType`.
|
|
314
|
-
*/
|
|
315
|
-
get type(): string;
|
|
316
|
-
}
|
|
317
289
|
/**
|
|
318
290
|
* A range of characters within a Malloy document.
|
|
319
291
|
*/
|
package/dist/malloy.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.CSVWriter = exports.JSONWriter = exports.DataWriter = exports.DataRecord = exports.DataArray = exports.Result = exports.ExploreMaterializer = exports.SQLBlockMaterializer = exports.PreparedResultMaterializer = exports.QueryMaterializer = exports.ModelMaterializer = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.Runtime = exports.ExploreField = exports.JoinRelationship = exports.QueryField = exports.Query = exports.StringField = exports.UnsupportedField = exports.JSONField = exports.BooleanField = exports.NumberField = exports.TimestampField = exports.DateField = exports.TimestampTimeframe = exports.DateTimeframe = exports.AtomicField = exports.AtomicFieldType = exports.Explore = exports.SourceRelationship = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.PreparedResult = exports.DocumentCompletion = exports.DocumentSymbol = exports.DocumentPosition = exports.DocumentRange = exports.
|
|
25
|
+
exports.CSVWriter = exports.JSONWriter = exports.DataWriter = exports.DataRecord = exports.DataArray = exports.Result = exports.ExploreMaterializer = exports.SQLBlockMaterializer = exports.PreparedResultMaterializer = exports.QueryMaterializer = exports.ModelMaterializer = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.Runtime = exports.ExploreField = exports.JoinRelationship = exports.QueryField = exports.Query = exports.StringField = exports.UnsupportedField = exports.JSONField = exports.BooleanField = exports.NumberField = exports.TimestampField = exports.DateField = exports.TimestampTimeframe = exports.DateTimeframe = exports.AtomicField = exports.AtomicFieldType = exports.Explore = exports.SourceRelationship = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.PreparedResult = exports.DocumentCompletion = exports.DocumentSymbol = exports.DocumentPosition = exports.DocumentRange = exports.Parse = exports.PreparedQuery = exports.Model = exports.MalloyError = exports.Malloy = void 0;
|
|
26
26
|
const lang_1 = require("./lang");
|
|
27
27
|
const model_1 = require("./model");
|
|
28
28
|
const luxon_1 = require("luxon");
|
|
@@ -546,17 +546,6 @@ class Parse {
|
|
|
546
546
|
constructor(translator) {
|
|
547
547
|
this.translator = translator;
|
|
548
548
|
}
|
|
549
|
-
/**
|
|
550
|
-
* Retrieve the document highlights for the parsed document.
|
|
551
|
-
*
|
|
552
|
-
* These highlights represent the parsed tokens contained in the document,
|
|
553
|
-
* and may be used for syntax highlighting in an IDE, for example.
|
|
554
|
-
*
|
|
555
|
-
* @return An array of document highlights.
|
|
556
|
-
*/
|
|
557
|
-
get highlights() {
|
|
558
|
-
return (this.translator.metadata().highlights || []).map(highlight => new DocumentHighlight(highlight));
|
|
559
|
-
}
|
|
560
549
|
/**
|
|
561
550
|
* Retrieve the symbols defined in the parsed document.
|
|
562
551
|
*
|
|
@@ -579,31 +568,6 @@ class Parse {
|
|
|
579
568
|
}
|
|
580
569
|
}
|
|
581
570
|
exports.Parse = Parse;
|
|
582
|
-
/**
|
|
583
|
-
* A document highlight.
|
|
584
|
-
*
|
|
585
|
-
* Represents a parsed token contained in a Malloy document
|
|
586
|
-
* and may be used for syntax highlighting in an IDE, for example.
|
|
587
|
-
*/
|
|
588
|
-
class DocumentHighlight {
|
|
589
|
-
constructor(documentHighlight) {
|
|
590
|
-
this._range = new DocumentRange(new DocumentPosition(documentHighlight.range.start.line, documentHighlight.range.start.character), new DocumentPosition(documentHighlight.range.end.line, documentHighlight.range.end.character));
|
|
591
|
-
this._type = documentHighlight.type;
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* @return The range of characters this highlight spans within its source document.
|
|
595
|
-
*/
|
|
596
|
-
get range() {
|
|
597
|
-
return this._range;
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* @return The type of highlight, which may be any `HighlightType`.
|
|
601
|
-
*/
|
|
602
|
-
get type() {
|
|
603
|
-
return this._type;
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
exports.DocumentHighlight = DocumentHighlight;
|
|
607
571
|
/**
|
|
608
572
|
* A range of characters within a Malloy document.
|
|
609
573
|
*/
|
package/package.json
CHANGED
|
@@ -1,68 +0,0 @@
|
|
|
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,21 +0,0 @@
|
|
|
1
|
-
import { SQLBlockSource } from '../../../model/malloy_types';
|
|
2
|
-
import { ModelDataRequest } from '../../translate-response';
|
|
3
|
-
import { DocStatement, Document, MalloyElement } from '../types/malloy-element';
|
|
4
|
-
import { SQLString } from './sql-string';
|
|
5
|
-
export declare class SQLStatement extends MalloyElement implements DocStatement {
|
|
6
|
-
readonly select: SQLString;
|
|
7
|
-
elementType: string;
|
|
8
|
-
is?: string;
|
|
9
|
-
connection?: string;
|
|
10
|
-
requestBlock?: SQLBlockSource;
|
|
11
|
-
constructor(select: SQLString);
|
|
12
|
-
sqlBlock(): SQLBlockSource;
|
|
13
|
-
private lookupCompiledSQL;
|
|
14
|
-
needs(doc: Document): ModelDataRequest;
|
|
15
|
-
/**
|
|
16
|
-
* This is the one statement which pauses execution. First time through
|
|
17
|
-
* it will generate a schema request, next time through it will either
|
|
18
|
-
* record the error or record the schema.
|
|
19
|
-
*/
|
|
20
|
-
execute(doc: Document): void;
|
|
21
|
-
}
|