@malloydata/malloy-tests 0.0.69-dev230808200646 → 0.0.69

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 (79) hide show
  1. package/dist/databases/all/db_index.spec.d.ts +1 -1
  2. package/dist/databases/all/db_index.spec.js +116 -6
  3. package/dist/databases/all/db_index.spec.js.map +1 -1
  4. package/dist/databases/all/expr.spec.js +542 -6
  5. package/dist/databases/all/expr.spec.js.map +1 -1
  6. package/dist/databases/all/functions.spec.d.ts +1 -1
  7. package/dist/databases/all/functions.spec.js +745 -6
  8. package/dist/databases/all/functions.spec.js.map +1 -1
  9. package/dist/databases/all/join.spec.d.ts +1 -1
  10. package/dist/databases/all/join.spec.js +272 -6
  11. package/dist/databases/all/join.spec.js.map +1 -1
  12. package/dist/databases/all/nomodel.spec.d.ts +1 -1
  13. package/dist/databases/all/nomodel.spec.js +919 -6
  14. package/dist/databases/all/nomodel.spec.js.map +1 -1
  15. package/dist/databases/all/orderby.spec.d.ts +1 -1
  16. package/dist/databases/all/orderby.spec.js +187 -6
  17. package/dist/databases/all/orderby.spec.js.map +1 -1
  18. package/dist/databases/all/problems.spec.d.ts +1 -1
  19. package/dist/databases/all/problems.spec.js +76 -6
  20. package/dist/databases/all/problems.spec.js.map +1 -1
  21. package/dist/databases/all/sql_expressions.spec.d.ts +1 -1
  22. package/dist/databases/all/sql_expressions.spec.js +58 -6
  23. package/dist/databases/all/sql_expressions.spec.js.map +1 -1
  24. package/dist/databases/all/time.spec.d.ts +1 -1
  25. package/dist/databases/all/time.spec.js +609 -5
  26. package/dist/databases/all/time.spec.js.map +1 -1
  27. package/dist/databases/shared/test_list.js +1 -20
  28. package/dist/databases/shared/test_list.js.map +1 -1
  29. package/dist/index.d.ts +0 -8
  30. package/dist/index.js +1 -17
  31. package/dist/index.js.map +1 -1
  32. package/package.json +6 -6
  33. package/src/databases/all/db_index.spec.ts +137 -6
  34. package/src/databases/all/expr.spec.ts +661 -7
  35. package/src/databases/all/functions.spec.ts +1092 -6
  36. package/src/databases/all/join.spec.ts +309 -6
  37. package/src/databases/all/nomodel.spec.ts +1114 -7
  38. package/src/databases/all/orderby.spec.ts +229 -6
  39. package/src/databases/all/problems.spec.ts +82 -6
  40. package/src/databases/all/sql_expressions.spec.ts +65 -6
  41. package/src/databases/all/time.spec.ts +734 -5
  42. package/src/databases/shared/test_list.ts +1 -20
  43. package/src/index.ts +0 -9
  44. package/dist/databases/shared/db_index.d.ts +0 -3
  45. package/dist/databases/shared/db_index.js +0 -123
  46. package/dist/databases/shared/db_index.js.map +0 -1
  47. package/dist/databases/shared/expr.d.ts +0 -3
  48. package/dist/databases/shared/expr.js +0 -551
  49. package/dist/databases/shared/expr.js.map +0 -1
  50. package/dist/databases/shared/functions.d.ts +0 -3
  51. package/dist/databases/shared/functions.js +0 -754
  52. package/dist/databases/shared/functions.js.map +0 -1
  53. package/dist/databases/shared/join.d.ts +0 -3
  54. package/dist/databases/shared/join.js +0 -302
  55. package/dist/databases/shared/join.js.map +0 -1
  56. package/dist/databases/shared/nomodel.d.ts +0 -3
  57. package/dist/databases/shared/nomodel.js +0 -950
  58. package/dist/databases/shared/nomodel.js.map +0 -1
  59. package/dist/databases/shared/orderby.d.ts +0 -3
  60. package/dist/databases/shared/orderby.js +0 -217
  61. package/dist/databases/shared/orderby.js.map +0 -1
  62. package/dist/databases/shared/problems.d.ts +0 -3
  63. package/dist/databases/shared/problems.js +0 -106
  64. package/dist/databases/shared/problems.js.map +0 -1
  65. package/dist/databases/shared/sql_expressions.d.ts +0 -3
  66. package/dist/databases/shared/sql_expressions.js +0 -88
  67. package/dist/databases/shared/sql_expressions.js.map +0 -1
  68. package/dist/databases/shared/time.d.ts +0 -3
  69. package/dist/databases/shared/time.js +0 -640
  70. package/dist/databases/shared/time.js.map +0 -1
  71. package/src/databases/shared/db_index.ts +0 -167
  72. package/src/databases/shared/expr.ts +0 -695
  73. package/src/databases/shared/functions.ts +0 -1126
  74. package/src/databases/shared/join.ts +0 -340
  75. package/src/databases/shared/nomodel.ts +0 -1150
  76. package/src/databases/shared/orderby.ts +0 -260
  77. package/src/databases/shared/problems.ts +0 -113
  78. package/src/databases/shared/sql_expressions.ts +0 -96
  79. package/src/databases/shared/time.ts +0 -786
@@ -1,260 +0,0 @@
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
- import {RuntimeList} from '../../runtimes';
26
- import '../../util/db-jest-matchers';
27
- import * as malloy from '@malloydata/malloy';
28
-
29
- export const orderBySharedTests = (
30
- runtimes: RuntimeList,
31
- _splitFunction?: (column: string, splitChar: string) => string
32
- ) => {
33
- afterAll(async () => {
34
- await runtimes.closeAll();
35
- });
36
-
37
- async function validateCompilation(
38
- databaseName: string,
39
- sql: string
40
- ): Promise<boolean> {
41
- try {
42
- const runtime = runtimes.runtimeMap.get(databaseName);
43
- if (runtime === undefined) {
44
- throw new Error(`Unknown database ${databaseName}`);
45
- }
46
- await (
47
- await runtime.connections.lookupConnection(databaseName)
48
- ).runSQL(`WITH test AS(\n${sql}) SELECT '[{"foo":1}]' as results`);
49
- } catch (e) {
50
- console.log(`SQL: didn't compile\n=============\n${sql}`);
51
- throw e;
52
- }
53
- return true;
54
- }
55
-
56
- const expressionModels = new Map<string, malloy.ModelMaterializer>();
57
- runtimes.runtimeMap.forEach((runtime, databaseName) =>
58
- expressionModels.set(
59
- databaseName,
60
- runtime.loadModel(`
61
- source: models is table('malloytest.aircraft_models'){
62
- measure: model_count is count()
63
- }
64
- `)
65
- )
66
- );
67
-
68
- expressionModels.forEach((orderByModel, databaseName) => {
69
- it(`boolean type - ${databaseName}`, async () => {
70
- const result = await orderByModel
71
- .loadQuery(
72
- `
73
- query: models-> {
74
- group_by: big is seats >=20
75
- aggregate: model_count is count()
76
- }
77
- `
78
- )
79
- .run();
80
- expect(result.data.row(0).cell('big').value).toBe(false);
81
- expect(result.data.row(0).cell('model_count').value).toBe(58451);
82
- });
83
-
84
- it(`boolean in pipeline - ${databaseName}`, async () => {
85
- const result = await orderByModel
86
- .loadQuery(
87
- `
88
- query: models->{
89
- group_by:
90
- manufacturer,
91
- big is seats >=21
92
- aggregate: model_count is count()
93
- }->{
94
- group_by: big
95
- aggregate: model_count is model_count.sum()
96
- }
97
- `
98
- )
99
- .run();
100
- expect(result.data.row(0).cell('big').value).toBe(false);
101
- expect(result.data.row(0).cell('model_count').value).toBe(58500);
102
- });
103
-
104
- it(`filtered measures in model are aggregates #352 - ${databaseName}`, async () => {
105
- const result = await orderByModel
106
- .loadQuery(
107
- `
108
- query: models->{
109
- aggregate: j_names is model_count {where: manufacturer ~ 'J%'}
110
- }
111
- -> {
112
- group_by: j_names
113
- }
114
- `
115
- )
116
- .run();
117
- expect(result.data.row(0).cell('j_names').value).toBe(1358);
118
- });
119
-
120
- it(`reserved words are quoted - ${databaseName}`, async () => {
121
- const sql = await orderByModel
122
- .loadQuery(
123
- `
124
- query: models->{
125
- aggregate: fetch is count()
126
- }->{
127
- group_by: fetch
128
- }
129
- `
130
- )
131
- .getSQL();
132
- await validateCompilation(databaseName, sql);
133
- });
134
-
135
- it(`reserved words are quoted in turtles - ${databaseName}`, async () => {
136
- const sql = await orderByModel
137
- .loadQuery(
138
- `
139
- query: models->{
140
- nest: withx is {
141
- group_by: select is UPPER(manufacturer)
142
- aggregate: fetch is count()
143
- }
144
- } -> {
145
- project:
146
- withxz is lower(withx.select)
147
- fetch is withx.fetch
148
- }
149
- `
150
- )
151
- .getSQL();
152
- await validateCompilation(databaseName, sql);
153
- });
154
-
155
- it.skip('reserved words in structure definitions', async () => {
156
- const sql = await orderByModel
157
- .loadQuery(
158
- `
159
- query: models->{
160
- nest: withx is {
161
- group_by: is select is UPPER(manufacturer)
162
- aggregate: fetch is count()
163
- }
164
- } -> {
165
- project: withxis lower(withx.select)
166
- project: fetch is with.fetch
167
- }
168
- `
169
- )
170
- .getSQL();
171
- await validateCompilation(databaseName, sql);
172
- });
173
-
174
- it(`aggregate and scalar conditions - ${databaseName}`, async () => {
175
- const sql = await orderByModel
176
- .loadQuery(
177
- `
178
- query: models->{
179
- aggregate: model_count is count(){? manufacturer ? ~'A%' }
180
- }
181
- `
182
- )
183
- .getSQL();
184
- await validateCompilation(databaseName, sql);
185
- });
186
-
187
- // I'm not sure I have the syntax right here...
188
- it(`modeled having simple - ${databaseName}`, async () => {
189
- const result = await orderByModel
190
- .loadQuery(
191
- `
192
- source: popular_names is from(models->{
193
- having: model_count > 100
194
- group_by: manufacturer
195
- aggregate: model_count
196
- })
197
-
198
- query: popular_names->{
199
- order_by: 2
200
- project: manufacturer, model_count
201
- }
202
- `
203
- )
204
- .run();
205
- expect(result.data.row(0).cell('model_count').value).toBe(102);
206
- });
207
-
208
- it(`modeled having complex - ${databaseName}`, async () => {
209
- const result = await orderByModel
210
- .loadQuery(
211
- `
212
- source: popular_names is from(models->{
213
- having: model_count > 100
214
- group_by: manufacturer
215
- aggregate: model_count
216
- nest: l is {
217
- top: 5
218
- group_by: manufacturer
219
- aggregate: model_count
220
- }
221
- })
222
-
223
- query: popular_names->{
224
- order_by: 2
225
- project: manufacturer, model_count
226
- }
227
- `
228
- )
229
- .run();
230
- expect(result.data.row(0).cell('model_count').value).toBe(102);
231
- });
232
-
233
- it(`turtle references joined element - ${databaseName}`, async () => {
234
- const sql = await orderByModel
235
- .loadQuery(
236
- `
237
- source: a is table('malloytest.aircraft'){
238
- primary_key: tail_num
239
- measure: aircraft_count is count(*)
240
- }
241
-
242
- source: f is table('malloytest.flights'){
243
- primary_key: id2
244
- join_one: a with tail_num
245
-
246
- measure: flight_count is count()
247
- query: foo is {
248
- group_by: carrier
249
- aggregate: flight_count
250
- aggregate: a.aircraft_count
251
- }
252
- }
253
- query: f->foo
254
- `
255
- )
256
- .getSQL();
257
- await validateCompilation(databaseName, sql);
258
- });
259
- });
260
- };
@@ -1,113 +0,0 @@
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
- import {RuntimeList} from '../../runtimes';
26
- import '../../util/db-jest-matchers';
27
-
28
- export const problemsSharedTests = (
29
- runtimes: RuntimeList,
30
- _splitFunction?: (column: string, splitChar: string) => string
31
- ) => {
32
- afterAll(async () => {
33
- await runtimes.closeAll();
34
- });
35
-
36
- async function getError<T>(fn: () => Promise<T>) {
37
- try {
38
- await fn();
39
- } catch (error) {
40
- return error;
41
- }
42
- }
43
-
44
- runtimes.runtimeMap.forEach((runtime, databaseName) => {
45
- describe('warnings', () => {
46
- // Today we don't show errors after the first model entry with an error,
47
- // so this can't work yet.
48
- it.skip(`can appear after errors - ${databaseName}`, async () => {
49
- const source = `
50
- source: foo is table('asdfds');
51
- source: bar is table('malloytest.state_facts') {
52
- dimension: a is LENGTH('foo')
53
- }
54
- `;
55
- const error = await getError(() => runtime.getModel(source));
56
- expect(error).not.toBeUndefined();
57
- expect(error).toMatchObject({
58
- problems: [
59
- {
60
- severity: 'error',
61
- },
62
- {
63
- message:
64
- "Case insensitivity for function names is deprecated, use 'length' instead",
65
- severity: 'warn',
66
- },
67
- ],
68
- });
69
- });
70
-
71
- it(`can appear before errors - ${databaseName}`, async () => {
72
- const source = `
73
- source: bar is table('malloytest.state_facts') {
74
- dimension: a is LENGTH('foo')
75
- }
76
- source: foo is table('asdfds');
77
- `;
78
- const error = await getError(() => runtime.getModel(source));
79
- expect(error).not.toBeUndefined();
80
- expect(error).toMatchObject({
81
- problems: [
82
- {
83
- message:
84
- "Case insensitivity for function names is deprecated, use 'length' instead",
85
- severity: 'warn',
86
- },
87
- {
88
- severity: 'error',
89
- },
90
- ],
91
- });
92
- });
93
-
94
- it(`can appear alone - ${databaseName}`, async () => {
95
- const source = `
96
- source: bar is table('malloytest.state_facts') {
97
- dimension: a is LENGTH('foo')
98
- }
99
- `;
100
- const model = await runtime.getModel(source);
101
- expect(model).toMatchObject({
102
- problems: [
103
- {
104
- message:
105
- "Case insensitivity for function names is deprecated, use 'length' instead",
106
- severity: 'warn',
107
- },
108
- ],
109
- });
110
- });
111
- });
112
- });
113
- };
@@ -1,96 +0,0 @@
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
- import {RuntimeList} from '../../runtimes';
26
- import '../../util/db-jest-matchers';
27
- // No prebuilt shared model, each test is complete. Makes debugging easier.
28
-
29
- export const sqlExpressionsSharedTests = (
30
- runtimes: RuntimeList,
31
- _splitFunction?: (column: string, splitChar: string) => string
32
- ) => {
33
- afterAll(async () => {
34
- await runtimes.closeAll();
35
- });
36
-
37
- runtimes.runtimeMap.forEach((runtime, databaseName) => {
38
- it(`sql expression with turducken - ${databaseName}`, async () => {
39
- const result = await runtime
40
- .loadQuery(
41
- `
42
- run: ${databaseName}.sql(
43
- """SELECT * FROM (%{
44
- ${databaseName}.table('malloytest.state_facts') -> {
45
- aggregate: c is count()
46
- }
47
- }) AS state_facts """
48
- ) -> {
49
- project: *
50
- }
51
- `
52
- )
53
- .run();
54
- expect(result.data.value[0]['c']).toBe(51);
55
- });
56
- it(`sql expression in second of two queries in same block, dependent on first query - ${databaseName}`, async () => {
57
- const result = await runtime
58
- .loadQuery(
59
- `
60
- query:
61
- a is ${databaseName}.table('malloytest.state_facts') -> {
62
- aggregate: c is count()
63
- }
64
- b is ${databaseName}.sql(
65
- """SELECT * FROM (%{ -> a -> { project: * } }) AS state_facts """
66
- ) -> {
67
- project: *
68
- }
69
- run: b
70
- `
71
- )
72
- .run();
73
- expect(result.data.value[0]['c']).toBe(51);
74
- });
75
- it(`sql expression in other sql expression - ${databaseName}`, async () => {
76
- const result = await runtime
77
- .loadQuery(
78
- `
79
- run: ${databaseName}.sql("""
80
- SELECT * from (%{
81
- ${databaseName}.sql("""SELECT 1 as one""") -> { group_by: one }
82
- }) as the_table
83
- """) -> { group_by: one }
84
- `
85
- )
86
- .run();
87
- expect(result.data.value[0]['one']).toBe(1);
88
- });
89
- it(`run sql expression as query - ${databaseName}`, async () => {
90
- const result = await runtime
91
- .loadQuery(`run: ${databaseName}.sql("""SELECT 1 as one""")`)
92
- .run();
93
- expect(result.data.value[0]['one']).toBe(1);
94
- });
95
- });
96
- };