@lightdash/warehouses 1.79.1 → 1.81.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/warehouseClientFromCredentials.d.ts +2 -1
- package/dist/warehouseClientFromCredentials.d.ts.map +1 -1
- package/dist/warehouseClientFromCredentials.js +2 -2
- package/dist/warehouseClients/DuckdbWarehouseClient.d.ts +6 -7
- package/dist/warehouseClients/DuckdbWarehouseClient.d.ts.map +1 -1
- package/dist/warehouseClients/DuckdbWarehouseClient.js +128 -14
- package/dist/warehouseClients/DuckdbWarehouseClient.test.js +307 -0
- package/dist/warehouseClients/MotherduckErrorClassifier.d.ts +3 -0
- package/dist/warehouseClients/MotherduckErrorClassifier.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckErrorClassifier.js +34 -0
- package/dist/warehouseClients/MotherduckErrorClassifier.test.d.ts +2 -0
- package/dist/warehouseClients/MotherduckErrorClassifier.test.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckErrorClassifier.test.js +31 -0
- package/dist/warehouseClients/MotherduckInstanceCache.catalog.test.d.ts +2 -0
- package/dist/warehouseClients/MotherduckInstanceCache.catalog.test.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckInstanceCache.catalog.test.js +52 -0
- package/dist/warehouseClients/MotherduckInstanceCache.d.ts +58 -0
- package/dist/warehouseClients/MotherduckInstanceCache.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckInstanceCache.integration.test.d.ts +2 -0
- package/dist/warehouseClients/MotherduckInstanceCache.integration.test.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckInstanceCache.integration.test.js +172 -0
- package/dist/warehouseClients/MotherduckInstanceCache.js +316 -0
- package/dist/warehouseClients/MotherduckInstanceCache.security.test.d.ts +2 -0
- package/dist/warehouseClients/MotherduckInstanceCache.security.test.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckInstanceCache.security.test.js +192 -0
- package/dist/warehouseClients/MotherduckInstanceCache.test.d.ts +2 -0
- package/dist/warehouseClients/MotherduckInstanceCache.test.d.ts.map +1 -0
- package/dist/warehouseClients/MotherduckInstanceCache.test.js +302 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from './warehouseClients/AthenaWarehouseClient';
|
|
|
6
6
|
export * from './warehouseClients/BigqueryWarehouseClient';
|
|
7
7
|
export * from './warehouseClients/DatabricksWarehouseClient';
|
|
8
8
|
export * from './warehouseClients/DuckdbWarehouseClient';
|
|
9
|
+
export { MotherduckInstanceCache } from './warehouseClients/MotherduckInstanceCache';
|
|
10
|
+
export type { MotherduckCacheEvent } from './warehouseClients/MotherduckInstanceCache';
|
|
9
11
|
export * from './warehouseClients/PostgresWarehouseClient';
|
|
10
12
|
export * from './warehouseClients/RedshiftWarehouseClient';
|
|
11
13
|
export * from './warehouseClients/redshiftIamCredentials';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yCAAyC,CAAC;AACxD,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AACrF,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,cAAc,4CAA4C,CAAC;AAC3D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yCAAyC,CAAC;AACxD,cAAc,+BAA+B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.MotherduckInstanceCache = void 0;
|
|
17
18
|
__exportStar(require("./ssh/sshTunnel"), exports);
|
|
18
19
|
__exportStar(require("./types"), exports);
|
|
19
20
|
__exportStar(require("./validateWarehouseColumnReferences"), exports);
|
|
@@ -22,6 +23,8 @@ __exportStar(require("./warehouseClients/AthenaWarehouseClient"), exports);
|
|
|
22
23
|
__exportStar(require("./warehouseClients/BigqueryWarehouseClient"), exports);
|
|
23
24
|
__exportStar(require("./warehouseClients/DatabricksWarehouseClient"), exports);
|
|
24
25
|
__exportStar(require("./warehouseClients/DuckdbWarehouseClient"), exports);
|
|
26
|
+
var MotherduckInstanceCache_1 = require("./warehouseClients/MotherduckInstanceCache");
|
|
27
|
+
Object.defineProperty(exports, "MotherduckInstanceCache", { enumerable: true, get: function () { return MotherduckInstanceCache_1.MotherduckInstanceCache; } });
|
|
25
28
|
__exportStar(require("./warehouseClients/PostgresWarehouseClient"), exports);
|
|
26
29
|
__exportStar(require("./warehouseClients/RedshiftWarehouseClient"), exports);
|
|
27
30
|
__exportStar(require("./warehouseClients/redshiftIamCredentials"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CreateWarehouseCredentials } from '@lightdash/common';
|
|
2
2
|
import { WarehouseClient } from './types';
|
|
3
|
-
|
|
3
|
+
import { type DuckdbWarehouseClientOptions } from './warehouseClients/DuckdbWarehouseClient';
|
|
4
|
+
export declare const warehouseClientFromCredentials: (credentials: CreateWarehouseCredentials, options?: DuckdbWarehouseClientOptions) => WarehouseClient;
|
|
4
5
|
//# sourceMappingURL=warehouseClientFromCredentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"warehouseClientFromCredentials.d.ts","sourceRoot":"","sources":["../src/warehouseClientFromCredentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,0BAA0B,EAG7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"warehouseClientFromCredentials.d.ts","sourceRoot":"","sources":["../src/warehouseClientFromCredentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,0BAA0B,EAG7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK1C,OAAO,EAEH,KAAK,4BAA4B,EACpC,MAAM,0CAA0C,CAAC;AAMlD,eAAO,MAAM,8BAA8B,gBAC1B,0BAA0B,YAC7B,4BAA4B,KACvC,eA4BF,CAAC"}
|
|
@@ -11,7 +11,7 @@ const PostgresWarehouseClient_1 = require("./warehouseClients/PostgresWarehouseC
|
|
|
11
11
|
const RedshiftWarehouseClient_1 = require("./warehouseClients/RedshiftWarehouseClient");
|
|
12
12
|
const SnowflakeWarehouseClient_1 = require("./warehouseClients/SnowflakeWarehouseClient");
|
|
13
13
|
const TrinoWarehouseClient_1 = require("./warehouseClients/TrinoWarehouseClient");
|
|
14
|
-
const warehouseClientFromCredentials = (credentials) => {
|
|
14
|
+
const warehouseClientFromCredentials = (credentials, options) => {
|
|
15
15
|
switch (credentials.type) {
|
|
16
16
|
case common_1.WarehouseTypes.SNOWFLAKE:
|
|
17
17
|
return new SnowflakeWarehouseClient_1.SnowflakeWarehouseClient(credentials);
|
|
@@ -30,7 +30,7 @@ const warehouseClientFromCredentials = (credentials) => {
|
|
|
30
30
|
case common_1.WarehouseTypes.ATHENA:
|
|
31
31
|
return new AthenaWarehouseClient_1.AthenaWarehouseClient(credentials);
|
|
32
32
|
case common_1.WarehouseTypes.DUCKDB:
|
|
33
|
-
return new DuckdbWarehouseClient_1.DuckdbWarehouseClient(credentials);
|
|
33
|
+
return new DuckdbWarehouseClient_1.DuckdbWarehouseClient(credentials, options);
|
|
34
34
|
default:
|
|
35
35
|
return (0, common_1.assertUnreachable)(credentials, new common_1.UnexpectedServerError('Warehouse credentials type were not recognised'));
|
|
36
36
|
}
|
|
@@ -48,6 +48,8 @@ export type DuckdbWarehouseClientOptions = {
|
|
|
48
48
|
enableQueryProfiling?: boolean;
|
|
49
49
|
onQueryProfile?: (profile: DuckdbQueryProfileMetrics) => void;
|
|
50
50
|
embeddedQueryTimeoutMs?: number;
|
|
51
|
+
enableInstanceCache?: boolean;
|
|
52
|
+
projectUuid?: string;
|
|
51
53
|
};
|
|
52
54
|
export declare const mapFieldTypeFromTypeId: (typeId: number) => DimensionType;
|
|
53
55
|
export declare const getDuckdbTimestampDomainFromString: (typeName: string) => TimestampDomain | undefined;
|
|
@@ -57,6 +59,7 @@ export declare class DuckdbSqlBuilder extends WarehouseBaseSqlBuilder {
|
|
|
57
59
|
getMetricSql(sql: string, metric: Metric): string;
|
|
58
60
|
concatString(...args: string[]): string;
|
|
59
61
|
}
|
|
62
|
+
export declare const buildMotherduckConnectionString: ({ database, token, }: Pick<CreateDuckdbMotherduckCredentials, 'database' | 'token'>) => string;
|
|
60
63
|
export declare class DuckdbWarehouseClient extends WarehouseBaseClient<CreateDuckdbMotherduckCredentials> {
|
|
61
64
|
private static readonly sharedInstances;
|
|
62
65
|
private static readonly sharedInstanceResourceLimits;
|
|
@@ -75,6 +78,8 @@ export declare class DuckdbWarehouseClient extends WarehouseBaseClient<CreateDuc
|
|
|
75
78
|
private readonly enableQueryProfiling;
|
|
76
79
|
private readonly onQueryProfile?;
|
|
77
80
|
private readonly embeddedQueryTimeoutMs;
|
|
81
|
+
private readonly enableInstanceCache;
|
|
82
|
+
private readonly projectUuid?;
|
|
78
83
|
private allowsPreAggregateFileReads;
|
|
79
84
|
private hasWarnedAboutMotherduckTimezone;
|
|
80
85
|
constructor(credentials?: CreateDuckdbCredentials | DuckdbConnectionCredentials, options?: DuckdbWarehouseClientOptions);
|
|
@@ -118,14 +123,8 @@ export declare class DuckdbWarehouseClient extends WarehouseBaseClient<CreateDuc
|
|
|
118
123
|
private withSharedSession;
|
|
119
124
|
private hasResourceLimits;
|
|
120
125
|
private isMotherduck;
|
|
121
|
-
/**
|
|
122
|
-
* Dispatches to the appropriate session strategy:
|
|
123
|
-
* - Direct database (non-:memory: databasePath): connects to the MotherDuck path
|
|
124
|
-
* - Resource-limited: isolated ephemeral instance (e.g. parquet conversion)
|
|
125
|
-
* - Shared instance (has instanceCacheKey): warm cached instance for queries
|
|
126
|
-
* - Default: ephemeral query session
|
|
127
|
-
*/
|
|
128
126
|
private withSession;
|
|
127
|
+
private withMotherduckCachedSession;
|
|
129
128
|
/** Direct connection to the configured MotherDuck database. */
|
|
130
129
|
private withDirectSession;
|
|
131
130
|
private withEmbeddedQueryDeadline;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DuckdbWarehouseClient.d.ts","sourceRoot":"","sources":["../../src/warehouseClients/DuckdbWarehouseClient.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,OAAO,EACP,uBAAuB,EAGvB,iCAAiC,EACjC,aAAa,EAMb,MAAM,EAKN,m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,CAAC,CAKvC;IAEK,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAC1C,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACnB,CAAC,CAkBD;IAEK,QAAQ,CACV,GAAG,IAAI,EAAE,UAAU,CACf,mBAAmB,CAAC,iCAAiC,CAAC,CAAC,UAAU,CAAC,CACrE;;;;;OAGJ;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1B;IAEK,UAAU,CACZ,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAC9D,OAAO,CAAC,gBAAgB,CAAC,CA4C3B;IAEK,YAAY,CACd,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CACN;QACI,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACjB,EAAE,CACN,CAqBA;IAEK,SAAS,CACX,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAS3B;CACJ"}
|
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DuckdbWarehouseClient = exports.DuckdbSqlBuilder = exports.getDuckdbTimestampDomainFromString = exports.mapFieldTypeFromTypeId = void 0;
|
|
39
|
+
exports.DuckdbWarehouseClient = exports.buildMotherduckConnectionString = exports.DuckdbSqlBuilder = exports.getDuckdbTimestampDomainFromString = exports.mapFieldTypeFromTypeId = void 0;
|
|
7
40
|
const node_api_1 = require("@duckdb/node-api");
|
|
8
41
|
const common_1 = require("@lightdash/common");
|
|
9
42
|
const crypto_1 = require("crypto");
|
|
@@ -11,6 +44,8 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
11
44
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
12
45
|
const os_1 = __importDefault(require("os"));
|
|
13
46
|
const path_1 = __importDefault(require("path"));
|
|
47
|
+
const MotherduckErrorClassifier_1 = require("./MotherduckErrorClassifier");
|
|
48
|
+
const MotherduckInstanceCache = __importStar(require("./MotherduckInstanceCache"));
|
|
14
49
|
const WarehouseBaseClient_1 = __importDefault(require("./WarehouseBaseClient"));
|
|
15
50
|
const WarehouseBaseSqlBuilder_1 = __importDefault(require("./WarehouseBaseSqlBuilder"));
|
|
16
51
|
const mapFieldTypeFromTypeId = (typeId) => {
|
|
@@ -180,6 +215,7 @@ const buildMotherduckConnectionString = ({ database, token, }) => {
|
|
|
180
215
|
});
|
|
181
216
|
return `md:${encodeURIComponent(database)}?${params.toString()}`;
|
|
182
217
|
};
|
|
218
|
+
exports.buildMotherduckConnectionString = buildMotherduckConnectionString;
|
|
183
219
|
const EMBEDDED_DATASET_PATTERN = /^[a-z0-9_-]+$/;
|
|
184
220
|
const DEFAULT_EMBEDDED_DATA_DIRECTORY = path_1.default.resolve(__dirname, '../../../backend/assets/playground');
|
|
185
221
|
const EMBEDDED_RESOURCE_LIMITS = {
|
|
@@ -289,7 +325,7 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
289
325
|
if (!token) {
|
|
290
326
|
throw new common_1.ParameterError('MotherDuck token is required for DuckDB warehouse connections');
|
|
291
327
|
}
|
|
292
|
-
this.databasePath = buildMotherduckConnectionString({
|
|
328
|
+
this.databasePath = (0, exports.buildMotherduckConnectionString)({
|
|
293
329
|
database: effectiveCredentials.database,
|
|
294
330
|
token,
|
|
295
331
|
});
|
|
@@ -316,6 +352,8 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
316
352
|
this.onQueryProfile = options?.onQueryProfile;
|
|
317
353
|
this.embeddedQueryTimeoutMs =
|
|
318
354
|
options?.embeddedQueryTimeoutMs ?? EMBEDDED_QUERY_TIMEOUT_MS;
|
|
355
|
+
this.enableInstanceCache = options?.enableInstanceCache ?? false;
|
|
356
|
+
this.projectUuid = options?.projectUuid;
|
|
319
357
|
}
|
|
320
358
|
static hashDucklakeConfig(ducklake) {
|
|
321
359
|
return (0, crypto_1.createHash)('sha256')
|
|
@@ -954,16 +992,16 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
954
992
|
!this.ducklakeConfig &&
|
|
955
993
|
this.databasePath.startsWith('md:'));
|
|
956
994
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
return this.withDirectSession(callback, organizationUuid);
|
|
995
|
+
async withSession(callback, organizationUuid, retryable = () => true, onPhaseTiming) {
|
|
996
|
+
if (this.embeddedConfig) {
|
|
997
|
+
return this.withDirectSession(callback, organizationUuid, onPhaseTiming);
|
|
998
|
+
}
|
|
999
|
+
if (this.isMotherduck()) {
|
|
1000
|
+
if (this.enableInstanceCache &&
|
|
1001
|
+
this.credentials.requireUserCredentials !== true) {
|
|
1002
|
+
return this.withMotherduckCachedSession(callback, retryable, onPhaseTiming);
|
|
1003
|
+
}
|
|
1004
|
+
return this.withDirectSession(callback, organizationUuid, onPhaseTiming);
|
|
967
1005
|
}
|
|
968
1006
|
if (this.hasResourceLimits()) {
|
|
969
1007
|
return this.withIsolatedSession(callback);
|
|
@@ -973,8 +1011,81 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
973
1011
|
}
|
|
974
1012
|
return this.withEphemeralQuerySession(callback);
|
|
975
1013
|
}
|
|
1014
|
+
async withMotherduckCachedSession(callback, retryable, onPhaseTiming) {
|
|
1015
|
+
let activeEntryId;
|
|
1016
|
+
const runAttempt = () => MotherduckInstanceCache.withInstance(this.databasePath, { projectUuid: this.projectUuid }, async (instance, entryId, acquisitionTiming) => {
|
|
1017
|
+
activeEntryId = entryId;
|
|
1018
|
+
const sessionStart = performance.now();
|
|
1019
|
+
const connection = await instance.connect();
|
|
1020
|
+
const { connectMs } = acquisitionTiming;
|
|
1021
|
+
onPhaseTiming?.('connect', acquisitionTiming.waitMs +
|
|
1022
|
+
acquisitionTiming.instanceCreateMs +
|
|
1023
|
+
connectMs);
|
|
1024
|
+
try {
|
|
1025
|
+
const queryStart = performance.now();
|
|
1026
|
+
const result = await callback(connection);
|
|
1027
|
+
const queryMs = performance.now() - queryStart;
|
|
1028
|
+
const totalMs = performance.now() - sessionStart;
|
|
1029
|
+
this.logger?.info(`MotherDuck cached-instance session complete: entry_id=${entryId} connect=${(0, common_1.formatMilliseconds)(connectMs)}ms query=${(0, common_1.formatMilliseconds)(queryMs)}ms total=${(0, common_1.formatMilliseconds)(totalMs)}ms`, {
|
|
1030
|
+
entryId,
|
|
1031
|
+
projectUuid: this.projectUuid,
|
|
1032
|
+
connectMs,
|
|
1033
|
+
queryMs,
|
|
1034
|
+
totalMs,
|
|
1035
|
+
});
|
|
1036
|
+
return result;
|
|
1037
|
+
}
|
|
1038
|
+
finally {
|
|
1039
|
+
connection.closeSync?.();
|
|
1040
|
+
connection.disconnectSync?.();
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
try {
|
|
1044
|
+
return await runAttempt();
|
|
1045
|
+
}
|
|
1046
|
+
catch (error) {
|
|
1047
|
+
const errorClass = (0, MotherduckErrorClassifier_1.classifyMotherduckError)(error);
|
|
1048
|
+
const failedEntryId = activeEntryId;
|
|
1049
|
+
if (errorClass === 'auth') {
|
|
1050
|
+
if (failedEntryId) {
|
|
1051
|
+
await MotherduckInstanceCache.invalidate(failedEntryId, 'auth');
|
|
1052
|
+
}
|
|
1053
|
+
throw error;
|
|
1054
|
+
}
|
|
1055
|
+
if (errorClass !== 'stale' || !failedEntryId) {
|
|
1056
|
+
throw error;
|
|
1057
|
+
}
|
|
1058
|
+
await MotherduckInstanceCache.invalidate(failedEntryId, 'stale');
|
|
1059
|
+
if (!retryable()) {
|
|
1060
|
+
throw error;
|
|
1061
|
+
}
|
|
1062
|
+
activeEntryId = undefined;
|
|
1063
|
+
try {
|
|
1064
|
+
const result = await runAttempt();
|
|
1065
|
+
MotherduckInstanceCache.recordRetry(failedEntryId, 'recovered');
|
|
1066
|
+
this.logger?.info('MotherDuck cached-instance session retry recovered', {
|
|
1067
|
+
entryId: failedEntryId,
|
|
1068
|
+
projectUuid: this.projectUuid,
|
|
1069
|
+
});
|
|
1070
|
+
return result;
|
|
1071
|
+
}
|
|
1072
|
+
catch (retryError) {
|
|
1073
|
+
MotherduckInstanceCache.recordRetry(failedEntryId, 'failed');
|
|
1074
|
+
const retryErrorClass = (0, MotherduckErrorClassifier_1.classifyMotherduckError)(retryError);
|
|
1075
|
+
if (activeEntryId &&
|
|
1076
|
+
(retryErrorClass === 'stale' || retryErrorClass === 'auth')) {
|
|
1077
|
+
await MotherduckInstanceCache.invalidate(activeEntryId, retryErrorClass);
|
|
1078
|
+
}
|
|
1079
|
+
this.logger?.info('MotherDuck cached-instance session retry failed', {
|
|
1080
|
+
entryId: failedEntryId,
|
|
1081
|
+
projectUuid: this.projectUuid,
|
|
1082
|
+
});
|
|
1083
|
+
throw retryError;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
976
1087
|
/** Direct connection to the configured MotherDuck database. */
|
|
977
|
-
async withDirectSession(callback, organizationUuid) {
|
|
1088
|
+
async withDirectSession(callback, organizationUuid, onPhaseTiming) {
|
|
978
1089
|
const sessionStart = performance.now();
|
|
979
1090
|
const releaseEmbeddedConcurrency = this.embeddedConfig
|
|
980
1091
|
? DuckdbWarehouseClient.tryAcquireEmbeddedConcurrency(organizationUuid)
|
|
@@ -999,6 +1110,7 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
999
1110
|
const connectStart = performance.now();
|
|
1000
1111
|
connection = await instance.connect();
|
|
1001
1112
|
const connectMs = performance.now() - connectStart;
|
|
1113
|
+
onPhaseTiming?.('connect', instanceCreateMs + connectMs);
|
|
1002
1114
|
if (this.embeddedConfig) {
|
|
1003
1115
|
await DuckdbWarehouseClient.hardenInstance(connection);
|
|
1004
1116
|
}
|
|
@@ -1278,6 +1390,7 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
1278
1390
|
}
|
|
1279
1391
|
async streamQuery(sql, streamCallback, options) {
|
|
1280
1392
|
const reportPhase = options?.onPhaseTiming;
|
|
1393
|
+
let hasEmittedRows = false;
|
|
1281
1394
|
await this.withSession(async (db) => {
|
|
1282
1395
|
const sessionStart = performance.now();
|
|
1283
1396
|
if (options?.timezone) {
|
|
@@ -1325,6 +1438,7 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
1325
1438
|
reportPhase?.('query', performance.now() - queryStart);
|
|
1326
1439
|
fetchStart = performance.now();
|
|
1327
1440
|
}
|
|
1441
|
+
hasEmittedRows = true;
|
|
1328
1442
|
await streamCallback({ fields, rows });
|
|
1329
1443
|
}
|
|
1330
1444
|
if (fetchStart === undefined) {
|
|
@@ -1337,7 +1451,7 @@ class DuckdbWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
1337
1451
|
if (profilePath) {
|
|
1338
1452
|
await this.logQueryProfile(profilePath, this.logger, options?.tags);
|
|
1339
1453
|
}
|
|
1340
|
-
}, options?.tags?.organization_uuid);
|
|
1454
|
+
}, options?.tags?.organization_uuid, () => !hasEmittedRows, reportPhase);
|
|
1341
1455
|
}
|
|
1342
1456
|
async executeAsyncQuery(...args) {
|
|
1343
1457
|
const [queryArgs, resultsStreamCallback] = args;
|