Skip to content

Commit 51bf478

Browse files
committed
data chunk: enforce max rows
1 parent eb5e9f7 commit 51bf478

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

api/src/DuckDBDataChunk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class DuckDBDataChunk {
3232
return duckdb.data_chunk_get_size(this.chunk);
3333
}
3434
public set rowCount(count: number) {
35+
const maxRowCount = duckdb.vector_size();
36+
if (count > maxRowCount) {
37+
throw new Error(`A data chunk cannot have more than ${maxRowCount} rows`);
38+
}
3539
duckdb.data_chunk_set_size(this.chunk, count);
3640
}
3741
public getColumnVector(columnIndex: number): DuckDBVector {

api/test/api.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,17 @@ describe('api', () => {
14711471
const connection = await DuckDBConnection.create();
14721472
await connection.run('select 1');
14731473
});
1474+
test('data chunk max rows', () => {
1475+
try {
1476+
DuckDBDataChunk.create([INTEGER], 2049);
1477+
assert.fail('should throw');
1478+
} catch (err) {
1479+
assert.deepEqual(
1480+
err,
1481+
new Error('A data chunk cannot have more than 2048 rows')
1482+
);
1483+
}
1484+
});
14741485
test('write integer vector', () => {
14751486
const chunk = DuckDBDataChunk.create([INTEGER], 3);
14761487
const vector = chunk.getColumnVector(0) as DuckDBIntegerVector;

0 commit comments

Comments
 (0)