@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.
- package/dist/api/asynchronous.d.ts +13 -0
- package/dist/api/asynchronous.js +205 -0
- package/dist/api/asynchronous.spec.d.ts +1 -0
- package/dist/api/asynchronous.spec.js +238 -0
- package/dist/api/connection.d.ts +12 -0
- package/dist/api/connection.js +9 -0
- package/dist/api/core.d.ts +37 -0
- package/dist/api/core.js +448 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +36 -0
- package/dist/api/sessioned.d.ts +10 -0
- package/dist/api/sessioned.js +210 -0
- package/dist/api/sessioned.spec.d.ts +1 -0
- package/dist/api/sessioned.spec.js +417 -0
- package/dist/api/stateless.d.ts +4 -0
- package/dist/api/stateless.js +46 -0
- package/dist/api/stateless.spec.d.ts +1 -0
- package/dist/api/stateless.spec.js +394 -0
- package/dist/connection/base_connection.d.ts +3 -2
- package/dist/connection/base_connection.js +3 -1
- package/dist/connection/types.d.ts +2 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +28 -1
- package/dist/lang/ast/source-elements/sql-source.d.ts +4 -4
- package/dist/lang/ast/source-elements/sql-source.js +20 -12
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/parse-malloy.js +0 -1
- package/dist/lang/test/locations.spec.js +1 -1
- package/dist/lang/test/parse-expects.js +1 -1
- package/dist/lang/test/parse.spec.js +18 -15
- package/dist/lang/test/sql-block.spec.js +18 -21
- package/dist/lang/test/test-translator.d.ts +5 -3
- package/dist/lang/test/test-translator.js +10 -10
- package/dist/lang/translate-response.d.ts +6 -3
- package/dist/malloy.d.ts +2 -4
- package/dist/malloy.js +11 -45
- package/dist/model/malloy_types.d.ts +0 -5
- package/dist/model/sql_block.d.ts +4 -7
- package/dist/model/sql_block.js +31 -21
- package/dist/to_stable.js +9 -0
- package/package.json +3 -3
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const test_translator_1 = require("./test-translator");
|
|
27
27
|
require("./parse-expects");
|
|
28
|
+
const sql_block_1 = require("../../model/sql_block");
|
|
28
29
|
describe('model statements', () => {
|
|
29
30
|
describe('table method', () => {
|
|
30
31
|
test('table method works', () => {
|
|
@@ -193,10 +194,11 @@ describe('error handling', () => {
|
|
|
193
194
|
const needSchema = badTrans.translate();
|
|
194
195
|
expect(needSchema.compileSQL).toBeDefined();
|
|
195
196
|
if (needSchema.compileSQL) {
|
|
197
|
+
const key = (0, sql_block_1.sqlKey)(needSchema.compileSQL.connection, needSchema.compileSQL.selectStr);
|
|
196
198
|
badTrans.update({
|
|
197
199
|
errors: {
|
|
198
200
|
compileSQL: {
|
|
199
|
-
[
|
|
201
|
+
[key]: 'Nobody ZZZZ',
|
|
200
202
|
},
|
|
201
203
|
},
|
|
202
204
|
});
|
|
@@ -243,7 +245,8 @@ describe('translation need error locations', () => {
|
|
|
243
245
|
const req = m.translate().compileSQL;
|
|
244
246
|
expect(req).toBeDefined();
|
|
245
247
|
if (req) {
|
|
246
|
-
|
|
248
|
+
const key = (0, sql_block_1.sqlKey)(req.connection, req.selectStr);
|
|
249
|
+
m.update({ errors: { compileSQL: { [key]: 'Bad SQL!' } } });
|
|
247
250
|
}
|
|
248
251
|
expect(m).not.toTranslate();
|
|
249
252
|
const errList = m.problems();
|
|
@@ -472,7 +475,7 @@ describe('sql expressions', () => {
|
|
|
472
475
|
expect(compileSql).toBeDefined();
|
|
473
476
|
if (compileSql) {
|
|
474
477
|
m.translator.update({
|
|
475
|
-
compileSQL:
|
|
478
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
476
479
|
});
|
|
477
480
|
expect(m).toTranslate();
|
|
478
481
|
}
|
|
@@ -486,7 +489,7 @@ describe('sql expressions', () => {
|
|
|
486
489
|
expect(compileSql).toBeDefined();
|
|
487
490
|
if (compileSql) {
|
|
488
491
|
m.translator.update({
|
|
489
|
-
compileSQL:
|
|
492
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
490
493
|
});
|
|
491
494
|
expect(m).toTranslate();
|
|
492
495
|
}
|
|
@@ -500,7 +503,7 @@ describe('sql expressions', () => {
|
|
|
500
503
|
expect(compileSql).toBeDefined();
|
|
501
504
|
if (compileSql) {
|
|
502
505
|
m.translator.update({
|
|
503
|
-
compileSQL:
|
|
506
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
504
507
|
});
|
|
505
508
|
expect(m).toTranslate();
|
|
506
509
|
}
|
|
@@ -515,7 +518,7 @@ describe('sql expressions', () => {
|
|
|
515
518
|
expect(compileSql).toBeDefined();
|
|
516
519
|
if (compileSql) {
|
|
517
520
|
m.translator.update({
|
|
518
|
-
compileSQL:
|
|
521
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
519
522
|
});
|
|
520
523
|
expect(m).toTranslate();
|
|
521
524
|
}
|
|
@@ -529,7 +532,7 @@ describe('sql expressions', () => {
|
|
|
529
532
|
expect(compileSql).toBeDefined();
|
|
530
533
|
if (compileSql) {
|
|
531
534
|
m.update({
|
|
532
|
-
compileSQL:
|
|
535
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
533
536
|
});
|
|
534
537
|
expect(m).toTranslate();
|
|
535
538
|
}
|
|
@@ -543,7 +546,7 @@ describe('sql expressions', () => {
|
|
|
543
546
|
expect(compileSql).toBeDefined();
|
|
544
547
|
if (compileSql) {
|
|
545
548
|
m.update({
|
|
546
|
-
compileSQL:
|
|
549
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
547
550
|
});
|
|
548
551
|
expect(m).toTranslate();
|
|
549
552
|
}
|
|
@@ -557,7 +560,7 @@ describe('sql expressions', () => {
|
|
|
557
560
|
expect(compileSql).toBeDefined();
|
|
558
561
|
if (compileSql) {
|
|
559
562
|
m.update({
|
|
560
|
-
compileSQL:
|
|
563
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
561
564
|
});
|
|
562
565
|
expect(m).toLog((0, test_translator_1.errorMessage)('Cannot add view refinements to a source'));
|
|
563
566
|
}
|
|
@@ -574,7 +577,7 @@ describe('sql expressions', () => {
|
|
|
574
577
|
expect(compileSql).toBeDefined();
|
|
575
578
|
if (compileSql) {
|
|
576
579
|
m.translator.update({
|
|
577
|
-
compileSQL:
|
|
580
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
578
581
|
});
|
|
579
582
|
expect(m).toTranslate();
|
|
580
583
|
}
|
|
@@ -588,7 +591,7 @@ describe('sql expressions', () => {
|
|
|
588
591
|
expect(compileSql).toBeDefined();
|
|
589
592
|
if (compileSql) {
|
|
590
593
|
m.update({
|
|
591
|
-
compileSQL:
|
|
594
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
592
595
|
});
|
|
593
596
|
expect(m).toTranslate();
|
|
594
597
|
}
|
|
@@ -602,7 +605,7 @@ describe('sql expressions', () => {
|
|
|
602
605
|
expect(compileSql).toBeDefined();
|
|
603
606
|
if (compileSql) {
|
|
604
607
|
m.update({
|
|
605
|
-
compileSQL:
|
|
608
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
606
609
|
});
|
|
607
610
|
expect(m).toTranslate();
|
|
608
611
|
}
|
|
@@ -616,7 +619,7 @@ describe('sql expressions', () => {
|
|
|
616
619
|
expect(compileSql).toBeDefined();
|
|
617
620
|
if (compileSql) {
|
|
618
621
|
m.update({
|
|
619
|
-
compileSQL:
|
|
622
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
620
623
|
});
|
|
621
624
|
expect(m).toTranslate();
|
|
622
625
|
}
|
|
@@ -631,7 +634,7 @@ describe('sql expressions', () => {
|
|
|
631
634
|
expect(compileSql).toBeDefined();
|
|
632
635
|
if (compileSql) {
|
|
633
636
|
m.update({
|
|
634
|
-
compileSQL:
|
|
637
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
635
638
|
});
|
|
636
639
|
expect(m).toLog((0, test_translator_1.errorMessage)('A raw query cannot be refined'));
|
|
637
640
|
}
|
|
@@ -645,7 +648,7 @@ describe('sql expressions', () => {
|
|
|
645
648
|
expect(compileSql).toBeDefined();
|
|
646
649
|
if (compileSql) {
|
|
647
650
|
m.update({
|
|
648
|
-
compileSQL:
|
|
651
|
+
compileSQL: (0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
649
652
|
});
|
|
650
653
|
expect(m).toLog((0, test_translator_1.errorMessage)('Cannot add view refinements to a source'));
|
|
651
654
|
}
|
|
@@ -23,22 +23,24 @@
|
|
|
23
23
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const sql_block_1 = require("../../model/sql_block");
|
|
27
26
|
const test_translator_1 = require("./test-translator");
|
|
28
27
|
require("./parse-expects");
|
|
29
28
|
const parse_malloy_1 = require("../parse-malloy");
|
|
30
|
-
const
|
|
29
|
+
const sql_block_1 = require("../../model/sql_block");
|
|
31
30
|
describe('connection sql()', () => {
|
|
32
31
|
const selStmt = 'SELECT * FROM aTable';
|
|
33
32
|
function makeSchemaResponse(sql) {
|
|
34
33
|
const cname = sql.connection || 'bigquery';
|
|
34
|
+
const key = (0, sql_block_1.sqlKey)(cname, sql.selectStr);
|
|
35
35
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
[key]: {
|
|
37
|
+
type: 'sql_select',
|
|
38
|
+
name: key,
|
|
39
|
+
dialect: 'standardsql',
|
|
40
|
+
connection: cname,
|
|
41
|
+
selectStr: selStmt,
|
|
42
|
+
fields: test_translator_1.aTableDef.fields,
|
|
43
|
+
},
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
test('source from sql', () => {
|
|
@@ -51,9 +53,7 @@ describe('connection sql()', () => {
|
|
|
51
53
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
52
54
|
expect(needs).toBeDefined();
|
|
53
55
|
if (needs) {
|
|
54
|
-
|
|
55
|
-
const refKey = needs.name;
|
|
56
|
-
model.update({ compileSQL: { [refKey]: makeSchemaResponse(sql) } });
|
|
56
|
+
model.update({ compileSQL: makeSchemaResponse(needs) });
|
|
57
57
|
expect(model).toTranslate();
|
|
58
58
|
const users = model.getSourceDef('malloyUsers');
|
|
59
59
|
expect(users).toBeDefined();
|
|
@@ -74,8 +74,7 @@ describe('connection sql()', () => {
|
|
|
74
74
|
const needReq = model.translate();
|
|
75
75
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
76
76
|
expect(needs).toBeDefined();
|
|
77
|
-
|
|
78
|
-
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
77
|
+
model.update({ compileSQL: makeSchemaResponse(needs) });
|
|
79
78
|
expect(model).toTranslate();
|
|
80
79
|
});
|
|
81
80
|
it('simple turducken', () => {
|
|
@@ -86,12 +85,7 @@ describe('connection sql()', () => {
|
|
|
86
85
|
const compileSql = m.translate().compileSQL;
|
|
87
86
|
expect(compileSql).toBeDefined();
|
|
88
87
|
if (compileSql) {
|
|
89
|
-
|
|
90
|
-
const star = compileSql.select[1];
|
|
91
|
-
const where = compileSql.select[2];
|
|
92
|
-
expect(select).toEqual({ sql: 'SELECT * FROM ' });
|
|
93
|
-
expect((0, model_1.isSegmentSQL)(star)).toBeFalsy();
|
|
94
|
-
expect(where).toEqual({ sql: ' WHERE 1=1' });
|
|
88
|
+
expect(compileSql.selectStr).toEqual('SELECT * FROM (SELECT \n base.`astr` as `astr`\nFROM `aTable` as base\nGROUP BY 1\nORDER BY 1 asc\n) WHERE 1=1');
|
|
95
89
|
}
|
|
96
90
|
});
|
|
97
91
|
it('turduckenzilla', () => {
|
|
@@ -132,8 +126,11 @@ describe('connection sql()', () => {
|
|
|
132
126
|
source: sql_block is aConnection.sql("""${selStmt}""")
|
|
133
127
|
source: malloy_source is sql_block extend { primary_key: ai }
|
|
134
128
|
`);
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
expect(model).toParse();
|
|
130
|
+
const needReq = model.translate();
|
|
131
|
+
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
132
|
+
expect(needs).toBeDefined();
|
|
133
|
+
model.update({ compileSQL: makeSchemaResponse(needs) });
|
|
137
134
|
expect(model).toTranslate();
|
|
138
135
|
const modelDef = (_a = model === null || model === void 0 ? void 0 : model.translate()) === null || _a === void 0 ? void 0 : _a.modelDef;
|
|
139
136
|
// this tests the underlying api that .extendModel calls
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DocumentLocation, FieldDef, ModelDef, NamedModelObject, PipeSegment, Query, QueryFieldDef, StructDef, TurtleDef, SourceDef, SQLSourceDef
|
|
1
|
+
import { DocumentLocation, FieldDef, ModelDef, NamedModelObject, PipeSegment, Query, QueryFieldDef, StructDef, TurtleDef, SourceDef, SQLSourceDef } from '../../model/malloy_types';
|
|
2
2
|
import { MalloyElement } from '../ast';
|
|
3
3
|
import { NameSpace } from '../ast/types/name-space';
|
|
4
4
|
import { ModelEntry } from '../ast/types/model-entry';
|
|
5
5
|
import { MalloyChildTranslator, MalloyTranslator } from '../parse-malloy';
|
|
6
|
-
import { DataRequestResponse, TranslateResponse } from '../translate-response';
|
|
6
|
+
import { DataRequestResponse, SQLSourceRequest, TranslateResponse } from '../translate-response';
|
|
7
7
|
import { ExprValue } from '../ast/types/expr-value';
|
|
8
8
|
import { LogSeverity, MessageCode, MessageParameterType } from '../parse-log';
|
|
9
9
|
import { EventStream } from '../../runtime_types';
|
|
@@ -75,7 +75,9 @@ export declare function makeModelFunc(options: {
|
|
|
75
75
|
}): (unmarked: TemplateStringsArray, ...marked: string[]) => HasTranslator<TestTranslator>;
|
|
76
76
|
export declare function makeExprFunc(model: ModelDef, sourceName: string): (unmarked: TemplateStringsArray, ...marked: string[]) => HasTranslator<TestTranslator>;
|
|
77
77
|
export declare function markSource(unmarked: TemplateStringsArray, ...marked: string[]): MarkedSource;
|
|
78
|
-
export declare function getSelectOneStruct(sqlBlock:
|
|
78
|
+
export declare function getSelectOneStruct(sqlBlock: SQLSourceRequest): {
|
|
79
|
+
[key: string]: SQLSourceDef;
|
|
80
|
+
};
|
|
79
81
|
export declare function error<T extends MessageCode>(code: T, data?: MessageParameterType<T>): {
|
|
80
82
|
code: T;
|
|
81
83
|
data: MessageParameterType<T> | undefined;
|
|
@@ -30,6 +30,7 @@ const ast_1 = require("../ast");
|
|
|
30
30
|
const parse_malloy_1 = require("../parse-malloy");
|
|
31
31
|
const static_space_1 = require("../ast/field-space/static-space");
|
|
32
32
|
const global_name_space_1 = require("../ast/types/global-name-space");
|
|
33
|
+
const sql_block_1 = require("../../model/sql_block");
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
|
34
35
|
function pretty(thing) {
|
|
35
36
|
return (0, util_1.inspect)(thing, { breakLength: 72, depth: Infinity });
|
|
@@ -541,17 +542,16 @@ function markSource(unmarked, ...marked) {
|
|
|
541
542
|
}
|
|
542
543
|
exports.markSource = markSource;
|
|
543
544
|
function getSelectOneStruct(sqlBlock) {
|
|
544
|
-
const
|
|
545
|
-
if (!(0, malloy_types_1.isSegmentSQL)(selectThis)) {
|
|
546
|
-
throw new Error('weird test support error sorry');
|
|
547
|
-
}
|
|
545
|
+
const key = (0, sql_block_1.sqlKey)(sqlBlock.connection, sqlBlock.selectStr);
|
|
548
546
|
return {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
547
|
+
[key]: {
|
|
548
|
+
type: 'sql_select',
|
|
549
|
+
name: key,
|
|
550
|
+
dialect: 'standardsql',
|
|
551
|
+
connection: 'bigquery',
|
|
552
|
+
selectStr: sqlBlock.selectStr,
|
|
553
|
+
fields: [{ type: 'number', name: 'one' }],
|
|
554
|
+
},
|
|
555
555
|
};
|
|
556
556
|
}
|
|
557
557
|
exports.getSelectOneStruct = getSelectOneStruct;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Annotation, ModelDef
|
|
1
|
+
import { Annotation, ModelDef } from '../model/malloy_types';
|
|
2
2
|
import { MalloyElement } from './ast';
|
|
3
3
|
import { LogMessage } from './parse-log';
|
|
4
4
|
import { DocumentSymbol } from './parse-tree-walkers/document-symbol-walker';
|
|
@@ -25,9 +25,12 @@ export interface NeedSchemaData {
|
|
|
25
25
|
export interface NeedURLData {
|
|
26
26
|
urls: string[];
|
|
27
27
|
}
|
|
28
|
+
export interface SQLSourceRequest {
|
|
29
|
+
connection: string;
|
|
30
|
+
selectStr: string;
|
|
31
|
+
}
|
|
28
32
|
export interface NeedCompileSQL {
|
|
29
|
-
compileSQL:
|
|
30
|
-
partialModel: ModelDef | undefined;
|
|
33
|
+
compileSQL: SQLSourceRequest;
|
|
31
34
|
}
|
|
32
35
|
interface NeededData extends NeedURLData, NeedSchemaData, NeedCompileSQL {
|
|
33
36
|
}
|
package/dist/malloy.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { RunSQLOptions } from './run_sql_options';
|
|
4
4
|
import { DocumentCompletion as DocumentCompletionDefinition, DocumentSymbol as DocumentSymbolDefinition, LogMessage, MalloyTranslator } from './lang';
|
|
5
5
|
import { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-context-walker';
|
|
6
|
-
import { CompiledQuery, DocumentLocation, DocumentReference, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, NativeUnsupportedFieldDef, QueryRunStats, ImportLocation, Annotation,
|
|
6
|
+
import { CompiledQuery, DocumentLocation, DocumentReference, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, NativeUnsupportedFieldDef, QueryRunStats, ImportLocation, Annotation, SQLSourceDef, AtomicFieldDef, DateFieldDef, TimestampFieldDef, SourceDef, QueryToMaterialize } from './model';
|
|
7
7
|
import { EventStream, InvalidationKey, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
|
|
8
8
|
import { Connection, FetchSchemaOptions, InfoConnection, LookupConnection } from './connection/types';
|
|
9
9
|
import { Tag } from '@malloydata/malloy-tag';
|
|
@@ -87,11 +87,10 @@ export declare class Malloy {
|
|
|
87
87
|
* @param model A compiled model to build upon (optional).
|
|
88
88
|
* @return A (promise of a) compiled `Model`.
|
|
89
89
|
*/
|
|
90
|
-
static compile({ url, source, parse, urlReader, connections, model, refreshSchemaCache, noThrowOnError, eventStream,
|
|
90
|
+
static compile({ url, source, parse, urlReader, connections, model, refreshSchemaCache, noThrowOnError, eventStream, importBaseURL, cacheManager, }: {
|
|
91
91
|
urlReader: URLReader;
|
|
92
92
|
connections: LookupConnection<InfoConnection>;
|
|
93
93
|
model?: Model;
|
|
94
|
-
replaceMaterializedReferences?: boolean;
|
|
95
94
|
cacheManager?: CacheManager;
|
|
96
95
|
} & Compilable & CompileOptions & CompileQueryOptions & ParseOptions): Promise<Model>;
|
|
97
96
|
/**
|
|
@@ -103,7 +102,6 @@ export declare class Malloy {
|
|
|
103
102
|
schemas: Record<string, import("./model").TableSourceDef>;
|
|
104
103
|
errors: Record<string, string>;
|
|
105
104
|
}>;
|
|
106
|
-
static compileSQLBlock(dialect: string, partialModel: ModelDef | undefined, toCompile: SQLSentence, options?: CompileQueryOptions): SQLSourceDef;
|
|
107
105
|
/**
|
|
108
106
|
* Run a fully-prepared query.
|
|
109
107
|
*
|
package/dist/malloy.js
CHANGED
|
@@ -30,6 +30,7 @@ const dialect_1 = require("./dialect");
|
|
|
30
30
|
const version_1 = require("./version");
|
|
31
31
|
const uuid_1 = require("uuid");
|
|
32
32
|
const annotation_1 = require("./annotation");
|
|
33
|
+
const sql_block_1 = require("./model/sql_block");
|
|
33
34
|
const MALLOY_INTERNAL_URL = 'internal://internal.malloy';
|
|
34
35
|
class Malloy {
|
|
35
36
|
static get version() {
|
|
@@ -76,7 +77,7 @@ class Malloy {
|
|
|
76
77
|
* @param model A compiled model to build upon (optional).
|
|
77
78
|
* @return A (promise of a) compiled `Model`.
|
|
78
79
|
*/
|
|
79
|
-
static async compile({ url, source, parse, urlReader, connections, model, refreshSchemaCache, noThrowOnError, eventStream,
|
|
80
|
+
static async compile({ url, source, parse, urlReader, connections, model, refreshSchemaCache, noThrowOnError, eventStream, importBaseURL, cacheManager, }) {
|
|
80
81
|
var _a, _b, _c, _d, _e;
|
|
81
82
|
let refreshTimestamp;
|
|
82
83
|
if (refreshSchemaCache) {
|
|
@@ -243,31 +244,31 @@ class Malloy {
|
|
|
243
244
|
// Unlike other requests, these do not come in batches
|
|
244
245
|
const toCompile = result.compileSQL;
|
|
245
246
|
const connectionName = toCompile.connection;
|
|
247
|
+
const key = (0, sql_block_1.sqlKey)(toCompile.connection, toCompile.selectStr);
|
|
246
248
|
try {
|
|
247
249
|
const conn = await connections.lookupConnection(connectionName);
|
|
248
|
-
const
|
|
249
|
-
replaceMaterializedReferences,
|
|
250
|
-
materializedTablePrefix,
|
|
251
|
-
eventStream,
|
|
252
|
-
});
|
|
253
|
-
const resolved = await conn.fetchSchemaForSQLStruct(expanded, {
|
|
250
|
+
const resolved = await conn.fetchSchemaForSQLStruct(toCompile, {
|
|
254
251
|
refreshTimestamp,
|
|
255
252
|
modelAnnotation,
|
|
256
253
|
});
|
|
257
254
|
if (resolved.error) {
|
|
258
255
|
translator.update({
|
|
259
|
-
errors: {
|
|
256
|
+
errors: {
|
|
257
|
+
compileSQL: {
|
|
258
|
+
[key]: resolved.error,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
260
261
|
});
|
|
261
262
|
}
|
|
262
263
|
if (resolved.structDef) {
|
|
263
264
|
translator.update({
|
|
264
|
-
compileSQL: { [
|
|
265
|
+
compileSQL: { [key]: resolved.structDef },
|
|
265
266
|
});
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
catch (error) {
|
|
269
270
|
const errors = {};
|
|
270
|
-
errors[
|
|
271
|
+
errors[key] = error.toString();
|
|
271
272
|
translator.update({ errors: { compileSQL: errors } });
|
|
272
273
|
}
|
|
273
274
|
}
|
|
@@ -288,41 +289,6 @@ class Malloy {
|
|
|
288
289
|
}
|
|
289
290
|
return ret;
|
|
290
291
|
}
|
|
291
|
-
static compileSQLBlock(dialect, partialModel, toCompile, options) {
|
|
292
|
-
let queryModel = undefined;
|
|
293
|
-
let selectStr = '';
|
|
294
|
-
let parenAlready = false;
|
|
295
|
-
for (const segment of toCompile.select) {
|
|
296
|
-
if ((0, model_1.isSegmentSQL)(segment)) {
|
|
297
|
-
selectStr += segment.sql;
|
|
298
|
-
parenAlready = segment.sql.match(/\(\s*$/) !== null;
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
// TODO catch exceptions and throw errors ...
|
|
302
|
-
if (!queryModel) {
|
|
303
|
-
if (!partialModel) {
|
|
304
|
-
throw new Error('Internal error: Partial model missing when compiling SQL block');
|
|
305
|
-
}
|
|
306
|
-
queryModel = new model_1.QueryModel(partialModel, options === null || options === void 0 ? void 0 : options.eventStream);
|
|
307
|
-
}
|
|
308
|
-
const compiledSql = queryModel.compileQuery(segment, {
|
|
309
|
-
...options,
|
|
310
|
-
defaultRowLimit: undefined,
|
|
311
|
-
}, false).sql;
|
|
312
|
-
selectStr += parenAlready ? compiledSql : `(${compiledSql})`;
|
|
313
|
-
parenAlready = false;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
const { name, connection } = toCompile;
|
|
317
|
-
return {
|
|
318
|
-
type: 'sql_select',
|
|
319
|
-
name,
|
|
320
|
-
connection,
|
|
321
|
-
dialect,
|
|
322
|
-
selectStr,
|
|
323
|
-
fields: [],
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
292
|
static async run({ connections, preparedResult, sqlStruct, connection, options, }) {
|
|
327
293
|
if (!connection) {
|
|
328
294
|
if (!connections) {
|
|
@@ -603,11 +603,6 @@ export interface SQLStringSegment {
|
|
|
603
603
|
}
|
|
604
604
|
export type SQLPhraseSegment = Query | SQLStringSegment;
|
|
605
605
|
export declare function isSegmentSQL(f: SQLPhraseSegment): f is SQLStringSegment;
|
|
606
|
-
export interface SQLSentence {
|
|
607
|
-
name: string;
|
|
608
|
-
connection: string;
|
|
609
|
-
select: SQLPhraseSegment[];
|
|
610
|
-
}
|
|
611
606
|
export interface SQLSourceDef extends SourceDefBase {
|
|
612
607
|
type: 'sql_select';
|
|
613
608
|
selectStr: string;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* unique, but predictable so that it can be used to cache schema fetches.
|
|
6
|
-
*/
|
|
7
|
-
export declare function makeSQLSentence(select: SQLPhraseSegment[], connection: string): SQLSentence;
|
|
1
|
+
import { SQLSourceRequest } from '../lang/translate-response';
|
|
2
|
+
import { SQLPhraseSegment, ModelDef } from './malloy_types';
|
|
3
|
+
export declare function compileSQLInterpolation(select: SQLPhraseSegment[], connection: string, partialModel: ModelDef | undefined): SQLSourceRequest;
|
|
4
|
+
export declare function sqlKey(connectionName: string, sql: string): string;
|
package/dist/model/sql_block.js
CHANGED
|
@@ -22,32 +22,42 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
25
|
+
exports.sqlKey = exports.compileSQLInterpolation = void 0;
|
|
26
|
+
const malloy_query_1 = require("./malloy_query");
|
|
26
27
|
const malloy_types_1 = require("./malloy_types");
|
|
27
28
|
const utils_1 = require("./utils");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
function compileSQLInterpolation(select, connection, partialModel) {
|
|
30
|
+
let queryModel = undefined;
|
|
31
|
+
let selectStr = '';
|
|
32
|
+
let parenAlready = false;
|
|
33
|
+
for (const segment of select) {
|
|
34
|
+
if ((0, malloy_types_1.isSegmentSQL)(segment)) {
|
|
35
|
+
selectStr += segment.sql;
|
|
36
|
+
parenAlready = segment.sql.match(/\(\s*$/) !== null;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// TODO catch exceptions and throw errors ...
|
|
40
|
+
if (!queryModel) {
|
|
41
|
+
if (!partialModel) {
|
|
42
|
+
throw new Error('Internal error: Partial model missing when compiling SQL block');
|
|
43
|
+
}
|
|
44
|
+
queryModel = new malloy_query_1.QueryModel(partialModel);
|
|
45
|
+
}
|
|
46
|
+
const compiledSql = queryModel.compileQuery(segment, {
|
|
47
|
+
defaultRowLimit: undefined,
|
|
48
|
+
}, false).sql;
|
|
49
|
+
selectStr += parenAlready ? compiledSql : `(${compiledSql})`;
|
|
50
|
+
parenAlready = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
34
53
|
return {
|
|
35
|
-
name: `sql://${connection}/${nameFor(select)}`,
|
|
36
54
|
connection,
|
|
37
|
-
|
|
55
|
+
selectStr,
|
|
38
56
|
};
|
|
39
57
|
}
|
|
40
|
-
exports.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// indentify this piece of SQL. Now the actual SQL isn't known until
|
|
44
|
-
// runtime and I am not certain what the right thing to do is, and
|
|
45
|
-
// at this moment when I am still trying to imagine how this is all
|
|
46
|
-
// going to work, I am using stringify(), but I suspect I will be back
|
|
47
|
-
// here for later, and that the whole "how to determine the name of a query"
|
|
48
|
-
// algorithm needs to change
|
|
49
|
-
function nameFor(select) {
|
|
50
|
-
const phrases = select.map(el => (0, malloy_types_1.isSegmentSQL)(el) ? el.sql : JSON.stringify(el));
|
|
51
|
-
return (0, utils_1.generateHash)(phrases.join(';'));
|
|
58
|
+
exports.compileSQLInterpolation = compileSQLInterpolation;
|
|
59
|
+
function sqlKey(connectionName, sql) {
|
|
60
|
+
return `sql://${connectionName}/${(0, utils_1.generateHash)(sql)}`;
|
|
52
61
|
}
|
|
62
|
+
exports.sqlKey = sqlKey;
|
|
53
63
|
//# sourceMappingURL=sql_block.js.map
|
package/dist/to_stable.js
CHANGED
|
@@ -33,6 +33,15 @@ function modelDefToModelInfo(modelDef) {
|
|
|
33
33
|
modelInfo.entries.push(queryInfo);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
for (const query of modelDef.queryList) {
|
|
37
|
+
const outputStruct = (0, malloy_query_1.getResultStructDefForQuery)(modelDef, query);
|
|
38
|
+
const queryInfo = {
|
|
39
|
+
schema: {
|
|
40
|
+
fields: convertFieldInfos(outputStruct, outputStruct.fields),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
modelInfo.anonymous_queries.push(queryInfo);
|
|
44
|
+
}
|
|
36
45
|
return modelInfo;
|
|
37
46
|
}
|
|
38
47
|
exports.modelDefToModelInfo = modelDefToModelInfo;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.239-
|
|
3
|
+
"version": "0.0.239-dev250227145856",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@malloydata/malloy-interfaces": "^0.0.239-
|
|
45
|
-
"@malloydata/malloy-tag": "^0.0.239-
|
|
44
|
+
"@malloydata/malloy-interfaces": "^0.0.239-dev250227145856",
|
|
45
|
+
"@malloydata/malloy-tag": "^0.0.239-dev250227145856",
|
|
46
46
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
47
47
|
"assert": "^2.0.0",
|
|
48
48
|
"jest-diff": "^29.6.2",
|