@malloydata/malloy 0.0.195-dev241003204819 → 0.0.195-dev241007154000
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/connection/base_connection.d.ts +21 -7
- package/dist/connection/base_connection.js +62 -0
- package/dist/connection/types.d.ts +5 -5
- package/dist/dialect/dialect.d.ts +5 -3
- package/dist/dialect/dialect.js +15 -0
- package/dist/dialect/duckdb/duckdb.d.ts +3 -3
- package/dist/dialect/duckdb/duckdb.js +8 -3
- package/dist/dialect/postgres/postgres.d.ts +3 -3
- package/dist/dialect/postgres/postgres.js +5 -2
- package/dist/dialect/snowflake/snowflake.d.ts +3 -3
- package/dist/dialect/snowflake/snowflake.js +4 -1
- package/dist/dialect/standardsql/standardsql.d.ts +3 -3
- package/dist/dialect/standardsql/standardsql.js +5 -2
- package/dist/dialect/trino/trino.d.ts +3 -3
- package/dist/dialect/trino/trino.js +35 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -2
- package/dist/lang/ast/error-factory.d.ts +4 -3
- package/dist/lang/ast/error-factory.js +27 -17
- package/dist/lang/ast/expressions/constant-expression.d.ts +1 -0
- package/dist/lang/ast/expressions/constant-expression.js +3 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +3 -7
- package/dist/lang/ast/expressions/expr-aggregate-function.js +50 -54
- package/dist/lang/ast/expressions/expr-cast.js +2 -4
- package/dist/lang/ast/expressions/expr-func.js +1 -1
- package/dist/lang/ast/expressions/expr-granular-time.js +1 -1
- package/dist/lang/ast/expressions/expr-record-literal.d.ts +16 -0
- package/dist/lang/ast/expressions/expr-record-literal.js +57 -0
- package/dist/lang/ast/expressions/expr-time-extract.js +3 -3
- package/dist/lang/ast/expressions/expr-time.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-time.js +1 -1
- package/dist/lang/ast/expressions/time-literal.d.ts +6 -6
- package/dist/lang/ast/expressions/time-literal.js +1 -1
- package/dist/lang/ast/field-space/column-space-field.d.ts +6 -5
- package/dist/lang/ast/field-space/column-space-field.js +7 -4
- package/dist/lang/ast/field-space/dynamic-space.d.ts +8 -6
- package/dist/lang/ast/field-space/dynamic-space.js +35 -11
- package/dist/lang/ast/field-space/index-field-space.js +6 -3
- package/dist/lang/ast/field-space/ir-view-field.d.ts +1 -0
- package/dist/lang/ast/field-space/ir-view-field.js +3 -1
- package/dist/lang/ast/field-space/join-space-field.d.ts +2 -2
- package/dist/lang/ast/field-space/join-space-field.js +2 -2
- package/dist/lang/ast/field-space/parameter-space.d.ts +1 -0
- package/dist/lang/ast/field-space/parameter-space.js +4 -1
- package/dist/lang/ast/field-space/query-input-space.d.ts +4 -4
- package/dist/lang/ast/field-space/query-input-space.js +3 -5
- package/dist/lang/ast/field-space/query-spaces.d.ts +4 -4
- package/dist/lang/ast/field-space/query-spaces.js +1 -1
- package/dist/lang/ast/field-space/reference-field.js +10 -8
- package/dist/lang/ast/field-space/refined-space.d.ts +2 -2
- package/dist/lang/ast/field-space/static-space.d.ts +14 -5
- package/dist/lang/ast/field-space/static-space.js +45 -20
- package/dist/lang/ast/field-space/struct-space-field-base.d.ts +6 -5
- package/dist/lang/ast/field-space/struct-space-field-base.js +12 -4
- package/dist/lang/ast/index.d.ts +2 -1
- package/dist/lang/ast/index.js +2 -1
- package/dist/lang/ast/query-builders/index-builder.d.ts +2 -2
- package/dist/lang/ast/query-builders/project-builder.d.ts +2 -2
- package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
- package/dist/lang/ast/query-elements/query-arrow.js +2 -2
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +2 -2
- package/dist/lang/ast/query-elements/query-head-struct.js +2 -2
- package/dist/lang/ast/query-elements/query-raw.js +2 -2
- package/dist/lang/ast/query-elements/query-reference.js +1 -1
- package/dist/lang/ast/query-items/field-declaration.d.ts +8 -6
- package/dist/lang/ast/query-items/field-declaration.js +66 -24
- package/dist/lang/ast/query-properties/qop-desc.d.ts +2 -2
- package/dist/lang/ast/query-properties/qop-desc.js +1 -1
- package/dist/lang/ast/source-elements/named-source.d.ts +4 -4
- package/dist/lang/ast/source-elements/named-source.js +16 -8
- package/dist/lang/ast/source-elements/query-source.d.ts +3 -3
- package/dist/lang/ast/source-elements/query-source.js +5 -2
- package/dist/lang/ast/source-elements/refined-source.d.ts +3 -3
- package/dist/lang/ast/source-elements/refined-source.js +4 -4
- package/dist/lang/ast/source-elements/source.d.ts +2 -2
- package/dist/lang/ast/source-elements/source.js +2 -2
- package/dist/lang/ast/source-elements/sql-source.d.ts +4 -4
- package/dist/lang/ast/source-elements/sql-source.js +6 -6
- package/dist/lang/ast/source-elements/table-source.d.ts +2 -2
- package/dist/lang/ast/source-elements/table-source.js +1 -1
- package/dist/lang/ast/source-properties/{joins.d.ts → join.d.ts} +11 -14
- package/dist/lang/ast/source-properties/{joins.js → join.js} +35 -52
- package/dist/lang/ast/source-query-elements/sq-reference.js +6 -5
- package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
- package/dist/lang/ast/statements/define-source.js +1 -1
- package/dist/lang/ast/struct-utils.d.ts +3 -3
- package/dist/lang/ast/struct-utils.js +12 -3
- package/dist/lang/ast/time-utils.d.ts +3 -3
- package/dist/lang/ast/types/document-compile-result.d.ts +2 -2
- package/dist/lang/ast/types/expression-def.js +4 -4
- package/dist/lang/ast/types/field-space.d.ts +8 -3
- package/dist/lang/ast/types/lookup-result.d.ts +8 -5
- package/dist/lang/ast/types/malloy-element.d.ts +3 -3
- package/dist/lang/ast/types/malloy-element.js +10 -21
- package/dist/lang/ast/types/op-desc.d.ts +2 -2
- package/dist/lang/ast/types/pipeline-comp.d.ts +2 -2
- package/dist/lang/ast/types/query-comp.d.ts +3 -3
- package/dist/lang/ast/types/query-extend-property.d.ts +1 -2
- package/dist/lang/ast/types/query-extend-property.js +4 -2
- package/dist/lang/ast/types/source-property.d.ts +2 -2
- package/dist/lang/ast/types/source-property.js +2 -2
- package/dist/lang/ast/types/space-field.d.ts +10 -3
- package/dist/lang/ast/types/space-field.js +11 -2
- package/dist/lang/ast/types/time-result.d.ts +2 -2
- package/dist/lang/ast/view-elements/qop-desc-view.d.ts +3 -3
- package/dist/lang/ast/view-elements/qop-desc-view.js +1 -1
- package/dist/lang/ast/view-elements/reference-view.d.ts +4 -4
- package/dist/lang/ast/view-elements/reference-view.js +2 -6
- package/dist/lang/ast/view-elements/view-refine.d.ts +2 -2
- package/dist/lang/index.d.ts +1 -1
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +54 -21
- package/dist/lang/lib/Malloy/MalloyParser.js +1647 -1457
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +57 -9
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +35 -5
- package/dist/lang/malloy-to-ast.d.ts +4 -4
- package/dist/lang/malloy-to-ast.js +32 -4
- package/dist/lang/parse-log.d.ts +5 -9
- package/dist/lang/parse-malloy.d.ts +10 -10
- package/dist/lang/parse-malloy.js +2 -1
- package/dist/lang/test/annotation.spec.js +7 -1
- package/dist/lang/test/field-symbols.spec.js +21 -25
- package/dist/lang/test/imports.spec.js +12 -10
- package/dist/lang/test/lenses.spec.js +2 -2
- package/dist/lang/test/model_serialization.spec.d.ts +4 -4
- package/dist/lang/test/model_serialization.spec.js +19 -31
- package/dist/lang/test/parse.spec.js +3 -4
- package/dist/lang/test/query.spec.js +3 -2
- package/dist/lang/test/source.spec.js +7 -0
- package/dist/lang/test/sql-block.spec.js +8 -19
- package/dist/lang/test/test-translator.d.ts +4 -4
- package/dist/lang/test/test-translator.js +53 -61
- package/dist/lang/translate-response.d.ts +3 -3
- package/dist/malloy.d.ts +31 -149
- package/dist/malloy.js +111 -269
- package/dist/model/malloy_query.d.ts +25 -23
- package/dist/model/malloy_query.js +262 -323
- package/dist/model/malloy_types.d.ts +145 -155
- package/dist/model/malloy_types.js +81 -84
- package/dist/model/sql_block.d.ts +4 -4
- package/dist/model/sql_block.js +9 -12
- package/dist/tags.js +2 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.js +6 -0
- package/package.json +3 -2
- package/dist/lang/ast/space-seed.d.ts +0 -16
- package/dist/lang/ast/space-seed.js +0 -59
|
@@ -22,18 +22,15 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.SOURCE_EXPLORE = exports.
|
|
25
|
+
exports.SOURCE_EXPLORE = exports.GRANDPARENT_EXPLORE = exports.PARENT_EXPLORE = exports.CHILD_EXPLORE = void 0;
|
|
26
26
|
const malloy_1 = require("../../malloy");
|
|
27
27
|
exports.CHILD_EXPLORE = {
|
|
28
|
-
type: '
|
|
28
|
+
type: 'table',
|
|
29
29
|
name: 'some_ns.child',
|
|
30
30
|
as: 'child',
|
|
31
31
|
dialect: 'standardsql',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
tablePath: 'some_ns.child',
|
|
35
|
-
},
|
|
36
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
32
|
+
tablePath: 'some_ns.child',
|
|
33
|
+
connection: 'bigquery',
|
|
37
34
|
primaryKey: 'id1',
|
|
38
35
|
fields: [
|
|
39
36
|
{ type: 'string', name: 'carrier' },
|
|
@@ -46,15 +43,12 @@ exports.CHILD_EXPLORE = {
|
|
|
46
43
|
],
|
|
47
44
|
};
|
|
48
45
|
exports.PARENT_EXPLORE = {
|
|
49
|
-
type: '
|
|
46
|
+
type: 'table',
|
|
50
47
|
name: 'some_ns.parent',
|
|
51
48
|
as: 'parent',
|
|
52
49
|
dialect: 'standardsql',
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
tablePath: 'some_ns.parent',
|
|
56
|
-
},
|
|
57
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
50
|
+
tablePath: 'some_ns.parent',
|
|
51
|
+
connection: 'bigquery',
|
|
58
52
|
primaryKey: 'id2',
|
|
59
53
|
fields: [
|
|
60
54
|
{ type: 'string', name: 'name' },
|
|
@@ -66,37 +60,31 @@ exports.PARENT_EXPLORE = {
|
|
|
66
60
|
},
|
|
67
61
|
],
|
|
68
62
|
};
|
|
69
|
-
exports.
|
|
70
|
-
type: '
|
|
63
|
+
exports.GRANDPARENT_EXPLORE = {
|
|
64
|
+
type: 'table',
|
|
71
65
|
name: 'some_ns.gradparent',
|
|
72
|
-
as: '
|
|
66
|
+
as: 'grandparent',
|
|
73
67
|
dialect: 'standardsql',
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
tablePath: 'some_ns.gradparent',
|
|
77
|
-
},
|
|
78
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
68
|
+
tablePath: 'some_ns.grandparent',
|
|
69
|
+
connection: 'bigquery',
|
|
79
70
|
primaryKey: 'id3',
|
|
80
71
|
fields: [
|
|
81
72
|
{ type: 'string', name: 'name' },
|
|
82
73
|
{
|
|
83
74
|
type: 'number',
|
|
84
|
-
name: '
|
|
75
|
+
name: 'some_grandparent_count',
|
|
85
76
|
expressionType: 'aggregate',
|
|
86
77
|
e: { node: 'aggregate', function: 'count', e: { node: '' } },
|
|
87
78
|
},
|
|
88
79
|
],
|
|
89
80
|
};
|
|
90
81
|
exports.SOURCE_EXPLORE = {
|
|
91
|
-
type: '
|
|
82
|
+
type: 'table',
|
|
92
83
|
name: 'some_ns.source',
|
|
93
84
|
as: 'source',
|
|
94
85
|
dialect: 'standardsql',
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
tablePath: 'some_ns.source',
|
|
98
|
-
},
|
|
99
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
86
|
+
tablePath: 'some_ns.grandparent',
|
|
87
|
+
connection: 'bigquery',
|
|
100
88
|
primaryKey: 'id4',
|
|
101
89
|
fields: [
|
|
102
90
|
{ type: 'string', name: 'name' },
|
|
@@ -111,15 +99,15 @@ exports.SOURCE_EXPLORE = {
|
|
|
111
99
|
describe('serializeModel', () => {
|
|
112
100
|
test('Stringify on an `explore` with no parent nor source explore', async () => {
|
|
113
101
|
const parent_explore = new malloy_1.Explore(exports.PARENT_EXPLORE);
|
|
114
|
-
expect(JSON.stringify(parent_explore)).toStrictEqual('{"_structDef":{"type":"
|
|
102
|
+
expect(JSON.stringify(parent_explore)).toStrictEqual('{"_structDef":{"type":"table","name":"some_ns.parent","as":"parent","dialect":"standardsql","tablePath":"some_ns.parent","connection":"bigquery","primaryKey":"id2","fields":[{"type":"string","name":"name"},{"type":"number","name":"some_parent_count","expressionType":"aggregate","e":{"node":"aggregate","function":"count","e":{"node":""}}}]}}');
|
|
115
103
|
});
|
|
116
104
|
test('No parent nor source explore', async () => {
|
|
117
105
|
const parent_explore = new malloy_1.Explore(exports.PARENT_EXPLORE);
|
|
118
106
|
expect(malloy_1.Explore.fromJSON(parent_explore.toJSON())).toStrictEqual(parent_explore);
|
|
119
107
|
});
|
|
120
108
|
test('Having parent and source explores', async () => {
|
|
121
|
-
const
|
|
122
|
-
const parent_explore = new malloy_1.Explore(exports.PARENT_EXPLORE,
|
|
109
|
+
const grandparent_explore = new malloy_1.Explore(exports.GRANDPARENT_EXPLORE);
|
|
110
|
+
const parent_explore = new malloy_1.Explore(exports.PARENT_EXPLORE, grandparent_explore);
|
|
123
111
|
const source_explore = new malloy_1.Explore(exports.SOURCE_EXPLORE);
|
|
124
112
|
const child_explore = new malloy_1.Explore(exports.CHILD_EXPLORE, parent_explore, source_explore);
|
|
125
113
|
expect(malloy_1.Explore.fromJSON(child_explore.toJSON())).toStrictEqual(child_explore);
|
|
@@ -414,12 +414,11 @@ describe('pipeline comprehension', () => {
|
|
|
414
414
|
test('new query can refine and append to exisiting query', () => {
|
|
415
415
|
expect(`
|
|
416
416
|
source: aq is _db_.table('aTable') extend {
|
|
417
|
-
view: by_region is {
|
|
418
|
-
|
|
417
|
+
view: by_region is {
|
|
418
|
+
group_by: region is astr
|
|
419
419
|
nest: dateNest is { group_by: ad }
|
|
420
|
-
} -> {
|
|
421
|
-
select: astr, dateNest.ad
|
|
422
420
|
}
|
|
421
|
+
-> { select: dateNest.ad }
|
|
423
422
|
}
|
|
424
423
|
`).toTranslate();
|
|
425
424
|
});
|
|
@@ -482,7 +482,7 @@ describe('query:', () => {
|
|
|
482
482
|
expect(`run: ab -> {
|
|
483
483
|
group_by: b.astr
|
|
484
484
|
calculate: foo is lag(b)
|
|
485
|
-
}`).toLog((0, test_translator_1.errorMessage)('No matching overload for function lag(
|
|
485
|
+
}`).toLog((0, test_translator_1.errorMessage)('No matching overload for function lag(table)'));
|
|
486
486
|
});
|
|
487
487
|
// TODO this doesn't work today, we're not rigorous enough with integer
|
|
488
488
|
// subtypes. But we should probably make this typecheck properly.
|
|
@@ -990,7 +990,8 @@ describe('query:', () => {
|
|
|
990
990
|
const q = t.translated.queryList[0].pipeline[0];
|
|
991
991
|
if (q.type === 'reduce' && q.extendSource) {
|
|
992
992
|
expect(q.extendSource.length).toBe(1);
|
|
993
|
-
expect(q.extendSource[0]
|
|
993
|
+
expect((0, model_1.isJoined)(q.extendSource[0])).toBeTruthy();
|
|
994
|
+
expect(q.extendSource[0].type).toBe('table');
|
|
994
995
|
}
|
|
995
996
|
else {
|
|
996
997
|
fail('Did not generate extendSource');
|
|
@@ -180,6 +180,13 @@ describe('source:', () => {
|
|
|
180
180
|
source: aqs is a extend {
|
|
181
181
|
join_one: aq on ai = aq.ai
|
|
182
182
|
}
|
|
183
|
+
`).toTranslate();
|
|
184
|
+
});
|
|
185
|
+
test('can with join a single column query', () => {
|
|
186
|
+
expect(`
|
|
187
|
+
source: awith is a extend {
|
|
188
|
+
join_one: has_primary_key is a -> { group_by: one_val is astr } with astr
|
|
189
|
+
}
|
|
183
190
|
`).toTranslate();
|
|
184
191
|
});
|
|
185
192
|
});
|
|
@@ -23,29 +23,21 @@
|
|
|
23
23
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const model_1 = require("../../model");
|
|
27
26
|
const sql_block_1 = require("../../model/sql_block");
|
|
28
27
|
const test_translator_1 = require("./test-translator");
|
|
29
28
|
require("./parse-expects");
|
|
30
29
|
const parse_malloy_1 = require("../parse-malloy");
|
|
30
|
+
const model_1 = require("../../model");
|
|
31
31
|
describe('connection sql()', () => {
|
|
32
32
|
const selStmt = 'SELECT * FROM aTable';
|
|
33
33
|
function makeSchemaResponse(sql) {
|
|
34
34
|
const cname = sql.connection || 'bigquery';
|
|
35
35
|
return {
|
|
36
|
-
type: '
|
|
36
|
+
type: 'sql_select',
|
|
37
37
|
name: sql.name,
|
|
38
38
|
dialect: 'standardsql',
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
method: 'subquery',
|
|
42
|
-
sqlBlock: {
|
|
43
|
-
type: 'sqlBlock',
|
|
44
|
-
...sql,
|
|
45
|
-
selectStr: sql.select.filter(s => typeof s === 'string').join(''),
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
structRelationship: { type: 'basetable', connectionName: cname },
|
|
39
|
+
connection: cname,
|
|
40
|
+
selectStr: selStmt,
|
|
49
41
|
fields: test_translator_1.aTableDef.fields,
|
|
50
42
|
};
|
|
51
43
|
}
|
|
@@ -59,15 +51,12 @@ describe('connection sql()', () => {
|
|
|
59
51
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
60
52
|
expect(needs).toBeDefined();
|
|
61
53
|
if (needs) {
|
|
62
|
-
const sql = (0, sql_block_1.
|
|
54
|
+
const sql = (0, sql_block_1.makeSQLSentence)([{ sql: selStmt }], 'aConnection');
|
|
63
55
|
const refKey = needs.name;
|
|
64
56
|
model.update({ compileSQL: { [refKey]: makeSchemaResponse(sql) } });
|
|
65
57
|
expect(model).toTranslate();
|
|
66
58
|
const users = model.getSourceDef('malloyUsers');
|
|
67
59
|
expect(users).toBeDefined();
|
|
68
|
-
if (users && (0, model_1.isSQLBlockStruct)(users)) {
|
|
69
|
-
expect(users.declaredSQLBlock).toBeUndefined();
|
|
70
|
-
}
|
|
71
60
|
}
|
|
72
61
|
});
|
|
73
62
|
test('source from imported sql-based-source', () => {
|
|
@@ -85,7 +74,7 @@ describe('connection sql()', () => {
|
|
|
85
74
|
const needReq = model.translate();
|
|
86
75
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
87
76
|
expect(needs).toBeDefined();
|
|
88
|
-
const sql = (0, sql_block_1.
|
|
77
|
+
const sql = (0, sql_block_1.makeSQLSentence)([{ sql: selStmt }], '_db_');
|
|
89
78
|
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
90
79
|
expect(model).toTranslate();
|
|
91
80
|
});
|
|
@@ -101,7 +90,7 @@ describe('connection sql()', () => {
|
|
|
101
90
|
const star = compileSql.select[1];
|
|
102
91
|
const where = compileSql.select[2];
|
|
103
92
|
expect(select).toEqual({ sql: 'SELECT * FROM ' });
|
|
104
|
-
expect((0, model_1.
|
|
93
|
+
expect((0, model_1.isSegmentSQL)(star)).toBeFalsy();
|
|
105
94
|
expect(where).toEqual({ sql: ' WHERE 1=1' });
|
|
106
95
|
}
|
|
107
96
|
});
|
|
@@ -143,7 +132,7 @@ describe('connection sql()', () => {
|
|
|
143
132
|
source: sql_block is aConnection.sql("""${selStmt}""")
|
|
144
133
|
source: malloy_source is sql_block extend { primary_key: ai }
|
|
145
134
|
`);
|
|
146
|
-
const sql = (0, sql_block_1.
|
|
135
|
+
const sql = (0, sql_block_1.makeSQLSentence)([{ sql: selStmt }], 'aConnection');
|
|
147
136
|
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
148
137
|
expect(model).toTranslate();
|
|
149
138
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DocumentLocation, Expr, FieldDef, ModelDef, NamedModelObject, PipeSegment, Query, QueryFieldDef,
|
|
1
|
+
import { DocumentLocation, Expr, FieldDef, ModelDef, NamedModelObject, PipeSegment, Query, QueryFieldDef, StructDef, TurtleDef, SourceDef, SQLSourceDef, SQLSentence } 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';
|
|
@@ -8,7 +8,7 @@ import { ExprValue } from '../ast/types/expr-value';
|
|
|
8
8
|
import { LogSeverity, MessageCode, MessageParameterType } from '../parse-log';
|
|
9
9
|
import { EventStream } from '../../runtime_types';
|
|
10
10
|
export declare function pretty(thing: any): string;
|
|
11
|
-
export declare const aTableDef:
|
|
11
|
+
export declare const aTableDef: SourceDef;
|
|
12
12
|
/**
|
|
13
13
|
* When translating partial trees, there will not be a document node
|
|
14
14
|
* to handle namespace requests, this stands in for document in that case.
|
|
@@ -41,7 +41,7 @@ export declare class TestTranslator extends MalloyTranslator {
|
|
|
41
41
|
static inspectCompile: boolean;
|
|
42
42
|
compile(): void;
|
|
43
43
|
unresolved(): DataRequestResponse;
|
|
44
|
-
getSourceDef(srcName: string):
|
|
44
|
+
getSourceDef(srcName: string): SourceDef | undefined;
|
|
45
45
|
getQuery(queryName: string | number): Query | undefined;
|
|
46
46
|
}
|
|
47
47
|
export declare class BetaExpression extends TestTranslator {
|
|
@@ -73,7 +73,7 @@ export declare function makeModelFunc(options: {
|
|
|
73
73
|
wrap?: (code: string) => string;
|
|
74
74
|
}): (unmarked: TemplateStringsArray, ...marked: string[]) => HasTranslator<TestTranslator>;
|
|
75
75
|
export declare function markSource(unmarked: TemplateStringsArray, ...marked: string[]): MarkedSource;
|
|
76
|
-
export declare function getSelectOneStruct(sqlBlock:
|
|
76
|
+
export declare function getSelectOneStruct(sqlBlock: SQLSentence): SQLSourceDef;
|
|
77
77
|
export declare function exprToString(e: Expr, symbols?: Record<string, string>): string;
|
|
78
78
|
export declare function error<T extends MessageCode>(code: T, data?: MessageParameterType<T>): {
|
|
79
79
|
code: T;
|
|
@@ -37,11 +37,11 @@ function pretty(thing) {
|
|
|
37
37
|
exports.pretty = pretty;
|
|
38
38
|
const mockSchema = {
|
|
39
39
|
'aTable': {
|
|
40
|
-
type: '
|
|
40
|
+
type: 'table',
|
|
41
41
|
name: 'aTable',
|
|
42
42
|
dialect: 'standardsql',
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
tablePath: 'aTable',
|
|
44
|
+
connection: 'test',
|
|
45
45
|
fields: [
|
|
46
46
|
{ type: 'string', name: 'astr' },
|
|
47
47
|
{ type: 'number', name: 'af', numberType: 'float' },
|
|
@@ -52,32 +52,35 @@ const mockSchema = {
|
|
|
52
52
|
{ type: 'sql native', name: 'aun' },
|
|
53
53
|
{ type: 'sql native', name: 'aweird', rawType: 'weird' },
|
|
54
54
|
{
|
|
55
|
-
type: '
|
|
55
|
+
type: 'array',
|
|
56
56
|
name: 'astruct',
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
fields: [
|
|
57
|
+
elementTypeDef: { type: 'record_element' },
|
|
58
|
+
join: 'many',
|
|
59
|
+
fields: [
|
|
60
|
+
{
|
|
61
|
+
name: 'column',
|
|
62
|
+
type: 'number',
|
|
63
|
+
numberType: 'integer',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
60
66
|
dialect: 'standardsql',
|
|
61
67
|
},
|
|
62
68
|
{
|
|
63
|
-
type: '
|
|
69
|
+
type: 'record',
|
|
64
70
|
name: 'aninline',
|
|
65
|
-
structSource: { type: 'nested' },
|
|
66
|
-
structRelationship: { type: 'inline' },
|
|
67
71
|
fields: [{ type: 'number', name: 'column', numberType: 'integer' }],
|
|
72
|
+
join: 'one',
|
|
73
|
+
matrixOperation: 'left',
|
|
68
74
|
dialect: 'standardsql',
|
|
69
75
|
},
|
|
70
76
|
],
|
|
71
77
|
},
|
|
72
78
|
'malloytest.carriers': {
|
|
73
|
-
type: '
|
|
79
|
+
type: 'table',
|
|
74
80
|
name: 'malloytest.carriers',
|
|
75
81
|
dialect: 'standardsql',
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
tablePath: 'malloytest.carriers',
|
|
79
|
-
},
|
|
80
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
82
|
+
tablePath: 'malloytest.carriers',
|
|
83
|
+
connection: 'bigquery',
|
|
81
84
|
fields: [
|
|
82
85
|
{ name: 'code', type: 'string' },
|
|
83
86
|
{ name: 'name', type: 'string' },
|
|
@@ -86,14 +89,11 @@ const mockSchema = {
|
|
|
86
89
|
as: 'carriers',
|
|
87
90
|
},
|
|
88
91
|
'malloytest.flights': {
|
|
89
|
-
type: '
|
|
92
|
+
type: 'table',
|
|
90
93
|
name: 'malloytest.flights',
|
|
91
94
|
dialect: 'standardsql',
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
tablePath: 'malloytest.flights',
|
|
95
|
-
},
|
|
96
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
95
|
+
tablePath: 'malloytest.flights',
|
|
96
|
+
connection: 'bigquery',
|
|
97
97
|
fields: [
|
|
98
98
|
{ name: 'carrier', type: 'string' },
|
|
99
99
|
{ name: 'origin', type: 'string' },
|
|
@@ -115,14 +115,11 @@ const mockSchema = {
|
|
|
115
115
|
as: 'flights',
|
|
116
116
|
},
|
|
117
117
|
'malloytest.airports': {
|
|
118
|
-
type: '
|
|
118
|
+
type: 'table',
|
|
119
119
|
name: 'malloytest.airports',
|
|
120
120
|
dialect: 'standardsql',
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
tablePath: 'malloytest.airports',
|
|
124
|
-
},
|
|
125
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
121
|
+
tablePath: 'malloytest.airports',
|
|
122
|
+
connection: 'bigquery',
|
|
126
123
|
fields: [
|
|
127
124
|
{ name: 'id', type: 'number', numberType: 'integer' },
|
|
128
125
|
{ name: 'code', type: 'string' },
|
|
@@ -156,6 +153,24 @@ const mockSchema = {
|
|
|
156
153
|
},
|
|
157
154
|
};
|
|
158
155
|
exports.aTableDef = mockSchema['aTable'];
|
|
156
|
+
const bJoinedIntoA = {
|
|
157
|
+
type: 'table',
|
|
158
|
+
name: 'aTable',
|
|
159
|
+
dialect: 'standardsql',
|
|
160
|
+
tablePath: 'aTable',
|
|
161
|
+
connection: 'test',
|
|
162
|
+
as: 'b',
|
|
163
|
+
join: 'one',
|
|
164
|
+
matrixOperation: 'left',
|
|
165
|
+
onExpression: {
|
|
166
|
+
node: '=',
|
|
167
|
+
kids: {
|
|
168
|
+
left: { node: 'field', path: ['astr'] },
|
|
169
|
+
right: { node: 'field', path: ['b', 'astr'] },
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
fields: exports.aTableDef.fields,
|
|
173
|
+
};
|
|
159
174
|
/**
|
|
160
175
|
* When translating partial trees, there will not be a document node
|
|
161
176
|
* to handle namespace requests, this stands in for document in that case.
|
|
@@ -176,7 +191,7 @@ class TestRoot extends ast_1.MalloyElement {
|
|
|
176
191
|
if (global)
|
|
177
192
|
return global;
|
|
178
193
|
const struct = this.modelDef.contents[name];
|
|
179
|
-
if (
|
|
194
|
+
if ((0, malloy_types_1.modelObjIsSource)(struct)) {
|
|
180
195
|
const exported = this.modelDef.exports.includes(name);
|
|
181
196
|
return { entry: struct, exported };
|
|
182
197
|
}
|
|
@@ -232,25 +247,10 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
|
232
247
|
b: { ...exports.aTableDef, primaryKey: 'astr', as: 'b' },
|
|
233
248
|
ab: {
|
|
234
249
|
...exports.aTableDef,
|
|
235
|
-
as: 'ab',
|
|
236
250
|
primaryKey: 'astr',
|
|
237
251
|
fields: [
|
|
238
252
|
...exports.aTableDef.fields,
|
|
239
|
-
|
|
240
|
-
...exports.aTableDef,
|
|
241
|
-
as: 'b',
|
|
242
|
-
structRelationship: {
|
|
243
|
-
type: 'one',
|
|
244
|
-
matrixOperation: 'left',
|
|
245
|
-
onExpression: {
|
|
246
|
-
node: '=',
|
|
247
|
-
kids: {
|
|
248
|
-
left: { node: 'field', path: ['astr'] },
|
|
249
|
-
right: { node: 'field', path: ['b', 'astr'] },
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
},
|
|
253
|
+
bJoinedIntoA,
|
|
254
254
|
{
|
|
255
255
|
type: 'number',
|
|
256
256
|
name: 'acount',
|
|
@@ -345,7 +345,7 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
|
345
345
|
}
|
|
346
346
|
exploreFor(exploreName) {
|
|
347
347
|
const explore = this.nameSpace[exploreName];
|
|
348
|
-
if (explore &&
|
|
348
|
+
if (explore && (0, malloy_types_1.modelObjIsSource)(explore)) {
|
|
349
349
|
return explore;
|
|
350
350
|
}
|
|
351
351
|
throw new Error(`Expected model to contain source '${exploreName}'`);
|
|
@@ -365,7 +365,7 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
|
365
365
|
var _a;
|
|
366
366
|
const t = this.translate().translated;
|
|
367
367
|
const s = (_a = t === null || t === void 0 ? void 0 : t.modelDef) === null || _a === void 0 ? void 0 : _a.contents[srcName];
|
|
368
|
-
if (s &&
|
|
368
|
+
if (s && (0, malloy_types_1.modelObjIsSource)(s)) {
|
|
369
369
|
return s;
|
|
370
370
|
}
|
|
371
371
|
return undefined;
|
|
@@ -391,8 +391,8 @@ class BetaExpression extends TestTranslator {
|
|
|
391
391
|
}
|
|
392
392
|
testFS() {
|
|
393
393
|
const aStruct = this.internalModel.contents['ab'];
|
|
394
|
-
if (
|
|
395
|
-
const tstFS = new static_space_1.
|
|
394
|
+
if ((0, malloy_types_1.modelObjIsSource)(aStruct)) {
|
|
395
|
+
const tstFS = new static_space_1.StaticSourceSpace(aStruct);
|
|
396
396
|
return tstFS;
|
|
397
397
|
}
|
|
398
398
|
else {
|
|
@@ -531,23 +531,15 @@ function markSource(unmarked, ...marked) {
|
|
|
531
531
|
exports.markSource = markSource;
|
|
532
532
|
function getSelectOneStruct(sqlBlock) {
|
|
533
533
|
const selectThis = sqlBlock.select[0];
|
|
534
|
-
if (!(0, malloy_types_1.
|
|
534
|
+
if (!(0, malloy_types_1.isSegmentSQL)(selectThis)) {
|
|
535
535
|
throw new Error('weird test support error sorry');
|
|
536
536
|
}
|
|
537
537
|
return {
|
|
538
|
-
type: '
|
|
538
|
+
type: 'sql_select',
|
|
539
539
|
name: sqlBlock.name,
|
|
540
540
|
dialect: 'standardsql',
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
method: 'subquery',
|
|
544
|
-
sqlBlock: {
|
|
545
|
-
type: 'sqlBlock',
|
|
546
|
-
name: sqlBlock.name,
|
|
547
|
-
selectStr: selectThis.sql,
|
|
548
|
-
},
|
|
549
|
-
},
|
|
550
|
-
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
541
|
+
connection: 'bigquery',
|
|
542
|
+
selectStr: selectThis.sql,
|
|
551
543
|
fields: [{ type: 'number', name: 'one' }],
|
|
552
544
|
};
|
|
553
545
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Annotation, ModelDef, Query,
|
|
1
|
+
import { Annotation, ModelDef, Query, SQLSentence, SQLSourceDef } 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';
|
|
@@ -26,7 +26,7 @@ export interface NeedURLData {
|
|
|
26
26
|
urls: string[];
|
|
27
27
|
}
|
|
28
28
|
export interface NeedCompileSQL {
|
|
29
|
-
compileSQL:
|
|
29
|
+
compileSQL: SQLSentence;
|
|
30
30
|
partialModel: ModelDef | undefined;
|
|
31
31
|
}
|
|
32
32
|
interface NeededData extends NeedURLData, NeedSchemaData, NeedCompileSQL {
|
|
@@ -58,7 +58,7 @@ interface TranslatedResponseData extends NeededData, ProblemResponse, FinalRespo
|
|
|
58
58
|
translated: {
|
|
59
59
|
modelDef: ModelDef;
|
|
60
60
|
queryList: Query[];
|
|
61
|
-
sqlBlocks:
|
|
61
|
+
sqlBlocks: SQLSourceDef[];
|
|
62
62
|
};
|
|
63
63
|
fromSources: string[];
|
|
64
64
|
}
|