@malloydata/db-trino 0.0.133-dev240319171426 → 0.0.133
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.d.ts +2 -0
- package/dist/{tmp_index.js → index.js} +6 -1
- package/dist/trino_connection.d.ts +63 -0
- package/dist/trino_connection.js +335 -0
- package/dist/trino_executor.d.ts +4 -0
- package/dist/trino_executor.js +53 -0
- package/package.json +3 -3
- package/dist/tmp_index.d.ts +0 -1
package/dist/index.d.ts
ADDED
|
@@ -22,4 +22,9 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
|
|
25
|
+
exports.TrinoExecutor = exports.TrinoConnection = void 0;
|
|
26
|
+
var trino_connection_1 = require("./trino_connection");
|
|
27
|
+
Object.defineProperty(exports, "TrinoConnection", { enumerable: true, get: function () { return trino_connection_1.TrinoConnection; } });
|
|
28
|
+
var trino_executor_1 = require("./trino_executor");
|
|
29
|
+
Object.defineProperty(exports, "TrinoExecutor", { enumerable: true, get: function () { return trino_executor_1.TrinoExecutor; } });
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Connection, ConnectionConfig, FetchSchemaOptions, MalloyQueryData, FieldAtomicTypeDef, PersistSQLResults, PooledConnection, QueryData, QueryOptionsReader, QueryRunStats, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from '@malloydata/malloy';
|
|
2
|
+
export interface TrinoManagerOptions {
|
|
3
|
+
credentials?: {
|
|
4
|
+
clientId: string;
|
|
5
|
+
clientSecret: string;
|
|
6
|
+
refreshToken: string | null;
|
|
7
|
+
};
|
|
8
|
+
projectId?: string | undefined;
|
|
9
|
+
userAgent: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TrinoConnectionConfiguration {
|
|
12
|
+
server?: string;
|
|
13
|
+
catalog?: string;
|
|
14
|
+
schema?: string;
|
|
15
|
+
user?: string;
|
|
16
|
+
password?: string;
|
|
17
|
+
}
|
|
18
|
+
type TrinoConnectionOptions = ConnectionConfig;
|
|
19
|
+
export declare class TrinoConnection implements Connection, PersistSQLResults {
|
|
20
|
+
trinoToMalloyTypes: {
|
|
21
|
+
[key: string]: FieldAtomicTypeDef;
|
|
22
|
+
};
|
|
23
|
+
private sqlToMalloyType;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
private readonly dialect;
|
|
26
|
+
static DEFAULT_QUERY_OPTIONS: RunSQLOptions;
|
|
27
|
+
private schemaCache;
|
|
28
|
+
private sqlSchemaCache;
|
|
29
|
+
private queryOptions?;
|
|
30
|
+
private config;
|
|
31
|
+
private trino;
|
|
32
|
+
constructor(option: TrinoConnectionOptions, queryOptions?: QueryOptionsReader);
|
|
33
|
+
constructor(name: string, queryOptions?: QueryOptionsReader, config?: TrinoConnectionConfiguration);
|
|
34
|
+
get dialectName(): string;
|
|
35
|
+
private readQueryOptions;
|
|
36
|
+
isPool(): this is PooledConnection;
|
|
37
|
+
canPersist(): this is PersistSQLResults;
|
|
38
|
+
canStream(): this is StreamingConnection;
|
|
39
|
+
get supportsNesting(): boolean;
|
|
40
|
+
manifestTemporaryTable(_sqlCommand: string): Promise<string>;
|
|
41
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions, _rowIndex?: number): Promise<MalloyQueryData>;
|
|
42
|
+
runSQLBlockAndFetchResultSchema(_sqlBlock: SQLBlock, _options?: RunSQLOptions): Promise<{
|
|
43
|
+
data: MalloyQueryData;
|
|
44
|
+
schema: StructDef;
|
|
45
|
+
}>;
|
|
46
|
+
fetchSchemaForTables(missing: Record<string, string>, { refreshTimestamp }: FetchSchemaOptions): Promise<{
|
|
47
|
+
schemas: Record<string, StructDef>;
|
|
48
|
+
errors: Record<string, string>;
|
|
49
|
+
}>;
|
|
50
|
+
private structDefFromTableSchema;
|
|
51
|
+
fetchSchemaForSQLBlock(_sqlRef: SQLBlock, { refreshTimestamp }: FetchSchemaOptions): Promise<{
|
|
52
|
+
structDef: StructDef;
|
|
53
|
+
error?: undefined;
|
|
54
|
+
} | {
|
|
55
|
+
error: string;
|
|
56
|
+
structDef?: undefined;
|
|
57
|
+
}>;
|
|
58
|
+
estimateQueryCost(_sqlCommand: string): Promise<QueryRunStats>;
|
|
59
|
+
executeSQLRaw(_sqlCommand: string): Promise<QueryData>;
|
|
60
|
+
test(): Promise<void>;
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.TrinoConnection = void 0;
|
|
26
|
+
const malloy_1 = require("@malloydata/malloy");
|
|
27
|
+
const trino_client_1 = require("trino-client");
|
|
28
|
+
// manage access to BQ, control costs, enforce global data/API limits
|
|
29
|
+
class TrinoConnection {
|
|
30
|
+
sqlToMalloyType(sqlType) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const baseSqlType = (_b = (_a = sqlType.match(/^(\w+)/)) === null || _a === void 0 ? void 0 : _a.at(0)) !== null && _b !== void 0 ? _b : sqlType;
|
|
33
|
+
if (this.trinoToMalloyTypes[baseSqlType]) {
|
|
34
|
+
return this.trinoToMalloyTypes[baseSqlType];
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
constructor(arg, queryOptions, config = {}) {
|
|
39
|
+
this.trinoToMalloyTypes = {
|
|
40
|
+
'varchar': { type: 'string' },
|
|
41
|
+
'integer': { type: 'number', numberType: 'integer' },
|
|
42
|
+
'bigint': { type: 'number', numberType: 'integer' },
|
|
43
|
+
'double': { type: 'number', numberType: 'float' },
|
|
44
|
+
'string': { type: 'string' },
|
|
45
|
+
'date': { type: 'date' },
|
|
46
|
+
// TODO(figutierrez0): cleanup.
|
|
47
|
+
/* 'INT64': {type: 'number', numberType: 'integer'},
|
|
48
|
+
'FLOAT': {type: 'number', numberType: 'float'},
|
|
49
|
+
'FLOAT64': {type: 'number', numberType: 'float'},
|
|
50
|
+
'NUMERIC': {type: 'number', numberType: 'float'},
|
|
51
|
+
'BIGNUMERIC': {type: 'number', numberType: 'float'},
|
|
52
|
+
'TIMESTAMP': {type: 'timestamp'},
|
|
53
|
+
'BOOLEAN': {type: 'boolean'},
|
|
54
|
+
'BOOL': {type: 'boolean'},
|
|
55
|
+
'JSON': {type: 'json'},*/
|
|
56
|
+
// TODO (https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#tablefieldschema):
|
|
57
|
+
// BYTES
|
|
58
|
+
// DATETIME
|
|
59
|
+
// TIME
|
|
60
|
+
// GEOGRAPHY
|
|
61
|
+
};
|
|
62
|
+
this.dialect = new malloy_1.StandardSQLDialect();
|
|
63
|
+
this.schemaCache = new Map();
|
|
64
|
+
this.sqlSchemaCache = new Map();
|
|
65
|
+
this.name = 'trino';
|
|
66
|
+
/* if (typeof arg === 'string') {
|
|
67
|
+
this.name = arg;
|
|
68
|
+
} else {
|
|
69
|
+
const {name, client_email, private_key, ...args} = arg;
|
|
70
|
+
this.name = name;
|
|
71
|
+
config = args;
|
|
72
|
+
if (client_email || private_key) {
|
|
73
|
+
config.credentials = {
|
|
74
|
+
client_email,
|
|
75
|
+
private_key,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}*/
|
|
79
|
+
// TODO: check user is set.
|
|
80
|
+
this.trino = trino_client_1.Trino.create({
|
|
81
|
+
server: config.server,
|
|
82
|
+
catalog: config.catalog,
|
|
83
|
+
schema: config.schema,
|
|
84
|
+
auth: new trino_client_1.BasicAuth(config.user, config.password),
|
|
85
|
+
});
|
|
86
|
+
this.queryOptions = queryOptions;
|
|
87
|
+
this.config = config;
|
|
88
|
+
}
|
|
89
|
+
get dialectName() {
|
|
90
|
+
return 'trino';
|
|
91
|
+
}
|
|
92
|
+
readQueryOptions() {
|
|
93
|
+
const options = TrinoConnection.DEFAULT_QUERY_OPTIONS;
|
|
94
|
+
if (this.queryOptions) {
|
|
95
|
+
if (this.queryOptions instanceof Function) {
|
|
96
|
+
return { ...options, ...this.queryOptions() };
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return { ...options, ...this.queryOptions };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return options;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
isPool() {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
canPersist() {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
canStream() {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
get supportsNesting() {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
async manifestTemporaryTable(_sqlCommand) {
|
|
119
|
+
throw new Error('not implemented 1');
|
|
120
|
+
}
|
|
121
|
+
/* private async _runSQL(
|
|
122
|
+
sqlCommand: string,
|
|
123
|
+
{rowLimit, abortSignal}: RunSQLOptions = {},
|
|
124
|
+
rowIndex = 0
|
|
125
|
+
): Promise<{
|
|
126
|
+
data: MalloyQueryData;
|
|
127
|
+
schema: Trino.ITableFieldSchema | undefined;
|
|
128
|
+
}> {
|
|
129
|
+
const defaultOptions = this.readQueryOptions();
|
|
130
|
+
const pageSize = rowLimit ?? defaultOptions.rowLimit;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const queryResultsOptions: QueryResultsOptions = {
|
|
134
|
+
maxResults: pageSize,
|
|
135
|
+
startIndex: rowIndex.toString(),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const jobResult = await this.createTrinoJobAndGetResults(
|
|
139
|
+
sqlCommand,
|
|
140
|
+
undefined,
|
|
141
|
+
queryResultsOptions,
|
|
142
|
+
abortSignal
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const totalRows = +(jobResult[2]?.totalRows
|
|
146
|
+
? jobResult[2].totalRows
|
|
147
|
+
: '0');
|
|
148
|
+
|
|
149
|
+
// TODO even though we have 10 minute timeout limit, we still should confirm that resulting metadata has "jobComplete: true"
|
|
150
|
+
const queryCostBytes = jobResult[2]?.totalBytesProcessed;
|
|
151
|
+
const data: MalloyQueryData = {
|
|
152
|
+
rows: jobResult[0],
|
|
153
|
+
totalRows,
|
|
154
|
+
runStats: {
|
|
155
|
+
queryCostBytes: queryCostBytes ? +queryCostBytes : undefined,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const schema = jobResult[2]?.schema;
|
|
159
|
+
|
|
160
|
+
return {data, schema};
|
|
161
|
+
} catch (e) {
|
|
162
|
+
throw maybeRewriteError(e);
|
|
163
|
+
}
|
|
164
|
+
}*/
|
|
165
|
+
async runSQL(sqlCommand, options = {},
|
|
166
|
+
// TODO(figutierrez): Use.
|
|
167
|
+
_rowIndex = 0) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
//sqlCommand = sqlCommand.replace(new RegExp('`', 'g'), '');
|
|
170
|
+
// TODO: default row limit.
|
|
171
|
+
sqlCommand = `SELECT * FROM (${sqlCommand}) limit ${(_a = options.rowLimit) !== null && _a !== void 0 ? _a : 50}`;
|
|
172
|
+
// TODO: fill in with options.
|
|
173
|
+
const result = await this.trino.query(sqlCommand);
|
|
174
|
+
let queryResult = await result.next();
|
|
175
|
+
if (queryResult.value.error) {
|
|
176
|
+
// TODO: handle.
|
|
177
|
+
throw new Error(`Failed to execute sql: ${sqlCommand}. \n Error: ${JSON.stringify(queryResult.value.error)}`);
|
|
178
|
+
}
|
|
179
|
+
const malloyRows = [];
|
|
180
|
+
while (queryResult !== null) {
|
|
181
|
+
const rows = (_b = queryResult.value.data) !== null && _b !== void 0 ? _b : [];
|
|
182
|
+
for (const row of rows) {
|
|
183
|
+
const malloyRow = {};
|
|
184
|
+
for (let i = 0; i < queryResult.value.columns.length; i++) {
|
|
185
|
+
const column = queryResult.value.columns[i];
|
|
186
|
+
// TODO: handle arrays etc.
|
|
187
|
+
if (column.type === 'json') {
|
|
188
|
+
malloyRow[column.name] = JSON.parse(row[i]);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
malloyRow[column.name] = row[i];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
malloyRows.push(malloyRow);
|
|
195
|
+
}
|
|
196
|
+
if (!queryResult.done) {
|
|
197
|
+
queryResult = await result.next();
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// TODO(figutierrez): Remove.
|
|
204
|
+
// eslint-disable-next-line no-console
|
|
205
|
+
console.log(`ROWS: ${JSON.stringify(malloyRows)} ${malloyRows.length}`);
|
|
206
|
+
// TODO: handle totalrows.
|
|
207
|
+
return { rows: malloyRows, totalRows: malloyRows.length };
|
|
208
|
+
}
|
|
209
|
+
async runSQLBlockAndFetchResultSchema(_sqlBlock, _options) {
|
|
210
|
+
/*const {data, schema: schemaRaw} = await this._runSQL(
|
|
211
|
+
sqlBlock.selectStr,
|
|
212
|
+
options
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// TODO need to probably surface the cause of the schema not present error
|
|
216
|
+
if (schemaRaw === undefined) {
|
|
217
|
+
throw new Error('Schema not present');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const schema = this.structDefFromSQLSchema(sqlBlock, schemaRaw);
|
|
221
|
+
return {data, schema};*/
|
|
222
|
+
throw new Error('Not implemented 3');
|
|
223
|
+
}
|
|
224
|
+
async fetchSchemaForTables(missing, { refreshTimestamp }) {
|
|
225
|
+
const schemas = {};
|
|
226
|
+
const errors = {};
|
|
227
|
+
for (const tableKey in missing) {
|
|
228
|
+
let inCache = this.schemaCache.get(tableKey);
|
|
229
|
+
const tablePath = missing[tableKey].replace(/malloytest/g, 'malloy_demo.faa');
|
|
230
|
+
if (!inCache ||
|
|
231
|
+
(refreshTimestamp && refreshTimestamp > inCache.timestamp)) {
|
|
232
|
+
const timestamp = refreshTimestamp !== null && refreshTimestamp !== void 0 ? refreshTimestamp : Date.now();
|
|
233
|
+
try {
|
|
234
|
+
const schema = await this.structDefFromTableSchema(tableKey,
|
|
235
|
+
// TODO: remove.
|
|
236
|
+
tablePath);
|
|
237
|
+
inCache = {
|
|
238
|
+
schema,
|
|
239
|
+
timestamp,
|
|
240
|
+
};
|
|
241
|
+
this.schemaCache.set(tableKey, inCache);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
inCache = { error: error.message, timestamp };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (inCache.schema !== undefined) {
|
|
248
|
+
schemas[tableKey] = inCache.schema;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
errors[tableKey] = inCache.error || 'Unknown schema fetch error';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return { schemas: schemas, errors: errors };
|
|
255
|
+
}
|
|
256
|
+
async structDefFromTableSchema(tableKey, tablePath) {
|
|
257
|
+
var _a, _b;
|
|
258
|
+
const structDef = {
|
|
259
|
+
type: 'struct',
|
|
260
|
+
name: tableKey,
|
|
261
|
+
dialect: this.dialectName,
|
|
262
|
+
structSource: {
|
|
263
|
+
type: 'table',
|
|
264
|
+
tablePath,
|
|
265
|
+
},
|
|
266
|
+
structRelationship: {
|
|
267
|
+
type: 'basetable',
|
|
268
|
+
connectionName: this.name,
|
|
269
|
+
},
|
|
270
|
+
fields: [],
|
|
271
|
+
};
|
|
272
|
+
try {
|
|
273
|
+
const result = await this.trino.query(`DESCRIBE ${tablePath}`);
|
|
274
|
+
const queryResult = await result.next();
|
|
275
|
+
if (queryResult.value.error) {
|
|
276
|
+
// TODO: handle.
|
|
277
|
+
throw new Error(`Failed to grab schema for table ${tablePath}: ${JSON.stringify(queryResult.value.error)}`);
|
|
278
|
+
}
|
|
279
|
+
const rows = (_a = queryResult.value.data) !== null && _a !== void 0 ? _a : [];
|
|
280
|
+
for (const row of rows) {
|
|
281
|
+
const fieldName = row[0];
|
|
282
|
+
const type = row[1];
|
|
283
|
+
const malloyType = (_b = this.sqlToMalloyType(type)) !== null && _b !== void 0 ? _b : {
|
|
284
|
+
type: 'unsupported',
|
|
285
|
+
rawType: type.toLowerCase(),
|
|
286
|
+
};
|
|
287
|
+
structDef.fields.push({ name: fieldName, ...malloyType });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
throw new Error(`Could not fetch schema for table ${tablePath} ${e}`);
|
|
292
|
+
}
|
|
293
|
+
// TODO: handle repeated etc.
|
|
294
|
+
return structDef;
|
|
295
|
+
}
|
|
296
|
+
async fetchSchemaForSQLBlock(_sqlRef,
|
|
297
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
298
|
+
{ refreshTimestamp }) {
|
|
299
|
+
throw new Error('Not implemented 5');
|
|
300
|
+
}
|
|
301
|
+
/* public async downloadMalloyQuery(
|
|
302
|
+
sqlCommand: string
|
|
303
|
+
): Promise<ResourceStream<RowMetadata>> {
|
|
304
|
+
const job = await this.createTrinoJob({
|
|
305
|
+
query: sqlCommand,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
return job.getQueryResultsStream();
|
|
309
|
+
}*/
|
|
310
|
+
async estimateQueryCost(_sqlCommand) {
|
|
311
|
+
/*const dryRunResults = await this.dryRunSQLQuery(sqlCommand);
|
|
312
|
+
return {
|
|
313
|
+
queryCostBytes: Number(
|
|
314
|
+
dryRunResults.metadata.statistics.totalBytesProcessed
|
|
315
|
+
),
|
|
316
|
+
};*/
|
|
317
|
+
throw new Error('Not impld 6');
|
|
318
|
+
}
|
|
319
|
+
async executeSQLRaw(_sqlCommand) {
|
|
320
|
+
/*const result = await this.createTrinoJobAndGetResults(sqlCommand);
|
|
321
|
+
return result[0];*/
|
|
322
|
+
throw new Error('Not implemented 7');
|
|
323
|
+
}
|
|
324
|
+
async test() {
|
|
325
|
+
// await this.dryRunSQLQuery('SELECT 1');
|
|
326
|
+
}
|
|
327
|
+
async close() {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.TrinoConnection = TrinoConnection;
|
|
332
|
+
TrinoConnection.DEFAULT_QUERY_OPTIONS = {
|
|
333
|
+
rowLimit: 10,
|
|
334
|
+
};
|
|
335
|
+
//# sourceMappingURL=trino_connection.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.TrinoExecutor = void 0;
|
|
26
|
+
class TrinoExecutor {
|
|
27
|
+
static getConnectionOptionsFromEnv() {
|
|
28
|
+
const server = process.env['TRINO_SERVER'];
|
|
29
|
+
if (server) {
|
|
30
|
+
const user = process.env['TRINO_USER'];
|
|
31
|
+
if (!user) {
|
|
32
|
+
throw Error('Trino server specified but no user was provided. Set TRINO_USER and TRINO_PASSWORD environment variables');
|
|
33
|
+
}
|
|
34
|
+
const password = process.env['TRINO_PASSWORD'];
|
|
35
|
+
// TODO(figutierrez): We may not need to support these.
|
|
36
|
+
const catalog = process.env['TRINO_CATALOG'];
|
|
37
|
+
const schema = process.env['TRINO_SCHEMA'];
|
|
38
|
+
return {
|
|
39
|
+
server,
|
|
40
|
+
user,
|
|
41
|
+
password,
|
|
42
|
+
catalog,
|
|
43
|
+
schema,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new Error('Tried to get Trino connection from Env, no TRINO_SERVER specified.');
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.TrinoExecutor = TrinoExecutor;
|
|
53
|
+
//# sourceMappingURL=trino_executor.js.map
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-trino",
|
|
3
|
-
"version": "0.0.133
|
|
3
|
+
"version": "0.0.133",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"homepage": "https://github.com/malloydata/malloy#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
package/dist/tmp_index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|