@malloydata/malloy-tests 0.0.195-dev241003204905 → 0.0.195

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/package.json CHANGED
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@jest/globals": "^29.4.3",
24
- "@malloydata/db-bigquery": "^0.0.195-dev241003204905",
25
- "@malloydata/db-duckdb": "^0.0.195-dev241003204905",
26
- "@malloydata/db-postgres": "^0.0.195-dev241003204905",
27
- "@malloydata/db-snowflake": "^0.0.195-dev241003204905",
28
- "@malloydata/db-trino": "^0.0.195-dev241003204905",
29
- "@malloydata/malloy": "^0.0.195-dev241003204905",
30
- "@malloydata/render": "^0.0.195-dev241003204905",
24
+ "@malloydata/db-bigquery": "^0.0.195",
25
+ "@malloydata/db-duckdb": "^0.0.195",
26
+ "@malloydata/db-postgres": "^0.0.195",
27
+ "@malloydata/db-snowflake": "^0.0.195",
28
+ "@malloydata/db-trino": "^0.0.195",
29
+ "@malloydata/malloy": "^0.0.195",
30
+ "@malloydata/render": "^0.0.195",
31
31
  "events": "^3.3.0",
32
32
  "jsdom": "^22.1.0",
33
33
  "luxon": "^2.4.0",
@@ -37,5 +37,5 @@
37
37
  "@types/jsdom": "^21.1.1",
38
38
  "@types/luxon": "^2.4.0"
39
39
  },
40
- "version": "0.0.195-dev241003204905"
40
+ "version": "0.0.195"
41
41
  }
@@ -81,12 +81,12 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
81
81
  });
82
82
  });
83
83
 
84
- it('bug with wrong join being used with annotation', async () => {
84
+ it('join dependencies tracked from annotated references', async () => {
85
85
  await expect(`
86
- run: aircraft -> {
87
- # foo
88
- group_by: aircraft_models.seats
89
- }
86
+ run: aircraft -> {
87
+ # ThisShouldNotAffectTheQuery
88
+ group_by: aircraft_models.seats
89
+ }
90
90
  `).malloyResultMatches(expressionModel, {
91
91
  seats: 0,
92
92
  });
@@ -23,17 +23,11 @@
23
23
 
24
24
  /* eslint-disable no-console */
25
25
 
26
- import {
27
- ModelDef,
28
- Query,
29
- StructDef,
30
- StructRelationship,
31
- } from '@malloydata/malloy';
26
+ import {ModelDef, Query, StructDef} from '@malloydata/malloy';
32
27
  import {describeIfDatabaseAvailable, fStringLike, fToQF} from '../../util';
33
28
 
34
29
  import * as malloy from '@malloydata/malloy';
35
30
  import {RuntimeList} from '../../runtimes';
36
-
37
31
  const [describe] = describeIfDatabaseAvailable(['bigquery']);
38
32
 
39
33
  describe('BigQuery hand-built expression test', () => {
@@ -43,18 +37,28 @@ describe('BigQuery hand-built expression test', () => {
43
37
  await runtimes.closeAll();
44
38
  });
45
39
 
46
- function withJoin(leftKey: string[], rightKey: string[]): StructRelationship {
47
- return {
48
- type: 'one',
49
- matrixOperation: 'left',
40
+ function withJoin(
41
+ sd: malloy.TableSourceDef,
42
+ join: 'one' | 'many',
43
+ as: string,
44
+ keyExpr: string
45
+ ): malloy.JoinFieldDef {
46
+ const [leftKey, rightKey] = keyExpr.split('=');
47
+ const ret: malloy.JoinFieldDef = {
48
+ ...sd,
49
+ join,
50
50
  onExpression: {
51
51
  node: '=',
52
52
  kids: {
53
- left: {node: 'field', path: leftKey},
54
- right: {node: 'field', path: rightKey},
53
+ left: {node: 'field', path: leftKey.split('.')},
54
+ right: {node: 'field', path: rightKey.split('.')},
55
55
  },
56
56
  },
57
57
  };
58
+ if (as !== ret.name) {
59
+ ret.as = as;
60
+ }
61
+ return ret;
58
62
  }
59
63
 
60
64
  async function validateCompilation(
@@ -83,16 +87,13 @@ describe('BigQuery hand-built expression test', () => {
83
87
  return model._loadQueryFromQueryDef(queryDef).getSQL();
84
88
  }
85
89
 
86
- const modelHandBase: StructDef = {
90
+ const modelHandBase: malloy.TableSourceDef = {
87
91
  name: 'malloydata-org.malloytest.aircraft_models',
88
92
  as: 'aircraft_models',
89
- type: 'struct',
93
+ type: 'table',
90
94
  dialect: 'standardsql',
91
- structSource: {
92
- type: 'table',
93
- tablePath: 'malloydata-org.malloytest.aircraft_models',
94
- },
95
- structRelationship: {type: 'basetable', connectionName: 'bigquery'},
95
+ tablePath: 'malloydata-org.malloytest.aircraft_models',
96
+ connection: 'bigquery',
96
97
  fields: [
97
98
  {type: 'string', name: 'aircraft_model_code'},
98
99
  {type: 'string', name: 'manufacturer'},
@@ -190,14 +191,11 @@ describe('BigQuery hand-built expression test', () => {
190
191
  };
191
192
 
192
193
  const aircraftHandBase: StructDef = {
193
- type: 'struct',
194
194
  name: 'malloydata-org.malloytest.aircraft',
195
195
  dialect: 'standardsql',
196
- structSource: {
197
- type: 'table',
198
- tablePath: 'malloydata-org.malloytest.aircraft',
199
- },
200
- structRelationship: {type: 'basetable', connectionName: 'bigquery'},
196
+ type: 'table',
197
+ tablePath: 'malloydata-org.malloytest.aircraft',
198
+ connection: 'bigquery',
201
199
  fields: [
202
200
  {type: 'string', name: 'tail_num'},
203
201
  {type: 'string', name: 'aircraft_serial'},
@@ -251,30 +249,22 @@ describe('BigQuery hand-built expression test', () => {
251
249
  {type: 'reduce', queryFields: fToQF(['aircraft_count'])},
252
250
  ],
253
251
  },
252
+ withJoin(
253
+ modelHandBase,
254
+ 'one',
255
+ 'aircraft_models',
256
+ 'aircraft_model_code=aircraft_models.aircraft_model_code'
257
+ ),
254
258
  ],
255
259
  primaryKey: 'tail_num',
256
260
  as: 'aircraft',
257
261
  };
258
262
 
259
- const aircraftHandStructDef: StructDef = {
260
- ...aircraftHandBase,
261
- fields: [
262
- ...aircraftHandBase.fields,
263
- {
264
- ...modelHandBase,
265
- structRelationship: withJoin(
266
- ['aircraft_model_code'],
267
- ['aircraft_models', 'aircraft_model_code']
268
- ),
269
- },
270
- ],
271
- };
272
-
273
263
  const handCodedModel: ModelDef = {
274
264
  name: 'Hand Coded Models',
275
265
  exports: ['aircraft'],
276
266
  contents: {
277
- aircraft: aircraftHandStructDef,
267
+ aircraft: aircraftHandBase,
278
268
  },
279
269
  };
280
270
 
@@ -712,18 +702,12 @@ describe('BigQuery hand-built expression test', () => {
712
702
  as: 'model_aircraft',
713
703
  fields: [
714
704
  ...modelHandBase.fields,
715
- {
716
- ...aircraftHandBase,
717
- structRelationship: {
718
- type: 'many',
719
- matrixOperation: 'left',
720
- onExpression: malloy.composeSQLExpr([
721
- {node: 'field', path: ['aircraft_model_code']},
722
- '=',
723
- {node: 'field', path: ['aircraft', 'aircraft_model_code']},
724
- ]),
725
- },
726
- },
705
+ withJoin(
706
+ aircraftHandBase,
707
+ 'many',
708
+ 'aircraft',
709
+ 'aircraft_model_code=aircraft.aircraft_model_code'
710
+ ),
727
711
  ],
728
712
  };
729
713
 
@@ -697,9 +697,7 @@ describe('airport_tests', () => {
697
697
  });
698
698
 
699
699
  it('nested_sums', async () => {
700
- const result = await runQuery(
701
- model,
702
- `
700
+ await expect(`
703
701
  run: airports->{
704
702
  aggregate: airport_count
705
703
  nest: by_state is {
@@ -716,34 +714,23 @@ describe('airport_tests', () => {
716
714
  sum_state is by_state.sum(by_state.airport_count),
717
715
  sum_fac is by_state.by_fac_type.sum(by_state.by_fac_type.airport_count)
718
716
  }
719
- `
720
- );
721
- // console.log(result.sql);
722
- expect(result.data.value[0]['sum_state']).toBe(19793);
723
- expect(result.data.value[0]['sum_fac']).toBe(19793);
717
+ `).malloyResultMatches(model, {sum_state: 19793, sum_fac: 19793});
724
718
  });
725
719
 
726
720
  it('pipeline_as_declared_turtle', async () => {
727
- const result = await runQuery(
728
- model,
729
- `
730
- source: my_airports is airports extend {
731
- view: pipe_turtle is {
732
- aggregate: a is airport_count
733
- } -> {
734
- select: a
735
- }
721
+ await expect(`
722
+ run: airports extend {
723
+ view: pipe_turtle is {
724
+ aggregate: a is airport_count
725
+ } -> {
726
+ select: a
736
727
  }
737
- run: my_airports->pipe_turtle
738
- `
739
- );
740
- expect(result.data.value[0]['a']).toBe(19793);
728
+ } -> pipe_turtle
729
+ `).malloyResultMatches(model, {a: 19793});
741
730
  });
742
731
 
743
732
  it('pipeline Turtle', async () => {
744
- const result = await runQuery(
745
- model,
746
- `
733
+ await expect(`
747
734
  run: bigquery.table('malloytest.airports')->{
748
735
  aggregate: airport_count is count()
749
736
  nest: pipe_turtle is {
@@ -760,13 +747,7 @@ describe('airport_tests', () => {
760
747
  aggregate: total_airports is a.sum()
761
748
  }
762
749
  }
763
- `
764
- );
765
-
766
- expect(
767
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
768
- (result.data.value[0] as any).pipe_turtle[0].total_airports
769
- ).toBe(1845);
750
+ `).malloyResultMatches(model, {'pipe_turtle.total_airports': 1845});
770
751
  });
771
752
 
772
753
  it.skip('crossjoined turtles', async () => {
@@ -25,8 +25,7 @@ import {
25
25
  DuckDBDialect,
26
26
  FetchSchemaOptions,
27
27
  MalloyError,
28
- SQLBlock,
29
- StructDef,
28
+ SQLSourceDef,
30
29
  registerDialect,
31
30
  } from '@malloydata/malloy';
32
31
  import {testRuntimeFor} from './runtimes';
@@ -57,19 +56,23 @@ async function getError<T>(promise: Promise<T>): Promise<Error | undefined> {
57
56
  describe('experimental dialects', () => {
58
57
  const duckdbX = 'duckdb_experimental';
59
58
  class DuckdbXConnection extends DuckDBConnection {
60
- public async fetchSchemaForSQLBlock(
61
- sqlRef: SQLBlock,
59
+ name = duckdbX;
60
+ public async festchSchemaFOrSQLSource(
61
+ sqlRef: SQLSourceDef,
62
62
  options: FetchSchemaOptions
63
63
  ): Promise<
64
- | {structDef: StructDef; error?: undefined}
64
+ | {structDef: SQLSourceDef; error?: undefined}
65
65
  | {error: string; structDef?: undefined}
66
66
  > {
67
- const result = await super.fetchSchemaForSQLBlock(sqlRef, options);
67
+ const result = await super.fetchSchemaForSQLStruct(sqlRef, options);
68
68
  if (result.error === undefined) {
69
69
  return {structDef: {...result.structDef, dialect: duckdbX}};
70
70
  }
71
71
  return result;
72
72
  }
73
+ get dialectName(): string {
74
+ return duckdbX;
75
+ }
73
76
  }
74
77
 
75
78
  const connection = new DuckdbXConnection(
@@ -80,6 +83,9 @@ describe('experimental dialects', () => {
80
83
  class DuckdbXDialect extends DuckDBDialect {
81
84
  experimental = true;
82
85
  name = duckdbX;
86
+ get dialectName(): string {
87
+ return duckdbX;
88
+ }
83
89
  }
84
90
 
85
91
  registerDialect(new DuckdbXDialect());
@@ -22,39 +22,219 @@
22
22
  */
23
23
 
24
24
  import {
25
- composeSQLExpr,
26
25
  ModelDef,
27
26
  StructDef,
28
- StructRelationship,
27
+ TableSourceDef,
28
+ JoinFieldDef,
29
29
  } from '@malloydata/malloy';
30
30
 
31
31
  import {fStringEq, fToIF, fToQF, fYearEq} from '../util';
32
32
 
33
33
  import {medicareModel, medicareStateFacts} from './medicare_model';
34
34
 
35
- function withJoin(leftKey: string, rightKey: string): StructRelationship {
36
- return {
37
- type: 'one',
38
- matrixOperation: 'left',
39
- onExpression: composeSQLExpr([
40
- {node: 'field', path: leftKey.split('.')},
41
- '=',
42
- {node: 'field', path: rightKey.split('.')},
43
- ]),
35
+ function withJoin(
36
+ sd: TableSourceDef,
37
+ join: 'one' | 'many',
38
+ as: string,
39
+ keyExpr: string
40
+ ): JoinFieldDef {
41
+ const [leftKey, rightKey] = keyExpr.split('=');
42
+ const ret: JoinFieldDef = {
43
+ ...sd,
44
+ join,
45
+ onExpression: {
46
+ node: '=',
47
+ kids: {
48
+ left: {node: 'field', path: leftKey.split('.')},
49
+ right: {node: 'field', path: rightKey.split('.')},
50
+ },
51
+ },
44
52
  };
53
+ if (as !== ret.name) {
54
+ ret.as = as;
55
+ }
56
+ return ret;
45
57
  }
46
58
 
59
+ const AIRCRAFT_MODELS: TableSourceDef = {
60
+ name: 'malloydata-org.malloytest.aircraft_models',
61
+ as: 'aircraft_models',
62
+ dialect: 'standardsql',
63
+ connection: 'bigquery',
64
+ primaryKey: 'aircraft_model_code',
65
+ type: 'table',
66
+ tablePath: 'malloydata-org.malloytest.aircraft_models',
67
+ fields: [
68
+ {type: 'string', name: 'aircraft_model_code'},
69
+ {type: 'string', name: 'manufacturer'},
70
+ {type: 'string', name: 'model'},
71
+ {
72
+ type: 'number',
73
+ name: 'aircraft_type_id',
74
+ numberType: 'integer',
75
+ },
76
+ {
77
+ type: 'number',
78
+ name: 'aircraft_engine_type_id',
79
+ numberType: 'integer',
80
+ },
81
+ {
82
+ type: 'number',
83
+ name: 'aircraft_category_id',
84
+ numberType: 'integer',
85
+ },
86
+ {type: 'number', name: 'amateur', numberType: 'integer'},
87
+ {type: 'number', name: 'engines', numberType: 'integer'},
88
+ {type: 'number', name: 'seats', numberType: 'integer'},
89
+ {type: 'number', name: 'weight', numberType: 'integer'},
90
+ {type: 'number', name: 'speed', numberType: 'integer'},
91
+ {
92
+ type: 'number',
93
+ expressionType: 'aggregate',
94
+ name: 'total_seats',
95
+ e: {
96
+ node: 'aggregate',
97
+ function: 'sum',
98
+ e: {node: 'field', path: ['seats']},
99
+ },
100
+ },
101
+ ],
102
+ };
103
+
104
+ const AIRPORTS: TableSourceDef = {
105
+ name: 'malloydata-org.malloytest.airports',
106
+ as: 'airports',
107
+ dialect: 'standardsql',
108
+ type: 'table',
109
+ tablePath: 'malloydata-org.malloytest.airports',
110
+ connection: 'bigquery',
111
+ primaryKey: 'code',
112
+ fields: [
113
+ {type: 'number', name: 'id', numberType: 'integer'},
114
+ {type: 'string', name: 'code'},
115
+ {type: 'string', name: 'site_number'},
116
+ {type: 'string', name: 'fac_type', as: 'facility_type'},
117
+ {type: 'string', name: 'fac_use', as: 'facility_use'},
118
+ {type: 'string', name: 'faa_region'},
119
+ {type: 'string', name: 'faa_dist'},
120
+ {type: 'string', name: 'city'},
121
+ {type: 'string', name: 'county'},
122
+ {type: 'string', name: 'state'},
123
+ {type: 'string', name: 'full_name'},
124
+ {type: 'string', name: 'own_type'},
125
+ {type: 'number', name: 'longitude', numberType: 'float'},
126
+ {type: 'number', name: 'latitude', numberType: 'float'},
127
+ {type: 'number', name: 'elevation', numberType: 'integer'},
128
+ {type: 'string', name: 'aero_cht'},
129
+ {type: 'number', name: 'cbd_dist', numberType: 'integer'},
130
+ {type: 'string', name: 'cbd_dir'},
131
+ {type: 'string', name: 'act_date'},
132
+ {type: 'string', name: 'cert'},
133
+ {type: 'string', name: 'fed_agree'},
134
+ {type: 'string', name: 'cust_intl'},
135
+ {type: 'string', name: 'c_ldg_rts'},
136
+ {type: 'string', name: 'joint_use'},
137
+ {type: 'string', name: 'mil_rts'},
138
+ {type: 'string', name: 'cntl_twr'},
139
+ {type: 'string', name: 'major'},
140
+ {
141
+ type: 'number',
142
+ name: 'count',
143
+ expressionType: 'aggregate',
144
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
145
+ },
146
+ ],
147
+ };
148
+
149
+ const CARRIERS: TableSourceDef = {
150
+ name: 'carriers',
151
+ dialect: 'standardsql',
152
+ type: 'table',
153
+ tablePath: 'malloydata-org.malloytest.carriers',
154
+ connection: 'bigquery',
155
+ primaryKey: 'code',
156
+ fields: [
157
+ {type: 'string', name: 'code'},
158
+ {type: 'string', name: 'name'},
159
+ {type: 'string', name: 'nickname'},
160
+ ],
161
+ };
162
+ const AIRCRAFT: TableSourceDef = {
163
+ name: 'aircraft',
164
+ dialect: 'standardsql',
165
+ type: 'table',
166
+ tablePath: 'malloydata-org.malloytest.aircraft',
167
+ primaryKey: 'tail_num',
168
+ connection: 'bigquery',
169
+ fields: [
170
+ {type: 'string', name: 'tail_num'},
171
+ {type: 'string', name: 'aircraft_serial'},
172
+ {type: 'string', name: 'aircraft_model_code'},
173
+ {type: 'string', name: 'aircraft_engine_code'},
174
+ {type: 'number', name: 'year_built', numberType: 'integer'},
175
+ {
176
+ type: 'number',
177
+ name: 'aircraft_type_id',
178
+ numberType: 'integer',
179
+ },
180
+ {
181
+ type: 'number',
182
+ name: 'aircraft_engine_type_id',
183
+ numberType: 'integer',
184
+ },
185
+ {
186
+ type: 'number',
187
+ name: 'registrant_type_id',
188
+ numberType: 'integer',
189
+ },
190
+ {type: 'string', name: 'name'},
191
+ {type: 'string', name: 'address1'},
192
+ {type: 'string', name: 'address2'},
193
+ {type: 'string', name: 'city'},
194
+ {type: 'string', name: 'state'},
195
+ {type: 'string', name: 'zip'},
196
+ {type: 'string', name: 'region'},
197
+ {type: 'string', name: 'county'},
198
+ {type: 'string', name: 'country'},
199
+ {type: 'string', name: 'certification'},
200
+ {type: 'string', name: 'status_code'},
201
+ {type: 'string', name: 'mode_s_code'},
202
+ {type: 'string', name: 'fract_owner'},
203
+ {
204
+ type: 'number',
205
+ name: 'aircraft_count',
206
+ expressionType: 'aggregate',
207
+ e: {node: 'aggregate', function: 'count', e: {node: ''}},
208
+ },
209
+ {
210
+ type: 'number',
211
+ name: 'total_engines',
212
+ expressionType: 'aggregate',
213
+ e: {
214
+ node: 'aggregate',
215
+ function: 'sum',
216
+ e: {node: 'field', path: ['aircraft_models', 'engines']},
217
+ },
218
+ },
219
+
220
+ // subjoin aircraft models
221
+ withJoin(
222
+ AIRCRAFT_MODELS,
223
+ 'one',
224
+ 'aircraft_models',
225
+ 'aircraft_model_code=aircraft_models.aircraft_model_code'
226
+ ),
227
+ ],
228
+ };
229
+
47
230
  /** Flight Model */
48
231
  export const FLIGHTS_EXPLORE: StructDef = {
49
- type: 'struct',
50
232
  name: 'malloydata-org.malloytest.flights',
51
233
  as: 'flights',
52
234
  dialect: 'standardsql',
53
- structSource: {
54
- type: 'table',
55
- tablePath: 'malloydata-org.malloytest.flights',
56
- },
57
- structRelationship: {type: 'basetable', connectionName: 'bigquery'},
235
+ type: 'table',
236
+ tablePath: 'malloydata-org.malloytest.flights',
237
+ connection: 'bigquery',
58
238
  primaryKey: 'id2',
59
239
  fields: [
60
240
  // Fields in the flights table.
@@ -90,280 +270,59 @@ export const FLIGHTS_EXPLORE: StructDef = {
90
270
  },
91
271
  },
92
272
 
93
- // carriers
94
- {
95
- type: 'struct',
96
- name: 'malloydata-org.malloytest.carriers',
97
- as: 'carriers',
98
- dialect: 'standardsql',
99
- structSource: {
100
- type: 'table',
101
- tablePath: 'malloydata-org.malloytest.carriers',
102
- },
103
- structRelationship: {
104
- type: 'one',
105
- matrixOperation: 'left',
106
- onExpression: composeSQLExpr([
107
- {node: 'field', path: ['carrier']},
108
- '=',
109
- {node: 'field', path: ['carriers', 'code']},
110
- ]),
111
- },
112
- primaryKey: 'code',
113
- fields: [
114
- {type: 'string', name: 'code'},
115
- {type: 'string', name: 'name'},
116
- {type: 'string', name: 'nickname'},
117
- ],
118
- },
273
+ withJoin(CARRIERS, 'one', 'carriers', 'carrier=carriers.code'),
119
274
 
120
275
  // aircraft
121
- {
122
- type: 'struct',
123
- name: 'malloydata-org.malloytest.aircraft',
124
- as: 'aircraft',
125
- dialect: 'standardsql',
126
- structSource: {
127
- type: 'table',
128
- tablePath: 'malloydata-org.malloytest.aircraft',
129
- },
130
- structRelationship: withJoin('tail_num', 'aircraft.tail_num'),
131
- primaryKey: 'tail_num',
132
- fields: [
133
- {type: 'string', name: 'tail_num'},
134
- {type: 'string', name: 'aircraft_serial'},
135
- {type: 'string', name: 'aircraft_model_code'},
136
- {type: 'string', name: 'aircraft_engine_code'},
137
- {type: 'number', name: 'year_built', numberType: 'integer'},
138
- {
139
- type: 'number',
140
- name: 'aircraft_type_id',
141
- numberType: 'integer',
142
- },
143
- {
144
- type: 'number',
145
- name: 'aircraft_engine_type_id',
146
- numberType: 'integer',
147
- },
148
- {
149
- type: 'number',
150
- name: 'registrant_type_id',
151
- numberType: 'integer',
152
- },
153
- {type: 'string', name: 'name'},
154
- {type: 'string', name: 'address1'},
155
- {type: 'string', name: 'address2'},
156
- {type: 'string', name: 'city'},
157
- {type: 'string', name: 'state'},
158
- {type: 'string', name: 'zip'},
159
- {type: 'string', name: 'region'},
160
- {type: 'string', name: 'county'},
161
- {type: 'string', name: 'country'},
162
- {type: 'string', name: 'certification'},
163
- {type: 'string', name: 'status_code'},
164
- {type: 'string', name: 'mode_s_code'},
165
- {type: 'string', name: 'fract_owner'},
166
- {
167
- type: 'number',
168
- name: 'aircraft_count',
169
- expressionType: 'aggregate',
170
- e: {node: 'aggregate', function: 'count', e: {node: ''}},
171
- },
172
- {
173
- type: 'number',
174
- name: 'total_engines',
175
- expressionType: 'aggregate',
176
- e: {
177
- node: 'aggregate',
178
- function: 'sum',
179
- e: {node: 'field', path: ['aircraft_models', 'engines']},
180
- },
181
- },
182
-
183
- // subjoin aircraft models
184
- {
185
- type: 'struct',
186
- name: 'malloydata-org.malloytest.aircraft_models',
187
- as: 'aircraft_models',
188
- dialect: 'standardsql',
189
- primaryKey: 'aircraft_model_code',
190
- structSource: {
191
- type: 'table',
192
- tablePath: 'malloydata-org.malloytest.aircraft_models',
193
- },
194
- structRelationship: withJoin(
195
- 'aircraft_model_code',
196
- 'aircraft_models.aircraft_model_code'
197
- ),
198
- fields: [
199
- {type: 'string', name: 'aircraft_model_code'},
200
- {type: 'string', name: 'manufacturer'},
201
- {type: 'string', name: 'model'},
202
- {
203
- type: 'number',
204
- name: 'aircraft_type_id',
205
- numberType: 'integer',
206
- },
207
- {
208
- type: 'number',
209
- name: 'aircraft_engine_type_id',
210
- numberType: 'integer',
211
- },
212
- {
213
- type: 'number',
214
- name: 'aircraft_category_id',
215
- numberType: 'integer',
216
- },
217
- {type: 'number', name: 'amateur', numberType: 'integer'},
218
- {type: 'number', name: 'engines', numberType: 'integer'},
219
- {type: 'number', name: 'seats', numberType: 'integer'},
220
- {type: 'number', name: 'weight', numberType: 'integer'},
221
- {type: 'number', name: 'speed', numberType: 'integer'},
222
- {
223
- type: 'number',
224
- expressionType: 'aggregate',
225
- name: 'total_seats',
226
- e: {
227
- node: 'aggregate',
228
- function: 'sum',
229
- e: {node: 'field', path: ['seats']},
230
- },
231
- },
232
- ],
233
- },
234
- ],
235
- },
276
+ withJoin(AIRCRAFT, 'one', 'aircraft', 'tail_num=aircraft.tail_num'),
236
277
 
237
278
  // origin
238
- {
239
- type: 'struct',
240
- name: 'malloydata-org.malloytest.airports',
241
- as: 'origin',
242
- dialect: 'standardsql',
243
- structSource: {
244
- type: 'table',
245
- tablePath: 'malloydata-org.malloytest.airports',
246
- },
247
- structRelationship: withJoin('origin_code', 'origin.code'),
248
- primaryKey: 'code',
249
- fields: [
250
- {type: 'number', name: 'id', numberType: 'integer'},
251
- {type: 'string', name: 'code'},
252
- {type: 'string', name: 'site_number'},
253
- {type: 'string', name: 'fac_type', as: 'facility_type'},
254
- {type: 'string', name: 'fac_use', as: 'facility_use'},
255
- {type: 'string', name: 'faa_region'},
256
- {type: 'string', name: 'faa_dist'},
257
- {type: 'string', name: 'city'},
258
- {type: 'string', name: 'county'},
259
- {type: 'string', name: 'state'},
260
- {type: 'string', name: 'full_name'},
261
- {type: 'string', name: 'own_type'},
262
- {type: 'number', name: 'longitude', numberType: 'float'},
263
- {type: 'number', name: 'latitude', numberType: 'float'},
264
- {type: 'number', name: 'elevation', numberType: 'integer'},
265
- {type: 'string', name: 'aero_cht'},
266
- {type: 'number', name: 'cbd_dist', numberType: 'integer'},
267
- {type: 'string', name: 'cbd_dir'},
268
- {type: 'string', name: 'act_date'},
269
- {type: 'string', name: 'cert'},
270
- {type: 'string', name: 'fed_agree'},
271
- {type: 'string', name: 'cust_intl'},
272
- {type: 'string', name: 'c_ldg_rts'},
273
- {type: 'string', name: 'joint_use'},
274
- {type: 'string', name: 'mil_rts'},
275
- {type: 'string', name: 'cntl_twr'},
276
- {type: 'string', name: 'major'},
277
- {
278
- type: 'number',
279
- name: 'count',
280
- expressionType: 'aggregate',
281
- e: {node: 'aggregate', function: 'count', e: {node: ''}},
282
- },
283
- ],
284
- },
279
+ withJoin(AIRPORTS, 'one', 'origin', 'origin_code=origin.code'),
285
280
 
286
281
  // destination
287
- {
288
- type: 'struct',
289
- name: 'malloydata-org.malloytest.airports',
290
- as: 'destination',
291
- dialect: 'standardsql',
292
- structSource: {
293
- type: 'table',
294
- tablePath: 'malloydata-org.malloytest.airports',
295
- },
296
- structRelationship: withJoin('destination_code', 'destination.code'),
297
- primaryKey: 'code',
298
- fields: [
299
- {type: 'number', name: 'id', numberType: 'integer'},
300
- {type: 'string', name: 'code'},
301
- {type: 'string', name: 'site_number'},
302
- {type: 'string', name: 'fac_type', as: 'facility_type'},
303
- {type: 'string', name: 'fac_use', as: 'facility_use'},
304
- {type: 'string', name: 'faa_region'},
305
- {type: 'string', name: 'faa_dist'},
306
- {type: 'string', name: 'city'},
307
- {type: 'string', name: 'county'},
308
- {type: 'string', name: 'state'},
309
- {type: 'string', name: 'full_name'},
310
- {type: 'string', name: 'own_type'},
311
- {type: 'number', name: 'longitude', numberType: 'float'},
312
- {type: 'number', name: 'latitude', numberType: 'float'},
313
- {type: 'number', name: 'elevation', numberType: 'integer'},
314
- {type: 'string', name: 'aero_cht'},
315
- {type: 'number', name: 'cbd_dist', numberType: 'integer'},
316
- {type: 'string', name: 'cbd_dir'},
317
- {type: 'string', name: 'act_date'},
318
- {type: 'string', name: 'cert'},
319
- {type: 'string', name: 'fed_agree'},
320
- {type: 'string', name: 'cust_intl'},
321
- {type: 'string', name: 'c_ldg_rts'},
322
- {type: 'string', name: 'joint_use'},
323
- {type: 'string', name: 'mil_rts'},
324
- {type: 'string', name: 'cntl_twr'},
325
- {type: 'string', name: 'major'},
326
- {
327
- type: 'number',
328
- name: 'count',
329
- expressionType: 'aggregate',
330
- e: {node: 'aggregate', function: 'count', e: {node: ''}},
331
- },
332
- ],
333
- },
282
+ withJoin(
283
+ AIRPORTS,
284
+ 'one',
285
+ 'destination',
286
+ 'destination_code=destination.code'
287
+ ),
334
288
 
335
289
  // derived table from a named query.
336
290
  {
337
- type: 'struct',
291
+ type: 'query_source',
338
292
  name: 'aircraft_facts',
339
293
  dialect: 'standardsql',
340
- structSource: {
294
+ connection: 'bigquery',
295
+ query: {
341
296
  type: 'query',
342
- query: {
343
- type: 'query',
344
- structRef: 'flights',
345
- name: 'aircraft_facts_query',
346
- pipeline: [
347
- {
348
- type: 'reduce',
349
- queryFields: fToQF([
350
- 'tail_num',
351
- {
352
- type: 'number',
353
- name: 'lifetime_distance',
354
- expressionType: 'aggregate',
355
- e: {
356
- node: 'aggregate',
357
- function: 'sum',
358
- e: {node: 'field', path: ['distance']},
359
- },
297
+ structRef: 'flights',
298
+ name: 'aircraft_facts_query',
299
+ pipeline: [
300
+ {
301
+ type: 'reduce',
302
+ queryFields: fToQF([
303
+ 'tail_num',
304
+ {
305
+ type: 'number',
306
+ name: 'lifetime_distance',
307
+ expressionType: 'aggregate',
308
+ e: {
309
+ node: 'aggregate',
310
+ function: 'sum',
311
+ e: {node: 'field', path: ['distance']},
360
312
  },
361
- ]),
362
- },
363
- ],
313
+ },
314
+ ]),
315
+ },
316
+ ],
317
+ },
318
+ join: 'one',
319
+ onExpression: {
320
+ node: '=',
321
+ kids: {
322
+ left: {node: 'field', path: ['tail_num']},
323
+ right: {node: 'field', path: ['aircraft_facts', 'tail_num']},
364
324
  },
365
325
  },
366
- structRelationship: withJoin('tail_num', 'aircraft_facts.tail_num'),
367
326
  primaryKey: 'tail_num',
368
327
  fields: [
369
328
  {type: 'string', name: 'tail_num'},
@@ -922,53 +881,7 @@ export const FLIGHTS_EXPLORE: StructDef = {
922
881
  ],
923
882
  };
924
883
 
925
- const tableAirports: StructDef = {
926
- type: 'struct',
927
- name: 'malloydata-org.malloytest.airports',
928
- as: 'table_airports',
929
- dialect: 'standardsql',
930
- structSource: {
931
- type: 'table',
932
- tablePath: 'malloydata-org.malloytest.airports',
933
- },
934
- structRelationship: {type: 'basetable', connectionName: 'bigquery'},
935
- primaryKey: 'code',
936
- fields: [
937
- {type: 'number', name: 'id', numberType: 'integer'},
938
- {type: 'string', name: 'code'},
939
- {type: 'string', name: 'site_number'},
940
- {type: 'string', name: 'fac_type', as: 'facility_type'},
941
- {type: 'string', name: 'fac_use', as: 'facility_use'},
942
- {type: 'string', name: 'faa_region'},
943
- {type: 'string', name: 'faa_dist'},
944
- {type: 'string', name: 'city'},
945
- {type: 'string', name: 'county'},
946
- {type: 'string', name: 'state'},
947
- {type: 'string', name: 'full_name'},
948
- {type: 'string', name: 'own_type'},
949
- {type: 'number', name: 'longitude', numberType: 'float'},
950
- {type: 'number', name: 'latitude', numberType: 'float'},
951
- {type: 'number', name: 'elevation', numberType: 'integer'},
952
- {type: 'string', name: 'aero_cht'},
953
- {type: 'number', name: 'cbd_dist', numberType: 'integer'},
954
- {type: 'string', name: 'cbd_dir'},
955
- {type: 'string', name: 'act_date'},
956
- {type: 'string', name: 'cert'},
957
- {type: 'string', name: 'fed_agree'},
958
- {type: 'string', name: 'cust_intl'},
959
- {type: 'string', name: 'c_ldg_rts'},
960
- {type: 'string', name: 'joint_use'},
961
- {type: 'string', name: 'mil_rts'},
962
- {type: 'string', name: 'cntl_twr'},
963
- {type: 'string', name: 'major'},
964
- {
965
- type: 'number',
966
- name: 'count',
967
- expressionType: 'aggregate',
968
- e: {node: 'aggregate', function: 'count', e: {node: ''}},
969
- },
970
- ],
971
- };
884
+ const tableAirports = {...AIRPORTS, as: 'table_airports'};
972
885
 
973
886
  /** Test model */
974
887
  export const testModel: ModelDef = {
@@ -213,44 +213,38 @@ export const medicareModel: StructDef = {
213
213
  ],
214
214
  name: 'malloydata-org.malloytest.bq_medicare_test',
215
215
  primaryKey: 'id',
216
- structRelationship: {type: 'basetable', connectionName: 'bigquery'},
217
- structSource: {
218
- type: 'table',
219
- tablePath: 'malloydata-org.malloytest.bq_medicare_test',
220
- },
221
- type: 'struct',
216
+ connection: 'bigquery',
217
+ type: 'table',
218
+ tablePath: 'malloydata-org.malloytest.bq_medicare_test',
222
219
  };
223
220
 
224
221
  export const medicareStateFacts: StructDef = {
225
222
  fields: [],
226
223
  name: 'medicare_state_facts',
227
224
  dialect: 'standardsql',
228
- structRelationship: {type: 'basetable', connectionName: 'bigquery'},
229
- structSource: {
230
- query: {
231
- structRef: 'medicare_test',
232
- pipeline: [
233
- {
234
- queryFields: fToQF([
235
- 'provider_state',
236
- {
237
- type: 'number',
238
- name: 'num_providers',
239
- expressionType: 'aggregate',
240
- e: composeSQLExpr([
241
- 'COUNT(DISTINCT ',
242
- {node: 'field', path: ['provider_id']},
243
- ')',
244
- ]),
245
- },
246
- ]),
247
- type: 'reduce',
248
- },
249
- ],
250
- },
251
- type: 'query',
225
+ connection: 'bigquery',
226
+ type: 'query_source',
227
+ query: {
228
+ structRef: 'medicare_test',
229
+ pipeline: [
230
+ {
231
+ queryFields: fToQF([
232
+ 'provider_state',
233
+ {
234
+ type: 'number',
235
+ name: 'num_providers',
236
+ expressionType: 'aggregate',
237
+ e: composeSQLExpr([
238
+ 'COUNT(DISTINCT ',
239
+ {node: 'field', path: ['provider_id']},
240
+ ')',
241
+ ]),
242
+ },
243
+ ]),
244
+ type: 'reduce',
245
+ },
246
+ ],
252
247
  },
253
- type: 'struct',
254
248
  };
255
249
 
256
250
  // export const medicareStateFacts: StructDef = {
@@ -30,6 +30,7 @@ import {
30
30
  MalloyError,
31
31
  LogMessage,
32
32
  SingleConnectionRuntime,
33
+ Tag,
33
34
  } from '@malloydata/malloy';
34
35
  import EventEmitter from 'events';
35
36
  import {inspect} from 'util';
@@ -60,8 +61,6 @@ declare global {
60
61
  *
61
62
  * * If you use an array, the number of rows in the result must match the rows in the match
62
63
  * * The empty match {} accepts ANY data, but will errror if there is not a row
63
- * * If the query is tagged with # test.debug then the test will fail and the result will be printed
64
- * * If the query is tagged with # test.verbose then the result will be printed only if the test fails
65
64
  * * A match key of nestName.colName expects nestName to be a query which returns multiple rows, it will match
66
65
  * fields from the first row of the rows of nestName
67
66
  * * A match key of nestName/colName expects nestName to be a record/struct type
@@ -134,18 +133,18 @@ expect.extend({
134
133
  }
135
134
 
136
135
  let query: QueryMaterializer;
136
+ let queryTestTag: Tag | undefined = undefined;
137
137
  try {
138
138
  query = runtime.loadQuery(querySrc);
139
+ const queryTags = (await query.getPreparedQuery()).tagParse().tag;
140
+ queryTestTag = queryTags.tag('test');
139
141
  } catch (e) {
140
142
  return {
141
143
  pass: false,
142
- message: () => `loadQuery failed: ${e.message}`,
144
+ message: () => `Could not prepare query to run: ${e.message}`,
143
145
  };
144
146
  }
145
147
 
146
- const queryTags = (await query.getPreparedQuery()).tagParse().tag;
147
- const queryTestTag = queryTags.tag('test');
148
-
149
148
  let result: Result;
150
149
  try {
151
150
  result = await query.run();
@@ -2,6 +2,11 @@
2
2
  rm -rf .tmp
3
3
  mkdir .tmp
4
4
 
5
+
6
+ if [ "x${BQ_CREDENTIALS_KEY}" = x ]; then
7
+ echo "######### BQ_CREDENTIALS_KEY is not set. Cannot start Trino"
8
+ exit 1
9
+ fi
5
10
  # generate config file
6
11
  > ./.tmp/bigquery.properties
7
12
  cat << EOF > ./.tmp/bigquery.properties
@@ -31,4 +36,4 @@ do
31
36
  fi
32
37
  done
33
38
 
34
- echo "Trino running on port localhost:8080"
39
+ echo "Trino running on port localhost:8080"