@malloydata/malloy-tests 0.0.95-dev231019211822 → 0.0.95
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/README.md +213 -1
- package/dist/api.spec.d.ts +1 -1
- package/dist/api.spec.js +6 -13
- package/dist/api.spec.js.map +1 -1
- package/dist/databases/all/db_index.spec.js +21 -41
- package/dist/databases/all/db_index.spec.js.map +1 -1
- package/dist/databases/all/expr.spec.js +262 -339
- package/dist/databases/all/expr.spec.js.map +1 -1
- package/dist/databases/all/functions.spec.js +37 -35
- package/dist/databases/all/functions.spec.js.map +1 -1
- package/dist/databases/all/join.spec.js +125 -169
- package/dist/databases/all/join.spec.js.map +1 -1
- package/dist/databases/all/nomodel.spec.js +335 -594
- package/dist/databases/all/nomodel.spec.js.map +1 -1
- package/dist/databases/all/orderby.spec.js +82 -128
- package/dist/databases/all/orderby.spec.js.map +1 -1
- package/dist/databases/all/sql_expressions.spec.js +27 -43
- package/dist/databases/all/sql_expressions.spec.js.map +1 -1
- package/dist/databases/all/time.spec.js +63 -103
- package/dist/databases/all/time.spec.js.map +1 -1
- package/dist/databases/bigquery/double_truncation.spec.js +1 -1
- package/dist/databases/bigquery/handexpr.spec.js +12 -12
- package/dist/databases/bigquery/injestion_time_partitioning.spec.js +22 -22
- package/dist/databases/bigquery/joined_filters.spec.js +3 -3
- package/dist/databases/bigquery/json.spec.d.ts +1 -1
- package/dist/databases/bigquery/json.spec.js +25 -45
- package/dist/databases/bigquery/json.spec.js.map +1 -1
- package/dist/databases/bigquery/malloy_query.spec.d.ts +1 -1
- package/dist/databases/bigquery/malloy_query.spec.js +47 -48
- package/dist/databases/bigquery/malloy_query.spec.js.map +1 -1
- package/dist/databases/bigquery/time.spec.js +9 -13
- package/dist/databases/bigquery/time.spec.js.map +1 -1
- package/dist/databases/bigquery/wildcard_table_names.spec.js +19 -19
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js +53 -87
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -1
- package/dist/databases/bigquery-postgres/multi_connection.spec.js +5 -20
- package/dist/databases/bigquery-postgres/multi_connection.spec.js.map +1 -1
- package/dist/databases/bigquery-postgres/streaming.spec.js +6 -6
- package/dist/databases/bigquery-postgres/streaming.spec.js.map +1 -1
- package/dist/databases/duckdb/duckdb.spec.js +24 -33
- package/dist/databases/duckdb/duckdb.spec.js.map +1 -1
- package/dist/databases/postgres/postgres.spec.js +46 -67
- package/dist/databases/postgres/postgres.spec.js.map +1 -1
- package/dist/jestMatcher.spec.d.ts +1 -0
- package/dist/jestMatcher.spec.js +81 -0
- package/dist/jestMatcher.spec.js.map +1 -0
- package/dist/render/render.spec.js +10 -12
- package/dist/render/render.spec.js.map +1 -1
- package/dist/tags.spec.js +22 -2
- package/dist/tags.spec.js.map +1 -1
- package/dist/util/db-jest-matchers.d.ts +17 -6
- package/dist/util/db-jest-matchers.js +81 -20
- package/dist/util/db-jest-matchers.js.map +1 -1
- package/dist/util/index.d.ts +1 -2
- package/dist/util/index.js +11 -13
- package/dist/util/index.js.map +1 -1
- package/package.json +6 -6
- package/src/api.spec.ts +7 -16
- package/src/databases/all/db_index.spec.ts +22 -48
- package/src/databases/all/expr.spec.ts +273 -431
- package/src/databases/all/functions.spec.ts +37 -35
- package/src/databases/all/join.spec.ts +130 -196
- package/src/databases/all/nomodel.spec.ts +333 -689
- package/src/databases/all/orderby.spec.ts +87 -161
- package/src/databases/all/sql_expressions.spec.ts +29 -49
- package/src/databases/all/time.spec.ts +73 -130
- package/src/databases/bigquery/double_truncation.spec.ts +1 -1
- package/src/databases/bigquery/handexpr.spec.ts +12 -12
- package/src/databases/bigquery/injestion_time_partitioning.spec.ts +22 -22
- package/src/databases/bigquery/joined_filters.spec.ts +3 -3
- package/src/databases/bigquery/json.spec.ts +25 -49
- package/src/databases/bigquery/malloy_query.spec.ts +47 -54
- package/src/databases/bigquery/time.spec.ts +13 -17
- package/src/databases/bigquery/wildcard_table_names.spec.ts +19 -19
- package/src/databases/bigquery-duckdb/nested_source_table.spec.ts +56 -98
- package/src/databases/bigquery-postgres/multi_connection.spec.ts +5 -23
- package/src/databases/bigquery-postgres/streaming.spec.ts +12 -6
- package/src/databases/duckdb/duckdb.spec.ts +31 -43
- package/src/databases/postgres/postgres.spec.ts +54 -84
- package/src/jestMatcher.spec.ts +88 -0
- package/src/render/render.spec.ts +10 -12
- package/src/tags.spec.ts +22 -2
- package/src/util/db-jest-matchers.ts +106 -32
- package/src/util/index.ts +16 -14
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Assumes that postgres has been installed via nix (installs but doesn't configure
|
|
|
12
12
|
|
|
13
13
|
ADD to environment: `export PGHOST=localhost`
|
|
14
14
|
|
|
15
|
-
**postgres_init.sh** - builds a database as the current user in .tmp/data/malloytestdb. Starts server
|
|
15
|
+
**postgres_init.sh** - builds a database as the current user in .tmp/data/malloytestdb. Starts server running on localhost:5432
|
|
16
16
|
copies the test data in `malloytest-postgres.sql.gz` into the database.
|
|
17
17
|
|
|
18
18
|
**postgres_start.sh** - starts the postgres server, once it has been installed (use after a reboot, for example)
|
|
@@ -27,3 +27,215 @@ Setting up DuckDB:
|
|
|
27
27
|
|
|
28
28
|
1. At top-level, run `npx ts-node scripts/build_duckdb_test_database.ts`
|
|
29
29
|
2. A file called `duckdb_test.db` should be created in the test/data/duckdb folder - tests will automatically look there.
|
|
30
|
+
|
|
31
|
+
# Using the custom matcher for running queries
|
|
32
|
+
|
|
33
|
+
There is now a custom matcher, `malloyResultMatches` for running queries. The customer matcher makes it easy to write readable tests which need to look at query results, and produces useful output when the test fails to make it easier to develop tests or respond to the output of failing tests.
|
|
34
|
+
|
|
35
|
+
## Check for results in the first row of output
|
|
36
|
+
|
|
37
|
+
The simplest case is to check for result in the first row of output. You need either a `Runtime` or a `Model` that was obtained from `runtime.loadModel`
|
|
38
|
+
|
|
39
|
+
```TypeScript
|
|
40
|
+
// If the spec file doesn't have the matcher, use this statement. You will have
|
|
41
|
+
// to adjust the path to find REPO/test/util/db-jest-matchers
|
|
42
|
+
import './util/db-jest-matchers';
|
|
43
|
+
|
|
44
|
+
const sampleSource = `duckdb.sql("""
|
|
45
|
+
SELECT 42 as num, 'whynot' as reason
|
|
46
|
+
UNION ALL SELECT 49, 'because'""")`;
|
|
47
|
+
|
|
48
|
+
test('simple', async () => {
|
|
49
|
+
await expect(`
|
|
50
|
+
run: ${sampleSource}
|
|
51
|
+
`).malloyResultMatches(runtimeOrModel, {num: 42, reason: 'whynot'});
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This will check the following things.
|
|
56
|
+
|
|
57
|
+
* There is at least one row of data in the output. So `.malloyQueryMatches(rt, {})` will fail if the query returns no rows
|
|
58
|
+
* There are entries in that row for each key. `{}` matches any row
|
|
59
|
+
* The entries are equal, but it will error if the expected data as a number and the returned data is a string.
|
|
60
|
+
|
|
61
|
+
## Accessing nested results
|
|
62
|
+
|
|
63
|
+
You can specify a nested key in a match using a dotted path to the value. Note this
|
|
64
|
+
example also shows passing a model instead of a runtime to the matcher.
|
|
65
|
+
|
|
66
|
+
```TypeScript
|
|
67
|
+
const model = runtime.loadModel(`source: sampleSource is ${sampleSource}`);
|
|
68
|
+
test('nested', async () => {
|
|
69
|
+
await expect(`
|
|
70
|
+
run: sampleSource -> {
|
|
71
|
+
nest: the_nest is {
|
|
72
|
+
select: nestNum is num, nestWhy is reasons
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`).malloyResultMatches(model, {
|
|
76
|
+
'the_nest.nestNum': 42,
|
|
77
|
+
'theNest.nestWhy': 'whynot',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
> [!WARNING]
|
|
83
|
+
> There is currently a ... feature ... where if the source code of a test
|
|
84
|
+
> contains the characters `nest:` and the runtime connection does not support nesting,
|
|
85
|
+
> the test passes without actually doing anything. There will better handling of
|
|
86
|
+
> this problem in the future, but if your test is mysteriously passing, this is why.
|
|
87
|
+
|
|
88
|
+
## Queries returning more than one row of data
|
|
89
|
+
|
|
90
|
+
An array of match rows may can also be used, if the test needs to verify more than the first row of results.
|
|
91
|
+
|
|
92
|
+
```TypeScript
|
|
93
|
+
test('multiple rows', async () => {
|
|
94
|
+
await expect(`
|
|
95
|
+
run: ${sampleSource}
|
|
96
|
+
`).malloyResultMatches(runtimeOrModel, [
|
|
97
|
+
{num: 42, reason: 'whynot'},
|
|
98
|
+
{num: 49, reason: 'because'},
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This will pass if ..
|
|
104
|
+
|
|
105
|
+
* There are exactly two rows of output. If there are not exactly two the matcher will fail. If the query makes more than two rows, you will need to add a `limit: 2` to allow the matcher to pass.
|
|
106
|
+
* Each row is matches the matching criteria, again `{}` means "pass if there is a row"
|
|
107
|
+
|
|
108
|
+
## Reading failure output
|
|
109
|
+
|
|
110
|
+
### Mis-matched data
|
|
111
|
+
|
|
112
|
+
When the data return is incorrect, the matcher will always show you the generated SQL before showing you the failed match. This is useful when you are debugging a dialect want to know exactly what SQL ran to produce the non matching result.
|
|
113
|
+
|
|
114
|
+
```TypeScript
|
|
115
|
+
test('wrong data', async () => {
|
|
116
|
+
await expect(`
|
|
117
|
+
run: ${sampleSource}
|
|
118
|
+
`).malloyResultMatches(runtimeOrModel, {num: 24, reason: 'i said so'});
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
● malloyResultMatches › wrong data
|
|
124
|
+
|
|
125
|
+
SQL Generated:
|
|
126
|
+
SELECT
|
|
127
|
+
base."num" as "num",
|
|
128
|
+
base."reason" as "reason"
|
|
129
|
+
FROM (
|
|
130
|
+
SELECT 42 as num, 'whynot' as reason
|
|
131
|
+
UNION ALL SELECT 49, 'because') as base
|
|
132
|
+
|
|
133
|
+
Expected {num: 24} Got: 42
|
|
134
|
+
Expected {reason: "i said so"} Got: "whynot"
|
|
135
|
+
|
|
136
|
+
120 | await expect(`
|
|
137
|
+
121 | run: ${sampleSource}
|
|
138
|
+
> 122 | `).malloyResultMatches(runtimeOrModel, {num: 24, reason: 'i said so'});
|
|
139
|
+
| ^
|
|
140
|
+
123 | });
|
|
141
|
+
124 | });
|
|
142
|
+
125 | afterAll(async () => await runtime.connection.close());
|
|
143
|
+
|
|
144
|
+
at Object.<anonymous> (test/src/jestMatcher.spec.ts:122:8)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Bad Malloy Code
|
|
148
|
+
|
|
149
|
+
If the Malloy code in your test is in error, the matcher tries to make a
|
|
150
|
+
it clear where the error is. Because many tests construct the query at runtime,
|
|
151
|
+
the matcher will print the entire text of the query in the failure message. Look for the line
|
|
152
|
+
starting with `!!!!!` to find your code error.
|
|
153
|
+
|
|
154
|
+
```TypeScript
|
|
155
|
+
test('malloyResultMatches with an error', async () => {
|
|
156
|
+
await expect(`
|
|
157
|
+
rug: ${sampleSource}
|
|
158
|
+
`).malloyResultMatches(runtime, [
|
|
159
|
+
{num: 42, reason: 'whynot'},
|
|
160
|
+
{num: 49, reason: 'because'},
|
|
161
|
+
]);
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
● jestMatcher › malloyResultMatches with an error
|
|
167
|
+
|
|
168
|
+
Error in query compilation
|
|
169
|
+
|
|
|
170
|
+
| rug: duckdb.sql("""
|
|
171
|
+
!!!!! ^ no viable alternative at input 'rug'
|
|
172
|
+
| SELECT 42 as num, 'whynot' as reason
|
|
173
|
+
| UNION ALL SELECT 49, 'because'
|
|
174
|
+
| """)
|
|
175
|
+
|
|
|
176
|
+
|
|
177
|
+
77 | UNION ALL SELECT 49, 'because'
|
|
178
|
+
78 | """)
|
|
179
|
+
> 79 | `).malloyResultMatches(runtime, [
|
|
180
|
+
| ^
|
|
181
|
+
80 | {num: 42, reason: 'whynot'},
|
|
182
|
+
81 | {num: 49, reason: 'because'},
|
|
183
|
+
82 | ]);
|
|
184
|
+
|
|
185
|
+
at Object.<anonymous> (test/src/jestMatcher.spec.ts:79:8)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Wrong Data Size
|
|
189
|
+
|
|
190
|
+
If an array is passed to `malloyResultMatches` each row will be matched, and an additional test will be added to make sure the that rows in the match set equals the rows in the result.
|
|
191
|
+
|
|
192
|
+
If you specify match data, that will also be tested for rows which exist in both the match set and the result set.
|
|
193
|
+
|
|
194
|
+
```TypeScript
|
|
195
|
+
test('failing exactly one row', async () => {
|
|
196
|
+
await expect(`
|
|
197
|
+
run: ${sampleSource}
|
|
198
|
+
`).malloyResultMatches(runtimeOrModel, [{}]);
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
● malloyResultMatches › failing exactly one row
|
|
204
|
+
|
|
205
|
+
SQL Generated:
|
|
206
|
+
SELECT
|
|
207
|
+
base."num" as "num",
|
|
208
|
+
base."reason" as "reason"
|
|
209
|
+
FROM (
|
|
210
|
+
SELECT 42 as num, 'whynot' as reason
|
|
211
|
+
UNION ALL SELECT 49, 'because') as base
|
|
212
|
+
|
|
213
|
+
Expected result.rows=1 Got: 2
|
|
214
|
+
|
|
215
|
+
126 | await expect(`
|
|
216
|
+
127 | run: ${sampleSource}
|
|
217
|
+
> 128 | `).malloyResultMatches(runtimeOrModel, [{}]);
|
|
218
|
+
| ^
|
|
219
|
+
129 | });
|
|
220
|
+
130 | });
|
|
221
|
+
131 | afterAll(async () => await runtime.connection.close());
|
|
222
|
+
|
|
223
|
+
at Object.<anonymous> (test/src/api.spec.ts:128:8)``
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### What it doesn't do
|
|
227
|
+
|
|
228
|
+
The old template for a test looked something like
|
|
229
|
+
|
|
230
|
+
```TypeScript
|
|
231
|
+
const result = await runtime.loadQuery(`QUERYTEXT`);
|
|
232
|
+
expect(result ....).toBeCorrectSomehow();
|
|
233
|
+
expect(result ....).toBeCorrectADifferentWay();
|
|
234
|
+
expect(result ....).toBeCorrectThisWayToo();
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The actual matcher for a result is limited to an equality test, in the old pattern you would have written something using an existing matcher for a data value
|
|
238
|
+
```TypeScript
|
|
239
|
+
expect(result.data.patch(0, 'numThings').value).toBeGreaterThan(7);
|
|
240
|
+
```
|
|
241
|
+
and if this is desirable, more work on the custom matcher would be needed to allow expressions like this to be written.
|
package/dist/api.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import './util/db-jest-matchers';
|
package/dist/api.spec.js
CHANGED
|
@@ -24,11 +24,12 @@
|
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const runtimes_1 = require("./runtimes");
|
|
27
|
+
require("./util/db-jest-matchers");
|
|
27
28
|
const runtime = (0, runtimes_1.runtimeFor)('duckdb');
|
|
28
29
|
describe('extendModel', () => {
|
|
29
30
|
test('can run query in extend section', async () => {
|
|
30
31
|
const model = runtime.loadModel(`
|
|
31
|
-
query: q1 is table('malloytest.aircraft')->{
|
|
32
|
+
query: q1 is duckdb.table('malloytest.aircraft')->{
|
|
32
33
|
where: state = 'CA'
|
|
33
34
|
group_by: state
|
|
34
35
|
}
|
|
@@ -37,7 +38,7 @@ describe('extendModel', () => {
|
|
|
37
38
|
const oneState = await q1.run();
|
|
38
39
|
expect(oneState.data.path(0, 'state').value).toBe('CA');
|
|
39
40
|
const extended = model.extendModel(`
|
|
40
|
-
query: q2 is table('malloytest.aircraft')->{
|
|
41
|
+
query: q2 is duckdb.table('malloytest.aircraft')->{
|
|
41
42
|
where: state = 'NV'
|
|
42
43
|
group_by: state
|
|
43
44
|
}
|
|
@@ -48,7 +49,7 @@ describe('extendModel', () => {
|
|
|
48
49
|
});
|
|
49
50
|
test('can reference query from previous section ', async () => {
|
|
50
51
|
const model = runtime.loadModel(`
|
|
51
|
-
query: q1 is table('malloytest.aircraft')->{
|
|
52
|
+
query: q1 is duckdb.table('malloytest.aircraft')->{
|
|
52
53
|
where: state = 'CA'
|
|
53
54
|
group_by: state
|
|
54
55
|
}
|
|
@@ -56,16 +57,7 @@ describe('extendModel', () => {
|
|
|
56
57
|
const q1 = model.loadQueryByName('q1');
|
|
57
58
|
const oneState = await q1.run();
|
|
58
59
|
expect(oneState.data.path(0, 'state').value).toBe('CA');
|
|
59
|
-
const extended = model.extendModel('query: q2 is
|
|
60
|
-
const q2 = extended.loadQueryByName('q2');
|
|
61
|
-
const twoState = await q2.run();
|
|
62
|
-
expect(twoState.data.path(0, 'state').value).toBe('CA');
|
|
63
|
-
});
|
|
64
|
-
test('can reference sql from previous section ', async () => {
|
|
65
|
-
const model = runtime.loadModel(`
|
|
66
|
-
sql: q1 is { connection: "duckdb" select: """SELECT 'CA' as state""" }
|
|
67
|
-
`);
|
|
68
|
-
const extended = model.extendModel('query: q2 is from_sql(q1)->{select: *}');
|
|
60
|
+
const extended = model.extendModel('query: q2 is q1 -> { select: * }');
|
|
69
61
|
const q2 = extended.loadQueryByName('q2');
|
|
70
62
|
const twoState = await q2.run();
|
|
71
63
|
expect(twoState.data.path(0, 'state').value).toBe('CA');
|
|
@@ -74,4 +66,5 @@ describe('extendModel', () => {
|
|
|
74
66
|
await expect(runtime.getQueryByName('', 'Dummy Query')).rejects.toThrow('Given query name does not refer to a named query.');
|
|
75
67
|
});
|
|
76
68
|
});
|
|
69
|
+
afterAll(async () => await runtime.connection.close());
|
|
77
70
|
//# sourceMappingURL=api.spec.js.map
|
package/dist/api.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.spec.js","sourceRoot":"","sources":["../src/api.spec.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAEH,yCAAsC;
|
|
1
|
+
{"version":3,"file":"api.spec.js","sourceRoot":"","sources":["../src/api.spec.ts"],"names":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AAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAExD,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,kCAAkC,CAAC,CAAC;QACvE,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACrE,mDAAmD,CACpD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC"}
|
|
@@ -35,7 +35,7 @@ afterAll(async () => {
|
|
|
35
35
|
runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
36
36
|
it(`basic index - ${databaseName}`, async () => {
|
|
37
37
|
const model = await runtime.loadModel(`
|
|
38
|
-
source: airports is table('malloytest.airports') {
|
|
38
|
+
source: airports is ${databaseName}.table('malloytest.airports') extend {
|
|
39
39
|
}
|
|
40
40
|
`);
|
|
41
41
|
let result = await model.search('airports', 'SANTA', 10);
|
|
@@ -60,7 +60,7 @@ runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
|
60
60
|
});
|
|
61
61
|
it(`index value map - ${databaseName}`, async () => {
|
|
62
62
|
const model = await runtime.loadModel(`
|
|
63
|
-
source: airports is table('malloytest.airports') {
|
|
63
|
+
source: airports is ${databaseName}.table('malloytest.airports') extend {
|
|
64
64
|
}
|
|
65
65
|
`);
|
|
66
66
|
const result = await model.searchValueMap('airports');
|
|
@@ -76,56 +76,36 @@ runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
it(`index no sample rows - ${databaseName}`, async () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
query: t-> {index:one, state }
|
|
86
|
-
-> {select: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
|
|
87
|
-
`)
|
|
88
|
-
.run();
|
|
89
|
-
// console.log(result.data.toObject());
|
|
90
|
-
expect(result.data.path(0, 'fieldName').value).toBe('one');
|
|
91
|
-
expect(result.data.path(0, 'weight').value).toBe(51);
|
|
79
|
+
await expect(`
|
|
80
|
+
run: ${databaseName}.table('malloytest.state_facts') extend {
|
|
81
|
+
dimension: one is 'one'
|
|
82
|
+
} -> {index:one, state }
|
|
83
|
+
-> {select: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
|
|
84
|
+
`).malloyResultMatches(runtime, { fieldName: 'one', weight: 51 });
|
|
92
85
|
});
|
|
93
86
|
// bigquery doesn't support row count based sampling.
|
|
94
|
-
(databaseName
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
source: t is table('malloytest.state_facts') {
|
|
87
|
+
(0, util_1.testIf)(databaseName !== 'bigquery')(`index rows count - ${databaseName}`, async () => {
|
|
88
|
+
await expect(`
|
|
89
|
+
run: ${databaseName}.table('malloytest.state_facts') extend {
|
|
98
90
|
dimension: one is 'one'
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
-> {select: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
|
|
103
|
-
`)
|
|
104
|
-
.run();
|
|
105
|
-
expect(result.data.path(0, 'fieldName').value).toBe('one');
|
|
106
|
-
expect(result.data.path(0, 'weight').value).toBe(10);
|
|
91
|
+
} -> {index:one, state; sample: 10 }
|
|
92
|
+
-> {select: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
|
|
93
|
+
`).malloyResultMatches(runtime, { fieldName: 'one', weight: 10 });
|
|
107
94
|
});
|
|
108
95
|
it(`index rows count - ${databaseName}`, async () => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
query: t-> {index:one, tailnum; sample: 50% }
|
|
116
|
-
-> {select: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
|
|
117
|
-
`)
|
|
118
|
-
.run();
|
|
119
|
-
// console.log(result.sql);
|
|
96
|
+
await expect(`
|
|
97
|
+
run: ${databaseName}.table('malloytest.flights') extend {
|
|
98
|
+
dimension: one is 'one'
|
|
99
|
+
} -> {index:one, tailnum; sample: 50% }
|
|
100
|
+
-> {select: fieldName, weight, fieldValue; order_by: 2 desc; where: fieldName = 'one'}
|
|
101
|
+
`).malloyResultMatches(runtime, { fieldName: 'one' });
|
|
120
102
|
// Hard to get consistent results here so just check that we get a value back.
|
|
121
|
-
//console.log(result.data.toObject());
|
|
122
|
-
expect(result.data.path(0, 'fieldName').value).toBe('one');
|
|
123
103
|
});
|
|
124
104
|
// it(`fanned data index - ${databaseName}`, async () => {
|
|
125
105
|
// const result = await runtime
|
|
126
106
|
// .loadModel(
|
|
127
107
|
// `
|
|
128
|
-
// source: movies is table('malloy-303216.imdb.movies') {
|
|
108
|
+
// source: movies is ${databaseName}.table('malloy-303216.imdb.movies') extend {
|
|
129
109
|
// }
|
|
130
110
|
// `
|
|
131
111
|
// )
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db_index.spec.js","sourceRoot":"","sources":["../../../src/databases/all/db_index.spec.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;;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