@malloydata/malloy 0.0.86-dev230920165629 → 0.0.86-dev230922170928
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/lang/ast/field-space/query-spaces.js +3 -0
- package/dist/lang/ast/query-items/field-references.d.ts +1 -0
- package/dist/lang/ast/query-items/field-references.js +1 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +28 -10
- package/dist/lang/lib/Malloy/MalloyParser.js +1454 -1318
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +11 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +7 -0
- package/dist/lang/malloy-to-ast.js +9 -1
- package/dist/lang/test/query.spec.js +9 -0
- package/dist/malloy.js +11 -11
- package/package.json +1 -1
|
@@ -197,6 +197,7 @@ import { ArgumentListContext } from "./MalloyParser";
|
|
|
197
197
|
import { FieldNameListContext } from "./MalloyParser";
|
|
198
198
|
import { FieldCollectionContext } from "./MalloyParser";
|
|
199
199
|
import { CollectionWildCardContext } from "./MalloyParser";
|
|
200
|
+
import { StarQualifiedContext } from "./MalloyParser";
|
|
200
201
|
import { TaggedRefContext } from "./MalloyParser";
|
|
201
202
|
import { RefExprContext } from "./MalloyParser";
|
|
202
203
|
import { CollectionMemberContext } from "./MalloyParser";
|
|
@@ -2352,6 +2353,16 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
2352
2353
|
* @param ctx the parse tree
|
|
2353
2354
|
*/
|
|
2354
2355
|
exitCollectionWildCard?: (ctx: CollectionWildCardContext) => void;
|
|
2356
|
+
/**
|
|
2357
|
+
* Enter a parse tree produced by `MalloyParser.starQualified`.
|
|
2358
|
+
* @param ctx the parse tree
|
|
2359
|
+
*/
|
|
2360
|
+
enterStarQualified?: (ctx: StarQualifiedContext) => void;
|
|
2361
|
+
/**
|
|
2362
|
+
* Exit a parse tree produced by `MalloyParser.starQualified`.
|
|
2363
|
+
* @param ctx the parse tree
|
|
2364
|
+
*/
|
|
2365
|
+
exitStarQualified?: (ctx: StarQualifiedContext) => void;
|
|
2355
2366
|
/**
|
|
2356
2367
|
* Enter a parse tree produced by `MalloyParser.taggedRef`.
|
|
2357
2368
|
* @param ctx the parse tree
|
|
@@ -197,6 +197,7 @@ import { ArgumentListContext } from "./MalloyParser";
|
|
|
197
197
|
import { FieldNameListContext } from "./MalloyParser";
|
|
198
198
|
import { FieldCollectionContext } from "./MalloyParser";
|
|
199
199
|
import { CollectionWildCardContext } from "./MalloyParser";
|
|
200
|
+
import { StarQualifiedContext } from "./MalloyParser";
|
|
200
201
|
import { TaggedRefContext } from "./MalloyParser";
|
|
201
202
|
import { RefExprContext } from "./MalloyParser";
|
|
202
203
|
import { CollectionMemberContext } from "./MalloyParser";
|
|
@@ -1483,6 +1484,12 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
|
1483
1484
|
* @return the visitor result
|
|
1484
1485
|
*/
|
|
1485
1486
|
visitCollectionWildCard?: (ctx: CollectionWildCardContext) => Result;
|
|
1487
|
+
/**
|
|
1488
|
+
* Visit a parse tree produced by `MalloyParser.starQualified`.
|
|
1489
|
+
* @param ctx the parse tree
|
|
1490
|
+
* @return the visitor result
|
|
1491
|
+
*/
|
|
1492
|
+
visitStarQualified?: (ctx: StarQualifiedContext) => Result;
|
|
1486
1493
|
/**
|
|
1487
1494
|
* Visit a parse tree produced by `MalloyParser.taggedRef`.
|
|
1488
1495
|
* @param ctx the parse tree
|
|
@@ -737,11 +737,19 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
737
737
|
return stmt;
|
|
738
738
|
}
|
|
739
739
|
visitCollectionWildCard(pcx) {
|
|
740
|
+
var _a;
|
|
740
741
|
const nameCx = pcx.fieldPath();
|
|
741
742
|
const join = nameCx
|
|
742
743
|
? this.getFieldPath(nameCx, ast.ProjectFieldReference)
|
|
743
744
|
: undefined;
|
|
744
|
-
|
|
745
|
+
const wild = this.astAt(new ast.WildcardFieldReference(join), pcx);
|
|
746
|
+
const exceptStmts = ((_a = pcx.starQualified()) === null || _a === void 0 ? void 0 : _a.fieldNameList()) || [];
|
|
747
|
+
for (const except of exceptStmts) {
|
|
748
|
+
for (const exceptThis of except.fieldName()) {
|
|
749
|
+
wild.except.add((0, parse_utils_1.getId)(exceptThis));
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return wild;
|
|
745
753
|
}
|
|
746
754
|
visitIndexFields(pcx) {
|
|
747
755
|
const refList = pcx.indexElement().map(el => {
|
|
@@ -654,6 +654,15 @@ describe('query:', () => {
|
|
|
654
654
|
const fields = query.pipeline[0].fields;
|
|
655
655
|
expect(fields.sort()).toEqual(afields.map(f => `b.${f}`));
|
|
656
656
|
});
|
|
657
|
+
test('expands star with exclusions', () => {
|
|
658
|
+
const selstar = (0, test_translator_1.model) `run: ab->{select: * { except: ai, except: aun, aweird }}`;
|
|
659
|
+
const filterdFields = afields.filter(f => f !== 'ai' && f !== 'aun' && f !== 'aweird');
|
|
660
|
+
expect(selstar).toTranslate();
|
|
661
|
+
const query = selstar.translator.getQuery(0);
|
|
662
|
+
expect(query).toBeDefined();
|
|
663
|
+
const fields = query.pipeline[0].fields;
|
|
664
|
+
expect(fields.sort()).toEqual(filterdFields);
|
|
665
|
+
});
|
|
657
666
|
test('star error checking', () => {
|
|
658
667
|
expect((0, test_translator_1.markSource) `run: a->{select: ${'zzz'}.*}`).translationToFailWith("No such field as 'zzz'");
|
|
659
668
|
expect((0, test_translator_1.markSource) `run: ab->{select: b.${'zzz'}.*}`).translationToFailWith("No such field as 'zzz'");
|
package/dist/malloy.js
CHANGED
|
@@ -178,10 +178,13 @@ class Malloy {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
static compileSQLBlock(partialModel, toCompile) {
|
|
181
|
-
let queryModel;
|
|
182
|
-
|
|
181
|
+
let queryModel = undefined;
|
|
182
|
+
let selectStr = '';
|
|
183
|
+
let parenAlready = false;
|
|
184
|
+
for (const segment of toCompile.select) {
|
|
183
185
|
if ((0, model_1.isSQLFragment)(segment)) {
|
|
184
|
-
|
|
186
|
+
selectStr += segment.sql;
|
|
187
|
+
parenAlready = segment.sql.match(/\(\s*$/) !== null;
|
|
185
188
|
}
|
|
186
189
|
else {
|
|
187
190
|
// TODO catch exceptions and throw errors ...
|
|
@@ -191,16 +194,13 @@ class Malloy {
|
|
|
191
194
|
}
|
|
192
195
|
queryModel = new model_1.QueryModel(partialModel);
|
|
193
196
|
}
|
|
194
|
-
|
|
197
|
+
const compiledSql = queryModel.compileQuery(segment, false).sql;
|
|
198
|
+
selectStr += parenAlready ? compiledSql : `(${compiledSql})`;
|
|
199
|
+
parenAlready = false;
|
|
195
200
|
}
|
|
196
|
-
}
|
|
201
|
+
}
|
|
197
202
|
const { name, connection } = toCompile;
|
|
198
|
-
return {
|
|
199
|
-
type: 'sqlBlock',
|
|
200
|
-
name,
|
|
201
|
-
connection,
|
|
202
|
-
selectStr: sqlStrings.join(''),
|
|
203
|
-
};
|
|
203
|
+
return { type: 'sqlBlock', name, connection, selectStr };
|
|
204
204
|
}
|
|
205
205
|
static async run({ connections, preparedResult, sqlStruct, connection, options, }) {
|
|
206
206
|
const sqlBlock = sqlStruct === null || sqlStruct === void 0 ? void 0 : sqlStruct.structSource.sqlBlock;
|