@lightdash/warehouses 0.3313.0 → 0.3315.3
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrinoWarehouseClient.d.ts","sourceRoot":"","sources":["../../src/warehouseClients/TrinoWarehouseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,sBAAsB,EAEtB,MAAM,EAGN,mBAAmB,EACnB,gBAAgB,EAGhB,gBAAgB,EAChB,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEH,iBAAiB,EAKpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM5C,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"TrinoWarehouseClient.d.ts","sourceRoot":"","sources":["../../src/warehouseClients/TrinoWarehouseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,sBAAsB,EAEtB,MAAM,EAGN,mBAAmB,EACnB,gBAAgB,EAGhB,gBAAgB,EAChB,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEH,iBAAiB,EAKpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM5C,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAShE,oBAAY,UAAU;IAClB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,IAAI,SAA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I,CAAC;IAoGV,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA4BlE,OAAO,CAAC,aAAa;IAQf,SAAS,CACX,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,gBAAgB,CAAC;IAetB,SAAS,CACX,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,gBAAgB,CAAC;IAyBtB,YAAY;;;;;CAqBrB"}
|
|
@@ -10,6 +10,10 @@ const processPromisesInBatches_1 = require("../utils/processPromisesInBatches");
|
|
|
10
10
|
const sql_1 = require("../utils/sql");
|
|
11
11
|
const WarehouseBaseClient_1 = __importDefault(require("./WarehouseBaseClient"));
|
|
12
12
|
const WarehouseBaseSqlBuilder_1 = __importDefault(require("./WarehouseBaseSqlBuilder"));
|
|
13
|
+
const TRINO_CLIENT_TAGS_HEADER = 'X-Trino-Client-Tags';
|
|
14
|
+
// Trino splits the header on commas and Node rejects non-latin1 header values,
|
|
15
|
+
// so tag keys/values are restricted to a safe charset
|
|
16
|
+
const sanitizeClientTag = (tag) => tag.replace(/[^a-zA-Z0-9_-]/g, '_').substring(0, 60);
|
|
13
17
|
var TrinoTypes;
|
|
14
18
|
(function (TrinoTypes) {
|
|
15
19
|
TrinoTypes["BOOLEAN"] = "boolean";
|
|
@@ -215,7 +219,16 @@ class TrinoWarehouseClient extends WarehouseBaseClient_1.default {
|
|
|
215
219
|
console.debug(`Setting Trino timezone to ${options?.timezone}`);
|
|
216
220
|
await session.query(`SET TIME ZONE '${options?.timezone}'`);
|
|
217
221
|
}
|
|
218
|
-
query = await session.query(
|
|
222
|
+
query = await session.query(options?.tags
|
|
223
|
+
? {
|
|
224
|
+
query: alteredQuery,
|
|
225
|
+
extraHeaders: {
|
|
226
|
+
[TRINO_CLIENT_TAGS_HEADER]: Object.entries(options.tags)
|
|
227
|
+
.map(([key, value]) => `${sanitizeClientTag(key)}=${sanitizeClientTag(value)}`)
|
|
228
|
+
.join(','),
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
: alteredQuery);
|
|
219
232
|
let queryResult = await query.next();
|
|
220
233
|
if (queryResult.value.error) {
|
|
221
234
|
throw new common_1.WarehouseQueryError(getErrorMessage(queryResult.value.error) ??
|
|
@@ -33,6 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
37
|
+
const common_1 = require("@lightdash/common");
|
|
36
38
|
const TrinoWarehouseClient_1 = require("./TrinoWarehouseClient");
|
|
37
39
|
const TrinoWarehouseClient_mock_1 = require("./TrinoWarehouseClient.mock");
|
|
38
40
|
const wharehouseClient = __importStar(require("./WarehouseClient.mock"));
|
|
@@ -92,4 +94,50 @@ describe('TrinoWarehouseClient', () => {
|
|
|
92
94
|
});
|
|
93
95
|
expect(warehouse.getCatalog(wharehouseClient.config)).resolves.toEqual(wharehouseClient.expectedWarehouseSchema);
|
|
94
96
|
});
|
|
97
|
+
describe('streamQuery client tag headers', () => {
|
|
98
|
+
it('sends X-Trino-Client-Tags header as comma-separated key=value pairs when tags are provided', async () => {
|
|
99
|
+
const warehouse = new TrinoWarehouseClient_1.TrinoWarehouseClient(TrinoWarehouseClient_mock_1.credentials);
|
|
100
|
+
queryResultMock.mockReturnValue({
|
|
101
|
+
next: vi
|
|
102
|
+
.fn()
|
|
103
|
+
.mockResolvedValue({ done: true, value: TrinoWarehouseClient_mock_1.queryResponse }),
|
|
104
|
+
});
|
|
105
|
+
await warehouse.runQuery('SELECT 1', {
|
|
106
|
+
dashboard_uuid: 'abc-123',
|
|
107
|
+
chart_uuid: 'def-456',
|
|
108
|
+
});
|
|
109
|
+
expect(queryResultMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
110
|
+
extraHeaders: expect.objectContaining({
|
|
111
|
+
'X-Trino-Client-Tags': 'dashboard_uuid=abc-123,chart_uuid=def-456',
|
|
112
|
+
}),
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
it('sanitizes tag values that are unsafe for the header', async () => {
|
|
116
|
+
const warehouse = new TrinoWarehouseClient_1.TrinoWarehouseClient(TrinoWarehouseClient_mock_1.credentials);
|
|
117
|
+
queryResultMock.mockReturnValue({
|
|
118
|
+
next: vi
|
|
119
|
+
.fn()
|
|
120
|
+
.mockResolvedValue({ done: true, value: TrinoWarehouseClient_mock_1.queryResponse }),
|
|
121
|
+
});
|
|
122
|
+
await warehouse.runQuery('SELECT 1', {
|
|
123
|
+
scheduler_name: 'Weekly report, EMEA 📊',
|
|
124
|
+
query_context: common_1.QueryExecutionContext.SCHEDULED_DELIVERY,
|
|
125
|
+
});
|
|
126
|
+
expect(queryResultMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
127
|
+
extraHeaders: {
|
|
128
|
+
'X-Trino-Client-Tags': 'scheduler_name=Weekly_report__EMEA___,query_context=scheduledDelivery',
|
|
129
|
+
},
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
it('sends query as plain string (no extraHeaders) when no tags are provided', async () => {
|
|
133
|
+
const warehouse = new TrinoWarehouseClient_1.TrinoWarehouseClient(TrinoWarehouseClient_mock_1.credentials);
|
|
134
|
+
queryResultMock.mockReturnValue({
|
|
135
|
+
next: vi
|
|
136
|
+
.fn()
|
|
137
|
+
.mockResolvedValue({ done: true, value: TrinoWarehouseClient_mock_1.queryResponse }),
|
|
138
|
+
});
|
|
139
|
+
await warehouse.runQuery('SELECT 1');
|
|
140
|
+
expect(queryResultMock).toHaveBeenCalledWith('SELECT 1');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
95
143
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash/warehouses",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3315.3",
|
|
4
4
|
"description": "Warehouse connectors for Lightdash",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"snowflake-sdk": "2.3.4",
|
|
30
30
|
"ssh2": "1.14.0",
|
|
31
31
|
"trino-client": "0.2.9",
|
|
32
|
-
"@lightdash/common": "0.
|
|
32
|
+
"@lightdash/common": "0.3315.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node-fetch": "2.6.13",
|