@malloydata/malloy 0.0.32-dev230428002803 → 0.0.32-dev230505153727
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/dialect.d.ts +1 -1
- package/dist/dialect/dialect.js +1 -1
- package/dist/dialect/duckdb.d.ts +1 -1
- package/dist/dialect/duckdb.js +2 -2
- package/dist/dialect/postgres.d.ts +1 -1
- package/dist/dialect/postgres.js +2 -2
- package/dist/model/malloy_query.js +6 -4
- package/package.json +1 -1
|
@@ -59,7 +59,7 @@ export declare abstract class Dialect {
|
|
|
59
59
|
abstract sqlRegexpMatch(expr: Expr, regex: string): Expr;
|
|
60
60
|
getFunctionInfo(functionName: string): FunctionInfo | undefined;
|
|
61
61
|
dialectExpr(df: DialectFragment): Expr;
|
|
62
|
-
sqlSumDistinct(_key: string, _value: string): string;
|
|
62
|
+
sqlSumDistinct(_key: string, _value: string, _funcName: string): string;
|
|
63
63
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
64
64
|
sqlOrderBy(orderTerms: string[]): string;
|
|
65
65
|
}
|
package/dist/dialect/dialect.js
CHANGED
package/dist/dialect/duckdb.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare class DuckDBDialect extends Dialect {
|
|
|
45
45
|
sqlCast(cast: TypecastFragment): Expr;
|
|
46
46
|
sqlRegexpMatch(expr: Expr, regexp: string): Expr;
|
|
47
47
|
sqlLiteralTime(timeString: string, type: TimeFieldType, _timezone: string): string;
|
|
48
|
-
sqlSumDistinct(key: string, value: string): string;
|
|
48
|
+
sqlSumDistinct(key: string, value: string, funcName: string): string;
|
|
49
49
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
50
50
|
sqlOrderBy(orderTerms: string[]): string;
|
|
51
51
|
sqlLiteralString(literal: string): string;
|
package/dist/dialect/duckdb.js
CHANGED
|
@@ -321,10 +321,10 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
321
321
|
throw new Error(`Unknown Literal time format ${type}`);
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
|
-
sqlSumDistinct(key, value) {
|
|
324
|
+
sqlSumDistinct(key, value, funcName) {
|
|
325
325
|
// return `sum_distinct(list({key:${key}, val: ${value}}))`;
|
|
326
326
|
return `(
|
|
327
|
-
SELECT
|
|
327
|
+
SELECT ${funcName}(a.val) as value
|
|
328
328
|
FROM (
|
|
329
329
|
SELECT UNNEST(list(distinct {key:${key}, val: ${value}})) a
|
|
330
330
|
)
|
|
@@ -45,7 +45,7 @@ export declare class PostgresDialect extends Dialect {
|
|
|
45
45
|
sqlLiteralTime(timeString: string, type: TimeFieldType, _timezone: string): string;
|
|
46
46
|
getFunctionInfo(functionName: string): FunctionInfo | undefined;
|
|
47
47
|
sqlMeasureTime(from: TimeValue, to: TimeValue, units: string): Expr;
|
|
48
|
-
sqlSumDistinct(key: string, value: string): string;
|
|
48
|
+
sqlSumDistinct(key: string, value: string, funcName: string): string;
|
|
49
49
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
50
50
|
sqlOrderBy(orderTerms: string[]): string;
|
|
51
51
|
sqlLiteralString(literal: string): string;
|
package/dist/dialect/postgres.js
CHANGED
|
@@ -296,10 +296,10 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
296
296
|
}
|
|
297
297
|
throw new Error(`Unknown or unhandled postgres time unit: ${units}`);
|
|
298
298
|
}
|
|
299
|
-
sqlSumDistinct(key, value) {
|
|
299
|
+
sqlSumDistinct(key, value, funcName) {
|
|
300
300
|
// return `sum_distinct(list({key:${key}, val: ${value}}))`;
|
|
301
301
|
return `(
|
|
302
|
-
SELECT
|
|
302
|
+
SELECT ${funcName}((a::json->>'f2')::DOUBLE PRECISION) as value
|
|
303
303
|
FROM (
|
|
304
304
|
SELECT UNNEST(array_agg(distinct row_to_json(row(${key},${value}))::text)) a
|
|
305
305
|
) a
|
|
@@ -290,7 +290,7 @@ class QueryField extends QueryNode {
|
|
|
290
290
|
let ret;
|
|
291
291
|
if (distinctKeySQL) {
|
|
292
292
|
if (this.parent.dialect.supportsSumDistinctFunction) {
|
|
293
|
-
ret = this.parent.dialect.sqlSumDistinct(distinctKeySQL, dimSQL);
|
|
293
|
+
ret = this.parent.dialect.sqlSumDistinct(distinctKeySQL, dimSQL, 'SUM');
|
|
294
294
|
}
|
|
295
295
|
else {
|
|
296
296
|
ret = sqlSumDistinct(this.parent.dialect, dimSQL, distinctKeySQL);
|
|
@@ -318,13 +318,15 @@ class QueryField extends QueryNode {
|
|
|
318
318
|
countDistinctKeySQL = `CASE WHEN ${state.whereSQL} THEN ${distinctKeySQL} END`;
|
|
319
319
|
}
|
|
320
320
|
let sumDistinctSQL;
|
|
321
|
+
let avgDistinctSQL;
|
|
321
322
|
if (this.parent.dialect.supportsSumDistinctFunction) {
|
|
322
|
-
|
|
323
|
+
avgDistinctSQL = this.parent.dialect.sqlSumDistinct(distinctKeySQL, dimSQL, 'AVG');
|
|
323
324
|
}
|
|
324
325
|
else {
|
|
325
326
|
sumDistinctSQL = sqlSumDistinct(this.parent.dialect, dimSQL, distinctKeySQL);
|
|
327
|
+
avgDistinctSQL = `(${sumDistinctSQL})/NULLIF(COUNT(DISTINCT CASE WHEN ${dimSQL} IS NOT NULL THEN ${countDistinctKeySQL} END),0)`;
|
|
326
328
|
}
|
|
327
|
-
return
|
|
329
|
+
return avgDistinctSQL;
|
|
328
330
|
}
|
|
329
331
|
else {
|
|
330
332
|
return `AVG(${dimSQL})`;
|
|
@@ -1667,7 +1669,7 @@ class QueryQuery extends QueryField {
|
|
|
1667
1669
|
let structSQL = qs.structSourceSQL(stageWriter);
|
|
1668
1670
|
if ((0, malloy_types_1.isJoinOn)(structRelationship)) {
|
|
1669
1671
|
if (ji.makeUniqueKey) {
|
|
1670
|
-
structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * FROM ${structSQL})`;
|
|
1672
|
+
structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * FROM ${structSQL} as x)`;
|
|
1671
1673
|
}
|
|
1672
1674
|
let onCondition = '';
|
|
1673
1675
|
if (qs.parent === undefined) {
|