@malloydata/malloy 0.0.30-dev230405202234 → 0.0.30
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/lang/ast/sources/named-source.js +1 -1
- package/dist/lang/ast/sources/sql-source.js +6 -4
- package/dist/lang/ast/types/malloy-element.js +8 -8
- package/dist/lang/ast/types/model-entry.d.ts +0 -1
- package/dist/lang/test/parse.spec.js +0 -129
- package/dist/lang/test/sql-block.spec.d.ts +1 -0
- package/dist/lang/test/sql-block.spec.js +180 -0
- package/dist/malloy.js +1 -1
- package/dist/model/malloy_types.d.ts +2 -1
- package/dist/model/malloy_types.js +3 -3
- package/package.json +1 -1
|
@@ -77,7 +77,7 @@ class NamedSource extends source_1.Source {
|
|
|
77
77
|
this.log(`Must use 'from()' for query source '${this.refName}`);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
else if (
|
|
80
|
+
else if ((0, malloy_types_1.isSQLBlockStruct)(entry) && entry.declaredSQLBlock) {
|
|
81
81
|
this.log(`Must use 'from_sql()' for sql source '${this.refName}`);
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.SQLSource = void 0;
|
|
26
|
+
const malloy_types_1 = require("../../../model/malloy_types");
|
|
26
27
|
const named_source_1 = require("./named-source");
|
|
27
28
|
class SQLSource extends named_source_1.NamedSource {
|
|
28
29
|
constructor() {
|
|
@@ -43,11 +44,12 @@ class SQLSource extends named_source_1.NamedSource {
|
|
|
43
44
|
this.log(`Cannot use 'from_sql()' to explore query '${this.refName}'`);
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
|
-
else if (
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
else if ((0, malloy_types_1.isSQLBlockStruct)(entry) && entry.declaredSQLBlock) {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
|
+
const { declaredSQLBlock, ...newEntry } = entry;
|
|
50
|
+
return newEntry;
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
this.log(`Cannot use 'from_sql()' to explore '${this.refName}'`);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
exports.SQLSource = SQLSource;
|
|
@@ -102,7 +102,7 @@ class MalloyElement {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
else if ((result === null || result === void 0 ? void 0 : result.entry.type) === 'struct') {
|
|
105
|
-
if ((0, malloy_types_1.
|
|
105
|
+
if ((0, malloy_types_1.isSQLBlockStruct)(result.entry) && result.entry.declaredSQLBlock) {
|
|
106
106
|
this.addReference({
|
|
107
107
|
type: 'sqlBlockReference',
|
|
108
108
|
text: key,
|
|
@@ -349,11 +349,7 @@ class Document extends MalloyElement {
|
|
|
349
349
|
const entry = (0, cloneDeep_1.default)(orig);
|
|
350
350
|
if (entry.type === 'struct' || entry.type === 'query') {
|
|
351
351
|
const exported = extendingModelDef.exports.includes(nm);
|
|
352
|
-
|
|
353
|
-
if (sqlType) {
|
|
354
|
-
this.sqlBlocks.push(entry);
|
|
355
|
-
}
|
|
356
|
-
this.setEntry(nm, { entry, exported, sqlType });
|
|
352
|
+
this.setEntry(nm, { entry, exported });
|
|
357
353
|
}
|
|
358
354
|
}
|
|
359
355
|
}
|
|
@@ -383,13 +379,17 @@ class Document extends MalloyElement {
|
|
|
383
379
|
return def;
|
|
384
380
|
}
|
|
385
381
|
defineSQL(sql, name) {
|
|
386
|
-
const ret = {
|
|
382
|
+
const ret = {
|
|
383
|
+
...sql,
|
|
384
|
+
as: `$${this.sqlBlocks.length}`,
|
|
385
|
+
declaredSQLBlock: true,
|
|
386
|
+
};
|
|
387
387
|
if (name) {
|
|
388
388
|
if (this.getEntry(name)) {
|
|
389
389
|
return false;
|
|
390
390
|
}
|
|
391
391
|
ret.as = name;
|
|
392
|
-
this.setEntry(name, { entry: ret
|
|
392
|
+
this.setEntry(name, { entry: ret });
|
|
393
393
|
}
|
|
394
394
|
this.sqlBlocks.push(ret);
|
|
395
395
|
return true;
|
|
@@ -27,21 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const model_1 = require("../../model");
|
|
30
|
-
const sql_block_1 = require("../../model/sql_block");
|
|
31
30
|
const test_translator_1 = require("./test-translator");
|
|
32
31
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
33
32
|
const granular_result_1 = require("../ast/types/granular-result");
|
|
34
33
|
require("./parse-expects");
|
|
35
|
-
function unlocatedStructDef(sd) {
|
|
36
|
-
const ret = { ...sd };
|
|
37
|
-
ret.fields = sd.fields.map(f => {
|
|
38
|
-
const nf = { ...f };
|
|
39
|
-
delete nf.location;
|
|
40
|
-
return nf;
|
|
41
|
-
});
|
|
42
|
-
delete ret.location;
|
|
43
|
-
return ret;
|
|
44
|
-
}
|
|
45
34
|
function exprOK(s) {
|
|
46
35
|
return () => {
|
|
47
36
|
expect(new test_translator_1.BetaExpression(s)).modelParsed();
|
|
@@ -849,124 +838,6 @@ describe('unspported fields in schema', () => {
|
|
|
849
838
|
expect(uModel).modelCompiled();
|
|
850
839
|
});
|
|
851
840
|
});
|
|
852
|
-
describe('sql:', () => {
|
|
853
|
-
function makeSchemaResponse(sql) {
|
|
854
|
-
const cname = sql.connection || 'bigquery';
|
|
855
|
-
return {
|
|
856
|
-
type: 'struct',
|
|
857
|
-
name: sql.name,
|
|
858
|
-
dialect: "standardsql'",
|
|
859
|
-
structSource: {
|
|
860
|
-
type: 'sql',
|
|
861
|
-
method: 'subquery',
|
|
862
|
-
sqlBlock: {
|
|
863
|
-
type: 'sqlBlock',
|
|
864
|
-
...sql,
|
|
865
|
-
selectStr: sql.select.filter(s => typeof s === 'string').join(''),
|
|
866
|
-
},
|
|
867
|
-
},
|
|
868
|
-
structRelationship: { type: 'basetable', connectionName: cname },
|
|
869
|
-
fields: test_translator_1.aTableDef.fields,
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
test('definition', () => {
|
|
873
|
-
const selStmt = 'SELECT * FROM aTable';
|
|
874
|
-
const model = new test_translator_1.TestTranslator(`
|
|
875
|
-
sql: users IS {
|
|
876
|
-
select: """${selStmt}"""
|
|
877
|
-
connection: "aConnection"
|
|
878
|
-
}
|
|
879
|
-
`);
|
|
880
|
-
const needReq = model.translate();
|
|
881
|
-
expect(model).modelParsed();
|
|
882
|
-
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
883
|
-
expect(needs).toBeDefined();
|
|
884
|
-
if (needs) {
|
|
885
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
886
|
-
expect(needs).toMatchObject(sql);
|
|
887
|
-
const refKey = needs.name;
|
|
888
|
-
expect(refKey).toBeDefined();
|
|
889
|
-
if (refKey) {
|
|
890
|
-
const sr = makeSchemaResponse(sql);
|
|
891
|
-
model.update({ compileSQL: { [refKey]: sr } });
|
|
892
|
-
expect(model).modelCompiled();
|
|
893
|
-
expect(unlocatedStructDef(model.sqlBlocks[0])).toEqual(unlocatedStructDef({ ...sr, as: 'users' }));
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
});
|
|
897
|
-
test('source from sql', () => {
|
|
898
|
-
const selStmt = 'SELECT * FROM aTable';
|
|
899
|
-
const model = new test_translator_1.TestTranslator(`
|
|
900
|
-
sql: users IS { select: """${selStmt}""" }
|
|
901
|
-
source: malloyUsers is from_sql(users) { primary_key: ai }
|
|
902
|
-
`);
|
|
903
|
-
expect(model).modelParsed();
|
|
904
|
-
const needReq = model.translate();
|
|
905
|
-
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
906
|
-
expect(needs).toBeDefined();
|
|
907
|
-
if (needs) {
|
|
908
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
909
|
-
const refKey = needs.name;
|
|
910
|
-
model.update({ compileSQL: { [refKey]: makeSchemaResponse(sql) } });
|
|
911
|
-
expect(model).modelCompiled();
|
|
912
|
-
const users = model.getSourceDef('malloyUsers');
|
|
913
|
-
expect(users).toBeDefined();
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
test('explore from imported sql-based-source', () => {
|
|
917
|
-
const selStmt = 'SELECT * FROM aTable';
|
|
918
|
-
const createModel = `
|
|
919
|
-
sql: users IS { select: """${selStmt}""" }
|
|
920
|
-
source: malloyUsers is from_sql(users) { primary_key: ai }
|
|
921
|
-
`;
|
|
922
|
-
const model = new test_translator_1.TestTranslator(`
|
|
923
|
-
import "createModel.malloy"
|
|
924
|
-
source: importUsers is malloyUsers
|
|
925
|
-
`);
|
|
926
|
-
model.importZone.define('internal://test/langtests/createModel.malloy', createModel);
|
|
927
|
-
expect(model).modelParsed();
|
|
928
|
-
const needReq = model.translate();
|
|
929
|
-
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
930
|
-
expect(needs).toBeDefined();
|
|
931
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
932
|
-
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
933
|
-
expect(model).modelCompiled();
|
|
934
|
-
});
|
|
935
|
-
it('turducken', () => {
|
|
936
|
-
const m = new test_translator_1.TestTranslator(`
|
|
937
|
-
sql: someSql is {
|
|
938
|
-
select: """SELECT * FROM %{ a -> { group_by: astr } }% WHERE 1=1"""
|
|
939
|
-
}
|
|
940
|
-
`);
|
|
941
|
-
expect(m).modelParsed();
|
|
942
|
-
const compileSql = m.translate().compileSQL;
|
|
943
|
-
expect(compileSql).toBeDefined();
|
|
944
|
-
if (compileSql) {
|
|
945
|
-
const select = compileSql.select[0];
|
|
946
|
-
const star = compileSql.select[1];
|
|
947
|
-
const where = compileSql.select[2];
|
|
948
|
-
expect(select).toEqual({ sql: 'SELECT * FROM ' });
|
|
949
|
-
expect((0, model_1.isSQLFragment)(star)).toBeFalsy();
|
|
950
|
-
expect(where).toEqual({ sql: ' WHERE 1=1' });
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
it('model preserved', () => {
|
|
954
|
-
const selStmt = 'SELECT * FROM aTable';
|
|
955
|
-
const shouldBeOK = `
|
|
956
|
-
source: newa is a
|
|
957
|
-
sql: someSql is { select: """${selStmt}""" }
|
|
958
|
-
source: newaa is newa
|
|
959
|
-
`;
|
|
960
|
-
const model = new test_translator_1.TestTranslator(shouldBeOK);
|
|
961
|
-
expect(model).modelParsed();
|
|
962
|
-
const needReq = model.translate();
|
|
963
|
-
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
964
|
-
expect(needs).toBeDefined();
|
|
965
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
966
|
-
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
967
|
-
expect(model).modelCompiled();
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
841
|
describe('error handling', () => {
|
|
971
842
|
test('field and query with same name does not overflow', () => {
|
|
972
843
|
expect(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './parse-expects';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2023 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
* a copy of this software and associated documentation files
|
|
8
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
9
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
10
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
11
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
12
|
+
* subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be
|
|
15
|
+
* included in all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
21
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
22
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const model_1 = require("../../model");
|
|
27
|
+
const sql_block_1 = require("../../model/sql_block");
|
|
28
|
+
const test_translator_1 = require("./test-translator");
|
|
29
|
+
require("./parse-expects");
|
|
30
|
+
const parse_malloy_1 = require("../parse-malloy");
|
|
31
|
+
function unlocatedStructDef(sd) {
|
|
32
|
+
const ret = { ...sd };
|
|
33
|
+
ret.fields = sd.fields.map(f => {
|
|
34
|
+
const nf = { ...f };
|
|
35
|
+
delete nf.location;
|
|
36
|
+
return nf;
|
|
37
|
+
});
|
|
38
|
+
delete ret.location;
|
|
39
|
+
return ret;
|
|
40
|
+
}
|
|
41
|
+
describe('sql:', () => {
|
|
42
|
+
const selStmt = 'SELECT * FROM aTable';
|
|
43
|
+
function makeSchemaResponse(sql) {
|
|
44
|
+
const cname = sql.connection || 'bigquery';
|
|
45
|
+
return {
|
|
46
|
+
type: 'struct',
|
|
47
|
+
name: sql.name,
|
|
48
|
+
dialect: 'standardsql',
|
|
49
|
+
structSource: {
|
|
50
|
+
type: 'sql',
|
|
51
|
+
method: 'subquery',
|
|
52
|
+
sqlBlock: {
|
|
53
|
+
type: 'sqlBlock',
|
|
54
|
+
...sql,
|
|
55
|
+
selectStr: sql.select.filter(s => typeof s === 'string').join(''),
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
structRelationship: { type: 'basetable', connectionName: cname },
|
|
59
|
+
fields: test_translator_1.aTableDef.fields,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
test('definition', () => {
|
|
63
|
+
const model = new test_translator_1.TestTranslator(`
|
|
64
|
+
sql: users IS {
|
|
65
|
+
select: """${selStmt}"""
|
|
66
|
+
connection: "aConnection"
|
|
67
|
+
}
|
|
68
|
+
`);
|
|
69
|
+
const needReq = model.translate();
|
|
70
|
+
expect(model).modelParsed();
|
|
71
|
+
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
72
|
+
expect(needs).toBeDefined();
|
|
73
|
+
if (needs) {
|
|
74
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
75
|
+
expect(needs).toMatchObject(sql);
|
|
76
|
+
const refKey = needs.name;
|
|
77
|
+
expect(refKey).toBeDefined();
|
|
78
|
+
if (refKey) {
|
|
79
|
+
const sr = makeSchemaResponse(sql);
|
|
80
|
+
model.update({ compileSQL: { [refKey]: sr } });
|
|
81
|
+
expect(model).modelCompiled();
|
|
82
|
+
const expectThis = unlocatedStructDef({ ...sr, as: 'users' });
|
|
83
|
+
if ((0, model_1.isSQLBlockStruct)(expectThis)) {
|
|
84
|
+
expectThis.declaredSQLBlock = true;
|
|
85
|
+
}
|
|
86
|
+
expect(unlocatedStructDef(model.sqlBlocks[0])).toEqual(expectThis);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
test('source from sql', () => {
|
|
91
|
+
const model = new test_translator_1.TestTranslator(`
|
|
92
|
+
sql: users IS { select: """${selStmt}""" }
|
|
93
|
+
source: malloyUsers is from_sql(users) { primary_key: ai }
|
|
94
|
+
`);
|
|
95
|
+
expect(model).modelParsed();
|
|
96
|
+
const needReq = model.translate();
|
|
97
|
+
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
98
|
+
expect(needs).toBeDefined();
|
|
99
|
+
if (needs) {
|
|
100
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
101
|
+
const refKey = needs.name;
|
|
102
|
+
model.update({ compileSQL: { [refKey]: makeSchemaResponse(sql) } });
|
|
103
|
+
expect(model).modelCompiled();
|
|
104
|
+
const users = model.getSourceDef('malloyUsers');
|
|
105
|
+
expect(users).toBeDefined();
|
|
106
|
+
if (users && (0, model_1.isSQLBlockStruct)(users)) {
|
|
107
|
+
expect(users.declaredSQLBlock).toBeUndefined();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
test('explore from imported sql-based-source', () => {
|
|
112
|
+
const createModel = `
|
|
113
|
+
sql: users IS { select: """${selStmt}""" }
|
|
114
|
+
source: malloyUsers is from_sql(users) { primary_key: ai }
|
|
115
|
+
`;
|
|
116
|
+
const model = new test_translator_1.TestTranslator(`
|
|
117
|
+
import "createModel.malloy"
|
|
118
|
+
source: importUsers is malloyUsers
|
|
119
|
+
query: malloyUsers -> { project: * }
|
|
120
|
+
query: importUsers -> { project: * }
|
|
121
|
+
`);
|
|
122
|
+
model.importZone.define('internal://test/langtests/createModel.malloy', createModel);
|
|
123
|
+
expect(model).modelParsed();
|
|
124
|
+
const needReq = model.translate();
|
|
125
|
+
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
126
|
+
expect(needs).toBeDefined();
|
|
127
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
128
|
+
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
129
|
+
expect(model).modelCompiled();
|
|
130
|
+
});
|
|
131
|
+
it('turducken', () => {
|
|
132
|
+
const m = new test_translator_1.TestTranslator(`
|
|
133
|
+
sql: someSql is {
|
|
134
|
+
select: """SELECT * FROM %{ a -> { group_by: astr } }% WHERE 1=1"""
|
|
135
|
+
}
|
|
136
|
+
`);
|
|
137
|
+
expect(m).modelParsed();
|
|
138
|
+
const compileSql = m.translate().compileSQL;
|
|
139
|
+
expect(compileSql).toBeDefined();
|
|
140
|
+
if (compileSql) {
|
|
141
|
+
const select = compileSql.select[0];
|
|
142
|
+
const star = compileSql.select[1];
|
|
143
|
+
const where = compileSql.select[2];
|
|
144
|
+
expect(select).toEqual({ sql: 'SELECT * FROM ' });
|
|
145
|
+
expect((0, model_1.isSQLFragment)(star)).toBeFalsy();
|
|
146
|
+
expect(where).toEqual({ sql: ' WHERE 1=1' });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
it('model preserved', () => {
|
|
150
|
+
const shouldBeOK = `
|
|
151
|
+
source: newa is a
|
|
152
|
+
sql: someSql is { select: """${selStmt}""" }
|
|
153
|
+
source: newaa is newa
|
|
154
|
+
`;
|
|
155
|
+
const model = new test_translator_1.TestTranslator(shouldBeOK);
|
|
156
|
+
expect(model).modelParsed();
|
|
157
|
+
const needReq = model.translate();
|
|
158
|
+
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
159
|
+
expect(needs).toBeDefined();
|
|
160
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
161
|
+
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
162
|
+
expect(model).modelCompiled();
|
|
163
|
+
});
|
|
164
|
+
test('explore from extended sql-based-source', () => {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
const model = new test_translator_1.TestTranslator(`
|
|
167
|
+
sql: sql_block IS { select: """${selStmt}""" }
|
|
168
|
+
source: malloy_source is from_sql(sql_block) { primary_key: ai }
|
|
169
|
+
`);
|
|
170
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
171
|
+
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
172
|
+
expect(model).modelCompiled();
|
|
173
|
+
const modelDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.translate()) === null || _a === void 0 ? void 0 : _a.translated) === null || _b === void 0 ? void 0 : _b.modelDef;
|
|
174
|
+
const extModel = new parse_malloy_1.MalloyTranslator('sqlblocktest://main');
|
|
175
|
+
extModel.importZone.define('sqlblocktest://main', 'query: malloy_source -> { project: * }');
|
|
176
|
+
extModel.translate(modelDef);
|
|
177
|
+
expect(extModel).toBeErrorless();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
//# sourceMappingURL=sql-block.spec.js.map
|
package/dist/malloy.js
CHANGED
|
@@ -155,7 +155,7 @@ class Malloy {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
if (resolved.structDef) {
|
|
158
|
-
if ((0, model_1.
|
|
158
|
+
if ((0, model_1.isSQLBlockStruct)(resolved.structDef)) {
|
|
159
159
|
translator.update({
|
|
160
160
|
compileSQL: { [expanded.name]: resolved.structDef },
|
|
161
161
|
});
|
|
@@ -453,8 +453,9 @@ export interface StructDef extends NamedObject, ResultStructMetadata, Filtered {
|
|
|
453
453
|
}
|
|
454
454
|
export interface SQLBlockStructDef extends StructDef {
|
|
455
455
|
structSource: SubquerySource;
|
|
456
|
+
declaredSQLBlock?: boolean;
|
|
456
457
|
}
|
|
457
|
-
export declare function
|
|
458
|
+
export declare function isSQLBlockStruct(sd: StructDef): sd is SQLBlockStructDef;
|
|
458
459
|
/** any of the different field types */
|
|
459
460
|
export declare type FieldTypeDef = FieldStringDef | FieldDateDef | FieldTimestampDef | FieldNumberDef | FieldBooleanDef | FieldJSONDef | FieldUnsupportedDef;
|
|
460
461
|
export declare function isFieldTypeDef(f: FieldDef): f is FieldTypeDef;
|
|
@@ -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.isMeasureLike = exports.getPhysicalFields = exports.getDimensions = exports.isPhysical = exports.isDimensional = exports.isTurtleDef = exports.getIdentifier = exports.isFieldStructDef = exports.isFieldTimeBased = exports.isFieldTypeDef = exports.
|
|
25
|
+
exports.isMeasureLike = exports.getPhysicalFields = exports.getDimensions = exports.isPhysical = exports.isDimensional = exports.isTurtleDef = exports.getIdentifier = exports.isFieldStructDef = exports.isFieldTimeBased = exports.isFieldTypeDef = exports.isSQLBlockStruct = exports.isSQLFragment = exports.isJoinOn = exports.isIndexSegment = exports.isSamplingEnable = exports.isSamplingPercent = exports.isSamplingRows = exports.isQuerySegment = exports.isProjectSegment = exports.isReduceSegment = exports.refIsStructDef = exports.isByExpression = exports.isByName = exports.ValueType = exports.isExtractUnit = exports.isTimestampUnit = exports.isDateUnit = exports.FieldIsIntrinsic = exports.isAtomicFieldType = exports.isTimeFieldType = exports.hasExpression = exports.maxExpressionType = exports.expressionIsCalculation = exports.expressionIsAggregate = exports.mkExpr = exports.isApplyFragment = exports.isApplyValue = exports.isParameterFragment = exports.isFieldFragment = exports.isAnalyticFragment = exports.malloyFunctions = exports.isUngroupFragment = exports.isAsymmetricFragment = exports.isAggregateFragment = exports.isDialectFragment = exports.isFilterFragment = exports.isFilteredAliasedName = exports.paramHasValue = exports.isConditionParameter = exports.isValueParameter = void 0;
|
|
26
26
|
exports.isValueDate = exports.isValueTimestamp = exports.isValueBoolean = exports.isValueNumber = exports.isValueString = void 0;
|
|
27
27
|
function isValueParameter(p) {
|
|
28
28
|
return p.value !== undefined;
|
|
@@ -296,11 +296,11 @@ function isSQLFragment(f) {
|
|
|
296
296
|
return f.sql !== undefined;
|
|
297
297
|
}
|
|
298
298
|
exports.isSQLFragment = isSQLFragment;
|
|
299
|
-
function
|
|
299
|
+
function isSQLBlockStruct(sd) {
|
|
300
300
|
const src = sd.structSource;
|
|
301
301
|
return src.type === 'sql' && src.method === 'subquery';
|
|
302
302
|
}
|
|
303
|
-
exports.
|
|
303
|
+
exports.isSQLBlockStruct = isSQLBlockStruct;
|
|
304
304
|
function isFieldTypeDef(f) {
|
|
305
305
|
return (f.type === 'string' ||
|
|
306
306
|
f.type === 'date' ||
|