@malloydata/malloy 0.0.3 → 0.0.4
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/ast-expr.d.ts +0 -1
- package/dist/lang/ast/ast-main.d.ts +2 -2
- package/package.json +1 -1
- package/dist/connection_utils.js +0 -56
- package/dist/dialect/dialect.js +0 -77
- package/dist/dialect/dialect_map.js +0 -35
- package/dist/dialect/duckdb.js +0 -347
- package/dist/dialect/index.js +0 -27
- package/dist/dialect/postgres.js +0 -315
- package/dist/dialect/standardsql.js +0 -362
- package/dist/index.js +0 -47
- package/dist/lang/ast/apply-expr.js +0 -231
- package/dist/lang/ast/ast-expr.js +0 -1041
- package/dist/lang/ast/ast-main.js +0 -2087
- package/dist/lang/ast/ast-time-expr.js +0 -549
- package/dist/lang/ast/ast-types.js +0 -215
- package/dist/lang/ast/index.js +0 -34
- package/dist/lang/ast/time-utils.js +0 -94
- package/dist/lang/field-space.js +0 -631
- package/dist/lang/field-utils.js +0 -33
- package/dist/lang/index.js +0 -22
- package/dist/lang/parse-log.js +0 -41
- package/dist/lang/reference-list.js +0 -80
- package/dist/lang/space-field.js +0 -346
- package/dist/lang/test/document-help-context-walker.spec.js +0 -45
- package/dist/lang/test/document-symbol-walker.spec.js +0 -100
- package/dist/lang/test/field-symbols.spec.js +0 -172
- package/dist/lang/test/parse.spec.js +0 -1951
- package/dist/lang/test/test-translator.js +0 -334
- package/dist/lang/zone.js +0 -97
- package/dist/malloy.js +0 -2360
- package/dist/model/index.js +0 -34
- package/dist/model/malloy_query.js +0 -2994
- package/dist/model/malloy_types.js +0 -283
- package/dist/model/sql_block.js +0 -41
- package/dist/model/utils.js +0 -84
- package/dist/runtime_types.js +0 -15
|
@@ -141,7 +141,6 @@ export declare class ExprParens extends ExpressionDef {
|
|
|
141
141
|
readonly expr: ExpressionDef;
|
|
142
142
|
elementType: string;
|
|
143
143
|
constructor(expr: ExpressionDef);
|
|
144
|
-
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
145
144
|
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
146
145
|
getExpression(fs: FieldSpace): ExprValue;
|
|
147
146
|
}
|
|
@@ -303,9 +303,9 @@ export declare class WildcardFieldReference extends MalloyElement {
|
|
|
303
303
|
}
|
|
304
304
|
export declare class OrderBy extends MalloyElement {
|
|
305
305
|
readonly field: number | FieldName;
|
|
306
|
-
readonly dir?: "
|
|
306
|
+
readonly dir?: "asc" | "desc" | undefined;
|
|
307
307
|
elementType: string;
|
|
308
|
-
constructor(field: number | FieldName, dir?: "
|
|
308
|
+
constructor(field: number | FieldName, dir?: "asc" | "desc" | undefined);
|
|
309
309
|
get modelField(): string | number;
|
|
310
310
|
getOrderBy(_fs: FieldSpace): model.OrderBy;
|
|
311
311
|
}
|
package/package.json
CHANGED
package/dist/connection_utils.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2022 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* This program is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU General Public License
|
|
7
|
-
* version 2 as published by the Free Software Foundation.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU General Public License for more details.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.toAsyncGenerator = void 0;
|
|
16
|
-
async function* toAsyncGenerator(startStreaming) {
|
|
17
|
-
let done = false;
|
|
18
|
-
function getResults(startStreaming) {
|
|
19
|
-
let resolve;
|
|
20
|
-
const promise = new Promise((res) => {
|
|
21
|
-
resolve = res;
|
|
22
|
-
});
|
|
23
|
-
startStreaming((error) => {
|
|
24
|
-
resolve({ done: true, isError: true, error });
|
|
25
|
-
}, (data) => {
|
|
26
|
-
resolve({
|
|
27
|
-
done: false,
|
|
28
|
-
value: data,
|
|
29
|
-
isError: false,
|
|
30
|
-
next: new Promise((res) => {
|
|
31
|
-
resolve = res;
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
34
|
-
}, () => {
|
|
35
|
-
resolve({ done: true, isError: false });
|
|
36
|
-
});
|
|
37
|
-
return promise;
|
|
38
|
-
}
|
|
39
|
-
let next = getResults(startStreaming);
|
|
40
|
-
while (!done) {
|
|
41
|
-
const result = await next;
|
|
42
|
-
if (result.done) {
|
|
43
|
-
done = true;
|
|
44
|
-
if (result.isError) {
|
|
45
|
-
throw result.error;
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
next = result.next;
|
|
51
|
-
yield result.value;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.toAsyncGenerator = toAsyncGenerator;
|
|
56
|
-
//# sourceMappingURL=connection_utils.js.map
|
package/dist/dialect/dialect.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2021 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* This program is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU General Public License
|
|
7
|
-
* version 2 as published by the Free Software Foundation.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU General Public License for more details.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Dialect = void 0;
|
|
16
|
-
// Can't get these from "../model" because model includes this file
|
|
17
|
-
// and that can create a circular reference problem. This is a patch
|
|
18
|
-
// and really indicates a problem in the relationship between
|
|
19
|
-
// dialect and model, it's going to come up again some time.
|
|
20
|
-
const malloy_types_1 = require("../model/malloy_types");
|
|
21
|
-
class Dialect {
|
|
22
|
-
sqlFinalStage(_lastStageName, _fields) {
|
|
23
|
-
throw new Error("Dialect has no final Stage but called Anyway");
|
|
24
|
-
}
|
|
25
|
-
// default implementation will probably work most of the time
|
|
26
|
-
sqlDateToString(sqlDateExp) {
|
|
27
|
-
return `CAST(DATE(${sqlDateExp}) AS ${this.stringTypeName} )`;
|
|
28
|
-
}
|
|
29
|
-
// BigQuery has some fieldNames that are Pseudo Fields and shouldn't be
|
|
30
|
-
// included in projections.
|
|
31
|
-
ignoreInProject(_fieldName) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
getFunctionInfo(functionName) {
|
|
35
|
-
return this.functionInfo[functionName.toLowerCase()];
|
|
36
|
-
}
|
|
37
|
-
dialectExpr(df) {
|
|
38
|
-
switch (df.function) {
|
|
39
|
-
case "now":
|
|
40
|
-
return this.sqlNow();
|
|
41
|
-
case "timeDiff":
|
|
42
|
-
return this.sqlMeasureTime(df.left, df.right, df.units);
|
|
43
|
-
case "delta":
|
|
44
|
-
return this.sqlAlterTime(df.op, df.base, df.delta, df.units);
|
|
45
|
-
case "trunc":
|
|
46
|
-
return this.sqlTrunc(df.expr, df.units);
|
|
47
|
-
case "extract":
|
|
48
|
-
return this.sqlExtract(df.expr, df.units);
|
|
49
|
-
case "cast":
|
|
50
|
-
return this.sqlCast(df);
|
|
51
|
-
case "regexpMatch":
|
|
52
|
-
return this.sqlRegexpMatch(df.expr, df.regexp);
|
|
53
|
-
case "div": {
|
|
54
|
-
if (this.divisionIsInteger) {
|
|
55
|
-
return (0, malloy_types_1.mkExpr) `${df.numerator}*1.0/${df.denominator}`;
|
|
56
|
-
}
|
|
57
|
-
return (0, malloy_types_1.mkExpr) `${df.numerator}/${df.denominator}`;
|
|
58
|
-
}
|
|
59
|
-
case "timeLiteral":
|
|
60
|
-
return [this.sqlLiteralTime(df.literal, df.literalType, df.timezone)];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
sqlSumDistinct(_key, _value) {
|
|
64
|
-
return "sqlSumDistinct called bu not implemented";
|
|
65
|
-
}
|
|
66
|
-
sqlSampleTable(tableSQL, sample) {
|
|
67
|
-
if (sample !== undefined) {
|
|
68
|
-
throw new Error(`Sampling is not supported on dialect ${this.name}.`);
|
|
69
|
-
}
|
|
70
|
-
return tableSQL;
|
|
71
|
-
}
|
|
72
|
-
sqlOrderBy(orderTerms) {
|
|
73
|
-
return `ORDER BY ${orderTerms.join(",")}`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.Dialect = Dialect;
|
|
77
|
-
//# sourceMappingURL=dialect.js.map
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2021 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* This program is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU General Public License
|
|
7
|
-
* version 2 as published by the Free Software Foundation.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU General Public License for more details.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.registerDialect = exports.getDialect = void 0;
|
|
16
|
-
const _1 = require(".");
|
|
17
|
-
const postgres_1 = require("./postgres");
|
|
18
|
-
const standardsql_1 = require("./standardsql");
|
|
19
|
-
const dialectMap = new Map();
|
|
20
|
-
function getDialect(name) {
|
|
21
|
-
const d = dialectMap.get(name);
|
|
22
|
-
if (d === undefined) {
|
|
23
|
-
throw new Error(`Unknown Dialect ${name}`);
|
|
24
|
-
}
|
|
25
|
-
return d;
|
|
26
|
-
}
|
|
27
|
-
exports.getDialect = getDialect;
|
|
28
|
-
function registerDialect(d) {
|
|
29
|
-
dialectMap.set(d.name, d);
|
|
30
|
-
}
|
|
31
|
-
exports.registerDialect = registerDialect;
|
|
32
|
-
registerDialect(new postgres_1.PostgresDialect());
|
|
33
|
-
registerDialect(new standardsql_1.StandardSQLDialect());
|
|
34
|
-
registerDialect(new _1.DuckDBDialect());
|
|
35
|
-
//# sourceMappingURL=dialect_map.js.map
|
package/dist/dialect/duckdb.js
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2021 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* This program is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU General Public License
|
|
7
|
-
* version 2 as published by the Free Software Foundation.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU General Public License for more details.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.DuckDBDialect = void 0;
|
|
16
|
-
const model_1 = require("../model");
|
|
17
|
-
const utils_1 = require("../model/utils");
|
|
18
|
-
const dialect_1 = require("./dialect");
|
|
19
|
-
// need to refactor runSQL to take a SQLBlock instead of just a sql string.
|
|
20
|
-
const hackSplitComment = "-- hack: split on this";
|
|
21
|
-
const keywords = `
|
|
22
|
-
ALL
|
|
23
|
-
ANALYSE
|
|
24
|
-
ANALYZE
|
|
25
|
-
AND
|
|
26
|
-
ANY
|
|
27
|
-
ARRAY
|
|
28
|
-
AS
|
|
29
|
-
ASC_P
|
|
30
|
-
ASYMMETRIC
|
|
31
|
-
BOTH
|
|
32
|
-
CASE
|
|
33
|
-
CAST
|
|
34
|
-
CHECK_P
|
|
35
|
-
COLLATE
|
|
36
|
-
COLUMN
|
|
37
|
-
CONSTRAINT
|
|
38
|
-
CREATE_P
|
|
39
|
-
CURRENT_CATALOG
|
|
40
|
-
CURRENT_DATE
|
|
41
|
-
CURRENT_ROLE
|
|
42
|
-
CURRENT_TIME
|
|
43
|
-
CURRENT_TIMESTAMP
|
|
44
|
-
CURRENT_USER
|
|
45
|
-
DEFAULT
|
|
46
|
-
DEFERRABLE
|
|
47
|
-
DESC_P
|
|
48
|
-
DISTINCT
|
|
49
|
-
DO
|
|
50
|
-
ELSE
|
|
51
|
-
END_P
|
|
52
|
-
EXCEPT
|
|
53
|
-
FALSE_P
|
|
54
|
-
FETCH
|
|
55
|
-
FOR
|
|
56
|
-
FOREIGN
|
|
57
|
-
FROM
|
|
58
|
-
GRANT
|
|
59
|
-
GROUP_P
|
|
60
|
-
HAVING
|
|
61
|
-
IN_P
|
|
62
|
-
INITIALLY
|
|
63
|
-
INTERSECT
|
|
64
|
-
INTO
|
|
65
|
-
LATERAL_P
|
|
66
|
-
LEADING
|
|
67
|
-
LIMIT
|
|
68
|
-
LOCALTIME
|
|
69
|
-
LOCALTIMESTAMP
|
|
70
|
-
NOT
|
|
71
|
-
NULL_P
|
|
72
|
-
OFFSET
|
|
73
|
-
ON
|
|
74
|
-
ONLY
|
|
75
|
-
OR
|
|
76
|
-
ORDER
|
|
77
|
-
PLACING
|
|
78
|
-
PRIMARY
|
|
79
|
-
REFERENCES
|
|
80
|
-
RETURNING
|
|
81
|
-
SELECT
|
|
82
|
-
SESSION_USER
|
|
83
|
-
SOME
|
|
84
|
-
SYMMETRIC
|
|
85
|
-
TABLE
|
|
86
|
-
THEN
|
|
87
|
-
TO
|
|
88
|
-
TRAILING
|
|
89
|
-
TRUE_P
|
|
90
|
-
UNION
|
|
91
|
-
UNIQUE
|
|
92
|
-
USER
|
|
93
|
-
USING
|
|
94
|
-
VARIADIC
|
|
95
|
-
WHEN
|
|
96
|
-
WHERE
|
|
97
|
-
WINDOW
|
|
98
|
-
WITH
|
|
99
|
-
`.split(/\s/);
|
|
100
|
-
const castMap = {
|
|
101
|
-
number: "double precision",
|
|
102
|
-
string: "varchar",
|
|
103
|
-
};
|
|
104
|
-
const pgExtractionMap = {
|
|
105
|
-
day_of_week: "dow",
|
|
106
|
-
day_of_year: "doy",
|
|
107
|
-
};
|
|
108
|
-
const inSeconds = {
|
|
109
|
-
second: 1,
|
|
110
|
-
minute: 60,
|
|
111
|
-
hour: 3600,
|
|
112
|
-
};
|
|
113
|
-
class DuckDBDialect extends dialect_1.Dialect {
|
|
114
|
-
constructor() {
|
|
115
|
-
super(...arguments);
|
|
116
|
-
this.name = "duckdb";
|
|
117
|
-
this.defaultNumberType = "DOUBLE";
|
|
118
|
-
this.hasFinalStage = false;
|
|
119
|
-
this.stringTypeName = "VARCHAR";
|
|
120
|
-
this.divisionIsInteger = true;
|
|
121
|
-
this.supportsSumDistinctFunction = true;
|
|
122
|
-
this.unnestWithNumbers = true;
|
|
123
|
-
this.defaultSampling = { rows: 50000 };
|
|
124
|
-
this.supportUnnestArrayAgg = true;
|
|
125
|
-
this.supportsCTEinCoorelatedSubQueries = true;
|
|
126
|
-
this.functionInfo = {
|
|
127
|
-
concat: { returnType: "string" },
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
// hack until they support temporary macros.
|
|
131
|
-
get udfPrefix() {
|
|
132
|
-
return `__udf${Math.floor(Math.random() * 100000)}`;
|
|
133
|
-
}
|
|
134
|
-
quoteTablePath(tableName) {
|
|
135
|
-
return tableName.match(/\//) ? `'${tableName}'` : tableName;
|
|
136
|
-
}
|
|
137
|
-
sqlGroupSetTable(groupSetCount) {
|
|
138
|
-
return `CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,${groupSetCount},1)) as group_set ) as group_set`;
|
|
139
|
-
}
|
|
140
|
-
sqlAnyValue(groupSet, fieldName) {
|
|
141
|
-
return `FIRST(${fieldName}) FILTER (WHERE ${fieldName} IS NOT NULL)`;
|
|
142
|
-
}
|
|
143
|
-
mapFields(fieldList) {
|
|
144
|
-
return fieldList.join(", ");
|
|
145
|
-
}
|
|
146
|
-
sqlAggregateTurtle(groupSet, fieldList, orderBy, limit) {
|
|
147
|
-
let tail = "";
|
|
148
|
-
if (limit !== undefined) {
|
|
149
|
-
tail += `[1:${limit}]`;
|
|
150
|
-
}
|
|
151
|
-
const fields = fieldList
|
|
152
|
-
.map((f) => `\n ${f.sqlOutputName}: ${f.sqlExpression}`)
|
|
153
|
-
.join(", ");
|
|
154
|
-
return `COALESCE(LIST({${fields}} ${orderBy}) FILTER (WHERE group_set=${groupSet})${tail},[])`;
|
|
155
|
-
}
|
|
156
|
-
sqlAnyValueTurtle(groupSet, fieldList) {
|
|
157
|
-
const fields = fieldList
|
|
158
|
-
.map((f) => `${f.sqlExpression} as ${f.sqlOutputName}`)
|
|
159
|
-
.join(", ");
|
|
160
|
-
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN ROW(${fields}))`;
|
|
161
|
-
}
|
|
162
|
-
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
163
|
-
return `MAX(CASE WHEN group_set=${groupSet} THEN ${name}__${groupSet} END) as ${sqlName}`;
|
|
164
|
-
}
|
|
165
|
-
sqlCoaleseMeasuresInline(groupSet, fieldList) {
|
|
166
|
-
const fields = fieldList
|
|
167
|
-
.map((f) => `${f.sqlOutputName}: ${f.sqlExpression} `)
|
|
168
|
-
.join(", ");
|
|
169
|
-
const nullValues = fieldList
|
|
170
|
-
.map((f) => `${f.sqlOutputName}: NULL`)
|
|
171
|
-
.join(", ");
|
|
172
|
-
return `COALESCE(FIRST({${fields}}) FILTER(WHERE group_set=${groupSet}), {${nullValues}})`;
|
|
173
|
-
}
|
|
174
|
-
sqlUnnestAlias(source, alias, _fieldList, _needDistinctKey) {
|
|
175
|
-
return `LEFT JOIN (select UNNEST(generate_series(1,
|
|
176
|
-
100000, --
|
|
177
|
-
-- (SELECT genres_length FROM movies limit 1),
|
|
178
|
-
1)) as __row_id) as ${alias} ON ${alias}.__row_id <= array_length(${source})`;
|
|
179
|
-
}
|
|
180
|
-
sqlSumDistinctHashedKey(_sqlDistinctKey) {
|
|
181
|
-
return "uses sumDistinctFunction, should not be called";
|
|
182
|
-
}
|
|
183
|
-
sqlGenerateUUID() {
|
|
184
|
-
return `GEN_RANDOM_UUID()`;
|
|
185
|
-
}
|
|
186
|
-
sqlDateToString(sqlDateExp) {
|
|
187
|
-
return `(${sqlDateExp})::date::varchar`;
|
|
188
|
-
}
|
|
189
|
-
sqlFieldReference(alias, fieldName, _fieldType, _isNested, isArray) {
|
|
190
|
-
if (isArray) {
|
|
191
|
-
return alias;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
return `${alias}.${this.sqlMaybeQuoteIdentifier(fieldName)}`;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
sqlUnnestPipelineHead(isSingleton, sourceSQLExpression) {
|
|
198
|
-
let p = sourceSQLExpression;
|
|
199
|
-
if (isSingleton) {
|
|
200
|
-
p = `[${p}]`;
|
|
201
|
-
}
|
|
202
|
-
return `(SELECT UNNEST(${p}) as base)`;
|
|
203
|
-
}
|
|
204
|
-
sqlCreateFunction(id, funcText) {
|
|
205
|
-
return `DROP MACRO IF EXISTS ${id}; \n${hackSplitComment}\n CREATE MACRO ${id}(_param) AS (\n${(0, utils_1.indent)(funcText)}\n);\n${hackSplitComment}\n`;
|
|
206
|
-
}
|
|
207
|
-
sqlCreateFunctionCombineLastStage(lastStageName, structDef) {
|
|
208
|
-
return `SELECT LIST(ROW(${structDef.fields
|
|
209
|
-
.map((fieldDef) => this.sqlMaybeQuoteIdentifier((0, model_1.getIdentifier)(fieldDef)))
|
|
210
|
-
.join(",")})) FROM ${lastStageName}\n`;
|
|
211
|
-
}
|
|
212
|
-
sqlSelectAliasAsStruct(alias, physicalFieldNames) {
|
|
213
|
-
return `ROW(${physicalFieldNames
|
|
214
|
-
.map((name) => `${alias}.${name}`)
|
|
215
|
-
.join(", ")})`;
|
|
216
|
-
}
|
|
217
|
-
// TODO
|
|
218
|
-
// sqlMaybeQuoteIdentifier(identifier: string): string {
|
|
219
|
-
// return keywords.indexOf(identifier.toUpperCase()) > 0 ||
|
|
220
|
-
// identifier.match(/[a-zA-Z][a-zA-Z0-9]*/) === null || true
|
|
221
|
-
// ? '"' + identifier + '"'
|
|
222
|
-
// : identifier;
|
|
223
|
-
// }
|
|
224
|
-
sqlMaybeQuoteIdentifier(identifier) {
|
|
225
|
-
return '"' + identifier + '"';
|
|
226
|
-
}
|
|
227
|
-
// The simple way to do this is to add a comment on the table
|
|
228
|
-
// with the expiration time. https://www.postgresql.org/docs/current/sql-comment.html
|
|
229
|
-
// and have a reaper that read comments.
|
|
230
|
-
sqlCreateTableAsSelect(_tableName, _sql) {
|
|
231
|
-
throw new Error("Not implemented Yet");
|
|
232
|
-
}
|
|
233
|
-
getFunctionInfo(functionName) {
|
|
234
|
-
return this.functionInfo[functionName];
|
|
235
|
-
}
|
|
236
|
-
sqlMeasureTime(from, to, units) {
|
|
237
|
-
let lVal = from.value;
|
|
238
|
-
let rVal = to.value;
|
|
239
|
-
if (inSeconds[units]) {
|
|
240
|
-
lVal = (0, model_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
|
|
241
|
-
rVal = (0, model_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
|
|
242
|
-
const duration = (0, model_1.mkExpr) `(${rVal} - ${lVal})`;
|
|
243
|
-
return units == "second"
|
|
244
|
-
? duration
|
|
245
|
-
: (0, model_1.mkExpr) `FLOOR(${duration}/${inSeconds[units].toString()})`;
|
|
246
|
-
}
|
|
247
|
-
if (from.valueType != "date") {
|
|
248
|
-
lVal = (0, model_1.mkExpr) `CAST((${lVal}) AS DATE)`;
|
|
249
|
-
}
|
|
250
|
-
if (to.valueType != "date") {
|
|
251
|
-
rVal = (0, model_1.mkExpr) `CAST((${rVal}) AS DATE)`;
|
|
252
|
-
}
|
|
253
|
-
if (units == "week") {
|
|
254
|
-
// DuckDB's weeks start on Monday, but Malloy's weeks start on Sunday
|
|
255
|
-
lVal = (0, model_1.mkExpr) `(${lVal} + INTERVAL 1 DAY)`;
|
|
256
|
-
rVal = (0, model_1.mkExpr) `(${rVal} + INTERVAL 1 DAY)`;
|
|
257
|
-
}
|
|
258
|
-
return (0, model_1.mkExpr) `DATE_DIFF('${units}', ${lVal}, ${rVal})`;
|
|
259
|
-
}
|
|
260
|
-
sqlNow() {
|
|
261
|
-
return (0, model_1.mkExpr) `CURRENT_TIMESTAMP`;
|
|
262
|
-
}
|
|
263
|
-
sqlTrunc(sqlTime, units) {
|
|
264
|
-
// adjusting for monday/sunday weeks
|
|
265
|
-
const week = units == "week";
|
|
266
|
-
const truncThis = week
|
|
267
|
-
? (0, model_1.mkExpr) `${sqlTime.value} + INTERVAL 1 DAY`
|
|
268
|
-
: sqlTime.value;
|
|
269
|
-
const trunced = (0, model_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
|
|
270
|
-
return week ? (0, model_1.mkExpr) `(${trunced} - INTERVAL 1 DAY)` : trunced;
|
|
271
|
-
}
|
|
272
|
-
sqlExtract(from, units) {
|
|
273
|
-
const pgUnits = pgExtractionMap[units] || units;
|
|
274
|
-
const extracted = (0, model_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
|
|
275
|
-
return units == "day_of_week" ? (0, model_1.mkExpr) `(${extracted}+1)` : extracted;
|
|
276
|
-
}
|
|
277
|
-
sqlAlterTime(op, expr, n, timeframe) {
|
|
278
|
-
if (timeframe == "quarter") {
|
|
279
|
-
timeframe = "month";
|
|
280
|
-
n = (0, model_1.mkExpr) `${n}*3`;
|
|
281
|
-
}
|
|
282
|
-
if (timeframe == "week") {
|
|
283
|
-
timeframe = "day";
|
|
284
|
-
n = (0, model_1.mkExpr) `${n}*7`;
|
|
285
|
-
}
|
|
286
|
-
const interval = (0, model_1.mkExpr) `INTERVAL (${n}) ${timeframe}`;
|
|
287
|
-
return (0, model_1.mkExpr) `((${expr.value})) ${op} ${interval}`;
|
|
288
|
-
}
|
|
289
|
-
sqlCast(cast) {
|
|
290
|
-
if (cast.dstType !== cast.srcType) {
|
|
291
|
-
const castTo = castMap[cast.dstType] || cast.dstType;
|
|
292
|
-
return (0, model_1.mkExpr) `cast(${cast.expr} as ${castTo})`;
|
|
293
|
-
}
|
|
294
|
-
return cast.expr;
|
|
295
|
-
}
|
|
296
|
-
sqlRegexpMatch(expr, regexp) {
|
|
297
|
-
return (0, model_1.mkExpr) `REGEXP_MATCHES(${expr}, ${regexp})`;
|
|
298
|
-
}
|
|
299
|
-
sqlLiteralTime(timeString, type, _timezone) {
|
|
300
|
-
if (type == "date") {
|
|
301
|
-
return `DATE '${timeString}'`;
|
|
302
|
-
}
|
|
303
|
-
else if (type == "timestamp") {
|
|
304
|
-
return `TIMESTAMP '${timeString}'`;
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
throw new Error(`Unknown Literal time format ${type}`);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
sqlSumDistinct(key, value) {
|
|
311
|
-
// return `sum_distinct(list({key:${key}, val: ${value}}))`;
|
|
312
|
-
return `(
|
|
313
|
-
SELECT sum(a.val) as value
|
|
314
|
-
FROM (
|
|
315
|
-
SELECT UNNEST(list(distinct {key:${key}, val: ${value}})) a
|
|
316
|
-
)
|
|
317
|
-
)`;
|
|
318
|
-
}
|
|
319
|
-
// sqlSumDistinct(key: string, value: string): string {
|
|
320
|
-
// const _factor = 32;
|
|
321
|
-
// const precision = 0.000001;
|
|
322
|
-
// const keySQL = `md5_number_lower(${key}::varchar)::int128`;
|
|
323
|
-
// return `
|
|
324
|
-
// (SUM(DISTINCT ${keySQL} + FLOOR(IFNULL(${value},0)/${precision})::int128) - SUM(DISTINCT ${keySQL}))*${precision}
|
|
325
|
-
// `;
|
|
326
|
-
// }
|
|
327
|
-
// default duckdb to sampling 50K rows.
|
|
328
|
-
sqlSampleTable(tableSQL, sample) {
|
|
329
|
-
if (sample !== undefined) {
|
|
330
|
-
if ((0, model_1.isSamplingEnable)(sample) && sample.enable) {
|
|
331
|
-
sample = this.defaultSampling;
|
|
332
|
-
}
|
|
333
|
-
if ((0, model_1.isSamplingRows)(sample)) {
|
|
334
|
-
return `(SELECT * FROM ${tableSQL} USING SAMPLE ${sample.rows})`;
|
|
335
|
-
}
|
|
336
|
-
else if ((0, model_1.isSamplingPercent)(sample)) {
|
|
337
|
-
return `(SELECT * FROM ${tableSQL} USING SAMPLE ${sample.percent} PERCENT (bernoulli))`;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return tableSQL;
|
|
341
|
-
}
|
|
342
|
-
sqlOrderBy(orderTerms) {
|
|
343
|
-
return `ORDER BY ${orderTerms.map((t) => `${t} NULLS LAST`).join(",")}`;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
exports.DuckDBDialect = DuckDBDialect;
|
|
347
|
-
//# sourceMappingURL=duckdb.js.map
|
package/dist/dialect/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2021 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* This program is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU General Public License
|
|
7
|
-
* version 2 as published by the Free Software Foundation.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU General Public License for more details.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.registerDialect = exports.getDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.Dialect = void 0;
|
|
16
|
-
var dialect_1 = require("./dialect");
|
|
17
|
-
Object.defineProperty(exports, "Dialect", { enumerable: true, get: function () { return dialect_1.Dialect; } });
|
|
18
|
-
var standardsql_1 = require("./standardsql");
|
|
19
|
-
Object.defineProperty(exports, "StandardSQLDialect", { enumerable: true, get: function () { return standardsql_1.StandardSQLDialect; } });
|
|
20
|
-
var postgres_1 = require("./postgres");
|
|
21
|
-
Object.defineProperty(exports, "PostgresDialect", { enumerable: true, get: function () { return postgres_1.PostgresDialect; } });
|
|
22
|
-
var duckdb_1 = require("./duckdb");
|
|
23
|
-
Object.defineProperty(exports, "DuckDBDialect", { enumerable: true, get: function () { return duckdb_1.DuckDBDialect; } });
|
|
24
|
-
var dialect_map_1 = require("./dialect_map");
|
|
25
|
-
Object.defineProperty(exports, "getDialect", { enumerable: true, get: function () { return dialect_map_1.getDialect; } });
|
|
26
|
-
Object.defineProperty(exports, "registerDialect", { enumerable: true, get: function () { return dialect_map_1.registerDialect; } });
|
|
27
|
-
//# sourceMappingURL=index.js.map
|