@malloydata/malloy 0.0.239-dev250226010331 → 0.0.239-dev250227145856

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.
Files changed (41) hide show
  1. package/dist/api/asynchronous.d.ts +13 -0
  2. package/dist/api/asynchronous.js +205 -0
  3. package/dist/api/asynchronous.spec.d.ts +1 -0
  4. package/dist/api/asynchronous.spec.js +238 -0
  5. package/dist/api/connection.d.ts +12 -0
  6. package/dist/api/connection.js +9 -0
  7. package/dist/api/core.d.ts +37 -0
  8. package/dist/api/core.js +448 -0
  9. package/dist/api/index.d.ts +3 -0
  10. package/dist/api/index.js +36 -0
  11. package/dist/api/sessioned.d.ts +10 -0
  12. package/dist/api/sessioned.js +210 -0
  13. package/dist/api/sessioned.spec.d.ts +1 -0
  14. package/dist/api/sessioned.spec.js +417 -0
  15. package/dist/api/stateless.d.ts +4 -0
  16. package/dist/api/stateless.js +46 -0
  17. package/dist/api/stateless.spec.d.ts +1 -0
  18. package/dist/api/stateless.spec.js +394 -0
  19. package/dist/connection/base_connection.d.ts +3 -2
  20. package/dist/connection/base_connection.js +3 -1
  21. package/dist/connection/types.d.ts +2 -1
  22. package/dist/index.d.ts +5 -2
  23. package/dist/index.js +28 -1
  24. package/dist/lang/ast/source-elements/sql-source.d.ts +4 -4
  25. package/dist/lang/ast/source-elements/sql-source.js +20 -12
  26. package/dist/lang/malloy-to-ast.d.ts +1 -1
  27. package/dist/lang/parse-malloy.js +0 -1
  28. package/dist/lang/test/locations.spec.js +1 -1
  29. package/dist/lang/test/parse-expects.js +1 -1
  30. package/dist/lang/test/parse.spec.js +18 -15
  31. package/dist/lang/test/sql-block.spec.js +18 -21
  32. package/dist/lang/test/test-translator.d.ts +5 -3
  33. package/dist/lang/test/test-translator.js +10 -10
  34. package/dist/lang/translate-response.d.ts +6 -3
  35. package/dist/malloy.d.ts +2 -4
  36. package/dist/malloy.js +11 -45
  37. package/dist/model/malloy_types.d.ts +0 -5
  38. package/dist/model/sql_block.d.ts +4 -7
  39. package/dist/model/sql_block.js +31 -21
  40. package/dist/to_stable.js +9 -0
  41. package/package.json +3 -3
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const stateless_1 = require("./stateless");
10
+ describe('api', () => {
11
+ describe('compile model', () => {
12
+ test('compile model with table dependency', () => {
13
+ const result = (0, stateless_1.compileModel)({
14
+ model_url: 'file://test.malloy',
15
+ compiler_needs: {
16
+ table_schemas: [
17
+ {
18
+ connection_name: 'connection',
19
+ name: 'flights',
20
+ schema: {
21
+ fields: [
22
+ {
23
+ kind: 'dimension',
24
+ name: 'carrier',
25
+ type: { kind: 'string_type' },
26
+ },
27
+ ],
28
+ },
29
+ },
30
+ ],
31
+ files: [
32
+ {
33
+ url: 'file://test.malloy',
34
+ contents: "source: flights is connection.table('flights')",
35
+ },
36
+ ],
37
+ connections: [{ name: 'connection', dialect: 'duckdb' }],
38
+ },
39
+ });
40
+ const expected = {
41
+ model: {
42
+ entries: [
43
+ {
44
+ kind: 'source',
45
+ name: 'flights',
46
+ schema: {
47
+ fields: [
48
+ {
49
+ kind: 'dimension',
50
+ name: 'carrier',
51
+ type: { kind: 'string_type' },
52
+ },
53
+ ],
54
+ },
55
+ },
56
+ ],
57
+ anonymous_queries: [],
58
+ },
59
+ };
60
+ expect(result).toMatchObject(expected);
61
+ });
62
+ test('compile model with model extension', () => {
63
+ const result = (0, stateless_1.compileModel)({
64
+ model_url: 'file://test.malloy',
65
+ extend_model_url: 'file://base.malloy',
66
+ compiler_needs: {
67
+ table_schemas: [
68
+ {
69
+ connection_name: 'connection',
70
+ name: 'flights',
71
+ schema: {
72
+ fields: [
73
+ {
74
+ kind: 'dimension',
75
+ name: 'carrier',
76
+ type: { kind: 'string_type' },
77
+ },
78
+ ],
79
+ },
80
+ },
81
+ ],
82
+ files: [
83
+ {
84
+ url: 'file://base.malloy',
85
+ contents: "source: flights_base is connection.table('flights')",
86
+ },
87
+ {
88
+ url: 'file://test.malloy',
89
+ contents: 'source: flights is flights_base',
90
+ },
91
+ ],
92
+ connections: [{ name: 'connection', dialect: 'duckdb' }],
93
+ },
94
+ });
95
+ const expected = {
96
+ model: {
97
+ entries: [
98
+ {
99
+ kind: 'source',
100
+ name: 'flights_base',
101
+ schema: {
102
+ fields: [
103
+ {
104
+ kind: 'dimension',
105
+ name: 'carrier',
106
+ type: { kind: 'string_type' },
107
+ },
108
+ ],
109
+ },
110
+ },
111
+ {
112
+ kind: 'source',
113
+ name: 'flights',
114
+ schema: {
115
+ fields: [
116
+ {
117
+ kind: 'dimension',
118
+ name: 'carrier',
119
+ type: { kind: 'string_type' },
120
+ },
121
+ ],
122
+ },
123
+ },
124
+ ],
125
+ anonymous_queries: [],
126
+ },
127
+ };
128
+ expect(result).toMatchObject(expected);
129
+ });
130
+ test('compile model with sql dependency', () => {
131
+ const result = (0, stateless_1.compileModel)({
132
+ model_url: 'file://test.malloy',
133
+ compiler_needs: {
134
+ sql_schemas: [
135
+ {
136
+ connection_name: 'connection',
137
+ sql: 'SELECT 1 as one',
138
+ schema: {
139
+ fields: [
140
+ {
141
+ kind: 'dimension',
142
+ name: 'one',
143
+ type: { kind: 'number_type' },
144
+ },
145
+ ],
146
+ },
147
+ },
148
+ ],
149
+ files: [
150
+ {
151
+ url: 'file://test.malloy',
152
+ contents: "source: flights is connection.sql('SELECT 1 as one')",
153
+ },
154
+ ],
155
+ connections: [{ name: 'connection', dialect: 'duckdb' }],
156
+ },
157
+ });
158
+ const expected = {
159
+ model: {
160
+ entries: [
161
+ {
162
+ kind: 'source',
163
+ name: 'flights',
164
+ schema: {
165
+ fields: [
166
+ {
167
+ kind: 'dimension',
168
+ name: 'one',
169
+ type: { kind: 'number_type' },
170
+ },
171
+ ],
172
+ },
173
+ },
174
+ ],
175
+ anonymous_queries: [],
176
+ },
177
+ };
178
+ expect(result).toMatchObject(expected);
179
+ });
180
+ });
181
+ test('compile model with turducken sql dependency', () => {
182
+ const sql = '\n SELECT carrier FROM (SELECT \n base."carrier" as "carrier"\nFROM flights as base\nGROUP BY 1\nORDER BY 1 asc NULLS LAST\n)\n ';
183
+ const result = (0, stateless_1.compileModel)({
184
+ model_url: 'file://test.malloy',
185
+ compiler_needs: {
186
+ table_schemas: [
187
+ {
188
+ connection_name: 'connection',
189
+ name: 'flights',
190
+ schema: {
191
+ fields: [
192
+ {
193
+ kind: 'dimension',
194
+ name: 'carrier',
195
+ type: { kind: 'string_type' },
196
+ },
197
+ ],
198
+ },
199
+ },
200
+ ],
201
+ sql_schemas: [
202
+ {
203
+ connection_name: 'connection',
204
+ sql,
205
+ schema: {
206
+ fields: [
207
+ {
208
+ kind: 'dimension',
209
+ name: 'carrier',
210
+ type: { kind: 'string_type' },
211
+ },
212
+ ],
213
+ },
214
+ },
215
+ ],
216
+ files: [
217
+ {
218
+ url: 'file://test.malloy',
219
+ contents: `
220
+ source: flights is connection.table('flights')
221
+ source: sql_source is connection.sql("""
222
+ SELECT carrier FROM (%{
223
+ flights -> { group_by: carrier }
224
+ })
225
+ """)
226
+ `,
227
+ },
228
+ ],
229
+ connections: [{ name: 'connection', dialect: 'duckdb' }],
230
+ },
231
+ });
232
+ const expected = {
233
+ model: {
234
+ entries: [
235
+ {
236
+ kind: 'source',
237
+ name: 'flights',
238
+ schema: {
239
+ fields: [
240
+ {
241
+ kind: 'dimension',
242
+ name: 'carrier',
243
+ type: { kind: 'string_type' },
244
+ },
245
+ ],
246
+ },
247
+ },
248
+ {
249
+ kind: 'source',
250
+ name: 'sql_source',
251
+ schema: {
252
+ fields: [
253
+ {
254
+ kind: 'dimension',
255
+ name: 'carrier',
256
+ type: { kind: 'string_type' },
257
+ },
258
+ ],
259
+ },
260
+ },
261
+ ],
262
+ anonymous_queries: [],
263
+ },
264
+ };
265
+ expect(result).toMatchObject(expected);
266
+ });
267
+ describe('compile query', () => {
268
+ test('compile query with table dependency', () => {
269
+ const result = (0, stateless_1.compileQuery)({
270
+ model_url: 'file://test.malloy',
271
+ query: {
272
+ definition: {
273
+ kind: 'arrow',
274
+ source_reference: { name: 'flights' },
275
+ view: {
276
+ kind: 'segment',
277
+ operations: [
278
+ {
279
+ kind: 'group_by',
280
+ field: {
281
+ expression: { kind: 'field_reference', name: 'carrier' },
282
+ },
283
+ },
284
+ ],
285
+ },
286
+ },
287
+ },
288
+ compiler_needs: {
289
+ table_schemas: [
290
+ {
291
+ connection_name: 'connection',
292
+ name: 'flights',
293
+ schema: {
294
+ fields: [
295
+ {
296
+ kind: 'dimension',
297
+ name: 'carrier',
298
+ type: { kind: 'string_type' },
299
+ },
300
+ ],
301
+ },
302
+ },
303
+ ],
304
+ files: [
305
+ {
306
+ url: 'file://test.malloy',
307
+ contents: "source: flights is connection.table('flights')",
308
+ },
309
+ ],
310
+ connections: [{ name: 'connection', dialect: 'duckdb' }],
311
+ },
312
+ });
313
+ const expected = {
314
+ result: {
315
+ connection_name: 'connection',
316
+ sql: `SELECT \n\
317
+ base."carrier" as "carrier"
318
+ FROM flights as base
319
+ GROUP BY 1
320
+ ORDER BY 1 asc NULLS LAST
321
+ `,
322
+ schema: {
323
+ fields: [
324
+ {
325
+ kind: 'dimension',
326
+ name: 'carrier',
327
+ type: { kind: 'string_type' },
328
+ },
329
+ ],
330
+ },
331
+ },
332
+ };
333
+ expect(result).toMatchObject(expected);
334
+ });
335
+ });
336
+ describe('compiler errors', () => {
337
+ test('parse error should come back as a log', () => {
338
+ const result = (0, stateless_1.compileModel)({
339
+ model_url: 'file://test.malloy',
340
+ compiler_needs: {
341
+ files: [
342
+ {
343
+ url: 'file://test.malloy',
344
+ contents: 'run: flights -> { group_by: carrier }',
345
+ },
346
+ ],
347
+ },
348
+ });
349
+ const expected = {
350
+ logs: [
351
+ {
352
+ url: 'file://test.malloy',
353
+ severity: 'error',
354
+ message: "Reference to undefined object 'flights'",
355
+ range: {
356
+ start: { line: 0, character: 5 },
357
+ end: { line: 0, character: 12 },
358
+ },
359
+ },
360
+ ],
361
+ };
362
+ expect(result).toMatchObject(expected);
363
+ });
364
+ test('missing source should come back as a log', () => {
365
+ const result = (0, stateless_1.compileSource)({
366
+ model_url: 'file://test.malloy',
367
+ name: 'flights',
368
+ compiler_needs: {
369
+ files: [
370
+ {
371
+ url: 'file://test.malloy',
372
+ contents: '// nothing to see here',
373
+ },
374
+ ],
375
+ },
376
+ });
377
+ const expected = {
378
+ logs: [
379
+ {
380
+ url: 'file://test.malloy',
381
+ severity: 'error',
382
+ message: 'Model does not contain a source named flights',
383
+ range: {
384
+ start: { line: 0, character: 0 },
385
+ end: { line: 0, character: 0 },
386
+ },
387
+ },
388
+ ],
389
+ };
390
+ expect(result).toMatchObject(expected);
391
+ });
392
+ });
393
+ });
394
+ //# sourceMappingURL=stateless.spec.js.map
@@ -1,3 +1,4 @@
1
+ import { SQLSourceRequest } from '../lang/translate-response';
1
2
  import { MalloyQueryData, QueryRunStats, SQLSourceDef, StructDef, TableSourceDef } from '../model/malloy_types';
2
3
  import { RunSQLOptions } from '../run_sql_options';
3
4
  import { Connection, FetchSchemaOptions, PersistSQLResults, PooledConnection, StreamingConnection } from './types';
@@ -16,14 +17,14 @@ export declare abstract class BaseConnection implements Connection {
16
17
  abstract get name(): string;
17
18
  abstract get dialectName(): string;
18
19
  abstract fetchTableSchema(tableName: string, tablePath: string): Promise<TableSourceDef | string>;
19
- abstract fetchSelectSchema(sqlSource: SQLSourceDef): Promise<SQLSourceDef | string>;
20
+ abstract fetchSelectSchema(sqlSource: SQLSourceRequest): Promise<SQLSourceDef | string>;
20
21
  protected schemaCache: Record<string, CachedSchema<StructDef>>;
21
22
  protected checkSchemaCache<T extends StructDef>(schemaKey: string, schemaType: 'table' | 'sql_select', fillCache: () => Promise<T | string>, refreshTimestamp: number | undefined): Promise<CachedSchema<T>>;
22
23
  fetchSchemaForTables(missing: Record<string, string>, { refreshTimestamp }: FetchSchemaOptions): Promise<{
23
24
  schemas: Record<string, TableSourceDef>;
24
25
  errors: Record<string, string>;
25
26
  }>;
26
- fetchSchemaForSQLStruct(sqlRef: SQLSourceDef, { refreshTimestamp }: FetchSchemaOptions): Promise<{
27
+ fetchSchemaForSQLStruct(sqlRef: SQLSourceRequest, { refreshTimestamp }: FetchSchemaOptions): Promise<{
27
28
  structDef: SQLSourceDef;
28
29
  error?: undefined;
29
30
  } | {
@@ -7,6 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.BaseConnection = void 0;
10
+ const sql_block_1 = require("../model/sql_block");
10
11
  class BaseConnection {
11
12
  constructor() {
12
13
  this.schemaCache = {};
@@ -55,7 +56,8 @@ class BaseConnection {
55
56
  return { schemas, errors };
56
57
  }
57
58
  async fetchSchemaForSQLStruct(sqlRef, { refreshTimestamp }) {
58
- const inCache = await this.checkSchemaCache(sqlRef.name, 'sql_select', async () => await this.fetchSelectSchema(sqlRef), refreshTimestamp);
59
+ const key = (0, sql_block_1.sqlKey)(sqlRef.connection, sqlRef.selectStr);
60
+ const inCache = await this.checkSchemaCache(key, 'sql_select', async () => await this.fetchSelectSchema(sqlRef), refreshTimestamp);
59
61
  if (inCache.schema) {
60
62
  return { structDef: inCache.schema };
61
63
  }
@@ -1,6 +1,7 @@
1
1
  import { RunSQLOptions } from '../run_sql_options';
2
2
  import { Annotation, MalloyQueryData, QueryDataRow, QueryRunStats, SQLSourceDef, TableSourceDef } from '../model/malloy_types';
3
3
  import { Dialect } from '../dialect';
4
+ import { SQLSourceRequest } from '../lang/translate-response';
4
5
  /**
5
6
  * Options passed to fetchSchema methods.
6
7
  */
@@ -29,7 +30,7 @@ export interface InfoConnection {
29
30
  * @param block The SQL blocks to fetch schemas for.
30
31
  * @return A mapping of SQL block names to schemas.
31
32
  */
32
- fetchSchemaForSQLStruct(sentence: SQLSourceDef, options: FetchSchemaOptions): Promise<{
33
+ fetchSchemaForSQLStruct(sentence: SQLSourceRequest, options: FetchSchemaOptions): Promise<{
33
34
  structDef: SQLSourceDef;
34
35
  error?: undefined;
35
36
  } | {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { DuckDBDialect, StandardSQLDialect, TrinoDialect, PostgresDialect, SnowflakeDialect, MySQLDialect, registerDialect, arg, qtz, overload, minScalar, anyExprType, minAggregate, maxScalar, sql, makeParam, param, variadicParam, literal, spread, Dialect, TinyParser, } from './dialect';
2
2
  export type { DialectFieldList, DialectFunctionOverloadDef, QueryInfo, MalloyStandardFunctionImplementations, DefinitionBlueprint, DefinitionBlueprintMap, OverloadedDefinitionBlueprint, TinyToken, } from './dialect';
3
- export type { QueryDataRow, StructDef, TableSourceDef, SQLSourceDef, SourceDef, JoinFieldDef, NamedSourceDefs, MalloyQueryData, DateUnit, ExtractUnit, TimestampUnit, TemporalFieldType, QueryData, QueryValue, Expr, FilterCondition, SQLSentence, Argument, Parameter, FieldDef, PipeSegment, QueryFieldDef, IndexFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryResult, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Sampling, Annotation, LeafAtomicTypeDef, LeafAtomicDef, AtomicTypeDef, AtomicFieldDef, ArrayDef, ArrayTypeDef, RecordTypeDef, RepeatedRecordTypeDef, RecordDef, RepeatedRecordDef, RecordLiteralNode, ArrayLiteralNode, } from './model';
3
+ export type { QueryDataRow, StructDef, TableSourceDef, SQLSourceDef, SourceDef, JoinFieldDef, NamedSourceDefs, MalloyQueryData, DateUnit, ExtractUnit, TimestampUnit, TemporalFieldType, QueryData, QueryValue, Expr, FilterCondition, Argument, Parameter, FieldDef, PipeSegment, QueryFieldDef, IndexFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryResult, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Sampling, Annotation, LeafAtomicTypeDef, LeafAtomicDef, AtomicTypeDef, AtomicFieldDef, ArrayDef, ArrayTypeDef, RecordTypeDef, RepeatedRecordTypeDef, RecordDef, RepeatedRecordDef, RecordLiteralNode, ArrayLiteralNode, } from './model';
4
4
  export { isSourceDef, Segment, isLeafAtomic, isJoined, isJoinedSource, isSamplingEnable, isSamplingPercent, isSamplingRows, isRepeatedRecord, isScalarArray, mkArrayDef, mkFieldDef, expressionIsAggregate, expressionIsAnalytic, expressionIsCalculation, expressionIsScalar, expressionIsUngroupedAggregate, indent, composeSQLExpr, } from './model';
5
5
  export { MalloyTranslator, } from './lang';
6
6
  export type { LogMessage, TranslateResponse } from './lang';
@@ -11,4 +11,7 @@ export type { EventStream, ModelString, ModelURL, QueryString, QueryURL, URLRead
11
11
  export type { Connection, ConnectionConfig, ConnectionFactory, ConnectionParameter, ConnectionParameterValue, ConnectionConfigSchema, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
12
12
  export { toAsyncGenerator } from './connection_utils';
13
13
  export { modelDefToModelInfo } from './to_stable';
14
- export { annotationToTag } from './annotation';
14
+ export * as API from './api';
15
+ export type { SQLSourceRequest } from './lang/translate-response';
16
+ export { sqlKey } from './model/sql_block';
17
+ export { annotationToTag, annotationToTaglines } from './annotation';
package/dist/index.js CHANGED
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.Model = exports.MalloyTranslator = exports.composeSQLExpr = exports.indent = exports.expressionIsUngroupedAggregate = exports.expressionIsScalar = exports.expressionIsCalculation = exports.expressionIsAnalytic = exports.expressionIsAggregate = exports.mkFieldDef = exports.mkArrayDef = exports.isScalarArray = exports.isRepeatedRecord = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.isJoinedSource = exports.isJoined = exports.isLeafAtomic = exports.Segment = exports.isSourceDef = exports.TinyParser = exports.Dialect = exports.spread = exports.literal = exports.variadicParam = exports.param = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.MySQLDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.TrinoDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
4
- exports.annotationToTag = exports.modelDefToModelInfo = exports.toAsyncGenerator = exports.CacheManager = exports.InMemoryModelCache = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = void 0;
27
+ exports.annotationToTaglines = exports.annotationToTag = exports.sqlKey = exports.API = exports.modelDefToModelInfo = exports.toAsyncGenerator = exports.CacheManager = exports.InMemoryModelCache = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = void 0;
5
28
  /*
6
29
  * Copyright 2023 Google LLC
7
30
  *
@@ -100,6 +123,10 @@ var connection_utils_1 = require("./connection_utils");
100
123
  Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: function () { return connection_utils_1.toAsyncGenerator; } });
101
124
  var to_stable_1 = require("./to_stable");
102
125
  Object.defineProperty(exports, "modelDefToModelInfo", { enumerable: true, get: function () { return to_stable_1.modelDefToModelInfo; } });
126
+ exports.API = __importStar(require("./api"));
127
+ var sql_block_1 = require("./model/sql_block");
128
+ Object.defineProperty(exports, "sqlKey", { enumerable: true, get: function () { return sql_block_1.sqlKey; } });
103
129
  var annotation_1 = require("./annotation");
104
130
  Object.defineProperty(exports, "annotationToTag", { enumerable: true, get: function () { return annotation_1.annotationToTag; } });
131
+ Object.defineProperty(exports, "annotationToTaglines", { enumerable: true, get: function () { return annotation_1.annotationToTaglines; } });
105
132
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
- import { SQLSentence, InvokedStructRef, SourceDef } from '../../../model/malloy_types';
2
- import { NeedCompileSQL } from '../../translate-response';
1
+ import { InvokedStructRef, SourceDef } from '../../../model/malloy_types';
2
+ import { NeedCompileSQL, SQLSourceRequest } from '../../translate-response';
3
3
  import { Source } from './source';
4
4
  import { SQLString } from '../sql-elements/sql-string';
5
5
  import { ModelEntryReference, Document } from '../types/malloy-element';
@@ -7,10 +7,10 @@ export declare class SQLSource extends Source {
7
7
  readonly connectionName: ModelEntryReference;
8
8
  readonly select: SQLString;
9
9
  elementType: string;
10
- requestBlock?: SQLSentence;
10
+ requestBlock?: SQLSourceRequest;
11
11
  private connectionNameInvalid;
12
12
  constructor(connectionName: ModelEntryReference, select: SQLString);
13
- sqlSentence(): SQLSentence;
13
+ sqlSourceRequest(doc: Document): SQLSourceRequest;
14
14
  structRef(): InvokedStructRef;
15
15
  validateConnectionName(): boolean;
16
16
  needs(doc: Document): NeedCompileSQL | undefined;
@@ -34,11 +34,11 @@ class SQLSource extends source_1.Source {
34
34
  this.elementType = 'sqlSource';
35
35
  this.connectionNameInvalid = false;
36
36
  }
37
- sqlSentence() {
38
- if (!this.requestBlock) {
39
- this.requestBlock = (0, sql_block_1.makeSQLSentence)(this.select.sqlPhrases(), this.connectionName.refString);
40
- }
41
- return this.requestBlock;
37
+ sqlSourceRequest(doc) {
38
+ const partialModel = this.select.containsQueries
39
+ ? doc.modelDef()
40
+ : undefined;
41
+ return (0, sql_block_1.compileSQLInterpolation)(this.select.sqlPhrases(), this.connectionName.refString, partialModel);
42
42
  }
43
43
  structRef() {
44
44
  return {
@@ -69,18 +69,21 @@ class SQLSource extends source_1.Source {
69
69
  const childNeeds = super.needs(doc);
70
70
  if (childNeeds)
71
71
  return childNeeds;
72
- const sql = this.sqlSentence();
72
+ if (this.requestBlock === undefined) {
73
+ this.requestBlock = this.sqlSourceRequest(doc);
74
+ }
75
+ const sql = this.requestBlock;
73
76
  const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
74
77
  if (!sqlDefEntry) {
75
78
  this.logError('failed-to-fetch-sql-source-schema', "Cant't look up schema for sql block");
76
79
  return;
77
80
  }
78
- sqlDefEntry.reference(sql.name, this.location);
79
- const lookup = sqlDefEntry.getEntry(sql.name);
81
+ const key = (0, sql_block_1.sqlKey)(sql.connection, sql.selectStr);
82
+ sqlDefEntry.reference(key, this.location);
83
+ const lookup = sqlDefEntry.getEntry(key);
80
84
  if (lookup.status === 'reference') {
81
85
  return {
82
86
  compileSQL: sql,
83
- partialModel: this.select.containsQueries ? doc.modelDef() : undefined,
84
87
  };
85
88
  }
86
89
  else if (lookup.status === 'present') {
@@ -97,9 +100,14 @@ class SQLSource extends source_1.Source {
97
100
  this.logError('failed-to-fetch-sql-source-schema', "Cant't look up schema for sql block");
98
101
  return error_factory_1.ErrorFactory.structDef;
99
102
  }
100
- const sql = this.sqlSentence();
101
- sqlDefEntry.reference(sql.name, this.location);
102
- const lookup = sqlDefEntry.getEntry(sql.name);
103
+ if (this.requestBlock === undefined) {
104
+ this.logError('failed-to-fetch-sql-source-schema', 'Expected to have already compiled the sql block');
105
+ return error_factory_1.ErrorFactory.structDef;
106
+ }
107
+ const sql = this.requestBlock;
108
+ const key = (0, sql_block_1.sqlKey)(sql.connection, sql.selectStr);
109
+ sqlDefEntry.reference(key, this.location);
110
+ const lookup = sqlDefEntry.getEntry(key);
103
111
  if (lookup.status === 'error') {
104
112
  const msgLines = lookup.message.split(/\r?\n/);
105
113
  this.select.logError('invalid-sql-source', 'Invalid SQL, ' + msgLines.join('\n '));
@@ -231,7 +231,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
231
231
  visitSegRefine(pcx: parse.SegRefineContext): ast.ViewRefine;
232
232
  visitVArrow(pcx: parse.VArrowContext): ast.ViewArrow;
233
233
  visitSQRefinedQuery(pcx: parse.SQRefinedQueryContext): ast.SQRefine;
234
- visitSQTable(pcx: parse.SQTableContext): ast.SQSource | ErrorNode;
234
+ visitSQTable(pcx: parse.SQTableContext): ErrorNode | ast.SQSource;
235
235
  visitSQSQL(pcx: parse.SQSQLContext): ast.SQSource;
236
236
  visitExperimentalStatementForTesting(pcx: parse.ExperimentalStatementForTestingContext): ast.ExperimentalExperiment;
237
237
  visitRecordRef(pcx: parse.RecordRefContext): ast.RecordElement;
@@ -716,7 +716,6 @@ class MalloyTranslation {
716
716
  if (ret === null || ret === void 0 ? void 0 : ret.compileSQL) {
717
717
  return {
718
718
  compileSQL: ret.compileSQL,
719
- partialModel: ret.partialModel,
720
719
  };
721
720
  }
722
721
  }
@@ -116,7 +116,7 @@ describe('source locations', () => {
116
116
  expect(compileSql).toBeDefined();
117
117
  if (compileSql) {
118
118
  m.update({
119
- compileSQL: { [compileSql.name]: (0, test_translator_1.getSelectOneStruct)(compileSql) },
119
+ compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
120
120
  });
121
121
  expect(m).toTranslate();
122
122
  const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
@@ -57,7 +57,7 @@ function prettyNeeds(response) {
57
57
  }
58
58
  }
59
59
  if (response.compileSQL) {
60
- needString += `Compile SQL: ${response.compileSQL.name}`;
60
+ needString += `Compile SQL: ${response.compileSQL.selectStr}`;
61
61
  }
62
62
  if (response.urls) {
63
63
  needString += 'URLs:\n';