@malloydata/malloy 0.0.127-dev240308180053 → 0.0.127

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.
@@ -39,6 +39,8 @@ export declare abstract class Dialect {
39
39
  abstract supportsSafeCast: boolean;
40
40
  abstract supportsNesting: boolean;
41
41
  cantPartitionWindowFunctionsOnExpressions: boolean;
42
+ supportsPipelinesInViews: boolean;
43
+ supportsArraysInData: boolean;
42
44
  abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
43
45
  abstract quoteTablePath(tablePath: string): string;
44
46
  abstract sqlGroupSetTable(groupSetCount: number): string;
@@ -58,6 +58,10 @@ class Dialect {
58
58
  //
59
59
  // StandardSQL dialects can't partition on expression in window functions
60
60
  this.cantPartitionWindowFunctionsOnExpressions = false;
61
+ // Snowflake can't yet support pipelines in nested views.
62
+ this.supportsPipelinesInViews = true;
63
+ // Some dialects don't supporrt arrays.
64
+ this.supportsArraysInData = true;
61
65
  }
62
66
  sqlFinalStage(_lastStageName, _fields) {
63
67
  throw new Error('Dialect has no final Stage but called Anyway');
@@ -21,6 +21,8 @@ export declare class SnowflakeDialect extends Dialect {
21
21
  dontUnionIndex: boolean;
22
22
  supportsQualify: boolean;
23
23
  supportsNesting: boolean;
24
+ supportsPipelinesInViews: boolean;
25
+ supportsArraysInData: boolean;
24
26
  quoteTablePath(tablePath: string): string;
25
27
  sqlGroupSetTable(groupSetCount: number): string;
26
28
  sqlAnyValue(groupSet: number, fieldName: string): string;
@@ -36,7 +38,7 @@ export declare class SnowflakeDialect extends Dialect {
36
38
  sqlFieldReference(alias: string, fieldName: string, fieldType: string, isNested: boolean, _isArray: boolean): string;
37
39
  sqlUnnestPipelineHead(isSingleton: boolean, sourceSQLExpression: string): string;
38
40
  sqlCreateFunction(_id: string, _funcText: string): string;
39
- sqlCreateFunctionCombineLastStage(lastStageName: string): string;
41
+ sqlCreateFunctionCombineLastStage(_lastStageName: string): string;
40
42
  sqlSelectAliasAsStruct(alias: string): string;
41
43
  sqlMaybeQuoteIdentifier(identifier: string): string;
42
44
  sqlCreateTableAsSelect(tableName: string, sql: string): string;
@@ -93,13 +93,15 @@ class SnowflakeDialect extends dialect_1.Dialect {
93
93
  this.dontUnionIndex = false;
94
94
  this.supportsQualify = false;
95
95
  this.supportsNesting = true;
96
+ this.supportsPipelinesInViews = false;
97
+ this.supportsArraysInData = false;
96
98
  }
97
99
  // don't mess with the table pathing.
98
100
  quoteTablePath(tablePath) {
99
101
  return tablePath;
100
102
  }
101
103
  sqlGroupSetTable(groupSetCount) {
102
- return `SELECT index as group_set FROM TABLE(FLATTEN(ARRAY_GENERATE_RANGE(0, ${groupSetCount})))`;
104
+ return `CROSS JOIN (SELECT index as group_set FROM TABLE(FLATTEN(ARRAY_GENERATE_RANGE(0, ${groupSetCount + 1}))))`;
103
105
  }
104
106
  sqlAnyValue(groupSet, fieldName) {
105
107
  return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN ${fieldName} END) WITHIN GROUP (ORDER BY ${fieldName} ASC NULLS LAST))[0]`;
@@ -117,7 +119,7 @@ class SnowflakeDialect extends dialect_1.Dialect {
117
119
  sqlAggregateTurtle(groupSet, fieldList, orderBy, limit) {
118
120
  const fields = this.mapFieldsForObjectConstruct(fieldList);
119
121
  const orderByClause = orderBy ? ` WITHIN GROUP (${orderBy})` : '';
120
- const aggClause = `ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT(${fields}) END)${orderByClause}`;
122
+ const aggClause = `ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT_KEEP_NULL(${fields}) END)${orderByClause}`;
121
123
  if (limit === undefined) {
122
124
  return `COALESCE(${aggClause}, [])`;
123
125
  }
@@ -125,7 +127,7 @@ class SnowflakeDialect extends dialect_1.Dialect {
125
127
  }
126
128
  sqlAnyValueTurtle(groupSet, fieldList) {
127
129
  const fields = this.mapFieldsForObjectConstruct(fieldList);
128
- return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT(${fields}) END) WITHIN GROUP (ORDER BY 1 ASC NULLS LAST))[0]`;
130
+ return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT_KEEP_NULL(${fields}) END) WITHIN GROUP (ORDER BY 1 ASC NULLS LAST))[0]`;
129
131
  }
130
132
  sqlAnyValueLastTurtle(name, groupSet, sqlName) {
131
133
  return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN ${name} END) WITHIN GROUP (ORDER BY ${name} ASC NULLS LAST))[0] AS ${sqlName}`;
@@ -135,7 +137,7 @@ class SnowflakeDialect extends dialect_1.Dialect {
135
137
  const nullValues = fieldList
136
138
  .map(f => `'${f.sqlOutputName}', NULL`)
137
139
  .join(', ');
138
- return `COALESCE(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT(${fields}) END)[0], OBJECT_CONSTRUCT_KEEP_NULL(${nullValues}))`;
140
+ return `COALESCE(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT_KEEP_NULL(${fields}) END)[0], OBJECT_CONSTRUCT_KEEP_NULL(${nullValues}))`;
139
141
  }
140
142
  sqlUnnestAlias(source, alias, _fieldList, _needDistinctKey, isArray, _isInNestedPipeline) {
141
143
  if (isArray) {
@@ -195,6 +197,9 @@ class SnowflakeDialect extends dialect_1.Dialect {
195
197
  if (fieldType === 'string') {
196
198
  snowflakeType = 'varchar';
197
199
  }
200
+ else if (fieldType === 'struct') {
201
+ snowflakeType = 'variant';
202
+ }
198
203
  return `${alias}.value:"${fieldName}"::${snowflakeType}`;
199
204
  }
200
205
  }
@@ -208,11 +213,12 @@ class SnowflakeDialect extends dialect_1.Dialect {
208
213
  sqlCreateFunction(_id, _funcText) {
209
214
  throw new Error('not implemented yet');
210
215
  }
211
- sqlCreateFunctionCombineLastStage(lastStageName) {
212
- return `SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) FROM ${lastStageName}`;
216
+ sqlCreateFunctionCombineLastStage(_lastStageName) {
217
+ throw new Error('not implemented yet');
218
+ // return `SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) FROM ${lastStageName}`;
213
219
  }
214
220
  sqlSelectAliasAsStruct(alias) {
215
- return `OBJECT_CONSTRUCT(${alias}.*)`;
221
+ return `OBJECT_CONSTRUCT_KEEP_NULL(${alias}.*)`;
216
222
  }
217
223
  sqlMaybeQuoteIdentifier(identifier) {
218
224
  return `"${identifier}"`;
package/dist/malloy.d.ts CHANGED
@@ -5,6 +5,7 @@ import { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-con
5
5
  import { CompiledQuery, DocumentLocation, DocumentReference, FieldBooleanDef, FieldDateDef, FieldJSONDef, FieldNumberDef, FieldStringDef, FieldTimestampDef, FieldTypeDef, FilterExpression, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SQLBlock, SQLBlockSource, SQLBlockStructDef, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, FieldUnsupportedDef, QueryRunStats, ImportLocation, Annotation } from './model';
6
6
  import { Connection, InfoConnection, LookupConnection, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
7
7
  import { Tag, TagParse, TagParseSpec, Taggable } from './tags';
8
+ import { Dialect } from './dialect';
8
9
  export interface Loggable {
9
10
  debug: (message?: any, ...optionalParams: any[]) => void;
10
11
  info: (message?: any, ...optionalParams: any[]) => void;
@@ -851,6 +852,7 @@ export declare class SingleConnectionRuntime<T extends Connection = Connection>
851
852
  constructor(connection: T);
852
853
  get supportsNesting(): boolean;
853
854
  quote(column: string): string;
855
+ get dialect(): Dialect;
854
856
  getQuoter(): (arg: TemplateStringsArray) => string;
855
857
  }
856
858
  declare class FluentState<T> {
package/dist/malloy.js CHANGED
@@ -1758,6 +1758,9 @@ class SingleConnectionRuntime extends Runtime {
1758
1758
  quote(column) {
1759
1759
  return (0, dialect_1.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(column);
1760
1760
  }
1761
+ get dialect() {
1762
+ return (0, dialect_1.getDialect)(this.connection.dialectName);
1763
+ }
1761
1764
  getQuoter() {
1762
1765
  return (x) => this.quote(x.toString());
1763
1766
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.127-dev240308180053",
3
+ "version": "0.0.127",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",