@cubejs-backend/prestodb-driver 0.31.11 → 0.31.13

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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.31.13](https://github.com/cube-js/cube.js/compare/v0.31.12...v0.31.13) (2022-11-08)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Make Trino driver CommonJS compatible ([#5581](https://github.com/cube-js/cube.js/issues/5581)) ([ca8fd4e](https://github.com/cube-js/cube.js/commit/ca8fd4e42f4d8f87667507920f02cbb1a7072763))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.31.12](https://github.com/cube-js/cube.js/compare/v0.31.11...v0.31.12) (2022-11-05)
18
+
19
+
20
+ ### Features
21
+
22
+ * Trino driver ([e58c392](https://github.com/cube-js/cube.js/commit/e58c3924781b65f5631ee241b39a0bee1366273d))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.31.11](https://github.com/cube-js/cube.js/compare/v0.31.10...v0.31.11) (2022-11-02)
7
29
 
8
30
 
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @copyright Cube Dev, Inc.
3
+ * @license Apache-2.0
4
+ * @fileoverview The `PrestoDriver` and related types declaration.
5
+ */
6
+ import { DownloadQueryResultsOptions, DownloadQueryResultsResult, DriverCapabilities, DriverInterface, StreamOptions, StreamTableData, TableStructure, BaseDriver } from '@cubejs-backend/base-driver';
7
+ export declare type PrestoDriverConfiguration = {
8
+ host?: string;
9
+ port?: string;
10
+ catalog?: string;
11
+ schema?: string;
12
+ user?: string;
13
+ basic_auth?: {
14
+ user: string;
15
+ password: string;
16
+ };
17
+ ssl?: string;
18
+ dataSource?: string;
19
+ };
20
+ /**
21
+ * Presto driver class.
22
+ */
23
+ export declare class PrestoDriver extends BaseDriver implements DriverInterface {
24
+ /**
25
+ * Returns default concurrency value.
26
+ */
27
+ static getDefaultConcurrency(): number;
28
+ private config;
29
+ private catalog;
30
+ private client;
31
+ /**
32
+ * Class constructor.
33
+ */
34
+ constructor(config?: PrestoDriverConfiguration);
35
+ testConnection(): Promise<void>;
36
+ query(query: string, values: unknown[]): Promise<any[]>;
37
+ prepareQueryWithParams(query: string, values: unknown[]): string;
38
+ queryPromised(query: string, streaming: boolean): Promise<any[] | StreamTableData>;
39
+ downloadQueryResults(query: string, values: unknown[], options: DownloadQueryResultsOptions): Promise<DownloadQueryResultsResult>;
40
+ normalizeResultOverColumns(data: any[], columns: TableStructure): {
41
+ [x: string]: unknown;
42
+ }[];
43
+ stream(query: string, values: unknown[], _options: StreamOptions): Promise<StreamTableData>;
44
+ capabilities(): DriverCapabilities;
45
+ }
46
+ //# sourceMappingURL=PrestoDriver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrestoDriver.d.ts","sourceRoot":"","sources":["../../src/PrestoDriver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,2BAA2B,EAAE,0BAA0B,EACvD,kBAAkB,EAAE,eAAe,EACnC,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACX,MAAM,6BAA6B,CAAC;AAarC,oBAAY,yBAAyB,GAAG;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAW,YAAW,eAAe;IACrE;;OAEG;WACW,qBAAqB;IAInC,OAAO,CAAC,MAAM,CAA4B;IAE1C,OAAO,CAAC,OAAO,CAAqB;IAEpC,OAAO,CAAC,MAAM,CAAM;IAEpB;;OAEG;gBACgB,MAAM,GAAE,yBAA8B;IA8BlD,cAAc;IAWd,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAIvD,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAMvD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,eAAe,CAAC;IA0DlF,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAOjI,0BAA0B,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,cAAc;;;IAM/D,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC;IAM3F,YAAY,IAAI,kBAAkB;CAK1C"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * @copyright Cube Dev, Inc.
4
+ * @license Apache-2.0
5
+ * @fileoverview The `PrestoDriver` and related types declaration.
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.PrestoDriver = void 0;
12
+ const base_driver_1 = require("@cubejs-backend/base-driver");
13
+ const shared_1 = require("@cubejs-backend/shared");
14
+ const stream_1 = require("stream");
15
+ const ramda_1 = require("ramda");
16
+ const sqlstring_1 = __importDefault(require("sqlstring"));
17
+ const presto = require('presto-client');
18
+ /**
19
+ * Presto driver class.
20
+ */
21
+ class PrestoDriver extends base_driver_1.BaseDriver {
22
+ /**
23
+ * Class constructor.
24
+ */
25
+ constructor(config = {}) {
26
+ super();
27
+ const dataSource = config.dataSource ||
28
+ shared_1.assertDataSource('default');
29
+ this.config = {
30
+ host: shared_1.getEnv('dbHost', { dataSource }),
31
+ port: shared_1.getEnv('dbPort', { dataSource }),
32
+ catalog: shared_1.getEnv('prestoCatalog', { dataSource }) ||
33
+ shared_1.getEnv('dbCatalog', { dataSource }),
34
+ schema: shared_1.getEnv('dbName', { dataSource }) ||
35
+ shared_1.getEnv('dbSchema', { dataSource }),
36
+ user: shared_1.getEnv('dbUser', { dataSource }),
37
+ basic_auth: shared_1.getEnv('dbPass', { dataSource })
38
+ ? {
39
+ user: shared_1.getEnv('dbUser', { dataSource }),
40
+ password: shared_1.getEnv('dbPass', { dataSource }),
41
+ }
42
+ : undefined,
43
+ ssl: this.getSslOptions(dataSource),
44
+ ...config
45
+ };
46
+ this.catalog = this.config.catalog;
47
+ this.client = new presto.Client(this.config);
48
+ }
49
+ /**
50
+ * Returns default concurrency value.
51
+ */
52
+ static getDefaultConcurrency() {
53
+ return 2;
54
+ }
55
+ testConnection() {
56
+ const query = sqlstring_1.default.format('show catalogs like ?', [`%${this.catalog}%`]);
57
+ return this.queryPromised(query, false)
58
+ .then(catalogs => {
59
+ if (catalogs.length === 0) {
60
+ throw new Error(`Catalog not found '${this.catalog}'`);
61
+ }
62
+ });
63
+ }
64
+ query(query, values) {
65
+ return this.queryPromised(this.prepareQueryWithParams(query, values), false);
66
+ }
67
+ prepareQueryWithParams(query, values) {
68
+ return sqlstring_1.default.format(query, (values || []).map(value => (typeof value === 'string' ? {
69
+ toSqlString: () => sqlstring_1.default.escape(value).replace(/\\\\([_%])/g, '\\$1'),
70
+ } : value)));
71
+ }
72
+ queryPromised(query, streaming) {
73
+ const toError = (error) => new Error(error.error ? `${error.message}\n${error.error}` : error.message);
74
+ if (streaming) {
75
+ const rowStream = new stream_1.Transform({
76
+ writableObjectMode: true,
77
+ readableObjectMode: true,
78
+ transform(obj, encoding, callback) {
79
+ callback(null, obj);
80
+ }
81
+ });
82
+ return new Promise((resolve, reject) => {
83
+ this.client.execute({
84
+ query,
85
+ schema: this.config.schema || 'default',
86
+ columns: (error, columns) => {
87
+ resolve({
88
+ rowStream,
89
+ types: columns
90
+ });
91
+ },
92
+ data: (error, data, columns) => {
93
+ const normalData = this.normalizeResultOverColumns(data, columns);
94
+ for (const obj of normalData) {
95
+ rowStream.write(obj);
96
+ }
97
+ },
98
+ success: () => {
99
+ rowStream.end();
100
+ },
101
+ error: (error) => {
102
+ reject(toError(error));
103
+ }
104
+ });
105
+ });
106
+ }
107
+ else {
108
+ return new Promise((resolve, reject) => {
109
+ let fullData = [];
110
+ this.client.execute({
111
+ query,
112
+ schema: this.config.schema || 'default',
113
+ data: (error, data, columns) => {
114
+ const normalData = this.normalizeResultOverColumns(data, columns);
115
+ fullData = ramda_1.concat(normalData, fullData);
116
+ },
117
+ success: () => {
118
+ resolve(fullData);
119
+ },
120
+ error: (error) => {
121
+ reject(toError(error));
122
+ }
123
+ });
124
+ });
125
+ }
126
+ }
127
+ downloadQueryResults(query, values, options) {
128
+ if (options.streamImport) {
129
+ return this.stream(query, values, options);
130
+ }
131
+ return super.downloadQueryResults(query, values, options);
132
+ }
133
+ normalizeResultOverColumns(data, columns) {
134
+ const columnNames = ramda_1.map(ramda_1.prop('name'), columns || []);
135
+ const arrayToObject = ramda_1.zipObj(columnNames);
136
+ return ramda_1.map(arrayToObject, data || []);
137
+ }
138
+ stream(query, values, _options) {
139
+ const queryWithParams = this.prepareQueryWithParams(query, values);
140
+ return this.queryPromised(queryWithParams, true);
141
+ }
142
+ capabilities() {
143
+ return {
144
+ unloadWithoutTempTable: true
145
+ };
146
+ }
147
+ }
148
+ exports.PrestoDriver = PrestoDriver;
149
+ //# sourceMappingURL=PrestoDriver.js.map
@@ -0,0 +1 @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AO,WAAG,CAAC,aAAa,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,KAAa,EAAE,MAAiB,EAAE,QAAuB;QACrE,MAAM,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAEnE,OAAkC,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IAEM,YAAY;QACjB,OAAO;YACL,sBAAsB,EAAE,IAAI;SAC7B,CAAC;IACJ,CAAC;CACF;AAtJD,oCAsJC"}
@@ -0,0 +1,4 @@
1
+ import { PrestoDriver } from './PrestoDriver';
2
+ export default PrestoDriver;
3
+ export { PrestoDriver };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAe,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrestoDriver = void 0;
4
+ const PrestoDriver_1 = require("./PrestoDriver");
5
+ Object.defineProperty(exports, "PrestoDriver", { enumerable: true, get: function () { return PrestoDriver_1.PrestoDriver; } });
6
+ exports.default = PrestoDriver_1.PrestoDriver;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAGrC,6FAHA,2BAAY,OAGA;AADrB,kBAAe,2BAAY,CAAC"}
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ const fromExports = require('./dist/src');
2
+ const { PrestoDriver } = require('./dist/src/PrestoDriver');
3
+
4
+ const toExport = PrestoDriver;
5
+
6
+ // eslint-disable-next-line no-restricted-syntax
7
+ for (const [key, module] of Object.entries(fromExports)) {
8
+ toExport[key] = module;
9
+ }
10
+
11
+ module.exports = toExport;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@cubejs-backend/prestodb-driver",
3
3
  "description": "Cube.js Presto database driver",
4
4
  "author": "Cube Dev, Inc.",
5
- "version": "0.31.11",
5
+ "version": "0.31.13",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/cube-js/cube.js.git",
@@ -11,17 +11,25 @@
11
11
  "engines": {
12
12
  "node": "^12.0.0 || ^14.0.0 || >=16.0.0"
13
13
  },
14
- "main": "driver/PrestoDriver.js",
14
+ "files": [
15
+ "dist/src",
16
+ "index.js"
17
+ ],
18
+ "main": "index.js",
19
+ "typings": "dist/src/index.d.ts",
15
20
  "scripts": {
16
- "integration": "mocha",
17
- "integration:presto": "mocha",
18
- "lint": "eslint **/*.js",
19
- "lint:fix": "eslint --fix **/*.js"
21
+ "build": "rm -rf dist && npm run tsc",
22
+ "tsc": "tsc",
23
+ "watch": "tsc -w",
24
+ "integration": "jest dist/test",
25
+ "integration:presto": "jest dist/test",
26
+ "lint": "eslint src/* --ext .ts",
27
+ "lint:fix": "eslint --fix src/* --ext .ts"
20
28
  },
21
29
  "dependencies": {
22
- "@cubejs-backend/base-driver": "^0.31.11",
23
- "@cubejs-backend/shared": "^0.31.0",
24
- "presto-client": "^0.12.1",
30
+ "@cubejs-backend/base-driver": "^0.31.13",
31
+ "@cubejs-backend/shared": "^0.31.13",
32
+ "presto-client": "^0.12.2",
25
33
  "ramda": "^0.27.0",
26
34
  "sqlstring": "^2.3.1"
27
35
  },
@@ -31,12 +39,13 @@
31
39
  },
32
40
  "devDependencies": {
33
41
  "@cubejs-backend/linter": "^0.31.0",
34
- "mocha": "^8.1.3",
42
+ "jest": "^26.6.3",
35
43
  "should": "^13.2.3",
36
- "testcontainers": "^8.12"
44
+ "testcontainers": "^8.12",
45
+ "typescript": "~4.1.5"
37
46
  },
38
47
  "eslintConfig": {
39
48
  "extends": "../cubejs-linter"
40
49
  },
41
- "gitHead": "37e3849be3db4a5a44c0cc6205851bdcd4c70009"
50
+ "gitHead": "a304fb5d37667569e2ee70c633587d096945a7b0"
42
51
  }
@@ -1,4 +0,0 @@
1
- connector.name=postgresql
2
- connection-url=jdbc:postgresql://postgres:5432/presto
3
- connection-user=presto
4
- connection-password=9bee2c3975024292eff5829526722ac2
@@ -1,13 +0,0 @@
1
- version: '2.2'
2
-
3
- services:
4
- coordinator:
5
- image: trinodb/trino
6
- ports:
7
- - "8080:8080"
8
- container_name: "coordinator"
9
- healthcheck:
10
- test: "trino --execute 'SELECT 1' || exit 1"
11
- interval: 10s
12
- timeout: 5s
13
- retries: 5
@@ -1,109 +0,0 @@
1
- /**
2
- * @copyright Cube Dev, Inc.
3
- * @license Apache-2.0
4
- * @fileoverview The `PrestoDriver` and related types declaration.
5
- */
6
-
7
- const {
8
- getEnv,
9
- assertDataSource,
10
- } = require('@cubejs-backend/shared');
11
- const presto = require('presto-client');
12
- const {
13
- map, zipObj, prop, concat
14
- } = require('ramda');
15
- const { BaseDriver } = require('@cubejs-backend/base-driver');
16
- const SqlString = require('sqlstring');
17
-
18
- /**
19
- * Presto driver class.
20
- */
21
- class PrestoDriver extends BaseDriver {
22
- /**
23
- * Returns default concurrency value.
24
- */
25
- static getDefaultConcurrency() {
26
- return 2;
27
- }
28
-
29
- /**
30
- * Class constructor.
31
- */
32
- constructor(config = {}) {
33
- super();
34
-
35
- const dataSource =
36
- config.dataSource ||
37
- assertDataSource('default');
38
-
39
- this.config = {
40
- host: getEnv('dbHost', { dataSource }),
41
- port: getEnv('dbPort', { dataSource }),
42
- catalog:
43
- getEnv('prestoCatalog', { dataSource }) ||
44
- getEnv('dbCatalog', { dataSource }),
45
- schema:
46
- getEnv('dbName', { dataSource }) ||
47
- getEnv('dbSchema', { dataSource }),
48
- user: getEnv('dbUser', { dataSource }),
49
- basic_auth: getEnv('dbPass', { dataSource })
50
- ? {
51
- user: getEnv('dbUser', { dataSource }),
52
- password: getEnv('dbPass', { dataSource }),
53
- }
54
- : undefined,
55
- ssl: this.getSslOptions(dataSource),
56
- ...config
57
- };
58
- this.catalog = this.config.catalog;
59
- this.client = new presto.Client(this.config);
60
- }
61
-
62
- testConnection() {
63
- const query = SqlString.format('show catalogs like ?', [`%${this.catalog}%`]);
64
-
65
- return this.queryPromised(query)
66
- .then(catalogs => {
67
- if (catalogs.length === 0) {
68
- throw new Error(`Catalog not found '${this.catalog}'`);
69
- }
70
- });
71
- }
72
-
73
- query(query, values) {
74
- const queryWithParams = SqlString.format(query, (values || []).map(value => (typeof s === 'string' ? {
75
- toSqlString: () => SqlString.escape(value).replace(/\\\\([_%])/g, '\\$1')
76
- } : value)));
77
-
78
- return this.queryPromised(queryWithParams);
79
- }
80
-
81
- queryPromised(query) {
82
- return new Promise((resolve, reject) => {
83
- let fullData = [];
84
-
85
- this.client.execute({
86
- query,
87
- schema: this.config.schema || 'default',
88
- data: (error, data, columns) => {
89
- const normalData = this.normalizeResultOverColumns(data, columns);
90
- fullData = concat(normalData, fullData);
91
- },
92
- success: () => {
93
- resolve(fullData);
94
- },
95
- error: error => {
96
- reject(new Error(`${error.message}\n${error.error}`));
97
- }
98
- });
99
- });
100
- }
101
-
102
- normalizeResultOverColumns(data, columns) {
103
- const columnNames = map(prop('name'), columns || []);
104
- const arrayToObject = zipObj(columnNames);
105
- return map(arrayToObject, data || []);
106
- }
107
- }
108
-
109
- module.exports = PrestoDriver;
@@ -1,85 +0,0 @@
1
- /* globals describe, before, after, it */
2
- const path = require('path');
3
- const { DockerComposeEnvironment, Wait } = require('testcontainers');
4
-
5
- const PrestoDriver = require('../driver/PrestoDriver');
6
-
7
- require('should');
8
-
9
- describe('PrestoHouseDriver', () => {
10
- let env;
11
- let config;
12
-
13
- const doWithDriver = async (callback) => {
14
- const driver = new PrestoDriver(config);
15
-
16
- await callback(driver);
17
- };
18
-
19
- // eslint-disable-next-line consistent-return,func-names
20
- before(async function () {
21
- this.timeout(6 * 60 * 1000);
22
-
23
- const authOpts = {
24
- basic_auth: {
25
- user: 'presto',
26
- password: ''
27
- }
28
- };
29
-
30
- if (process.env.TEST_PRESTO_HOST) {
31
- config = {
32
- host: process.env.TEST_PRESTO_HOST || 'localhost',
33
- port: process.env.TEST_PRESTO_PORT || '8080',
34
- catalog: process.env.TEST_PRESTO_CATALOG || 'tpch',
35
- schema: 'sf1',
36
- ...authOpts
37
- };
38
-
39
- return;
40
- }
41
-
42
- const dc = new DockerComposeEnvironment(
43
- path.resolve(path.dirname(__filename), '../'),
44
- 'docker-compose.yml'
45
- );
46
-
47
- env = await dc
48
- .withStartupTimeout(240 * 1000)
49
- .withWaitStrategy('coordinator', Wait.forHealthCheck())
50
- .up();
51
-
52
- config = {
53
- host: env.getContainer('coordinator').getHost(),
54
- port: env.getContainer('coordinator').getMappedPort(8080),
55
- catalog: 'tpch',
56
- schema: 'sf1',
57
- ...authOpts
58
- };
59
- });
60
-
61
- // eslint-disable-next-line consistent-return,func-names
62
- after(async function () {
63
- this.timeout(30 * 1000);
64
-
65
- if (env) {
66
- await env.down();
67
- }
68
- });
69
-
70
- it('should construct', async () => {
71
- await doWithDriver(() => {
72
- //
73
- });
74
- });
75
-
76
- // eslint-disable-next-line func-names
77
- it('should test connection', async function () {
78
- // Presto can be slow after starting...
79
- this.timeout(10 * 1000);
80
-
81
- await doWithDriver(async (driver) => {
82
- await driver.testConnection();
83
- });
84
- });
85
- });