@lightdash/warehouses 3.389.0 → 3.390.1
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 TableListingFailure, 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';
|
|
@@ -68,7 +68,9 @@ export declare class DatabricksWarehouseClient extends WarehouseBaseClient<Creat
|
|
|
68
68
|
timezone?: string;
|
|
69
69
|
}): Promise<void>;
|
|
70
70
|
private static fetchAllRows;
|
|
71
|
+
private static describeAsJson;
|
|
71
72
|
private static getTableColumns;
|
|
73
|
+
getTableMetadata(tableName: string, schema: string, database: string): Promise<WarehouseTableMetadata | null>;
|
|
72
74
|
getCatalog(requests: {
|
|
73
75
|
database: string;
|
|
74
76
|
schema: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabricksWarehouseClient.d.ts","sourceRoot":"","sources":["../../src/warehouseClients/DatabricksWarehouseClient.ts"],"names":[],"mappings":"AACA,OAAqB,EACjB,iBAAiB,EACpB,MAAM,6CAA6C,CAAC;AAIrD,OAAO,EAAE,OAAO,IAAI,mBAAmB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AAO,CAAC,KACvC,OAAO,CAAC;IAAE,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"}
|
|
@@ -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);
|
|
@@ -577,13 +606,9 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
577
606
|
}
|
|
578
607
|
}
|
|
579
608
|
}
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
|
|
583
|
-
// DESCRIBE ... AS JSON gives the nested tree. A runtime that does not know
|
|
584
|
-
// the JSON form rejects the statement itself; only that case falls back
|
|
585
|
-
// to the flat column list, any other failure fails the fetch as before.
|
|
586
|
-
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) {
|
|
587
612
|
const q = '`';
|
|
588
613
|
const tableRef = `${q}${request.database}${q}.${q}${request.schema}${q}.${q}${request.table}${q}`;
|
|
589
614
|
let rows;
|
|
@@ -593,26 +618,15 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
593
618
|
catch (e) {
|
|
594
619
|
const condition = (0, exports.getDatabricksErrorCondition)(e);
|
|
595
620
|
if (condition === DatabricksErrorCondition.TableOrViewNotFound) {
|
|
596
|
-
return {
|
|
621
|
+
return { kind: 'not_found' };
|
|
597
622
|
}
|
|
598
623
|
if ((0, DatabricksWarehouseStartupRetry_1.isDatabricksWarehouseStartingError)(e) ||
|
|
599
624
|
condition !== DatabricksErrorCondition.ParseSyntaxError) {
|
|
600
625
|
throw e;
|
|
601
626
|
}
|
|
602
|
-
const message = getDatabricksErrorMessage(e);
|
|
603
|
-
const flatColumns = (await DatabricksWarehouseClient.fetchAllRows(session.getColumns({
|
|
604
|
-
catalogName: request.database,
|
|
605
|
-
schemaName: request.schema,
|
|
606
|
-
tableName: request.table,
|
|
607
|
-
}), 'getCatalog'));
|
|
608
627
|
return {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
path: column.COLUMN_NAME,
|
|
612
|
-
typeName: column.TYPE_NAME,
|
|
613
|
-
shape: undefined,
|
|
614
|
-
})),
|
|
615
|
-
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),
|
|
616
630
|
};
|
|
617
631
|
}
|
|
618
632
|
const json = rows[0] ? Object.values(rows[0])[0] : undefined;
|
|
@@ -621,15 +635,57 @@ class DatabricksWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
621
635
|
if (!isRecord(description) || !Array.isArray(description.columns)) {
|
|
622
636
|
throw new Error('no columns in the JSON description');
|
|
623
637
|
}
|
|
624
|
-
return {
|
|
625
|
-
discovery: 'described',
|
|
626
|
-
columns: flattenDescribedFields(description.columns),
|
|
627
|
-
};
|
|
638
|
+
return { kind: 'described', description };
|
|
628
639
|
}
|
|
629
640
|
catch (e) {
|
|
630
641
|
throw new common_1.WarehouseQueryError(`Could not read the description of ${tableRef}: ${(0, common_1.getErrorMessage)(e)}`);
|
|
631
642
|
}
|
|
632
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
|
+
}
|
|
633
689
|
async getCatalog(requests) {
|
|
634
690
|
const retry = new DatabricksWarehouseStartupRetry_1.DatabricksWarehouseStartupRetry();
|
|
635
691
|
const results = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash/warehouses",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.390.1",
|
|
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.
|
|
24
|
+
"@lightdash/common": "3.390.1",
|
|
25
25
|
"node-fetch": "2.7.0",
|
|
26
26
|
"pg": "8.13.1",
|
|
27
27
|
"pg-cursor": "2.10.0",
|