@malloydata/malloy 0.0.130-dev240311192728 → 0.0.130-dev240312011825

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.
@@ -27,20 +27,28 @@ const util_1 = require("../../functions/util");
27
27
  function fnStringAgg() {
28
28
  const value = (0, util_1.makeParam)('value', (0, util_1.maxScalar)('string'));
29
29
  const separator = (0, util_1.makeParam)('separator', (0, util_1.literal)((0, util_1.maxScalar)('string')));
30
- const orderBy = { type: 'aggregate_order_by' };
30
+ const orderBy = {
31
+ type: 'aggregate_order_by',
32
+ prefix: ' WITHIN GROUP(',
33
+ suffix: ')',
34
+ };
31
35
  return [
32
- (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param], (0, util_1.sql) `LISTAGG(${value.arg}, ',') WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false }),
33
- (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param, separator.param], (0, util_1.sql) `LISTAGG(${value.arg}, ${separator.arg}) WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false }),
36
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param], (0, util_1.sql) `LISTAGG(${value.arg}, ',')${orderBy}`, { supportsOrderBy: true, supportsLimit: false }),
37
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param, separator.param], (0, util_1.sql) `LISTAGG(${value.arg}, ${separator.arg})${orderBy}`, { supportsOrderBy: true, supportsLimit: false }),
34
38
  ];
35
39
  }
36
40
  exports.fnStringAgg = fnStringAgg;
37
41
  function fnStringAggDistinct() {
38
42
  const value = (0, util_1.makeParam)('value', (0, util_1.maxScalar)('string'));
39
43
  const separator = (0, util_1.makeParam)('separator', (0, util_1.literal)((0, util_1.maxScalar)('string')));
40
- const orderBy = { type: 'aggregate_order_by' };
44
+ const orderBy = {
45
+ type: 'aggregate_order_by',
46
+ prefix: ' WITHIN GROUP(',
47
+ suffix: ')',
48
+ };
41
49
  return [
42
- (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param], (0, util_1.sql) `LISTAGG(DISTINCT ${value.arg}, ',') WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false }),
43
- (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param, separator.param], (0, util_1.sql) `LISTAGG(DISTINCT ${value.arg}, ${separator.arg}) WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false }),
50
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param], (0, util_1.sql) `LISTAGG(DISTINCT ${value.arg}, ',')${orderBy}`, { supportsOrderBy: true, supportsLimit: false }),
51
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param, separator.param], (0, util_1.sql) `LISTAGG(DISTINCT ${value.arg}, ${separator.arg})${orderBy}`, { supportsOrderBy: true, supportsLimit: false }),
44
52
  ];
45
53
  }
46
54
  exports.fnStringAggDistinct = fnStringAggDistinct;
@@ -258,6 +258,7 @@ class QueryField extends QueryNode {
258
258
  throw new Error(`Function is not defined for dialect ${dialect}`);
259
259
  }
260
260
  return (0, utils_1.exprMap)(overload.dialect[dialect].e, fragment => {
261
+ var _a, _b;
261
262
  if (typeof fragment === 'string') {
262
263
  return [fragment];
263
264
  }
@@ -290,7 +291,9 @@ class QueryField extends QueryNode {
290
291
  }
291
292
  }
292
293
  else if (fragment.type === 'aggregate_order_by') {
293
- return orderBy ? [` ${orderBy}`] : [];
294
+ return orderBy
295
+ ? [` ${(_a = fragment.prefix) !== null && _a !== void 0 ? _a : ''}${orderBy}${(_b = fragment.suffix) !== null && _b !== void 0 ? _b : ''}`]
296
+ : [];
294
297
  }
295
298
  else if (fragment.type === 'aggregate_limit') {
296
299
  return limit ? [` ${limit}`] : [];
@@ -345,7 +348,8 @@ class QueryField extends QueryNode {
345
348
  const aggregateLimit = frag.limit ? `LIMIT ${frag.limit}` : undefined;
346
349
  if (frag.name === 'string_agg' &&
347
350
  distinctKey &&
348
- !context.dialect.supportsAggDistinct) {
351
+ !context.dialect.supportsAggDistinct &&
352
+ context.dialect.name !== 'snowflake') {
349
353
  return this.generateAsymmetricStringAggExpression(resultSet, context, args[0], args[1], distinctKey, frag.orderBy, context.dialect.name, state);
350
354
  }
351
355
  if (distinctKey) {
@@ -650,6 +654,7 @@ class QueryField extends QueryNode {
650
654
  }
651
655
  if (resultStruct.firstSegment.type === 'reduce') {
652
656
  const orderSQL = orderingField.fif.getAnalyticalSQL(false);
657
+ // const orderSQL = this.generateDimFragment(resultSet, context, arg, state)
653
658
  obSQL.push(` ${orderSQL} ${ordering.dir || 'ASC'}`);
654
659
  }
655
660
  else if (resultStruct.firstSegment.type === 'project') {
@@ -1143,6 +1148,11 @@ class FieldInstanceResult {
1143
1148
  for (const [_name, fi] of this.allFields) {
1144
1149
  if (fi instanceof FieldInstanceField) {
1145
1150
  if (fi.fieldUsage.type === 'result') {
1151
+ if (fi.f.fieldDef.type === 'turtle' ||
1152
+ fi.f.fieldDef.type === 'struct' ||
1153
+ (0, malloy_types_1.expressionIsAnalytic)(fi.f.fieldDef.expressionType)) {
1154
+ continue;
1155
+ }
1146
1156
  firstField || (firstField = fi.fieldUsage.resultIndex);
1147
1157
  if (['date', 'timestamp'].indexOf(fi.f.fieldDef.type) > -1) {
1148
1158
  return [{ dir: 'desc', field: fi.fieldUsage.resultIndex }];
@@ -2157,7 +2167,18 @@ class QueryQuery extends QueryField {
2157
2167
  `);
2158
2168
  }
2159
2169
  generateStage0Fields(resultSet, output, stageWriter) {
2170
+ const scalarFields = [];
2171
+ const otherFields = [];
2160
2172
  for (const [name, fi] of resultSet.allFields) {
2173
+ if (fi instanceof FieldInstanceField && isScalarField(fi.f)) {
2174
+ scalarFields.push([name, fi]);
2175
+ }
2176
+ else {
2177
+ otherFields.push([name, fi]);
2178
+ }
2179
+ }
2180
+ const orderedFields = [...scalarFields, ...otherFields];
2181
+ for (const [name, fi] of orderedFields) {
2161
2182
  const outputName = this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${resultSet.groupSet}`);
2162
2183
  if (fi instanceof FieldInstanceField) {
2163
2184
  if (fi.fieldUsage.type === 'result') {
@@ -126,6 +126,8 @@ export interface FunctionParameterFragment {
126
126
  export declare function isFunctionParameterFragment(f: Fragment): f is FunctionParameterFragment;
127
127
  export interface AggregateOrderByFragment {
128
128
  type: 'aggregate_order_by';
129
+ prefix?: string;
130
+ suffix?: string;
129
131
  }
130
132
  export interface AggregateLimitFragment {
131
133
  type: 'aggregate_limit';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.130-dev240311192728",
3
+ "version": "0.0.130-dev240312011825",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",