@malloydata/malloy 0.0.38-dev230606235314 → 0.0.38-dev230609221655
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/malloy.js +1 -1
- package/dist/model/malloy_query.d.ts +1 -0
- package/dist/model/malloy_query.js +32 -7
- package/package.json +1 -1
package/dist/malloy.js
CHANGED
|
@@ -339,7 +339,7 @@ class Model {
|
|
|
339
339
|
*/
|
|
340
340
|
getPreparedQueryByName(queryName) {
|
|
341
341
|
const query = this.modelDef.contents[queryName];
|
|
342
|
-
if (query.type === 'query') {
|
|
342
|
+
if ((query === null || query === void 0 ? void 0 : query.type) === 'query') {
|
|
343
343
|
return new PreparedQuery(query, this.modelDef, queryName);
|
|
344
344
|
}
|
|
345
345
|
throw new Error('Given query name does not refer to a named query.');
|
|
@@ -243,6 +243,7 @@ declare class QueryQuery extends QueryField {
|
|
|
243
243
|
/** returns a fields and primary key of a struct for this query */
|
|
244
244
|
getResultStructDef(resultStruct?: FieldInstanceResult, isRoot?: boolean): StructDef;
|
|
245
245
|
generateSQLJoinBlock(stageWriter: StageWriter, ji: JoinInstance): string;
|
|
246
|
+
generateSQLPassthroughKeys(qs: QueryStruct): string;
|
|
246
247
|
generateSQLJoins(stageWriter: StageWriter): string;
|
|
247
248
|
genereateSQLOrderBy(queryDef: QuerySegment, resultStruct: FieldInstanceResult): string;
|
|
248
249
|
generateSimpleSQL(stageWriter: StageWriter): string;
|
|
@@ -208,11 +208,15 @@ class QueryField extends QueryNode {
|
|
|
208
208
|
// find the structDef and return the path to the field...
|
|
209
209
|
const field = context.getFieldByName(expr.path);
|
|
210
210
|
if ((0, malloy_types_1.hasExpression)(field.fieldDef)) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
211
|
+
const ret = this.generateExpressionFromExpr(resultSet, field.parent, field.fieldDef.e, state);
|
|
212
|
+
// in order to avoid too many parens, there was some code here ..
|
|
213
|
+
// if (!ret.match(/^\(.*\)$/)) {
|
|
214
|
+
// ret = `(${ret})`;
|
|
215
|
+
// }
|
|
216
|
+
// but this failed when the expresion was (bool1)or(bool2)
|
|
217
|
+
// there could maybe be a smarter parse of the expression to avoid
|
|
218
|
+
// an extra paren, but correctness first, beauty AND correctness later
|
|
219
|
+
return `(${ret})`;
|
|
216
220
|
}
|
|
217
221
|
else {
|
|
218
222
|
// return field.parent.getIdentifier() + "." + field.fieldDef.name;
|
|
@@ -1675,7 +1679,8 @@ class QueryQuery extends QueryField {
|
|
|
1675
1679
|
let structSQL = qs.structSourceSQL(stageWriter);
|
|
1676
1680
|
if ((0, malloy_types_1.isJoinOn)(structRelationship)) {
|
|
1677
1681
|
if (ji.makeUniqueKey) {
|
|
1678
|
-
|
|
1682
|
+
const passKeys = this.generateSQLPassthroughKeys(qs);
|
|
1683
|
+
structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * ${passKeys} FROM ${structSQL} as x)`;
|
|
1679
1684
|
}
|
|
1680
1685
|
let onCondition = '';
|
|
1681
1686
|
if (qs.parent === undefined) {
|
|
@@ -1736,6 +1741,25 @@ class QueryQuery extends QueryField {
|
|
|
1736
1741
|
}
|
|
1737
1742
|
return s;
|
|
1738
1743
|
}
|
|
1744
|
+
// BigQuery has wildcard psudo columns that are treated differently
|
|
1745
|
+
// SELECT * FROM xxx doesn't include these psuedo columns but we need them so
|
|
1746
|
+
// filters can get pushed down properly when generating a UNIQUE key.
|
|
1747
|
+
// No other dialect really needs this so we are coding here but maybe someday
|
|
1748
|
+
// this makes its way into the dialect.
|
|
1749
|
+
generateSQLPassthroughKeys(qs) {
|
|
1750
|
+
let ret = '';
|
|
1751
|
+
if (qs.dialect.name === 'standardsql') {
|
|
1752
|
+
const psudoCols = [
|
|
1753
|
+
'_TABLE_SUFFIX',
|
|
1754
|
+
'_PARTITIONDATE',
|
|
1755
|
+
'_PARTITIONTIME',
|
|
1756
|
+
].filter(element => qs.getChildByName(element) !== undefined);
|
|
1757
|
+
if (psudoCols.length > 0) {
|
|
1758
|
+
ret = ', ' + psudoCols.join(', ');
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
return ret;
|
|
1762
|
+
}
|
|
1739
1763
|
generateSQLJoins(stageWriter) {
|
|
1740
1764
|
let s = '';
|
|
1741
1765
|
// get the first value from the map (weird, I know)
|
|
@@ -1752,7 +1776,8 @@ class QueryQuery extends QueryField {
|
|
|
1752
1776
|
const structRelationship = qs.fieldDef.structRelationship;
|
|
1753
1777
|
if (structRelationship.type === 'basetable') {
|
|
1754
1778
|
if (ji.makeUniqueKey) {
|
|
1755
|
-
|
|
1779
|
+
const passKeys = this.generateSQLPassthroughKeys(qs);
|
|
1780
|
+
structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * ${passKeys} FROM ${structSQL} as x)`;
|
|
1756
1781
|
}
|
|
1757
1782
|
s += `FROM ${structSQL} as ${this.parent.getIdentifier()}\n`;
|
|
1758
1783
|
}
|