@malloydata/malloy-tests 0.0.66-dev230807232724

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +29 -0
  2. package/bin/dump_malloytest.sh +1 -0
  3. package/bin/postgres_init.sh +9 -0
  4. package/bin/postgres_start.sh +2 -0
  5. package/bin/postgres_stop.sh +2 -0
  6. package/data/duckdb/README.md +4 -0
  7. package/data/duckdb/aircraft.parquet +0 -0
  8. package/data/duckdb/aircraft_models.parquet +0 -0
  9. package/data/duckdb/airports.parquet +0 -0
  10. package/data/duckdb/alltypes.parquet +0 -0
  11. package/data/duckdb/alltypes2.parquet +0 -0
  12. package/data/duckdb/bq_medicare_test.parquet +0 -0
  13. package/data/duckdb/carriers.parquet +0 -0
  14. package/data/duckdb/flights/part.0.parquet +0 -0
  15. package/data/duckdb/flights/part.1.parquet +0 -0
  16. package/data/duckdb/flights/part.2.parquet +0 -0
  17. package/data/duckdb/flights.parquet +0 -0
  18. package/data/duckdb/flights_partitioned.parquet +0 -0
  19. package/data/duckdb/ga_sample.parquet +0 -0
  20. package/data/duckdb/numbers.parquet +0 -0
  21. package/data/duckdb/state_facts.parquet +0 -0
  22. package/data/duckdb/test.json +3 -0
  23. package/data/duckdb/words.parquet +0 -0
  24. package/data/duckdb/words_bigger.parquet +0 -0
  25. package/data/postgres/malloytest-postgres.sql.gz +0 -0
  26. package/data/postgres/state_facts.sql +366 -0
  27. package/dist/api.spec.d.ts +1 -0
  28. package/dist/api.spec.js +77 -0
  29. package/dist/api.spec.js.map +1 -0
  30. package/dist/databases/all/expr.spec.d.ts +3 -0
  31. package/dist/databases/all/expr.spec.js +581 -0
  32. package/dist/databases/all/expr.spec.js.map +1 -0
  33. package/dist/databases/all/functions.spec.d.ts +2 -0
  34. package/dist/databases/all/functions.spec.js +784 -0
  35. package/dist/databases/all/functions.spec.js.map +1 -0
  36. package/dist/databases/all/index.spec.d.ts +2 -0
  37. package/dist/databases/all/index.spec.js +154 -0
  38. package/dist/databases/all/index.spec.js.map +1 -0
  39. package/dist/databases/all/join.spec.d.ts +2 -0
  40. package/dist/databases/all/join.spec.js +309 -0
  41. package/dist/databases/all/join.spec.js.map +1 -0
  42. package/dist/databases/all/nomodel.spec.d.ts +2 -0
  43. package/dist/databases/all/nomodel.spec.js +957 -0
  44. package/dist/databases/all/nomodel.spec.js.map +1 -0
  45. package/dist/databases/all/orderby.spec.d.ts +2 -0
  46. package/dist/databases/all/orderby.spec.js +224 -0
  47. package/dist/databases/all/orderby.spec.js.map +1 -0
  48. package/dist/databases/all/problems.spec.d.ts +2 -0
  49. package/dist/databases/all/problems.spec.js +113 -0
  50. package/dist/databases/all/problems.spec.js.map +1 -0
  51. package/dist/databases/all/sql_expressions.spec.d.ts +2 -0
  52. package/dist/databases/all/sql_expressions.spec.js +96 -0
  53. package/dist/databases/all/sql_expressions.spec.js.map +1 -0
  54. package/dist/databases/all/time.spec.d.ts +3 -0
  55. package/dist/databases/all/time.spec.js +647 -0
  56. package/dist/databases/all/time.spec.js.map +1 -0
  57. package/dist/databases/bigquery/double_truncation.spec.d.ts +1 -0
  58. package/dist/databases/bigquery/double_truncation.spec.js +50 -0
  59. package/dist/databases/bigquery/double_truncation.spec.js.map +1 -0
  60. package/dist/databases/bigquery/handexpr.spec.d.ts +1 -0
  61. package/dist/databases/bigquery/handexpr.spec.js +713 -0
  62. package/dist/databases/bigquery/handexpr.spec.js.map +1 -0
  63. package/dist/databases/bigquery/injestion_time_partitioning.spec.d.ts +1 -0
  64. package/dist/databases/bigquery/injestion_time_partitioning.spec.js +235 -0
  65. package/dist/databases/bigquery/injestion_time_partitioning.spec.js.map +1 -0
  66. package/dist/databases/bigquery/joined_filters.spec.d.ts +1 -0
  67. package/dist/databases/bigquery/joined_filters.spec.js +72 -0
  68. package/dist/databases/bigquery/joined_filters.spec.js.map +1 -0
  69. package/dist/databases/bigquery/json.spec.d.ts +1 -0
  70. package/dist/databases/bigquery/json.spec.js +86 -0
  71. package/dist/databases/bigquery/json.spec.js.map +1 -0
  72. package/dist/databases/bigquery/malloy_query.spec.d.ts +1 -0
  73. package/dist/databases/bigquery/malloy_query.spec.js +906 -0
  74. package/dist/databases/bigquery/malloy_query.spec.js.map +1 -0
  75. package/dist/databases/bigquery/performance.skipped.spec.d.ts +1 -0
  76. package/dist/databases/bigquery/performance.skipped.spec.js +70 -0
  77. package/dist/databases/bigquery/performance.skipped.spec.js.map +1 -0
  78. package/dist/databases/bigquery/time.spec.d.ts +1 -0
  79. package/dist/databases/bigquery/time.spec.js +55 -0
  80. package/dist/databases/bigquery/time.spec.js.map +1 -0
  81. package/dist/databases/bigquery/wildcard_table_names.spec.d.ts +1 -0
  82. package/dist/databases/bigquery/wildcard_table_names.spec.js +212 -0
  83. package/dist/databases/bigquery/wildcard_table_names.spec.js.map +1 -0
  84. package/dist/databases/bigquery-duckdb/nested_source_table.spec.d.ts +1 -0
  85. package/dist/databases/bigquery-duckdb/nested_source_table.spec.js +247 -0
  86. package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -0
  87. package/dist/databases/bigquery-postgres/multi_connection.spec.d.ts +1 -0
  88. package/dist/databases/bigquery-postgres/multi_connection.spec.js +138 -0
  89. package/dist/databases/bigquery-postgres/multi_connection.spec.js.map +1 -0
  90. package/dist/databases/bigquery-postgres/streaming.spec.d.ts +1 -0
  91. package/dist/databases/bigquery-postgres/streaming.spec.js +88 -0
  92. package/dist/databases/bigquery-postgres/streaming.spec.js.map +1 -0
  93. package/dist/databases/duckdb/duckdb.spec.d.ts +1 -0
  94. package/dist/databases/duckdb/duckdb.spec.js +116 -0
  95. package/dist/databases/duckdb/duckdb.spec.js.map +1 -0
  96. package/dist/databases/postgres/postgres.spec.d.ts +1 -0
  97. package/dist/databases/postgres/postgres.spec.js +137 -0
  98. package/dist/databases/postgres/postgres.spec.js.map +1 -0
  99. package/dist/databases/shared/test_list.d.ts +3 -0
  100. package/dist/databases/shared/test_list.js +24 -0
  101. package/dist/databases/shared/test_list.js.map +1 -0
  102. package/dist/dependencies.spec.d.ts +1 -0
  103. package/dist/dependencies.spec.js +63 -0
  104. package/dist/dependencies.spec.js.map +1 -0
  105. package/dist/index.d.ts +11 -0
  106. package/dist/index.js +49 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/model/utils.spec.d.ts +1 -0
  109. package/dist/model/utils.spec.js +38 -0
  110. package/dist/model/utils.spec.js.map +1 -0
  111. package/dist/models/faa_model.d.ts +5 -0
  112. package/dist/models/faa_model.js +977 -0
  113. package/dist/models/faa_model.js.map +1 -0
  114. package/dist/models/medicare_model.d.ts +4 -0
  115. package/dist/models/medicare_model.js +243 -0
  116. package/dist/models/medicare_model.js.map +1 -0
  117. package/dist/render/render.spec.d.ts +1 -0
  118. package/dist/render/render.spec.js +551 -0
  119. package/dist/render/render.spec.js.map +1 -0
  120. package/dist/runtimes.d.ts +33 -0
  121. package/dist/runtimes.js +147 -0
  122. package/dist/runtimes.js.map +1 -0
  123. package/dist/tags.spec.d.ts +1 -0
  124. package/dist/tags.spec.js +259 -0
  125. package/dist/tags.spec.js.map +1 -0
  126. package/dist/util/db-jest-matchers.d.ts +19 -0
  127. package/dist/util/db-jest-matchers.js +90 -0
  128. package/dist/util/db-jest-matchers.js.map +1 -0
  129. package/dist/util/index.d.ts +16 -0
  130. package/dist/util/index.js +171 -0
  131. package/dist/util/index.js.map +1 -0
  132. package/package.json +35 -0
  133. package/src/api.spec.ts +84 -0
  134. package/src/databases/all/expr.spec.ts +704 -0
  135. package/src/databases/all/functions.spec.ts +1135 -0
  136. package/src/databases/all/index.spec.ts +178 -0
  137. package/src/databases/all/join.spec.ts +350 -0
  138. package/src/databases/all/nomodel.spec.ts +1159 -0
  139. package/src/databases/all/orderby.spec.ts +268 -0
  140. package/src/databases/all/problems.spec.ts +121 -0
  141. package/src/databases/all/sql_expressions.spec.ts +107 -0
  142. package/src/databases/all/time.spec.ts +793 -0
  143. package/src/databases/bigquery/double_truncation.spec.ts +51 -0
  144. package/src/databases/bigquery/handexpr.spec.ts +782 -0
  145. package/src/databases/bigquery/injestion_time_partitioning.spec.ts +268 -0
  146. package/src/databases/bigquery/joined_filters.spec.ts +75 -0
  147. package/src/databases/bigquery/json.spec.ts +95 -0
  148. package/src/databases/bigquery/malloy_query.spec.ts +1036 -0
  149. package/src/databases/bigquery/performance.skipped.spec.ts +73 -0
  150. package/src/databases/bigquery/time.spec.ts +59 -0
  151. package/src/databases/bigquery/wildcard_table_names.spec.ts +233 -0
  152. package/src/databases/bigquery-duckdb/nested_source_table.spec.ts +268 -0
  153. package/src/databases/bigquery-postgres/multi_connection.spec.ts +143 -0
  154. package/src/databases/bigquery-postgres/streaming.spec.ts +100 -0
  155. package/src/databases/duckdb/duckdb.spec.ts +131 -0
  156. package/src/databases/postgres/postgres.spec.ts +167 -0
  157. package/src/databases/shared/test_list.ts +24 -0
  158. package/src/dependencies.spec.ts +62 -0
  159. package/src/index.ts +36 -0
  160. package/src/model/utils.spec.ts +37 -0
  161. package/src/models/faa_model.ts +995 -0
  162. package/src/models/medicare_model.ts +246 -0
  163. package/src/render/__snapshots__/render.spec.ts.snap +12574 -0
  164. package/src/render/render.spec.ts +670 -0
  165. package/src/runtimes.ts +182 -0
  166. package/src/tags.spec.ts +277 -0
  167. package/src/util/db-jest-matchers.ts +128 -0
  168. package/src/util/index.ts +191 -0
  169. package/tsconfig.json +25 -0
@@ -0,0 +1,178 @@
1
+ /* eslint-disable no-console */
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+
27
+ import {RuntimeList, allDatabases} from '../../runtimes';
28
+ import {databasesFromEnvironmentOr} from '../../util';
29
+
30
+ export const indexSharedTests = (
31
+ runtimes: RuntimeList,
32
+ _splitFunction?: (column: string, splitChar: string) => string
33
+ ) => {
34
+ // No prebuilt shared model, each test is complete. Makes debugging easier.
35
+ afterAll(async () => {
36
+ await runtimes.closeAll();
37
+ });
38
+
39
+ runtimes.runtimeMap.forEach((runtime, databaseName) => {
40
+ it(`basic index - ${databaseName}`, async () => {
41
+ const model = await runtime.loadModel(
42
+ `
43
+ source: airports is table('malloytest.airports') {
44
+ }
45
+ `
46
+ );
47
+ let result = await model.search('airports', 'SANTA', 10);
48
+
49
+ // if (result !== undefined) {
50
+ // console.log(result);
51
+ // } else {
52
+ // console.log("no result");
53
+ // }
54
+ expect(result).toBeDefined();
55
+ if (result !== undefined) {
56
+ expect(result[0].fieldName).toBe('county');
57
+ expect(result[0].fieldValue).toBe('SANTA ROSA');
58
+ expect(result[0].weight).toBe(26);
59
+ expect(result.length).toBe(10);
60
+ }
61
+
62
+ result = await model.search('airports', 'SANTA A', 100, 'city');
63
+ if (result !== undefined) {
64
+ // console.log(result);
65
+ expect(result[0].fieldName).toBe('city');
66
+ expect(result[0].fieldValue).toBe('SANTA ANA');
67
+ }
68
+ });
69
+
70
+ it(`index value map - ${databaseName}`, async () => {
71
+ const model = await runtime.loadModel(
72
+ `
73
+ source: airports is table('malloytest.airports') {
74
+ }
75
+ `
76
+ );
77
+ const result = await model.searchValueMap('airports');
78
+ // if (result !== undefined) {
79
+ // console.log(result[4].values);
80
+ // } else {
81
+ // console.log("no result");
82
+ // }
83
+ expect(result).toBeDefined();
84
+ if (result !== undefined) {
85
+ expect(result[4].values[0].fieldValue).toBe('WASHINGTON');
86
+ expect(result[4].values[0].weight).toBe(214);
87
+ }
88
+ });
89
+
90
+ it(`index no sample rows - ${databaseName}`, async () => {
91
+ const result = await runtime
92
+ .loadQuery(
93
+ `
94
+ source: t is table('malloytest.state_facts') {
95
+ dimension: one is 'one'
96
+ }
97
+
98
+ query: t-> {index:one, state }
99
+ -> {project: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
100
+ `
101
+ )
102
+ .run();
103
+ // console.log(result.data.toObject());
104
+ expect(result.data.path(0, 'fieldName').value).toBe('one');
105
+ expect(result.data.path(0, 'weight').value).toBe(51);
106
+ });
107
+
108
+ // bigquery doesn't support row count based sampling.
109
+ (databaseName === 'bigquery' ? it.skip : it)(
110
+ `index rows count - ${databaseName}`,
111
+ async () => {
112
+ const result = await runtime
113
+ .loadQuery(
114
+ `
115
+ source: t is table('malloytest.state_facts') {
116
+ dimension: one is 'one'
117
+ }
118
+
119
+ query: t-> {index:one, state; sample: 10 }
120
+ -> {project: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
121
+ `
122
+ )
123
+ .run();
124
+ expect(result.data.path(0, 'fieldName').value).toBe('one');
125
+ expect(result.data.path(0, 'weight').value).toBe(10);
126
+ }
127
+ );
128
+
129
+ it(`index rows count - ${databaseName}`, async () => {
130
+ const result = await runtime
131
+ .loadQuery(
132
+ `
133
+ source: t is table('malloytest.flights') {
134
+ dimension: one is 'one'
135
+ }
136
+
137
+ query: t-> {index:one, tailnum; sample: 50% }
138
+ -> {project: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
139
+ `
140
+ )
141
+ .run();
142
+ // console.log(result.sql);
143
+ // Hard to get consistent results here so just check that we get a value back.
144
+ //console.log(result.data.toObject());
145
+ expect(result.data.path(0, 'fieldName').value).toBe('one');
146
+ });
147
+
148
+ // it(`fanned data index - ${databaseName}`, async () => {
149
+ // const result = await runtime
150
+ // .loadModel(
151
+ // `
152
+ // source: movies is table('malloy-303216.imdb.movies') {
153
+ // }
154
+ // `
155
+ // )
156
+ // .search("movies", "Tom");
157
+ // // if (result !== undefined) {
158
+ // // console.log(result);
159
+ // // } else {
160
+ // // console.log("no result");
161
+ // // }
162
+ // expect(result).toBeDefined();
163
+ // if (result !== undefined) {
164
+ // expect(result[0].fieldName).toBe("county");
165
+ // expect(result[0].fieldValue).toBe("SANTA ROSA");
166
+ // expect(result[0].weight).toBe(26);
167
+ // }
168
+ // });
169
+ });
170
+ };
171
+
172
+ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
173
+
174
+ /*
175
+ * This test file reuses common tests definitions.
176
+ * For actual test development please go to: test/src/databases/shared/index.spec.ts
177
+ */
178
+ indexSharedTests(runtimes);
@@ -0,0 +1,350 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files
6
+ * (the "Software"), to deal in the Software without restriction,
7
+ * including without limitation the rights to use, copy, modify, merge,
8
+ * publish, distribute, sublicense, and/or sell copies of the Software,
9
+ * and to permit persons to whom the Software is furnished to do so,
10
+ * subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ /* eslint-disable no-console */
25
+
26
+ import {RuntimeList, allDatabases} from '../../runtimes';
27
+ import {databasesFromEnvironmentOr} from '../../util';
28
+
29
+ const joinModelText = `
30
+ source: aircraft_models is table('malloytest.aircraft_models') {
31
+ primary_key: aircraft_model_code
32
+ measure: model_count is count(*)
33
+ query: manufacturer_models is {
34
+ group_by: manufacturer
35
+ aggregate: num_models is count(*)
36
+ }
37
+ query: manufacturer_seats is {
38
+ group_by: manufacturer
39
+ aggregate: total_seats is seats.sum()
40
+ }
41
+ }
42
+
43
+ source: aircraft is table('malloytest.aircraft'){
44
+ primary_key: tail_num
45
+ measure: aircraft_count is count(*)
46
+ }
47
+
48
+ source: funnel is from(aircraft_models->manufacturer_models) {
49
+ join_one: seats is from(aircraft_models->manufacturer_seats)
50
+ with manufacturer
51
+ }
52
+ `;
53
+
54
+ // const models = new Map<string, malloy.ModelMaterializer>();
55
+ // runtimes.runtimeMap.forEach((runtime, key) => {
56
+ // models.set(key, runtime.loadModel(joinModelText));
57
+ // });
58
+
59
+ export const joinSharedTests = (
60
+ runtimes: RuntimeList,
61
+ _splitFunction?: (column: string, splitChar: string) => string
62
+ ) => {
63
+ afterAll(async () => {
64
+ await runtimes.closeAll();
65
+ });
66
+
67
+ describe('join expression tests', () => {
68
+ runtimes.runtimeMap.forEach((runtime, database) => {
69
+ it(`model source refine join - ${database}`, async () => {
70
+ const result = await runtime
71
+ .loadModel(joinModelText)
72
+ .loadQuery(
73
+ `
74
+ source: a2 is aircraft {
75
+ join_one: aircraft_models with aircraft_model_code
76
+ }
77
+
78
+ query: a2 -> {
79
+ aggregate:
80
+ aircraft_count
81
+ aircraft_models.model_count
82
+ }
83
+ `
84
+ )
85
+ .run();
86
+ expect(result.data.value[0]['model_count']).toBe(1416);
87
+ });
88
+
89
+ it(`model source refine in query join - ${database}`, async () => {
90
+ const result = await runtime
91
+ .loadModel(joinModelText)
92
+ .loadQuery(
93
+ `
94
+ query: aircraft {
95
+ join_one: aircraft_models with aircraft_model_code
96
+ } -> {
97
+ aggregate:
98
+ aircraft_count
99
+ aircraft_models.model_count
100
+ }
101
+ `
102
+ )
103
+ .run();
104
+ expect(result.data.value[0]['model_count']).toBe(1416);
105
+ });
106
+
107
+ it(`model: join fact table query - ${database}`, async () => {
108
+ const result = await runtime
109
+ .loadModel(joinModelText)
110
+ .loadQuery(
111
+ `
112
+ query: aircraft_models {
113
+ join_one: am_facts is from(
114
+ aircraft_models->{
115
+ group_by: m is manufacturer
116
+ aggregate: num_models is count(*)
117
+ }) with manufacturer
118
+ } -> {
119
+ project:
120
+ manufacturer
121
+ am_facts.num_models
122
+ order_by: 2 desc
123
+ limit: 1
124
+ }
125
+ `
126
+ )
127
+ .run();
128
+ expect(result.data.value[0]['num_models']).toBe(1147);
129
+ });
130
+
131
+ it(`model: source based on query - ${database}`, async () => {
132
+ const result = await runtime
133
+ .loadModel(joinModelText)
134
+ .loadQuery(
135
+ `
136
+ query:
137
+ aircraft_models-> {
138
+ group_by: m is manufacturer
139
+ aggregate: num_models is count(*)
140
+ }
141
+ -> {
142
+ project:
143
+ m
144
+ num_models
145
+ order_by: 2 desc
146
+ limit: 1
147
+ }
148
+ `
149
+ )
150
+ .run();
151
+ expect(result.data.value[0]['num_models']).toBe(1147);
152
+ });
153
+
154
+ it(`model: funnel - merge two queries - ${database}`, async () => {
155
+ const result = await runtime
156
+ .loadModel(joinModelText)
157
+ .loadQuery(
158
+ `
159
+ query: from(aircraft_models->{
160
+ group_by: m is manufacturer
161
+ aggregate: num_models is count(*)
162
+ }){
163
+ join_one: seats is from(
164
+ aircraft_models->{
165
+ group_by: m is manufacturer
166
+ aggregate: total_seats is seats.sum()
167
+ }
168
+ ) with m
169
+ }
170
+ -> {
171
+ project:
172
+ m
173
+ num_models
174
+ seats.total_seats
175
+ order_by: 2 desc
176
+ limit: 1
177
+ }
178
+ `
179
+ )
180
+ .run();
181
+ expect(result.data.value[0]['num_models']).toBe(1147);
182
+ expect(result.data.value[0]['total_seats']).toBe(252771);
183
+ });
184
+
185
+ it(`model: modeled funnel - ${database}`, async () => {
186
+ const result = await runtime
187
+ .loadModel(joinModelText)
188
+ .loadQuery(
189
+ `
190
+ source: foo is from(aircraft_models-> manufacturer_models){
191
+ join_one: seats is from(aircraft_models->manufacturer_seats)
192
+ with manufacturer
193
+ }
194
+ query: foo-> {
195
+ project:
196
+ manufacturer,
197
+ num_models,
198
+ seats.total_seats
199
+ order_by: 2 desc
200
+ limit: 1
201
+ }
202
+ `
203
+ )
204
+ .run();
205
+ expect(result.data.value[0]['num_models']).toBe(1147);
206
+ expect(result.data.value[0]['total_seats']).toBe(252771);
207
+ });
208
+
209
+ it(`model: modeled funnel2 - ${database}`, async () => {
210
+ const result = await runtime
211
+ .loadModel(joinModelText)
212
+ .loadQuery(
213
+ `
214
+ query: funnel->{
215
+ project:
216
+ manufacturer
217
+ num_models
218
+ seats.total_seats
219
+ order_by: 2 desc
220
+ limit: 1
221
+ }
222
+ `
223
+ )
224
+ .run();
225
+ expect(result.data.value[0]['num_models']).toBe(1147);
226
+ expect(result.data.value[0]['total_seats']).toBe(252771);
227
+ });
228
+
229
+ it(`model: double_pipe - ${database}`, async () => {
230
+ const result = await runtime
231
+ .loadModel(joinModelText)
232
+ .loadQuery(
233
+ `
234
+ query: aircraft_models->{
235
+ group_by: manufacturer
236
+ aggregate: f is count(*)
237
+ }->{
238
+ aggregate: f_sum is f.sum()
239
+ }->{
240
+ project: f_sum2 is f_sum+1
241
+ }
242
+ `
243
+ )
244
+ .run();
245
+ expect(result.data.value[0]['f_sum2']).toBe(60462);
246
+ });
247
+
248
+ test(`model: unnest is left join - ${database}`, async () => {
249
+ const result = await runtime
250
+ .loadModel(joinModelText)
251
+ .loadQuery(
252
+ `
253
+ // produce a table with 4 rows that has a nested element
254
+ query: a_states is table('malloytest.state_facts')-> {
255
+ where: state ? ~ 'A%'
256
+ group_by: state
257
+ nest: somthing is {group_by: state}
258
+ }
259
+
260
+ // join the 4 rows and reference the
261
+ // nested column. should return all the rows.
262
+ // If the unnest is an inner join, we'll get back just 4 rows.
263
+ query: table('malloytest.state_facts') {
264
+ join_one: a_states is from(->a_states) with state
265
+ }
266
+ -> {
267
+ group_by: state
268
+ aggregate: c is count()
269
+ nest: a is {
270
+ group_by: a_states.somthing.state
271
+ }
272
+ }
273
+ `
274
+ )
275
+ .run();
276
+ // console.log(result.data.toObject());
277
+ expect(result.data.rowCount).toBeGreaterThan(4);
278
+ });
279
+
280
+ // not sure how to solve this one yet.
281
+ it(`All joins at the same level - ${database}`, async () => {
282
+ const result = await runtime
283
+ .loadQuery(
284
+ `
285
+ source: flights is table('malloytest.flights') {
286
+ join_one: aircraft is table('malloytest.aircraft')
287
+ on tail_num = aircraft.tail_num
288
+ join_one: aircraft_models is table('malloytest.aircraft_models')
289
+ on aircraft.aircraft_model_code = aircraft_models.aircraft_model_code
290
+ }
291
+
292
+ query: flights -> {
293
+ group_by: aircraft_models.seats
294
+ aggregate: flight_count is count()
295
+ }
296
+ `
297
+ )
298
+ .run();
299
+ // console.log(result.data.toObject());
300
+ expect(result.data.rowCount).toBeGreaterThan(4);
301
+ });
302
+
303
+ it(`join issue440 - ${database}`, async () => {
304
+ const result = await runtime
305
+ .loadQuery(
306
+ `
307
+ source: aircraft_models is table('malloytest.aircraft_models')
308
+
309
+ source: aircraft is table('malloytest.aircraft')
310
+
311
+ source: flights is table('malloytest.flights'){
312
+ join_one: aircraft on aircraft.tail_num = tail_num
313
+ join_one: aircraft_models on aircraft_models.aircraft_model_code = aircraft.aircraft_model_code
314
+ }
315
+
316
+ query: flights-> {
317
+ group_by: testingtwo is aircraft_models.model
318
+ }
319
+ `
320
+ )
321
+ .run();
322
+ // console.log(result.data.toObject());
323
+ expect(result.data.rowCount).toBeGreaterThan(4);
324
+ });
325
+
326
+ it(`join issue1092 - ${database}`, async () => {
327
+ const result = await runtime
328
+ .loadQuery(
329
+ `
330
+ query: table('malloytest.state_facts') -> {
331
+ join_one: sf is table('malloytest.state_facts') on sf.state = state
332
+ aggregate: x is sf.births.sum() { ? state = 'CA' }
333
+ }
334
+ `
335
+ )
336
+ .run();
337
+ // console.log(result.data.toObject());
338
+ expect(result.data.rowCount).toBe(1);
339
+ });
340
+ });
341
+ });
342
+ };
343
+
344
+ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
345
+
346
+ /*
347
+ * This test file reuses common tests definitions.
348
+ * For actual test development please go to: test/src/databases/shared/join.spec.ts
349
+ */
350
+ joinSharedTests(runtimes);