@malloydata/malloy-tests 0.0.125 → 0.0.126-dev240305182920

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.
@@ -36,6 +36,7 @@ afterAll(async () => {
36
36
  });
37
37
 
38
38
  runtimes.runtimeMap.forEach((runtime, databaseName) => {
39
+ const q = runtime.getQuoter();
39
40
  it(`sql expression with turducken - ${databaseName}`, async () => {
40
41
  await expect(`
41
42
  run: ${databaseName}.sql(
@@ -63,14 +64,14 @@ runtimes.runtimeMap.forEach((runtime, databaseName) => {
63
64
  await expect(`
64
65
  run: ${databaseName}.sql("""
65
66
  SELECT * from (%{
66
- ${databaseName}.sql("""SELECT 1 as one""") -> { group_by: one }
67
+ ${databaseName}.sql("""SELECT 1 as ${q`one`} """) -> { group_by: one }
67
68
  }) as the_table
68
69
  """) -> { group_by: one }
69
70
  `).malloyResultMatches(runtime, {one: 1});
70
71
  });
71
72
  it(`run sql expression as query - ${databaseName}`, async () => {
72
73
  await expect(
73
- `run: ${databaseName}.sql("""SELECT 1 as one""")`
74
+ `run: ${databaseName}.sql("""SELECT 1 as ${q`one`} """)`
74
75
  ).malloyResultMatches(runtime, {one: 1});
75
76
  });
76
77
  });
@@ -24,10 +24,15 @@
24
24
 
25
25
  import {RuntimeList, allDatabases} from '../../runtimes';
26
26
  import '../../util/db-jest-matchers';
27
- import {mkSqlEqWith, runQuery, testIf} from '../../util';
27
+ import {
28
+ databasesFromEnvironmentOr,
29
+ mkSqlEqWith,
30
+ runQuery,
31
+ testIf,
32
+ } from '../../util';
28
33
  import {DateTime as LuxonDateTime} from 'luxon';
29
34
 
30
- const runtimes = new RuntimeList(allDatabases);
35
+ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
31
36
 
32
37
  const timeSQL =
33
38
  "SELECT DATE '2021-02-24' as t_date, TIMESTAMP '2021-02-24 03:05:06' as t_timestamp";
@@ -620,12 +625,12 @@ describe.each(runtimes.runtimeList)('%s: tz literals', (dbName, runtime) => {
620
625
  const query = runtime.loadQuery(
621
626
  `
622
627
  run: ${dbName}.sql("SELECT 1") -> {
623
- group_by: literalTime is @2020-02-20 00:00:00
628
+ group_by: literal_time is @2020-02-20 00:00:00
624
629
  }
625
630
  `
626
631
  );
627
632
  const result = await query.run();
628
- const literal = result.data.path(0, 'literalTime').value as Date;
633
+ const literal = result.data.path(0, 'literal_time').value as Date;
629
634
  const have = LuxonDateTime.fromJSDate(literal);
630
635
  expect(have.valueOf()).toEqual(utc_2020.valueOf());
631
636
  });
@@ -634,12 +639,12 @@ describe.each(runtimes.runtimeList)('%s: tz literals', (dbName, runtime) => {
634
639
  const query = runtime.loadQuery(
635
640
  `
636
641
  run: ${dbName}.sql("SELECT 1") -> {
637
- group_by: literalTime is @2020-02-20 00:00:00[America/Mexico_City]
642
+ group_by: literal_time is @2020-02-20 00:00:00[America/Mexico_City]
638
643
  }
639
644
  `
640
645
  );
641
646
  const result = await query.run();
642
- const literal = result.data.path(0, 'literalTime').value as Date;
647
+ const literal = result.data.path(0, 'literal_time').value as Date;
643
648
  const have = LuxonDateTime.fromJSDate(literal);
644
649
  expect(have.valueOf()).toEqual(zone_2020.valueOf());
645
650
  });
@@ -651,12 +656,12 @@ describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
651
656
  `
652
657
  run: ${dbName}.sql("SELECT 1") -> {
653
658
  timezone: '${zone}'
654
- group_by: literalTime is @2020-02-20 00:00:00
659
+ group_by: literal_time is @2020-02-20 00:00:00
655
660
  }
656
661
  `
657
662
  );
658
663
  const result = await query.run();
659
- const literal = result.data.path(0, 'literalTime').value as Date;
664
+ const literal = result.data.path(0, 'literal_time').value as Date;
660
665
  const have = LuxonDateTime.fromJSDate(literal);
661
666
  expect(have.valueOf()).toEqual(zone_2020.valueOf());
662
667
  });
package/src/runtimes.ts CHANGED
@@ -33,7 +33,24 @@ import {
33
33
  import {BigQueryConnection} from '@malloydata/db-bigquery';
34
34
  import {DuckDBConnection} from '@malloydata/db-duckdb';
35
35
  import {DuckDBWASMConnection} from '@malloydata/db-duckdb/wasm';
36
+ import {SnowflakeConnection} from '@malloydata/db-snowflake';
36
37
  import {PooledPostgresConnection} from '@malloydata/db-postgres';
38
+ import {SnowflakeExecutor} from '@malloydata/db-snowflake/src/snowflake_executor';
39
+
40
+ export class SnowflakeTestConnection extends SnowflakeConnection {
41
+ public async runSQL(
42
+ sqlCommand: string,
43
+ options?: RunSQLOptions
44
+ ): Promise<MalloyQueryData> {
45
+ try {
46
+ return await super.runSQL(sqlCommand, options);
47
+ } catch (e) {
48
+ // eslint-disable-next-line no-console
49
+ console.log(`Error in SQL:\n ${sqlCommand}`);
50
+ throw e;
51
+ }
52
+ }
53
+ }
37
54
 
38
55
  export class BigQueryTestConnection extends BigQueryConnection {
39
56
  // we probably need a better way to do this.
@@ -119,34 +136,53 @@ export function rows(qr: Result): QueryDataRow[] {
119
136
 
120
137
  export function runtimeFor(dbName: string): SingleConnectionRuntime {
121
138
  let connection;
122
- switch (dbName) {
123
- case 'bigquery':
124
- connection = new BigQueryTestConnection(
125
- dbName,
126
- {},
127
- {projectId: 'malloy-data'}
128
- );
129
- break;
130
- case 'postgres':
131
- connection = new PostgresTestConnection(dbName);
132
- break;
133
- case 'duckdb':
134
- connection = new DuckDBTestConnection(dbName);
135
- break;
136
- case 'duckdb_wasm':
137
- connection = new DuckDBWASMTestConnection(dbName);
138
- break;
139
- default:
140
- throw new Error(`Unknown runtime "${dbName}`);
139
+ try {
140
+ switch (dbName) {
141
+ case 'bigquery':
142
+ connection = new BigQueryTestConnection(
143
+ dbName,
144
+ {},
145
+ {projectId: 'malloy-data'}
146
+ );
147
+ break;
148
+ case 'postgres':
149
+ connection = new PostgresTestConnection(dbName);
150
+ break;
151
+ case 'duckdb':
152
+ connection = new DuckDBTestConnection(dbName);
153
+ break;
154
+ case 'duckdb_wasm':
155
+ connection = new DuckDBWASMTestConnection(dbName);
156
+ break;
157
+ case 'snowflake':
158
+ {
159
+ const connOptions = SnowflakeExecutor.getConnectionOptionsFromEnv();
160
+ connection = new SnowflakeTestConnection(dbName, {connOptions});
161
+ }
162
+ break;
163
+ default:
164
+ throw new Error(`Unknown runtime "${dbName}`);
165
+ }
166
+ return testRuntimeFor(connection);
167
+ } catch (error) {
168
+ throw new Error(
169
+ `Failed to create connection \`${dbName}\`: ${error.message}`
170
+ );
141
171
  }
142
- return testRuntimeFor(connection);
143
172
  }
144
173
 
145
174
  export function testRuntimeFor(connection: Connection) {
146
175
  return new SingleConnectionRuntime(files, connection);
147
176
  }
148
177
 
149
- export const allDatabases = ['postgres', 'bigquery', 'duckdb', 'duckdb_wasm'];
178
+ export const allDatabases = [
179
+ 'postgres',
180
+ 'bigquery',
181
+ 'duckdb',
182
+ 'duckdb_wasm',
183
+ 'snowflake',
184
+ ];
185
+
150
186
  type RuntimeDatabaseNames = (typeof allDatabases)[number];
151
187
 
152
188
  export class RuntimeList {
@@ -139,9 +139,17 @@ expect.extend({
139
139
  return {pass: false, message: () => failMsg};
140
140
  }
141
141
 
142
+ const debug = querySrc.indexOf('--debug') >= 0;
142
143
  const allRows = Array.isArray(shouldEqual) ? shouldEqual : [shouldEqual];
143
144
  let i = 0;
144
145
  const fails: string[] = [];
146
+
147
+ if (debug) {
148
+ fails.push(
149
+ `Debug: Result Data: ${JSON.stringify(result.data.toObject())}`
150
+ );
151
+ }
152
+
145
153
  const gotRows = result.data.toObject().length;
146
154
  if (Array.isArray(shouldEqual)) {
147
155
  if (gotRows !== allRows.length) {
package/tsconfig.json CHANGED
@@ -18,6 +18,9 @@
18
18
  {
19
19
  "path": "../packages/malloy-db-postgres"
20
20
  },
21
+ {
22
+ "path": "../packages/malloy-db-snowflake"
23
+ },
21
24
  {
22
25
  "path": "../packages/malloy-db-duckdb"
23
26
  },