@lightdash/warehouses 3.388.0 → 3.390.0

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,6 +1,6 @@
1
1
  import { ConnectionOptions } from '@databricks/sql/dist/contracts/IDBSQLClient';
2
2
  import { TTypeId as DatabricksDataTypes } from '@databricks/sql/thrift/TCLIService_types';
3
- import { AnyType, CreateDatabricksCredentials, Metric, SupportedDbtAdapter, TimeIntervalUnit, UnnestSql, UnnestSqlArgs, WarehouseResults, WarehouseTypes, type ResultNumericKind, type TimestampDomain } from '@lightdash/common';
3
+ import { AnyType, CreateDatabricksCredentials, Metric, SupportedDbtAdapter, TimeIntervalUnit, UnnestSql, UnnestSqlArgs, WarehouseResults, WarehouseTypes, type ResultNumericKind, type TableListingFailure, type TimestampDomain, type WarehouseTableMetadata } from '@lightdash/common';
4
4
  import { type RequestInit } from 'node-fetch';
5
5
  import { WarehouseCatalog } from '../types';
6
6
  import WarehouseBaseClient from './WarehouseBaseClient';
@@ -48,6 +48,8 @@ export declare enum DatabricksErrorCondition {
48
48
  ParseSyntaxError = "PARSE_SYNTAX_ERROR"
49
49
  }
50
50
  export declare const getDatabricksErrorCondition: (error: unknown) => DatabricksErrorCondition | undefined;
51
+ /** Reads why `information_schema.tables` could not be listed; `other` when the message names no known reason. */
52
+ export declare const getDatabricksTableListingFailure: (error: unknown, configuredCatalog: string | null) => TableListingFailure;
51
53
  export declare class DatabricksWarehouseClient extends WarehouseBaseClient<CreateDatabricksCredentials> {
52
54
  schema: string;
53
55
  catalog?: string;
@@ -66,7 +68,9 @@ export declare class DatabricksWarehouseClient extends WarehouseBaseClient<Creat
66
68
  timezone?: string;
67
69
  }): Promise<void>;
68
70
  private static fetchAllRows;
71
+ private static describeAsJson;
69
72
  private static getTableColumns;
73
+ getTableMetadata(tableName: string, schema: string, database: string): Promise<WarehouseTableMetadata | null>;
70
74
  getCatalog(requests: {
71
75
  database: string;
72
76
  schema: string;
@@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,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAgCxD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,SAC9B,MAAM,YACF,MAAM,gBACF,MAAM,iBACL,MAAM,cACT,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,KACvC,OAAO,CAAC;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACrB,CAsCA,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.refreshDatabricksOAuthToken = exports.exchangeDatabricksOAuthCredentials = exports.DatabricksWarehouseClient = exports.getDatabricksErrorCondition = exports.DatabricksErrorCondition = exports.DatabricksSqlBuilder = exports.getDatabricksTimestampDomain = exports.getDatabricksNumericKind = exports.isDatabricksCliOAuthClientId = exports.DATABRICKS_DEFAULT_OAUTH_CLIENT_ID = void 0;
6
+ exports.refreshDatabricksOAuthToken = exports.exchangeDatabricksOAuthCredentials = exports.DatabricksWarehouseClient = exports.getDatabricksTableListingFailure = exports.getDatabricksErrorCondition = exports.DatabricksErrorCondition = exports.DatabricksSqlBuilder = exports.getDatabricksTimestampDomain = exports.getDatabricksNumericKind = exports.isDatabricksCliOAuthClientId = exports.DATABRICKS_DEFAULT_OAUTH_CLIENT_ID = void 0;
7
7
  const sql_1 = require("@databricks/sql");
8
8
  const StatusError_1 = __importDefault(require("@databricks/sql/dist/errors/StatusError"));
9
9
  const TCLIService_types_1 = require("@databricks/sql/thrift/TCLIService_types");
@@ -311,6 +311,35 @@ const flattenDescribedFields = (fields, prefix = '') => {
311
311
  ];
312
312
  });
313
313
  };
314
+ const nonEmptyString = (value) => typeof value === 'string' && value.trim() !== '' ? value : null;
315
+ // Picks named fields of a JSON table description; never spread it, it carries owner, location and properties.
316
+ const getDescribedTableMetadata = (description) => {
317
+ const definition = nonEmptyString(description.view_text);
318
+ return {
319
+ tableType: description.type === 'METRIC_VIEW'
320
+ ? common_1.METRIC_VIEW_TABLE_TYPE
321
+ : (0, common_1.getWarehouseTableType)(description.type),
322
+ comment: nonEmptyString(description.comment),
323
+ columns: (Array.isArray(description.columns)
324
+ ? description.columns
325
+ : []).flatMap((column) => isRecord(column) && typeof column.name === 'string'
326
+ ? [
327
+ {
328
+ name: column.name,
329
+ type: mapFieldType(isRecord(column.type)
330
+ ? describeNode(column.type).typeName
331
+ : DatabricksTypes.STRING),
332
+ comment: nonEmptyString(column.comment),
333
+ isMeasure: column.is_measure === true,
334
+ },
335
+ ]
336
+ : []),
337
+ definition: definition === null ? null : (0, common_1.truncateTableDefinition)(definition),
338
+ metricView: description.type === 'METRIC_VIEW' && definition !== null
339
+ ? (0, common_1.parseMetricViewDefinition)(definition)
340
+ : null,
341
+ };
342
+ };
314
343
  const getDatabricksErrorMessage = (error) => error instanceof StatusError_1.default && error.message
315
344
  ? error.message
316
345
  : (0, common_1.getErrorMessage)(error);
@@ -334,6 +363,54 @@ const getDatabricksErrorCondition = (error) => {
334
363
  return Object.values(DatabricksErrorCondition).find((known) => known === condition);
335
364
  };
336
365
  exports.getDatabricksErrorCondition = getDatabricksErrorCondition;
366
+ const splitSecurable = (name) => name.replaceAll('`', '').split('.').filter(Boolean);
367
+ /** Reads why `information_schema.tables` could not be listed; `other` when the message names no known reason. */
368
+ const getDatabricksTableListingFailure = (error, configuredCatalog) => {
369
+ const message = getDatabricksErrorMessage(error);
370
+ const quoted = /['`]([^'`\s]+)['`]/.exec(message)?.[1];
371
+ if (/\b(NO_SUCH_CATALOG_EXCEPTION|CATALOG_NOT_FOUND)\b/.test(message) ||
372
+ /Catalog '[^']+' was not found/.test(message)) {
373
+ return {
374
+ kind: 'catalog_not_found',
375
+ catalog: quoted ? splitSecurable(quoted)[0] : configuredCatalog,
376
+ message,
377
+ };
378
+ }
379
+ if (/\b(TABLE_OR_VIEW_NOT_FOUND|SCHEMA_NOT_FOUND)\b/.test(message) &&
380
+ /information_schema/i.test(message)) {
381
+ return {
382
+ kind: 'no_information_schema',
383
+ catalog: configuredCatalog,
384
+ message,
385
+ };
386
+ }
387
+ const missingGrant = /does not have (?:permission )?([A-Z][A-Z_ ]*?) on (?:(Catalog|Schema|Table|View) )?['`]?([\w.`-]+?)['`]?\.?(?:\s|$)/.exec(message);
388
+ if (missingGrant ||
389
+ /\b(INSUFFICIENT_PERMISSIONS\w*|PERMISSION_DENIED)\b/.test(message)) {
390
+ const securable = missingGrant?.[3] ?? quoted;
391
+ const parts = securable ? splitSecurable(securable) : [];
392
+ const type = missingGrant?.[2];
393
+ const depths = {
394
+ Catalog: 1,
395
+ Schema: 2,
396
+ Table: 3,
397
+ View: 3,
398
+ };
399
+ const depth = type ? depths[type] : null;
400
+ // Right-align a partly qualified name to catalog.schema.table
401
+ const padding = Array.from({ length: depth === null ? 0 : depth - parts.length }, () => null);
402
+ const aligned = [...padding, ...parts];
403
+ return {
404
+ kind: 'missing_privilege',
405
+ privilege: missingGrant?.[1] ?? null,
406
+ catalog: aligned[0] ?? null,
407
+ schema: depth === 1 ? null : (aligned[1] ?? null),
408
+ message,
409
+ };
410
+ }
411
+ return { kind: 'other', message };
412
+ };
413
+ exports.getDatabricksTableListingFailure = getDatabricksTableListingFailure;
337
414
  // Don't let close errors override the original error
338
415
  const closeQuietly = async (close, context) => {
339
416
  try {
@@ -529,13 +606,9 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
529
606
  }
530
607
  }
531
608
  }
532
- // DESCRIBE ... AS JSON gives the nested tree; older all-purpose clusters
533
- // reject the JSON form, so those tables keep the flat column list and
534
- // carry the reason for the compiler to surface.
535
- // DESCRIBE ... AS JSON gives the nested tree. A runtime that does not know
536
- // the JSON form rejects the statement itself; only that case falls back
537
- // to the flat column list, any other failure fails the fetch as before.
538
- static async getTableColumns(session, request) {
609
+ // A runtime that does not know the JSON form rejects the statement itself;
610
+ // only that case is `unsupported`, any other failure throws.
611
+ static async describeAsJson(session, request) {
539
612
  const q = '`';
540
613
  const tableRef = `${q}${request.database}${q}.${q}${request.schema}${q}.${q}${request.table}${q}`;
541
614
  let rows;
@@ -545,26 +618,15 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
545
618
  catch (e) {
546
619
  const condition = (0, exports.getDatabricksErrorCondition)(e);
547
620
  if (condition === DatabricksErrorCondition.TableOrViewNotFound) {
548
- return { discovery: 'described', columns: [] };
621
+ return { kind: 'not_found' };
549
622
  }
550
623
  if ((0, DatabricksWarehouseStartupRetry_1.isDatabricksWarehouseStartingError)(e) ||
551
624
  condition !== DatabricksErrorCondition.ParseSyntaxError) {
552
625
  throw e;
553
626
  }
554
- const message = getDatabricksErrorMessage(e);
555
- const flatColumns = (await DatabricksWarehouseClient.fetchAllRows(session.getColumns({
556
- catalogName: request.database,
557
- schemaName: request.schema,
558
- tableName: request.table,
559
- }), 'getCatalog'));
560
627
  return {
561
- discovery: 'unsupported',
562
- columns: flatColumns.map((column) => ({
563
- path: column.COLUMN_NAME,
564
- typeName: column.TYPE_NAME,
565
- shape: undefined,
566
- })),
567
- reason: `Databricks did not describe ${request.table} as JSON (${message}); nested columns need a SQL warehouse or Databricks Runtime 16.2 or newer.`,
628
+ kind: 'unsupported',
629
+ message: getDatabricksErrorMessage(e),
568
630
  };
569
631
  }
570
632
  const json = rows[0] ? Object.values(rows[0])[0] : undefined;
@@ -573,15 +635,57 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
573
635
  if (!isRecord(description) || !Array.isArray(description.columns)) {
574
636
  throw new Error('no columns in the JSON description');
575
637
  }
576
- return {
577
- discovery: 'described',
578
- columns: flattenDescribedFields(description.columns),
579
- };
638
+ return { kind: 'described', description };
580
639
  }
581
640
  catch (e) {
582
641
  throw new common_1.WarehouseQueryError(`Could not read the description of ${tableRef}: ${(0, common_1.getErrorMessage)(e)}`);
583
642
  }
584
643
  }
644
+ // DESCRIBE ... AS JSON gives the nested tree; older all-purpose clusters
645
+ // reject the JSON form, so those tables keep the flat column list and
646
+ // carry the reason for the compiler to surface.
647
+ static async getTableColumns(session, request) {
648
+ const described = await DatabricksWarehouseClient.describeAsJson(session, request);
649
+ switch (described.kind) {
650
+ case 'described':
651
+ return {
652
+ discovery: 'described',
653
+ columns: flattenDescribedFields(described.description.columns),
654
+ };
655
+ case 'not_found':
656
+ return { discovery: 'described', columns: [] };
657
+ case 'unsupported': {
658
+ const flatColumns = (await DatabricksWarehouseClient.fetchAllRows(session.getColumns({
659
+ catalogName: request.database,
660
+ schemaName: request.schema,
661
+ tableName: request.table,
662
+ }), 'getCatalog'));
663
+ return {
664
+ discovery: 'unsupported',
665
+ columns: flatColumns.map((column) => ({
666
+ path: column.COLUMN_NAME,
667
+ typeName: column.TYPE_NAME,
668
+ shape: undefined,
669
+ })),
670
+ reason: `Databricks did not describe ${request.table} as JSON (${described.message}); nested columns need a SQL warehouse or Databricks Runtime 16.2 or newer.`,
671
+ };
672
+ }
673
+ default:
674
+ return (0, common_1.assertUnreachable)(described, 'Unknown Databricks table description');
675
+ }
676
+ }
677
+ async getTableMetadata(tableName, schema, database) {
678
+ const { session, close } = await this.openSession(new DatabricksWarehouseStartupRetry_1.DatabricksWarehouseStartupRetry());
679
+ try {
680
+ const described = await DatabricksWarehouseClient.describeAsJson(session, { database, schema, table: tableName });
681
+ return described.kind === 'described'
682
+ ? getDescribedTableMetadata(described.description)
683
+ : null;
684
+ }
685
+ finally {
686
+ await closeQuietly(close, 'getTableMetadata');
687
+ }
688
+ }
585
689
  async getCatalog(requests) {
586
690
  const retry = new DatabricksWarehouseStartupRetry_1.DatabricksWarehouseStartupRetry();
587
691
  const results = new Map();
@@ -662,7 +766,16 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
662
766
  WHERE table_schema <> 'information_schema'
663
767
  ORDER BY 1,2,3
664
768
  `;
665
- const { rows } = await this.runQuery(query, {}, undefined, undefined);
769
+ let rows;
770
+ try {
771
+ ({ rows } = await this.runQuery(query, {}, undefined, undefined));
772
+ }
773
+ catch (e) {
774
+ const failure = (0, exports.getDatabricksTableListingFailure)(e, this.catalog ?? null);
775
+ if (failure.kind === 'other')
776
+ throw e;
777
+ throw new common_1.WarehouseTableListingError(failure);
778
+ }
666
779
  return rows.map((row) => ({
667
780
  database: row.table_catalog,
668
781
  schema: row.table_schema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/warehouses",
3
- "version": "3.388.0",
3
+ "version": "3.390.0",
4
4
  "description": "Warehouse connectors for Lightdash",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "@databricks/sql": "1.13.0",
22
22
  "@duckdb/node-api": "1.5.2-r.2",
23
23
  "@google-cloud/bigquery": "8.3.1",
24
- "@lightdash/common": "3.388.0",
24
+ "@lightdash/common": "3.390.0",
25
25
  "node-fetch": "2.7.0",
26
26
  "pg": "8.13.1",
27
27
  "pg-cursor": "2.10.0",