@malloydata/db-trino 0.0.138-dev240402171233 → 0.0.138-dev240402220928

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.
@@ -59,6 +59,7 @@ export declare class TrinoConnection implements Connection, PersistSQLResults {
59
59
  }>;
60
60
  private structDefFromSqlBlock;
61
61
  private executeAndWait;
62
+ private splitColumns;
62
63
  malloyTypeFromTrinoType(name: string, trinoType: string): FieldAtomicTypeDef | StructDef;
63
64
  structDefFromSchema(rows: string[][], structDef: StructDef): void;
64
65
  private loadSchemaForSqlBlock;
@@ -174,7 +174,6 @@ class TrinoConnection {
174
174
  return col;
175
175
  }
176
176
  convertNest(structDef, dataRows) {
177
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
178
177
  const ret = [];
179
178
  if (structDef.structRelationship.type === 'nested' &&
180
179
  !structDef.structRelationship.isArray) {
@@ -193,7 +192,8 @@ class TrinoConnection {
193
192
  let queryResult = await result.next();
194
193
  if (queryResult.value.error) {
195
194
  // TODO: handle.
196
- throw new Error(`Failed to execute sql: ${sqlCommand}. \n Error: ${JSON.stringify(queryResult.value.error)}`);
195
+ const { failureInfo: _, ...error } = queryResult.value.error;
196
+ throw new Error(`Failed to execute sql: ${sqlCommand}. \n Error: ${JSON.stringify(error)}`);
197
197
  }
198
198
  const malloyColumns = queryResult.value.columns.map(c => this.malloyTypeFromTrinoType(c.name, c.type));
199
199
  // Debugging types
@@ -340,6 +340,37 @@ class TrinoConnection {
340
340
  while (!(await result.next()).done)
341
341
  ;
342
342
  }
343
+ splitColumns(s) {
344
+ const columns = [];
345
+ let parens = 0;
346
+ let column = '';
347
+ let eatSpaces = true;
348
+ for (let idx = 0; idx < s.length; idx++) {
349
+ const c = s.charAt(idx);
350
+ if (eatSpaces && c === ' ') {
351
+ // Eat space
352
+ }
353
+ else {
354
+ eatSpaces = false;
355
+ if (!parens && c === ',') {
356
+ columns.push(column);
357
+ column = '';
358
+ eatSpaces = true;
359
+ }
360
+ else {
361
+ column += c;
362
+ }
363
+ if (c === '(') {
364
+ parens += 1;
365
+ }
366
+ else if (c === ')') {
367
+ parens -= 1;
368
+ }
369
+ }
370
+ }
371
+ columns.push(column);
372
+ return columns;
373
+ }
343
374
  malloyTypeFromTrinoType(name, trinoType) {
344
375
  var _a;
345
376
  let malloyType;
@@ -377,7 +408,7 @@ class TrinoConnection {
377
408
  // TODO: Trino doesn't quote or escape commas in field names,
378
409
  // so some magic is going to need to be applied before we get here
379
410
  // to avoid confusion if a field name contains a comma
380
- const innerTypes = structMatch[1].split(/,\s+/);
411
+ const innerTypes = this.splitColumns(structMatch[1]);
381
412
  malloyType = {
382
413
  type: 'struct',
383
414
  name,
@@ -421,7 +452,7 @@ class TrinoConnection {
421
452
  structDefFromSchema(rows, structDef) {
422
453
  for (const row of rows) {
423
454
  const name = row[0];
424
- const type = row[1] || row[4];
455
+ const type = row[4] || row[1];
425
456
  const malloyType = this.malloyTypeFromTrinoType(name, type);
426
457
  // console.log('>', row, '\n<', malloyType);
427
458
  structDef.fields.push({ name, ...malloyType });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-trino",
3
- "version": "0.0.138-dev240402171233",
3
+ "version": "0.0.138-dev240402220928",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",