@malloydata/malloy 0.0.40 → 0.0.41-dev230615144150
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.
|
@@ -87,7 +87,7 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
87
87
|
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN ROW(${fields}))`;
|
|
88
88
|
}
|
|
89
89
|
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
90
|
-
return `MAX(CASE WHEN group_set=${groupSet} THEN ${name}
|
|
90
|
+
return `MAX(CASE WHEN group_set=${groupSet} THEN ${name} END) as ${sqlName}`;
|
|
91
91
|
}
|
|
92
92
|
sqlCoaleseMeasuresInline(groupSet, fieldList) {
|
|
93
93
|
const fields = fieldList
|
|
@@ -105,7 +105,7 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
105
105
|
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN STRUCT(${fields}))`;
|
|
106
106
|
}
|
|
107
107
|
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
108
|
-
return `(ARRAY_AGG(${name}
|
|
108
|
+
return `(ARRAY_AGG(${name}) FILTER (WHERE group_set=${groupSet} AND ${name} IS NOT NULL))[1] as ${sqlName}`;
|
|
109
109
|
}
|
|
110
110
|
sqlCoaleseMeasuresInline(groupSet, fieldList) {
|
|
111
111
|
const fields = this.mapFields(fieldList);
|
|
@@ -198,7 +198,7 @@ class StandardSQLDialect extends dialect_1.Dialect {
|
|
|
198
198
|
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN STRUCT(${fields}))`;
|
|
199
199
|
}
|
|
200
200
|
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
201
|
-
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN ${name}
|
|
201
|
+
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN ${name} END) as ${sqlName}`;
|
|
202
202
|
}
|
|
203
203
|
sqlCoaleseMeasuresInline(groupSet, fieldList) {
|
|
204
204
|
const fields = fieldList
|
|
@@ -274,9 +274,10 @@ ${(0, utils_1.indent)(sql)}
|
|
|
274
274
|
return `(SELECT AS STRUCT ${alias}.*)`;
|
|
275
275
|
}
|
|
276
276
|
sqlMaybeQuoteIdentifier(identifier) {
|
|
277
|
-
return this.keywords.indexOf(identifier.toUpperCase()) > 0
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
// return this.keywords.indexOf(identifier.toUpperCase()) > 0
|
|
278
|
+
// ? '`' + identifier + '`'
|
|
279
|
+
// : identifier;
|
|
280
|
+
return '`' + identifier + '`';
|
|
280
281
|
}
|
|
281
282
|
sqlNow() {
|
|
282
283
|
return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP()`;
|
|
@@ -35,6 +35,9 @@ const utils_1 = require("./utils");
|
|
|
35
35
|
function generateSQLStringLiteral(sourceString) {
|
|
36
36
|
return `'${sourceString}'`;
|
|
37
37
|
}
|
|
38
|
+
function identifierNormalize(s) {
|
|
39
|
+
return s.replace(/[^a-zA-Z0-9_]/g, '_o_');
|
|
40
|
+
}
|
|
38
41
|
class StageWriter {
|
|
39
42
|
constructor(useCTE = true, parent) {
|
|
40
43
|
this.withs = [];
|
|
@@ -1947,7 +1950,7 @@ class QueryQuery extends QueryField {
|
|
|
1947
1950
|
const passKeys = this.generateSQLPassthroughKeys(qs);
|
|
1948
1951
|
structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * ${passKeys} FROM ${structSQL} as x)`;
|
|
1949
1952
|
}
|
|
1950
|
-
s += `FROM ${structSQL} as ${
|
|
1953
|
+
s += `FROM ${structSQL} as ${ji.alias}\n`;
|
|
1951
1954
|
}
|
|
1952
1955
|
else {
|
|
1953
1956
|
throw new Error('Internal Error, queries must start from a basetable');
|
|
@@ -2051,10 +2054,11 @@ class QueryQuery extends QueryField {
|
|
|
2051
2054
|
output.lateralJoinSQLExpressions.push(`${exp} as ${outputName}`);
|
|
2052
2055
|
output.sql.push(outputFieldName);
|
|
2053
2056
|
if (fi.f.fieldDef.type === 'number') {
|
|
2054
|
-
const
|
|
2057
|
+
const outputNameString = this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${resultSet.groupSet}_string`);
|
|
2058
|
+
const outputFieldNameString = `__lateral_join_bag.${outputNameString}`;
|
|
2055
2059
|
output.sql.push(outputFieldNameString);
|
|
2056
2060
|
output.dimensionIndexes.push(output.fieldIndex++);
|
|
2057
|
-
output.lateralJoinSQLExpressions.push(`CAST(${exp} as STRING) as ${
|
|
2061
|
+
output.lateralJoinSQLExpressions.push(`CAST(${exp} as STRING) as ${outputNameString}`);
|
|
2058
2062
|
fi.partitionSQL = outputFieldNameString;
|
|
2059
2063
|
}
|
|
2060
2064
|
}
|
|
@@ -2268,7 +2272,7 @@ class QueryQuery extends QueryField {
|
|
|
2268
2272
|
dimensionIndexes.push(fieldIndex++);
|
|
2269
2273
|
}
|
|
2270
2274
|
else if (isCalculatedField(fi.f)) {
|
|
2271
|
-
fieldsSQL.push(this.parent.dialect.sqlAnyValueLastTurtle(name, this.rootResult.groupSet, sqlName));
|
|
2275
|
+
fieldsSQL.push(this.parent.dialect.sqlAnyValueLastTurtle(this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${this.rootResult.groupSet}`), this.rootResult.groupSet, sqlName));
|
|
2272
2276
|
fieldIndex++;
|
|
2273
2277
|
}
|
|
2274
2278
|
}
|
|
@@ -2279,7 +2283,7 @@ class QueryQuery extends QueryField {
|
|
|
2279
2283
|
fieldIndex++;
|
|
2280
2284
|
}
|
|
2281
2285
|
else if (fi.firstSegment.type === 'project') {
|
|
2282
|
-
fieldsSQL.push(this.parent.dialect.sqlAnyValueLastTurtle(name, this.rootResult.groupSet, sqlName));
|
|
2286
|
+
fieldsSQL.push(this.parent.dialect.sqlAnyValueLastTurtle(this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${this.rootResult.groupSet}`), this.rootResult.groupSet, sqlName));
|
|
2283
2287
|
fieldIndex++;
|
|
2284
2288
|
}
|
|
2285
2289
|
}
|
|
@@ -2793,7 +2797,7 @@ class QueryStruct extends QueryNode {
|
|
|
2793
2797
|
// make a unique alias name
|
|
2794
2798
|
if (ret === undefined) {
|
|
2795
2799
|
const aliases = Array.from(this.pathAliasMap.values());
|
|
2796
|
-
const base = (0, malloy_types_1.getIdentifier)(this.fieldDef);
|
|
2800
|
+
const base = identifierNormalize((0, malloy_types_1.getIdentifier)(this.fieldDef));
|
|
2797
2801
|
let name = `${base}_0`;
|
|
2798
2802
|
let n = 1;
|
|
2799
2803
|
while (aliases.includes(name) && n < 1000) {
|
|
@@ -2860,7 +2864,7 @@ class QueryStruct extends QueryNode {
|
|
|
2860
2864
|
return 'base';
|
|
2861
2865
|
}
|
|
2862
2866
|
else {
|
|
2863
|
-
return super.getIdentifier();
|
|
2867
|
+
return identifierNormalize(super.getIdentifier());
|
|
2864
2868
|
}
|
|
2865
2869
|
}
|
|
2866
2870
|
// if this is an inline object, include the parents alias.
|