@malloydata/malloy 0.0.66-dev230803195842 → 0.0.66

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.
@@ -23,9 +23,9 @@ export declare type DialectFieldList = DialectField[];
23
23
  export declare abstract class Dialect {
24
24
  abstract name: string;
25
25
  abstract defaultNumberType: string;
26
+ abstract defaultDecimalType: string;
26
27
  abstract udfPrefix: string;
27
28
  abstract hasFinalStage: boolean;
28
- abstract stringTypeName: string;
29
29
  abstract divisionIsInteger: boolean;
30
30
  abstract supportsSumDistinctFunction: boolean;
31
31
  abstract unnestWithNumbers: boolean;
@@ -36,6 +36,7 @@ export declare abstract class Dialect {
36
36
  abstract dontUnionIndex: boolean;
37
37
  abstract supportsQualify: boolean;
38
38
  abstract supportsSafeCast: boolean;
39
+ abstract supportsNesting: boolean;
39
40
  abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
40
41
  abstract quoteTablePath(tablePath: string): string;
41
42
  abstract sqlGroupSetTable(groupSetCount: number): string;
@@ -67,6 +68,7 @@ export declare abstract class Dialect {
67
68
  abstract sqlLiteralString(literal: string): string;
68
69
  abstract sqlLiteralRegexp(literal: string): string;
69
70
  abstract sqlRegexpMatch(expr: Expr, regex: Expr): Expr;
71
+ abstract castToString(expression: string): string;
70
72
  sqlLiteralNumber(literal: string): string;
71
73
  dialectExpr(qi: QueryInfo, df: DialectFragment): Expr;
72
74
  sqlSumDistinct(_key: string, _value: string, _funcName: string): string;
@@ -57,7 +57,7 @@ class Dialect {
57
57
  }
58
58
  // default implementation will probably work most of the time
59
59
  sqlDateToString(sqlDateExp) {
60
- return `CAST(DATE(${sqlDateExp}) AS ${this.stringTypeName} )`;
60
+ return this.castToString(`DATE(${sqlDateExp})`);
61
61
  }
62
62
  // BigQuery has some fieldNames that are Pseudo Fields and shouldn't be
63
63
  // included in projections.
@@ -4,8 +4,8 @@ import { Dialect, DialectFieldList, QueryInfo } from '../dialect';
4
4
  export declare class DuckDBDialect extends Dialect {
5
5
  name: string;
6
6
  defaultNumberType: string;
7
+ defaultDecimalType: string;
7
8
  hasFinalStage: boolean;
8
- stringTypeName: string;
9
9
  divisionIsInteger: boolean;
10
10
  supportsSumDistinctFunction: boolean;
11
11
  unnestWithNumbers: boolean;
@@ -18,6 +18,7 @@ export declare class DuckDBDialect extends Dialect {
18
18
  dontUnionIndex: boolean;
19
19
  supportsQualify: boolean;
20
20
  supportsSafeCast: boolean;
21
+ supportsNesting: boolean;
21
22
  get udfPrefix(): string;
22
23
  quoteTablePath(tableName: string): string;
23
24
  sqlGroupSetTable(groupSetCount: number): string;
@@ -53,4 +54,5 @@ export declare class DuckDBDialect extends Dialect {
53
54
  sqlLiteralString(literal: string): string;
54
55
  sqlLiteralRegexp(literal: string): string;
55
56
  getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
57
+ castToString(expression: string): string;
56
58
  }
@@ -42,8 +42,8 @@ class DuckDBDialect extends dialect_1.Dialect {
42
42
  super(...arguments);
43
43
  this.name = 'duckdb';
44
44
  this.defaultNumberType = 'DOUBLE';
45
+ this.defaultDecimalType = 'NUMERIC';
45
46
  this.hasFinalStage = false;
46
- this.stringTypeName = 'VARCHAR';
47
47
  this.divisionIsInteger = true;
48
48
  this.supportsSumDistinctFunction = true;
49
49
  this.unnestWithNumbers = true;
@@ -54,6 +54,7 @@ class DuckDBDialect extends dialect_1.Dialect {
54
54
  this.dontUnionIndex = true;
55
55
  this.supportsQualify = true;
56
56
  this.supportsSafeCast = true;
57
+ this.supportsNesting = true;
57
58
  }
58
59
  // hack until they support temporary macros.
59
60
  get udfPrefix() {
@@ -334,6 +335,9 @@ class DuckDBDialect extends dialect_1.Dialect {
334
335
  getGlobalFunctionDef(name) {
335
336
  return functions_1.DUCKDB_FUNCTIONS.get(name);
336
337
  }
338
+ castToString(expression) {
339
+ return `CAST(${expression} as VARCHAR)`;
340
+ }
337
341
  }
338
342
  exports.DuckDBDialect = DuckDBDialect;
339
343
  //# sourceMappingURL=duckdb.js.map
@@ -1,3 +1,5 @@
1
+ export type { DialectFunctionOverloadDef } from './functions/util';
2
+ export { anyExprType, makeParam, overload, minScalar, sql, } from './functions/util';
1
3
  export { Dialect } from './dialect';
2
4
  export type { DialectFieldList } from './dialect';
3
5
  export { StandardSQLDialect } from './standardsql';
@@ -22,7 +22,13 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.getDialectFunction = exports.registerDialect = exports.getDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.Dialect = void 0;
25
+ exports.getDialectFunction = exports.registerDialect = exports.getDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.Dialect = exports.sql = exports.minScalar = exports.overload = exports.makeParam = exports.anyExprType = void 0;
26
+ var util_1 = require("./functions/util");
27
+ Object.defineProperty(exports, "anyExprType", { enumerable: true, get: function () { return util_1.anyExprType; } });
28
+ Object.defineProperty(exports, "makeParam", { enumerable: true, get: function () { return util_1.makeParam; } });
29
+ Object.defineProperty(exports, "overload", { enumerable: true, get: function () { return util_1.overload; } });
30
+ Object.defineProperty(exports, "minScalar", { enumerable: true, get: function () { return util_1.minScalar; } });
31
+ Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return util_1.sql; } });
26
32
  var dialect_1 = require("./dialect");
27
33
  Object.defineProperty(exports, "Dialect", { enumerable: true, get: function () { return dialect_1.Dialect; } });
28
34
  var standardsql_1 = require("./standardsql");
@@ -4,9 +4,9 @@ import { Dialect, DialectFieldList, QueryInfo } from '../dialect';
4
4
  export declare class PostgresDialect extends Dialect {
5
5
  name: string;
6
6
  defaultNumberType: string;
7
+ defaultDecimalType: string;
7
8
  udfPrefix: string;
8
9
  hasFinalStage: boolean;
9
- stringTypeName: string;
10
10
  divisionIsInteger: boolean;
11
11
  supportsSumDistinctFunction: boolean;
12
12
  unnestWithNumbers: boolean;
@@ -20,6 +20,7 @@ export declare class PostgresDialect extends Dialect {
20
20
  dontUnionIndex: boolean;
21
21
  supportsQualify: boolean;
22
22
  globalFunctions: import("../functions/function_map").FunctionMap;
23
+ supportsNesting: boolean;
23
24
  quoteTablePath(tablePath: string): string;
24
25
  sqlGroupSetTable(groupSetCount: number): string;
25
26
  sqlAnyValue(groupSet: number, fieldName: string): string;
@@ -54,4 +55,5 @@ export declare class PostgresDialect extends Dialect {
54
55
  sqlLiteralString(literal: string): string;
55
56
  sqlLiteralRegexp(literal: string): string;
56
57
  getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
58
+ castToString(expression: string): string;
57
59
  }
@@ -56,9 +56,9 @@ class PostgresDialect extends dialect_1.Dialect {
56
56
  super(...arguments);
57
57
  this.name = 'postgres';
58
58
  this.defaultNumberType = 'DOUBLE PRECISION';
59
+ this.defaultDecimalType = 'NUMERIC';
59
60
  this.udfPrefix = 'pg_temp.__udf';
60
61
  this.hasFinalStage = true;
61
- this.stringTypeName = 'VARCHAR';
62
62
  this.divisionIsInteger = true;
63
63
  this.supportsSumDistinctFunction = false;
64
64
  this.unnestWithNumbers = false;
@@ -70,6 +70,7 @@ class PostgresDialect extends dialect_1.Dialect {
70
70
  this.dontUnionIndex = false;
71
71
  this.supportsQualify = false;
72
72
  this.globalFunctions = functions_1.POSTGRES_FUNCTIONS;
73
+ this.supportsNesting = true;
73
74
  }
74
75
  quoteTablePath(tablePath) {
75
76
  return tablePath
@@ -356,6 +357,9 @@ class PostgresDialect extends dialect_1.Dialect {
356
357
  getGlobalFunctionDef(name) {
357
358
  return functions_1.POSTGRES_FUNCTIONS.get(name);
358
359
  }
360
+ castToString(expression) {
361
+ return `CAST(${expression} as VARCHAR)`;
362
+ }
359
363
  }
360
364
  exports.PostgresDialect = PostgresDialect;
361
365
  //# sourceMappingURL=postgres.js.map
@@ -4,9 +4,9 @@ import { Dialect, DialectFieldList, QueryInfo } from '../dialect';
4
4
  export declare class StandardSQLDialect extends Dialect {
5
5
  name: string;
6
6
  defaultNumberType: string;
7
+ defaultDecimalType: string;
7
8
  udfPrefix: string;
8
9
  hasFinalStage: boolean;
9
- stringTypeName: string;
10
10
  divisionIsInteger: boolean;
11
11
  supportsSumDistinctFunction: boolean;
12
12
  unnestWithNumbers: boolean;
@@ -19,6 +19,7 @@ export declare class StandardSQLDialect extends Dialect {
19
19
  dontUnionIndex: boolean;
20
20
  supportsQualify: boolean;
21
21
  supportsSafeCast: boolean;
22
+ supportsNesting: boolean;
22
23
  quoteTablePath(tablePath: string): string;
23
24
  sqlGroupSetTable(groupSetCount: number): string;
24
25
  sqlAnyValue(groupSet: number, fieldName: string): string;
@@ -50,4 +51,5 @@ export declare class StandardSQLDialect extends Dialect {
50
51
  sqlLiteralString(literal: string): string;
51
52
  sqlLiteralRegexp(literal: string): string;
52
53
  getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
54
+ castToString(expression: string): string;
53
55
  }
@@ -62,9 +62,9 @@ class StandardSQLDialect extends dialect_1.Dialect {
62
62
  super(...arguments);
63
63
  this.name = 'standardsql';
64
64
  this.defaultNumberType = 'FLOAT64';
65
+ this.defaultDecimalType = 'NUMERIC';
65
66
  this.udfPrefix = '__udf';
66
67
  this.hasFinalStage = false;
67
- this.stringTypeName = 'STRING';
68
68
  this.divisionIsInteger = false;
69
69
  this.supportsSumDistinctFunction = false;
70
70
  this.unnestWithNumbers = false;
@@ -75,6 +75,7 @@ class StandardSQLDialect extends dialect_1.Dialect {
75
75
  this.dontUnionIndex = true; // bigquery can't use a sample table more than once in a query.
76
76
  this.supportsQualify = true;
77
77
  this.supportsSafeCast = true;
78
+ this.supportsNesting = true;
78
79
  this.keywords = `
79
80
  ALL
80
81
  AND
@@ -416,6 +417,9 @@ ${(0, utils_1.indent)(sql)}
416
417
  getGlobalFunctionDef(name) {
417
418
  return functions_1.STANDARDSQL_FUNCTIONS.get(name);
418
419
  }
420
+ castToString(expression) {
421
+ return `CAST(${expression} as STRING)`;
422
+ }
419
423
  }
420
424
  exports.StandardSQLDialect = StandardSQLDialect;
421
425
  //# sourceMappingURL=standardsql.js.map
package/dist/index.d.ts CHANGED
@@ -3,9 +3,9 @@ export { Segment, isFilteredAliasedName, flattenQuery, expressionIsCalculation,
3
3
  export { HighlightType, MalloyTranslator, } from './lang';
4
4
  export type { LogMessage, TranslateResponse } from './lang';
5
5
  export { Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, Result, QueryMaterializer, CSVWriter, JSONWriter, Parse, DataWriter, Explore, } from './malloy';
6
- export type { Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, } from './malloy';
6
+ export type { Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, } from './malloy';
7
7
  export type { RunSQLOptions } from './run_sql_options';
8
- export type { URLReader, InfoConnection, LookupConnection, Connection, DialectProvider, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from './runtime_types';
9
- export type { Loggable } from './malloy';
8
+ export { DialectProvider } from './runtime_types';
9
+ export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from './runtime_types';
10
10
  export { toAsyncGenerator } from './connection_utils';
11
11
  export { Tags, type MalloyTags, type MalloyTagProperties } from './tags';
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Tags = exports.toAsyncGenerator = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.expressionIsCalculation = exports.flattenQuery = exports.isFilteredAliasedName = exports.Segment = void 0;
25
+ exports.Tags = exports.toAsyncGenerator = exports.DialectProvider = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.expressionIsCalculation = exports.flattenQuery = exports.isFilteredAliasedName = exports.Segment = void 0;
26
26
  var model_1 = require("./model");
27
27
  // Used in Composer Demo
28
28
  Object.defineProperty(exports, "Segment", { enumerable: true, get: function () { return model_1.Segment; } });
@@ -55,6 +55,8 @@ Object.defineProperty(exports, "JSONWriter", { enumerable: true, get: function (
55
55
  Object.defineProperty(exports, "Parse", { enumerable: true, get: function () { return malloy_1.Parse; } });
56
56
  Object.defineProperty(exports, "DataWriter", { enumerable: true, get: function () { return malloy_1.DataWriter; } });
57
57
  Object.defineProperty(exports, "Explore", { enumerable: true, get: function () { return malloy_1.Explore; } });
58
+ var runtime_types_1 = require("./runtime_types");
59
+ Object.defineProperty(exports, "DialectProvider", { enumerable: true, get: function () { return runtime_types_1.DialectProvider; } });
58
60
  var connection_utils_1 = require("./connection_utils");
59
61
  Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: function () { return connection_utils_1.toAsyncGenerator; } });
60
62
  var tags_1 = require("./tags");
package/dist/malloy.d.ts CHANGED
@@ -802,6 +802,7 @@ export declare class SingleConnectionRuntime<T extends Connection = Connection>
802
802
  readonly connection: T;
803
803
  constructor(urls: URLReader, connection: T);
804
804
  constructor(connection: T);
805
+ get supportsNesting(): boolean;
805
806
  }
806
807
  declare class FluentState<T> {
807
808
  protected runtime: Runtime;
package/dist/malloy.js CHANGED
@@ -27,6 +27,7 @@ const lang_1 = require("./lang");
27
27
  const model_1 = require("./model");
28
28
  const luxon_1 = require("luxon");
29
29
  const tags_1 = require("./tags");
30
+ const dialect_1 = require("./dialect");
30
31
  class Malloy {
31
32
  // TODO load from file built during release
32
33
  static get version() {
@@ -1631,6 +1632,9 @@ class SingleConnectionRuntime extends Runtime {
1631
1632
  this.connection = connection;
1632
1633
  }
1633
1634
  }
1635
+ get supportsNesting() {
1636
+ return (0, dialect_1.getDialect)(this.connection.dialectName).supportsNesting;
1637
+ }
1634
1638
  }
1635
1639
  exports.SingleConnectionRuntime = SingleConnectionRuntime;
1636
1640
  class FluentState {
@@ -765,7 +765,7 @@ function sqlSumDistinct(dialect, sqlExp, sqlDistintKey) {
765
765
  const sumSQL = `
766
766
  (
767
767
  SUM(DISTINCT
768
- (CAST(ROUND(COALESCE(${sqlExp},0)*(${multiplier}*1.0), ${NUMERIC_DECIMAL_PRECISION}) AS NUMERIC) +
768
+ (CAST(ROUND(COALESCE(${sqlExp},0)*(${multiplier}*1.0), ${NUMERIC_DECIMAL_PRECISION}) AS ${dialect.defaultDecimalType}) +
769
769
  ${uniqueInt}
770
770
  ))
771
771
  -
@@ -1861,7 +1861,7 @@ class QueryQuery extends QueryField {
1861
1861
  if ((0, malloy_types_1.isJoinOn)(structRelationship)) {
1862
1862
  if (ji.makeUniqueKey) {
1863
1863
  const passKeys = this.generateSQLPassthroughKeys(qs);
1864
- structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * ${passKeys} FROM ${structSQL} as x)`;
1864
+ structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, x.* ${passKeys} FROM ${structSQL} as x)`;
1865
1865
  }
1866
1866
  let onCondition = '';
1867
1867
  if (qs.parent === undefined) {
@@ -1958,7 +1958,7 @@ class QueryQuery extends QueryField {
1958
1958
  if (structRelationship.type === 'basetable') {
1959
1959
  if (ji.makeUniqueKey) {
1960
1960
  const passKeys = this.generateSQLPassthroughKeys(qs);
1961
- structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, * ${passKeys} FROM ${structSQL} as x)`;
1961
+ structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, x.* ${passKeys} FROM ${structSQL} as x)`;
1962
1962
  }
1963
1963
  s += `FROM ${structSQL} as ${ji.alias}\n`;
1964
1964
  }
@@ -2152,7 +2152,7 @@ class QueryQuery extends QueryField {
2152
2152
  r = r.parent;
2153
2153
  }
2154
2154
  fields.push(`MAX(CASE WHEN group_set IN (${result.childGroups.join(',')}) THEN __delete__${result.groupSet} END) OVER(partition by ${dimensions
2155
- .map(x => `CAST(${x} AS ${this.parent.dialect.stringTypeName}) `)
2155
+ .map(this.parent.dialect.castToString)
2156
2156
  .join(',')}) as __shaving__${result.groupSet}`);
2157
2157
  }
2158
2158
  }
@@ -2589,7 +2589,7 @@ class QueryQueryIndexStage extends QueryQuery {
2589
2589
  s += " CASE group_set\n WHEN 99999 THEN ''";
2590
2590
  for (let i = 0; i < fields.length; i++) {
2591
2591
  if (fields[i].type === 'number') {
2592
- s += ` WHEN ${i} THEN CAST(MIN(${fields[i].expression}) AS ${dialect.stringTypeName}) || ' to ' || CAST(MAX(${fields[i].expression}) AS ${dialect.stringTypeName})\n`;
2592
+ s += ` WHEN ${i} THEN ${dialect.castToString(`MIN(${fields[i].expression})`)} || ' to ' || ${dialect.castToString(`MAX(${fields[i].expression})`)}\n`;
2593
2593
  }
2594
2594
  if (fields[i].type === 'timestamp' || fields[i].type === 'date') {
2595
2595
  s += ` WHEN ${i} THEN MIN(${dialect.sqlDateToString(fields[i].expression)}) || ' to ' || MAX(${dialect.sqlDateToString(fields[i].expression)})\n`;
@@ -80,6 +80,7 @@ export interface Connection extends InfoConnection {
80
80
  canStream(): this is StreamingConnection;
81
81
  close(): Promise<void>;
82
82
  estimateQueryCost(sqlCommand: string): Promise<QueryRunStats>;
83
+ get dialectName(): string;
83
84
  }
84
85
  export interface TestableConnection extends Connection {
85
86
  test(): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.66-dev230803195842",
3
+ "version": "0.0.66",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",