@malloydata/malloy 0.0.130-dev240311164559 → 0.0.130-dev240311202005

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';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ // eslint-disable-next-line no-restricted-imports
26
+ const utils_1 = require("./utils");
27
+ describe('model/utils', () => {
28
+ it('should generate deterministic hashes', () => {
29
+ const hash1 = (0, utils_1.generateHash)('test-content');
30
+ expect(hash1).toEqual('ab17568f-0362-503d-a9c6-76fb0b203636');
31
+ });
32
+ it('should generate unique hashes', () => {
33
+ const hash1 = (0, utils_1.generateHash)('test-content');
34
+ const hash2 = (0, utils_1.generateHash)('test-content-different');
35
+ expect(hash1).not.toEqual(hash2);
36
+ });
37
+ });
38
+ //# sourceMappingURL=utils.spec.js.map
@@ -0,0 +1,14 @@
1
+ /// <reference types="jest" />
2
+ /**
3
+ * Accepts databases in env, either via comma-separated dialect list
4
+ * (MALLOY_DATABASES=) or a single database (MALLOY_DATABASE=). returns either
5
+ * databases defined in env or a default list that was passed.
6
+ */
7
+ export declare function databasesFromEnvironmentOr(defaultDatabases: string[]): string[];
8
+ /**
9
+ * Confirms that one or more of the databases being tested overlaps with
10
+ * the databases a test suite can accept. If there is overlap, return a tuple
11
+ * of jest.describe and the dialects to be tested if there is no overlap,
12
+ * return a tuple if jest.describe.skip and the dialects to be tested
13
+ */
14
+ export declare function describeIfDatabaseAvailable(acceptableDatabases: string[]): [jest.Describe, string[]];
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.describeIfDatabaseAvailable = exports.databasesFromEnvironmentOr = void 0;
26
+ /**
27
+ * Accepts databases in env, either via comma-separated dialect list
28
+ * (MALLOY_DATABASES=) or a single database (MALLOY_DATABASE=). returns either
29
+ * databases defined in env or a default list that was passed.
30
+ */
31
+ function databasesFromEnvironmentOr(defaultDatabases) {
32
+ return process.env['MALLOY_DATABASES']
33
+ ? process.env['MALLOY_DATABASES'].split(',')
34
+ : process.env['MALLOY_DATABASE']
35
+ ? [process.env['MALLOY_DATABASE']]
36
+ : defaultDatabases;
37
+ }
38
+ exports.databasesFromEnvironmentOr = databasesFromEnvironmentOr;
39
+ /**
40
+ * A replacement for [describe()] that mimics [describe.skip()]
41
+ */
42
+ const describeSkip = Object.assign((name, fn) => describe.skip(name, fn), {
43
+ skip: describe.skip,
44
+ // eslint-disable-next-line no-restricted-properties
45
+ only: describe.only,
46
+ each: (() => () => it.skip('skipped', () => { })),
47
+ });
48
+ /**
49
+ * Confirms that one or more of the databases being tested overlaps with
50
+ * the databases a test suite can accept. If there is overlap, return a tuple
51
+ * of jest.describe and the dialects to be tested if there is no overlap,
52
+ * return a tuple if jest.describe.skip and the dialects to be tested
53
+ */
54
+ function describeIfDatabaseAvailable(acceptableDatabases) {
55
+ const currentDatabases = databasesFromEnvironmentOr(acceptableDatabases);
56
+ const overlap = acceptableDatabases.filter(d => currentDatabases.includes(d));
57
+ return overlap.length > 0 ? [describe, overlap] : [describeSkip, overlap];
58
+ }
59
+ exports.describeIfDatabaseAvailable = describeIfDatabaseAvailable;
60
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.130-dev240311164559",
3
+ "version": "0.0.130-dev240311202005",
4
4
  "license": "MIT",
5
+ "exports": {
6
+ ".": "./dist/index.js",
7
+ "./test": "./dist/test/index.js"
8
+ },
9
+ "typesVersions": {
10
+ "*": {
11
+ "index": [
12
+ "./dist/index.d.ts"
13
+ ],
14
+ "test": [
15
+ "./dist/test/index.d.ts"
16
+ ]
17
+ }
18
+ },
5
19
  "main": "dist/index.js",
6
20
  "types": "dist/index.d.ts",
7
21
  "homepage": "https://github.com/malloydata/malloy#readme",