@malloydata/db-trino 0.0.235-dev250207190835 → 0.0.235-dev250207192049
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConnectionConfig, MalloyQueryData, PersistSQLResults, QueryData, QueryOptionsReader, QueryRunStats, RunSQLOptions, TrinoDialect, StructDef, TableSourceDef, SQLSourceDef, AtomicTypeDef, Dialect, FieldDef, TestableConnection } from '@malloydata/malloy';
|
|
2
2
|
import { BaseConnection } from '@malloydata/malloy/connection';
|
|
3
3
|
export interface TrinoManagerOptions {
|
|
4
4
|
credentials?: {
|
|
@@ -27,9 +27,10 @@ export interface BaseRunner {
|
|
|
27
27
|
error?: string;
|
|
28
28
|
}[];
|
|
29
29
|
error?: string;
|
|
30
|
+
profilingUrl?: string;
|
|
30
31
|
}>;
|
|
31
32
|
}
|
|
32
|
-
export declare abstract class TrinoPrestoConnection extends BaseConnection implements
|
|
33
|
+
export declare abstract class TrinoPrestoConnection extends BaseConnection implements TestableConnection, PersistSQLResults {
|
|
33
34
|
name: string;
|
|
34
35
|
private client;
|
|
35
36
|
private queryOptions?;
|
|
@@ -65,6 +66,7 @@ export declare abstract class TrinoPrestoConnection extends BaseConnection imple
|
|
|
65
66
|
export declare class PrestoConnection extends TrinoPrestoConnection {
|
|
66
67
|
constructor(name: string, queryOptions?: QueryOptionsReader, config?: TrinoConnectionConfiguration);
|
|
67
68
|
constructor(option: TrinoConnectionOptions, queryOptions?: QueryOptionsReader);
|
|
69
|
+
get dialectName(): string;
|
|
68
70
|
static schemaFromExplain(explainResult: MalloyQueryData, structDef: StructDef, dialect: Dialect): void;
|
|
69
71
|
protected fillStructDefForSqlBlockSchema(sql: string, structDef: StructDef): Promise<void>;
|
|
70
72
|
unpackArray(_fields: FieldDef[], data: unknown): unknown[];
|
|
@@ -72,5 +74,6 @@ export declare class PrestoConnection extends TrinoPrestoConnection {
|
|
|
72
74
|
export declare class TrinoConnection extends TrinoPrestoConnection {
|
|
73
75
|
constructor(name: string, queryOptions?: QueryOptionsReader, config?: TrinoConnectionConfiguration);
|
|
74
76
|
constructor(option: TrinoConnectionOptions, queryOptions?: QueryOptionsReader);
|
|
77
|
+
get dialectName(): string;
|
|
75
78
|
protected fillStructDefForSqlBlockSchema(sql: string, structDef: StructDef): Promise<void>;
|
|
76
79
|
}
|
package/dist/trino_connection.js
CHANGED
|
@@ -30,7 +30,7 @@ const crypto_1 = require("crypto");
|
|
|
30
30
|
const trino_client_1 = require("trino-client");
|
|
31
31
|
class PrestoRunner {
|
|
32
32
|
constructor(config) {
|
|
33
|
-
|
|
33
|
+
const prestoClientConfig = {
|
|
34
34
|
catalog: config.catalog,
|
|
35
35
|
host: config.server,
|
|
36
36
|
port: config.port,
|
|
@@ -38,7 +38,14 @@ class PrestoRunner {
|
|
|
38
38
|
timezone: 'America/Costa_Rica',
|
|
39
39
|
user: config.user || 'anyone',
|
|
40
40
|
extraHeaders: { 'X-Presto-Session': 'legacy_unnest=true' },
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
|
+
if (config.user && config.password) {
|
|
43
|
+
prestoClientConfig.basicAuthentication = {
|
|
44
|
+
user: config.user,
|
|
45
|
+
password: config.password,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
this.client = new presto_js_client_1.PrestoClient(prestoClientConfig);
|
|
42
49
|
}
|
|
43
50
|
async runSQL(sql, limit, _abortSignal) {
|
|
44
51
|
let ret = undefined;
|
|
@@ -180,8 +187,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
180
187
|
if (r.error) {
|
|
181
188
|
throw new Error(r.error);
|
|
182
189
|
}
|
|
183
|
-
const inputRows = r
|
|
184
|
-
const columns = r.columns;
|
|
190
|
+
const { rows: inputRows, columns, profilingUrl } = r;
|
|
185
191
|
const malloyColumns = columns.map(c => (0, malloy_1.mkFieldDef)(this.malloyTypeFromTrinoType(c.type), c.name));
|
|
186
192
|
const malloyRows = [];
|
|
187
193
|
const rows = inputRows !== null && inputRows !== void 0 ? inputRows : [];
|
|
@@ -194,7 +200,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
194
200
|
}
|
|
195
201
|
malloyRows.push(malloyRow);
|
|
196
202
|
}
|
|
197
|
-
return { rows: malloyRows, totalRows: malloyRows.length };
|
|
203
|
+
return { rows: malloyRows, totalRows: malloyRows.length, profilingUrl };
|
|
198
204
|
}
|
|
199
205
|
resultRow(colSchema, rawRow) {
|
|
200
206
|
if (colSchema.type === 'record') {
|
|
@@ -296,7 +302,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
296
302
|
throw new Error('Not implemented 7');
|
|
297
303
|
}
|
|
298
304
|
async test() {
|
|
299
|
-
|
|
305
|
+
await this.runSQL('SELECT 1');
|
|
300
306
|
}
|
|
301
307
|
async close() {
|
|
302
308
|
return;
|
|
@@ -310,6 +316,9 @@ class PrestoConnection extends TrinoPrestoConnection {
|
|
|
310
316
|
constructor(arg, queryOptions, config = {}) {
|
|
311
317
|
super(typeof arg === 'string' ? arg : arg.name, new PrestoRunner(config), queryOptions);
|
|
312
318
|
}
|
|
319
|
+
get dialectName() {
|
|
320
|
+
return 'presto';
|
|
321
|
+
}
|
|
313
322
|
static schemaFromExplain(explainResult, structDef, dialect) {
|
|
314
323
|
if (explainResult.rows.length === 0) {
|
|
315
324
|
throw new Error('Received empty explain result when trying to fetch schema.');
|
|
@@ -339,6 +348,9 @@ class TrinoConnection extends TrinoPrestoConnection {
|
|
|
339
348
|
constructor(arg, queryOptions, config = {}) {
|
|
340
349
|
super(typeof arg === 'string' ? arg : arg.name, new TrinoRunner(config), queryOptions);
|
|
341
350
|
}
|
|
351
|
+
get dialectName() {
|
|
352
|
+
return 'trino';
|
|
353
|
+
}
|
|
342
354
|
async fillStructDefForSqlBlockSchema(sql, structDef) {
|
|
343
355
|
const tmpQueryName = `myMalloyQuery${(0, crypto_1.randomUUID)().replace(/-/g, '')}`;
|
|
344
356
|
await this.executeAndWait(`PREPARE ${tmpQueryName} FROM ${sql}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-trino",
|
|
3
|
-
"version": "0.0.235-
|
|
3
|
+
"version": "0.0.235-dev250207192049",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prepublishOnly": "npm run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@malloydata/malloy": "^0.0.235-
|
|
25
|
+
"@malloydata/malloy": "^0.0.235-dev250207192049",
|
|
26
26
|
"@prestodb/presto-js-client": "^1.0.0",
|
|
27
27
|
"gaxios": "^4.2.0",
|
|
28
28
|
"trino-client": "^0.2.2"
|