Skip to content

Commit b754b77

Browse files
authored
[PECOBLR-306] Make LZ4 compression configurable (#288)
1 parent f357caa commit b754b77

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

lib/DBSQLSession.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class DBSQLSession implements IDBSQLSession {
202202
...getArrowOptions(clientConfig),
203203
canDownloadResult: options.useCloudFetch ?? clientConfig.useCloudFetch,
204204
parameters: getQueryParameters(options.namedParameters, options.ordinalParameters),
205-
canDecompressLZ4Result: clientConfig.useLZ4Compression && Boolean(LZ4),
205+
canDecompressLZ4Result: (options.useLZ4Compression ?? clientConfig.useLZ4Compression) && Boolean(LZ4),
206206
});
207207
const response = await this.handleResponse(operationPromise);
208208
const operation = this.createOperation(response);

lib/contracts/IDBSQLSession.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ExecuteStatementOptions = {
1717
runAsync?: boolean;
1818
maxRows?: number | bigint | Int64 | null;
1919
useCloudFetch?: boolean;
20+
useLZ4Compression?: boolean;
2021
stagingAllowedLocalPath?: string | string[];
2122
namedParameters?: Record<string, DBSQLParameter | DBSQLParameterValue>;
2223
ordinalParameters?: Array<DBSQLParameter | DBSQLParameterValue>;

tests/unit/result/ArrowResultHandler.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,17 @@ describe('ArrowResultHandler', () => {
229229
});
230230
expect(await result.hasMore()).to.be.false;
231231
});
232+
233+
it('should handle data without LZ4 compression', async () => {
234+
const rowSetProvider = new ResultsProviderStub([sampleRowSet1], undefined);
235+
const result = new ArrowResultHandler(new ClientContextStub(), rowSetProvider, {
236+
status: { statusCode: TStatusCode.SUCCESS_STATUS },
237+
arrowSchema: sampleArrowSchema,
238+
lz4Compressed: false,
239+
});
240+
241+
const { batches } = await result.fetchNext({ limit: 10000 });
242+
const expectedBatches = sampleRowSet1.arrowBatches?.map(({ batch }) => batch) ?? []; // Ensure iterable
243+
expect(batches).to.deep.eq([sampleArrowSchema, ...expectedBatches]);
244+
});
232245
});

tests/unit/result/CloudFetchResultHandler.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,24 @@ describe('CloudFetchResultHandler', () => {
379379
expect(context.invokeWithRetryStub.callCount).to.be.equal(1);
380380
}
381381
});
382+
383+
it('should handle data without LZ4 compression', async () => {
384+
const context = new ClientContextStub();
385+
const rowSetProvider = new ResultsProviderStub([sampleRowSet1], undefined);
386+
387+
const result = new CloudFetchResultHandler(context, rowSetProvider, {
388+
lz4Compressed: false,
389+
status: { statusCode: TStatusCode.SUCCESS_STATUS },
390+
});
391+
392+
context.invokeWithRetryStub.callsFake(async () => ({
393+
request: new Request('localhost'),
394+
response: new Response(sampleArrowBatch, { status: 200 }), // Return only the batch
395+
}));
396+
397+
const { batches } = await result.fetchNext({ limit: 10000 });
398+
399+
// Ensure the batches array matches the expected structure
400+
expect(batches).to.deep.eq([sampleArrowBatch]);
401+
});
382402
});

0 commit comments

Comments
 (0)