@malloydata/malloy-tests 0.0.147 → 0.0.148-dev240529172135

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.147",
25
- "@malloydata/db-duckdb": "^0.0.147",
26
- "@malloydata/db-postgres": "^0.0.147",
27
- "@malloydata/db-snowflake": "^0.0.147",
28
- "@malloydata/db-trino": "^0.0.147",
29
- "@malloydata/malloy": "^0.0.147",
30
- "@malloydata/render": "^0.0.147",
24
+ "@malloydata/db-bigquery": "^0.0.148-dev240529172135",
25
+ "@malloydata/db-duckdb": "^0.0.148-dev240529172135",
26
+ "@malloydata/db-postgres": "^0.0.148-dev240529172135",
27
+ "@malloydata/db-snowflake": "^0.0.148-dev240529172135",
28
+ "@malloydata/db-trino": "^0.0.148-dev240529172135",
29
+ "@malloydata/malloy": "^0.0.148-dev240529172135",
30
+ "@malloydata/render": "^0.0.148-dev240529172135",
31
31
  "jsdom": "^22.1.0",
32
32
  "luxon": "^2.4.0",
33
33
  "madge": "^6.0.0"
@@ -36,5 +36,5 @@
36
36
  "@types/jsdom": "^21.1.1",
37
37
  "@types/luxon": "^2.4.0"
38
38
  },
39
- "version": "0.0.147"
39
+ "version": "0.0.148-dev240529172135"
40
40
  }
@@ -0,0 +1,116 @@
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
+ import {
25
+ DuckDBDialect,
26
+ FetchSchemaOptions,
27
+ MalloyError,
28
+ SQLBlock,
29
+ StructDef,
30
+ registerDialect,
31
+ } from '@malloydata/malloy';
32
+ import {testRuntimeFor} from './runtimes';
33
+ import './util/db-jest-matchers';
34
+ import {DuckDBConnection} from '@malloydata/db-duckdb';
35
+
36
+ const envDatabases = (
37
+ process.env['MALLOY_DATABASES'] ||
38
+ process.env['MALLOY_DATABASE'] ||
39
+ 'duckdb'
40
+ ).split(',');
41
+
42
+ let describe = globalThis.describe;
43
+ if (!envDatabases.includes('duckdb')) {
44
+ describe = describe.skip;
45
+ describe.skip = describe;
46
+ }
47
+
48
+ async function getError<T>(promise: Promise<T>): Promise<Error | undefined> {
49
+ try {
50
+ await promise;
51
+ } catch (error) {
52
+ return error;
53
+ }
54
+ return undefined;
55
+ }
56
+
57
+ describe('experimental dialects', () => {
58
+ const duckdbX = 'duckdb_experimental';
59
+ class DuckdbXConnection extends DuckDBConnection {
60
+ public async fetchSchemaForSQLBlock(
61
+ sqlRef: SQLBlock,
62
+ options: FetchSchemaOptions
63
+ ): Promise<
64
+ | {structDef: StructDef; error?: undefined}
65
+ | {error: string; structDef?: undefined}
66
+ > {
67
+ const result = await super.fetchSchemaForSQLBlock(sqlRef, options);
68
+ if (result.error === undefined) {
69
+ return {structDef: {...result.structDef, dialect: duckdbX}};
70
+ }
71
+ return result;
72
+ }
73
+ }
74
+
75
+ const connection = new DuckdbXConnection(
76
+ duckdbX,
77
+ 'test/data/duckdb/duckdb_test.db'
78
+ );
79
+
80
+ class DuckdbXDialect extends DuckDBDialect {
81
+ experimental = true;
82
+ name = duckdbX;
83
+ }
84
+
85
+ registerDialect(new DuckdbXDialect());
86
+ const runtime = testRuntimeFor(connection);
87
+ runtime.isTestRuntime = false; // Enables checking experimental dialects
88
+
89
+ test('generate an error when used without experiment enabled', async () => {
90
+ const error = await getError(
91
+ runtime.getModel(`
92
+ source: s is ${duckdbX}.sql('SELECT 1 as one')
93
+ `)
94
+ );
95
+ expect(error).not.toBeUndefined();
96
+ if (error !== undefined) {
97
+ const problems = (error as MalloyError).problems;
98
+ expect(problems.length).toBe(1);
99
+ expect(problems[0].message).toContain(
100
+ `##! experimental.dialect.${duckdbX}`
101
+ );
102
+ }
103
+ });
104
+
105
+ test('does not generate an error when used with experiment enabled', async () => {
106
+ await runtime.getModel(`
107
+ ##! experimental.dialect.${duckdbX}
108
+ source: s is ${duckdbX}.sql('SELECT 1 as one')
109
+ `);
110
+ });
111
+
112
+ afterAll(async () => {
113
+ await runtime.connection.close();
114
+ registerDialect(new DuckDBDialect());
115
+ });
116
+ });