@malloydata/db-trino 0.0.138-dev240402185231 → 0.0.138-dev240402223657

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
+ splitColumns(s: string): string[];
62
63
  malloyTypeFromTrinoType(name: string, trinoType: string): FieldAtomicTypeDef | StructDef;
63
64
  structDefFromSchema(rows: string[][], structDef: StructDef): void;
64
65
  private loadSchemaForSqlBlock;
@@ -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,
@@ -27,9 +27,15 @@ const ARRAY_SCHEMA = 'array(integer)';
27
27
  const STRUCT_SCHEMA = 'row(a double, b integer, c varchar(60))';
28
28
  const DEEP_SCHEMA = 'array(row(a double, b integer, c varchar(60)))';
29
29
  describe('Trino connection', () => {
30
+ let connection;
31
+ beforeAll(() => {
32
+ connection = new _1.TrinoConnection('trino', {}, _1.TrinoExecutor.getConnectionOptionsFromEnv());
33
+ });
34
+ afterAll(() => {
35
+ connection.close();
36
+ });
30
37
  describe('schema parser', () => {
31
38
  it('parses arrays', () => {
32
- const connection = new _1.TrinoConnection('trino', {}, _1.TrinoExecutor.getConnectionOptionsFromEnv());
33
39
  expect(connection.malloyTypeFromTrinoType('test', ARRAY_SCHEMA)).toEqual({
34
40
  'name': 'test',
35
41
  'type': 'struct',
@@ -103,5 +109,15 @@ describe('Trino connection', () => {
103
109
  });
104
110
  });
105
111
  });
112
+ describe('splitColumns', () => {
113
+ it('handles internal rows', () => {
114
+ const nested = 'popular_name varchar, airport_count double, by_state array(row(state varchar, airport_count double))';
115
+ expect(connection.splitColumns(nested)).toEqual([
116
+ 'popular_name varchar',
117
+ 'airport_count double',
118
+ 'by_state array(row(state varchar, airport_count double))',
119
+ ]);
120
+ });
121
+ });
106
122
  });
107
123
  //# sourceMappingURL=trino_connection.spec.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-trino",
3
- "version": "0.0.138-dev240402185231",
3
+ "version": "0.0.138-dev240402223657",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",