@malloydata/db-snowflake 0.0.375 → 0.0.377
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/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/dist/snowflake_connection.d.ts +48 -13
- package/dist/snowflake_connection.js +144 -228
- package/dist/snowflake_connection.js.map +1 -1
- package/dist/snowflake_connection.spec.js +179 -14
- package/dist/snowflake_connection.spec.js.map +1 -1
- package/dist/snowflake_sample_strategy.spec.js +97 -0
- package/dist/snowflake_sample_strategy.spec.js.map +1 -0
- package/dist/snowflake_table_name.d.ts +19 -0
- package/dist/snowflake_table_name.js +80 -0
- package/dist/snowflake_table_name.js.map +1 -0
- package/dist/snowflake_variant_schema.d.ts +43 -0
- package/dist/snowflake_variant_schema.js +203 -0
- package/dist/snowflake_variant_schema.js.map +1 -0
- package/dist/snowflake_variant_schema.spec.js +150 -0
- package/dist/snowflake_variant_schema.spec.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +34 -1
- package/src/snowflake_connection.spec.ts +219 -15
- package/src/snowflake_connection.ts +218 -262
- package/src/snowflake_sample_strategy.spec.ts +130 -0
- package/src/snowflake_table_name.ts +94 -0
- package/src/snowflake_variant_schema.spec.ts +188 -0
- package/src/snowflake_variant_schema.ts +301 -0
- package/dist/snowflake_executor.spec.js +0 -89
- package/dist/snowflake_executor.spec.js.map +0 -1
- package/dist/snowflake_setup.spec.js +0 -76
- package/dist/snowflake_setup.spec.js.map +0 -1
- package/src/snowflake_executor.spec.ts +0 -103
- package/src/snowflake_setup.spec.ts +0 -56
- /package/dist/{snowflake_executor.spec.d.ts → snowflake_sample_strategy.spec.d.ts} +0 -0
- /package/dist/{snowflake_setup.spec.d.ts → snowflake_variant_schema.spec.d.ts} +0 -0
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright Contributors to the Malloy project
|
|
4
|
-
* SPDX-License-Identifier: MIT
|
|
5
|
-
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
-
var ownKeys = function(o) {
|
|
24
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
-
var ar = [];
|
|
26
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
return ownKeys(o);
|
|
30
|
-
};
|
|
31
|
-
return function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
-
};
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
const malloy = __importStar(require("@malloydata/malloy"));
|
|
44
|
-
const snowflake_connection_1 = require("./snowflake_connection");
|
|
45
|
-
const snowflake_executor_1 = require("./snowflake_executor");
|
|
46
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
47
|
-
describe('setupSQL', () => {
|
|
48
|
-
const connOptions = snowflake_executor_1.SnowflakeExecutor.getConnectionOptionsFromEnv() ||
|
|
49
|
-
snowflake_executor_1.SnowflakeExecutor.getConnectionOptionsFromToml();
|
|
50
|
-
const uid = crypto_1.default.randomBytes(4).toString('hex');
|
|
51
|
-
const connections = [];
|
|
52
|
-
function makeConn(name, setupSQL) {
|
|
53
|
-
const conn = new snowflake_connection_1.SnowflakeConnection(name, { connOptions, setupSQL });
|
|
54
|
-
connections.push(conn);
|
|
55
|
-
return conn;
|
|
56
|
-
}
|
|
57
|
-
afterAll(async () => {
|
|
58
|
-
await Promise.all(connections.map(c => c.close()));
|
|
59
|
-
});
|
|
60
|
-
it('runs a single setup statement', async () => {
|
|
61
|
-
const conn = makeConn('snowflake_setup_single', `SET setup_test_${uid} = 42`);
|
|
62
|
-
const result = await conn.runSQL(`SELECT $setup_test_${uid} AS V`);
|
|
63
|
-
expect(malloy.API.rowDataToNumber(result.rows[0]['V'])).toBe(42);
|
|
64
|
-
});
|
|
65
|
-
it('runs multiple semicolon-newline-separated statements', async () => {
|
|
66
|
-
const conn = makeConn('snowflake_setup_multi', [`SET setup_a_${uid} = 10`, `SET setup_b_${uid} = 20`].join(';\n'));
|
|
67
|
-
const result = await conn.runSQL(`SELECT $setup_a_${uid} + $setup_b_${uid} AS V`);
|
|
68
|
-
expect(malloy.API.rowDataToNumber(result.rows[0]['V'])).toBe(30);
|
|
69
|
-
});
|
|
70
|
-
it('handles multi-line statements', async () => {
|
|
71
|
-
const conn = makeConn('snowflake_setup_multiline', `SET\n setup_ml_${uid} = 99`);
|
|
72
|
-
const result = await conn.runSQL(`SELECT $setup_ml_${uid} AS V`);
|
|
73
|
-
expect(malloy.API.rowDataToNumber(result.rows[0]['V'])).toBe(99);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
//# sourceMappingURL=snowflake_setup.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snowflake_setup.spec.js","sourceRoot":"","sources":["../src/snowflake_setup.spec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2DAA6C;AAC7C,iEAA2D;AAC3D,6DAAuD;AACvD,oDAA4B;AAE5B,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,MAAM,WAAW,GACf,sCAAiB,CAAC,2BAA2B,EAAE;QAC/C,sCAAiB,CAAC,4BAA4B,EAAE,CAAC;IACnD,MAAM,GAAG,GAAG,gBAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,WAAW,GAA0B,EAAE,CAAC;IAE9C,SAAS,QAAQ,CAAC,IAAY,EAAE,QAAgB;QAC9C,MAAM,IAAI,GAAG,IAAI,0CAAmB,CAAC,IAAI,EAAE,EAAC,WAAW,EAAE,QAAQ,EAAC,CAAC,CAAC;QACpE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,IAAI,GAAG,QAAQ,CACnB,wBAAwB,EACxB,kBAAkB,GAAG,OAAO,CAC7B,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,sB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ge, 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 {SnowflakeExecutor} from './snowflake_executor';
|
|
25
|
-
import type {QueryData, RunSQLOptions} from '@malloydata/malloy';
|
|
26
|
-
import {describeIfDatabaseAvailable} from '@malloydata/malloy/test';
|
|
27
|
-
|
|
28
|
-
const [describe] = describeIfDatabaseAvailable(['snowflake']);
|
|
29
|
-
|
|
30
|
-
class SnowflakeExecutorTestSetup {
|
|
31
|
-
private executor_: SnowflakeExecutor;
|
|
32
|
-
constructor(executor: SnowflakeExecutor) {
|
|
33
|
-
this.executor_ = executor;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async runBatch(sqlText: string): Promise<QueryData> {
|
|
37
|
-
let ret: QueryData = [];
|
|
38
|
-
await (async () => {
|
|
39
|
-
const rows = await this.executor_.batch(sqlText);
|
|
40
|
-
return rows;
|
|
41
|
-
})().then((rows: QueryData) => {
|
|
42
|
-
ret = rows;
|
|
43
|
-
});
|
|
44
|
-
return ret;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async runStreaming(sqlText: string, queryOptions?: RunSQLOptions) {
|
|
48
|
-
const rows: QueryData = [];
|
|
49
|
-
await (async () => {
|
|
50
|
-
for await (const row of await this.executor_.stream(
|
|
51
|
-
sqlText,
|
|
52
|
-
queryOptions
|
|
53
|
-
)) {
|
|
54
|
-
rows.push(row);
|
|
55
|
-
}
|
|
56
|
-
})();
|
|
57
|
-
return rows;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async done() {
|
|
61
|
-
await this.executor_.done();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
describe('db:SnowflakeExecutor', () => {
|
|
66
|
-
let db: SnowflakeExecutorTestSetup;
|
|
67
|
-
let query: string;
|
|
68
|
-
|
|
69
|
-
beforeAll(() => {
|
|
70
|
-
const connOptions =
|
|
71
|
-
SnowflakeExecutor.getConnectionOptionsFromEnv() ||
|
|
72
|
-
SnowflakeExecutor.getConnectionOptionsFromToml();
|
|
73
|
-
const executor = new SnowflakeExecutor(connOptions);
|
|
74
|
-
db = new SnowflakeExecutorTestSetup(executor);
|
|
75
|
-
query = `
|
|
76
|
-
select
|
|
77
|
-
*
|
|
78
|
-
from
|
|
79
|
-
(
|
|
80
|
-
values
|
|
81
|
-
(1, 'one'),
|
|
82
|
-
(2, 'two'),
|
|
83
|
-
(3, 'three'),
|
|
84
|
-
(4, 'four'),
|
|
85
|
-
(5, 'five')
|
|
86
|
-
);
|
|
87
|
-
`;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
afterAll(async () => {
|
|
91
|
-
await db.done();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('verifies batch execute', async () => {
|
|
95
|
-
const rows = await db.runBatch(query);
|
|
96
|
-
expect(rows.length).toBe(5);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('verifies stream iterable', async () => {
|
|
100
|
-
const rows = await db.runStreaming(query, {rowLimit: 2});
|
|
101
|
-
expect(rows.length).toBe(2);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright Contributors to the Malloy project
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as malloy from '@malloydata/malloy';
|
|
7
|
-
import {SnowflakeConnection} from './snowflake_connection';
|
|
8
|
-
import {SnowflakeExecutor} from './snowflake_executor';
|
|
9
|
-
import crypto from 'crypto';
|
|
10
|
-
|
|
11
|
-
describe('setupSQL', () => {
|
|
12
|
-
const connOptions =
|
|
13
|
-
SnowflakeExecutor.getConnectionOptionsFromEnv() ||
|
|
14
|
-
SnowflakeExecutor.getConnectionOptionsFromToml();
|
|
15
|
-
const uid = crypto.randomBytes(4).toString('hex');
|
|
16
|
-
const connections: SnowflakeConnection[] = [];
|
|
17
|
-
|
|
18
|
-
function makeConn(name: string, setupSQL: string): SnowflakeConnection {
|
|
19
|
-
const conn = new SnowflakeConnection(name, {connOptions, setupSQL});
|
|
20
|
-
connections.push(conn);
|
|
21
|
-
return conn;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
afterAll(async () => {
|
|
25
|
-
await Promise.all(connections.map(c => c.close()));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('runs a single setup statement', async () => {
|
|
29
|
-
const conn = makeConn(
|
|
30
|
-
'snowflake_setup_single',
|
|
31
|
-
`SET setup_test_${uid} = 42`
|
|
32
|
-
);
|
|
33
|
-
const result = await conn.runSQL(`SELECT $setup_test_${uid} AS V`);
|
|
34
|
-
expect(malloy.API.rowDataToNumber(result.rows[0]['V'])).toBe(42);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('runs multiple semicolon-newline-separated statements', async () => {
|
|
38
|
-
const conn = makeConn(
|
|
39
|
-
'snowflake_setup_multi',
|
|
40
|
-
[`SET setup_a_${uid} = 10`, `SET setup_b_${uid} = 20`].join(';\n')
|
|
41
|
-
);
|
|
42
|
-
const result = await conn.runSQL(
|
|
43
|
-
`SELECT $setup_a_${uid} + $setup_b_${uid} AS V`
|
|
44
|
-
);
|
|
45
|
-
expect(malloy.API.rowDataToNumber(result.rows[0]['V'])).toBe(30);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('handles multi-line statements', async () => {
|
|
49
|
-
const conn = makeConn(
|
|
50
|
-
'snowflake_setup_multiline',
|
|
51
|
-
`SET\n setup_ml_${uid} = 99`
|
|
52
|
-
);
|
|
53
|
-
const result = await conn.runSQL(`SELECT $setup_ml_${uid} AS V`);
|
|
54
|
-
expect(malloy.API.rowDataToNumber(result.rows[0]['V'])).toBe(99);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
File without changes
|
|
File without changes
|