@malloydata/malloy 0.0.310 → 0.0.311
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/dialect/pg_impl.js +6 -2
- package/dist/dialect/postgres/postgres.js +2 -1
- package/dist/lang/ast/field-space/refined-space.js +1 -1
- package/dist/lang/ast/field-space/rename-space-field.d.ts +3 -2
- package/dist/lang/ast/field-space/rename-space-field.js +16 -4
- package/dist/lang/ast/source-properties/renames.d.ts +9 -4
- package/dist/lang/ast/source-properties/renames.js +16 -2
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +7 -5
- package/dist/lang/lib/Malloy/MalloyParser.js +1537 -1521
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +5 -5
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +3 -3
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/malloy-to-ast.js +7 -3
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +1 -1
- package/dist/model/filter_compilers.js +11 -7
- package/dist/model/malloy_types.d.ts +1 -0
- package/dist/model/query_model_impl.js +9 -3
- package/dist/model/sql_block.js +2 -0
- package/dist/model/stage_writer.d.ts +3 -0
- package/dist/model/stage_writer.js +11 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -124,7 +124,7 @@ import { AccessModifierListContext } from "./MalloyParser";
|
|
|
124
124
|
import { DefMeasuresContext } from "./MalloyParser";
|
|
125
125
|
import { DefDimensionsContext } from "./MalloyParser";
|
|
126
126
|
import { RenameListContext } from "./MalloyParser";
|
|
127
|
-
import {
|
|
127
|
+
import { RenameEntryContext } from "./MalloyParser";
|
|
128
128
|
import { DefListContext } from "./MalloyParser";
|
|
129
129
|
import { FieldDefContext } from "./MalloyParser";
|
|
130
130
|
import { FieldNameDefContext } from "./MalloyParser";
|
|
@@ -1666,15 +1666,15 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
1666
1666
|
*/
|
|
1667
1667
|
exitRenameList?: (ctx: RenameListContext) => void;
|
|
1668
1668
|
/**
|
|
1669
|
-
* Enter a parse tree produced by `MalloyParser.
|
|
1669
|
+
* Enter a parse tree produced by `MalloyParser.renameEntry`.
|
|
1670
1670
|
* @param ctx the parse tree
|
|
1671
1671
|
*/
|
|
1672
|
-
|
|
1672
|
+
enterRenameEntry?: (ctx: RenameEntryContext) => void;
|
|
1673
1673
|
/**
|
|
1674
|
-
* Exit a parse tree produced by `MalloyParser.
|
|
1674
|
+
* Exit a parse tree produced by `MalloyParser.renameEntry`.
|
|
1675
1675
|
* @param ctx the parse tree
|
|
1676
1676
|
*/
|
|
1677
|
-
|
|
1677
|
+
exitRenameEntry?: (ctx: RenameEntryContext) => void;
|
|
1678
1678
|
/**
|
|
1679
1679
|
* Enter a parse tree produced by `MalloyParser.defList`.
|
|
1680
1680
|
* @param ctx the parse tree
|
|
@@ -124,7 +124,7 @@ import { AccessModifierListContext } from "./MalloyParser";
|
|
|
124
124
|
import { DefMeasuresContext } from "./MalloyParser";
|
|
125
125
|
import { DefDimensionsContext } from "./MalloyParser";
|
|
126
126
|
import { RenameListContext } from "./MalloyParser";
|
|
127
|
-
import {
|
|
127
|
+
import { RenameEntryContext } from "./MalloyParser";
|
|
128
128
|
import { DefListContext } from "./MalloyParser";
|
|
129
129
|
import { FieldDefContext } from "./MalloyParser";
|
|
130
130
|
import { FieldNameDefContext } from "./MalloyParser";
|
|
@@ -1085,11 +1085,11 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
|
1085
1085
|
*/
|
|
1086
1086
|
visitRenameList?: (ctx: RenameListContext) => Result;
|
|
1087
1087
|
/**
|
|
1088
|
-
* Visit a parse tree produced by `MalloyParser.
|
|
1088
|
+
* Visit a parse tree produced by `MalloyParser.renameEntry`.
|
|
1089
1089
|
* @param ctx the parse tree
|
|
1090
1090
|
* @return the visitor result
|
|
1091
1091
|
*/
|
|
1092
|
-
|
|
1092
|
+
visitRenameEntry?: (ctx: RenameEntryContext) => Result;
|
|
1093
1093
|
/**
|
|
1094
1094
|
* Visit a parse tree produced by `MalloyParser.defList`.
|
|
1095
1095
|
* @param ctx the parse tree
|
|
@@ -112,7 +112,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
112
112
|
getAccessLabelProp(pcx: parse.AccessLabelPropContext | undefined): AccessModifierLabel | undefined;
|
|
113
113
|
visitDefMeasures(pcx: parse.DefMeasuresContext): ast.Measures;
|
|
114
114
|
visitQueryExtend(pcx: parse.QueryExtendContext): ast.ExtendBlock;
|
|
115
|
-
|
|
115
|
+
visitRenameEntry(pcx: parse.RenameEntryContext): ast.RenameField;
|
|
116
116
|
visitDefExploreRename(pcx: parse.DefExploreRenameContext): ast.Renames;
|
|
117
117
|
visitFilterClauseList(pcx: parse.FilterClauseListContext): ast.Filter;
|
|
118
118
|
visitDrillClauseList(pcx: parse.FilterClauseListContext): ast.Drill;
|
|
@@ -526,17 +526,21 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
526
526
|
const el = new ast.ExtendBlock(extensions);
|
|
527
527
|
return this.astAt(el, pcx);
|
|
528
528
|
}
|
|
529
|
-
|
|
529
|
+
visitRenameEntry(pcx) {
|
|
530
530
|
const newName = pcx.fieldName(0);
|
|
531
531
|
const oldName = pcx.fieldName(1);
|
|
532
532
|
const rename = new ast.RenameField((0, parse_utils_1.getId)(newName), this.getFieldName(oldName));
|
|
533
|
+
const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
|
|
534
|
+
rename.extendNote({ notes });
|
|
533
535
|
return this.astAt(rename, pcx);
|
|
534
536
|
}
|
|
535
537
|
visitDefExploreRename(pcx) {
|
|
536
538
|
const accessLabel = this.getAccessLabel(pcx.accessLabel());
|
|
537
|
-
const rcxs = pcx.renameList().
|
|
538
|
-
const renames = rcxs.map(rcx => this.
|
|
539
|
+
const rcxs = pcx.renameList().renameEntry();
|
|
540
|
+
const renames = rcxs.map(rcx => this.visitRenameEntry(rcx));
|
|
539
541
|
const stmt = new ast.Renames(renames, accessLabel);
|
|
542
|
+
const blockNotes = this.getNotes(pcx.tags());
|
|
543
|
+
stmt.extendNote({ blockNotes });
|
|
540
544
|
return this.astAt(stmt, pcx);
|
|
541
545
|
}
|
|
542
546
|
visitFilterClauseList(pcx) {
|
|
@@ -73,10 +73,12 @@ exports.FilterCompilers = {
|
|
|
73
73
|
case '>':
|
|
74
74
|
case '<':
|
|
75
75
|
case '>=':
|
|
76
|
-
case '<=':
|
|
76
|
+
case '<=': {
|
|
77
|
+
const op = nc.not ? invertCompare(nc.operator) : nc.operator;
|
|
77
78
|
return nc.values
|
|
78
|
-
.map(v => `${x} ${
|
|
79
|
+
.map(v => `${x} ${op} ${v}`)
|
|
79
80
|
.join(nc.not ? ' AND ' : ' OR ');
|
|
81
|
+
}
|
|
80
82
|
case 'range': {
|
|
81
83
|
let startOp = nc.startOperator;
|
|
82
84
|
let endOp = nc.endOperator;
|
|
@@ -103,14 +105,16 @@ exports.FilterCompilers = {
|
|
|
103
105
|
},
|
|
104
106
|
booleanCompile(bc, x, _d) {
|
|
105
107
|
switch (bc.operator) {
|
|
108
|
+
case 'true':
|
|
109
|
+
return bc.not ? `NOT COALESCE(${x}, false)` : `COALESCE(${x}, false)`;
|
|
106
110
|
case 'false':
|
|
107
|
-
return
|
|
111
|
+
return bc.not
|
|
112
|
+
? `COALESCE(${x} != false, true)`
|
|
113
|
+
: `COALESCE(${x} = false, false)`;
|
|
108
114
|
case 'false_or_null':
|
|
109
|
-
return
|
|
115
|
+
return bc.not ? `COALESCE(${x}, false)` : `NOT COALESCE(${x}, false)`;
|
|
110
116
|
case 'null':
|
|
111
117
|
return bc.not ? `${x} IS NOT NULL` : `${x} IS NULL`;
|
|
112
|
-
case 'true':
|
|
113
|
-
return x;
|
|
114
118
|
}
|
|
115
119
|
},
|
|
116
120
|
stringCompile(sc, x, d) {
|
|
@@ -166,7 +170,7 @@ exports.FilterCompilers = {
|
|
|
166
170
|
}
|
|
167
171
|
case 'or': {
|
|
168
172
|
const clauses = sc.members.map(c => exports.FilterCompilers.stringCompile(c, x, d));
|
|
169
|
-
return clauses.join('
|
|
173
|
+
return clauses.join(' OR ');
|
|
170
174
|
}
|
|
171
175
|
case ',': {
|
|
172
176
|
/*
|
|
@@ -975,6 +975,7 @@ export interface PrepareResultOptions {
|
|
|
975
975
|
replaceMaterializedReferences?: boolean;
|
|
976
976
|
materializedTablePrefix?: string;
|
|
977
977
|
defaultRowLimit?: number;
|
|
978
|
+
isPartialQuery?: boolean;
|
|
978
979
|
}
|
|
979
980
|
type UTD = AtomicTypeDef | TypedDef | FunctionParameterTypeDef | FunctionReturnTypeDef | undefined;
|
|
980
981
|
/**
|
|
@@ -73,8 +73,14 @@ class QueryModelImpl {
|
|
|
73
73
|
loadQuery(query, stageWriter, prepareResultOptions, emitFinalStage = false, isJoinedSubquery = false) {
|
|
74
74
|
var _a;
|
|
75
75
|
const malloy = '';
|
|
76
|
+
const structRef = (_a = query.compositeResolvedSourceDef) !== null && _a !== void 0 ? _a : query.structRef;
|
|
77
|
+
const queryStruct = this.getStructFromRef(structRef, query.sourceArguments, prepareResultOptions);
|
|
78
|
+
// If this query is being written as part of a SQL block don't use CTE (WITH ...)
|
|
79
|
+
const noCTE = prepareResultOptions &&
|
|
80
|
+
prepareResultOptions.isPartialQuery &&
|
|
81
|
+
queryStruct.dialect.name !== 'postgres'; // postgres does weird stuff with final stages that won't work here.
|
|
76
82
|
if (!stageWriter) {
|
|
77
|
-
stageWriter = new stage_writer_1.StageWriter(
|
|
83
|
+
stageWriter = new stage_writer_1.StageWriter(!noCTE, undefined);
|
|
78
84
|
}
|
|
79
85
|
const turtleDef = {
|
|
80
86
|
type: 'turtle',
|
|
@@ -82,8 +88,7 @@ class QueryModelImpl {
|
|
|
82
88
|
pipeline: query.pipeline,
|
|
83
89
|
filterList: query.filterList,
|
|
84
90
|
};
|
|
85
|
-
const
|
|
86
|
-
const q = query_query_1.QueryQuery.makeQuery(turtleDef, this.getStructFromRef(structRef, query.sourceArguments, prepareResultOptions), stageWriter, isJoinedSubquery, (name) => this.structs.get(name));
|
|
91
|
+
const q = query_query_1.QueryQuery.makeQuery(turtleDef, queryStruct, stageWriter, isJoinedSubquery, (name) => this.structs.get(name));
|
|
87
92
|
const ret = q.generateSQLFromPipeline(stageWriter);
|
|
88
93
|
if (emitFinalStage && q.parent.dialect.hasFinalStage) {
|
|
89
94
|
// const fieldNames: string[] = [];
|
|
@@ -102,6 +107,7 @@ class QueryModelImpl {
|
|
|
102
107
|
// );
|
|
103
108
|
ret.lastStageName = stageWriter.addStage(q.parent.dialect.sqlFinalStage(ret.lastStageName, fieldNames));
|
|
104
109
|
}
|
|
110
|
+
// console.log('---', stageWriter.combineStages(true).sql, '---');
|
|
105
111
|
return {
|
|
106
112
|
lastStageName: ret.lastStageName,
|
|
107
113
|
malloy,
|
package/dist/model/sql_block.js
CHANGED
|
@@ -46,8 +46,10 @@ function compileSQLInterpolation(select, connection, partialModel) {
|
|
|
46
46
|
}
|
|
47
47
|
const compiledSql = queryModel.compileQuery(segment, {
|
|
48
48
|
defaultRowLimit: undefined,
|
|
49
|
+
isPartialQuery: true,
|
|
49
50
|
}, false).sql;
|
|
50
51
|
selectStr += parenAlready ? compiledSql : `(${compiledSql})`;
|
|
52
|
+
// console.log(selectStr);
|
|
51
53
|
parenAlready = false;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -3,12 +3,15 @@ import type { QueryToMaterialize, StructDef, Query } from './malloy_types';
|
|
|
3
3
|
export declare class StageWriter {
|
|
4
4
|
parent: StageWriter | undefined;
|
|
5
5
|
withs: string[];
|
|
6
|
+
stageNames: string[];
|
|
6
7
|
udfs: string[];
|
|
7
8
|
pdts: string[];
|
|
8
9
|
dependenciesToMaterialize: Record<string, QueryToMaterialize>;
|
|
9
10
|
stagePrefix: string;
|
|
10
11
|
useCTE: boolean;
|
|
12
|
+
stageNumber: number;
|
|
11
13
|
constructor(useCTE: boolean | undefined, parent: StageWriter | undefined);
|
|
14
|
+
private nextName;
|
|
12
15
|
getName(id: number): string;
|
|
13
16
|
root(): StageWriter;
|
|
14
17
|
addStage(sql: string): string;
|
|
@@ -11,14 +11,20 @@ class StageWriter {
|
|
|
11
11
|
constructor(useCTE = true, parent) {
|
|
12
12
|
this.parent = parent;
|
|
13
13
|
this.withs = [];
|
|
14
|
+
this.stageNames = [];
|
|
14
15
|
this.udfs = [];
|
|
15
16
|
this.pdts = [];
|
|
16
17
|
this.dependenciesToMaterialize = {};
|
|
17
18
|
this.stagePrefix = '__stage';
|
|
19
|
+
this.stageNumber = 0;
|
|
18
20
|
this.useCTE = useCTE;
|
|
19
21
|
}
|
|
22
|
+
nextName() {
|
|
23
|
+
const stageName = `${this.stagePrefix}${this.root().stageNumber++}`;
|
|
24
|
+
return stageName;
|
|
25
|
+
}
|
|
20
26
|
getName(id) {
|
|
21
|
-
return
|
|
27
|
+
return this.stageNames[id];
|
|
22
28
|
}
|
|
23
29
|
root() {
|
|
24
30
|
if (this.parent === undefined) {
|
|
@@ -31,7 +37,9 @@ class StageWriter {
|
|
|
31
37
|
addStage(sql) {
|
|
32
38
|
if (this.useCTE) {
|
|
33
39
|
this.withs.push(sql);
|
|
34
|
-
|
|
40
|
+
const stageName = this.nextName();
|
|
41
|
+
this.stageNames.push(stageName);
|
|
42
|
+
return stageName;
|
|
35
43
|
}
|
|
36
44
|
else {
|
|
37
45
|
this.withs[0] = sql;
|
|
@@ -102,7 +110,7 @@ class StageWriter {
|
|
|
102
110
|
}
|
|
103
111
|
const udfs = this.udfs.join('\n');
|
|
104
112
|
const pdts = this.pdts.join('\n');
|
|
105
|
-
const sql = this.combineStages(false).sql;
|
|
113
|
+
const sql = this.useCTE ? this.combineStages(false).sql : '';
|
|
106
114
|
return udfs + pdts + sql + this.withs[lastStageNum];
|
|
107
115
|
}
|
|
108
116
|
generateCoorelatedSubQuery(dialect, structDef) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.311";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.311';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.311",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@malloydata/malloy-filter": "0.0.
|
|
45
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
46
|
-
"@malloydata/malloy-tag": "0.0.
|
|
44
|
+
"@malloydata/malloy-filter": "0.0.311",
|
|
45
|
+
"@malloydata/malloy-interfaces": "0.0.311",
|
|
46
|
+
"@malloydata/malloy-tag": "0.0.311",
|
|
47
47
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
48
48
|
"assert": "^2.0.0",
|
|
49
49
|
"jaro-winkler": "^0.2.8",
|