Skip to content

Commit f2597dd

Browse files
committed
fix: resolve alignment errors and CI timeouts in conformance tests
Use DataView instead of typed arrays in encodeColumnarRun to avoid Float64Array/BigInt64Array alignment requirements. Fix HashJoin batch tail loss when memory budget exceeded mid-batch. Increase vitest hook/test timeout to 300s for 5M-row conformance tests on CI runners.
1 parent a0ea79f commit f2597dd

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/operators.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,17 +1174,21 @@ export class HashJoinOperator implements Operator {
11741174
const inMemoryRows: Row[] = [...firstBatch];
11751175
this.buildSizeBytes = batchSizeBytes;
11761176
let exceeds = false;
1177+
let exceededBatchTail: Row[] = [];
11771178

11781179
while (true) {
11791180
const batch = await this.right.next();
11801181
if (!batch) break;
1181-
for (const row of batch) {
1182+
for (let ri = 0; ri < batch.length; ri++) {
1183+
const row = batch[ri];
11821184
const rowSize = estimateRowSize(row);
11831185
this.buildSizeBytes += rowSize;
11841186
inMemoryRows.push(row);
11851187

11861188
if (this.spill && this.buildSizeBytes > this.memoryBudget) {
11871189
exceeds = true;
1190+
// Capture remaining rows in this batch that we haven't visited
1191+
exceededBatchTail = batch.slice(ri + 1);
11881192
break;
11891193
}
11901194
}
@@ -1209,7 +1213,11 @@ export class HashJoinOperator implements Operator {
12091213
await this.partitionRightRows(inMemoryRows);
12101214
inMemoryRows.length = 0;
12111215

1212-
// Continue consuming remaining right-side rows
1216+
// Partition the remaining rows from the batch that triggered the exceed
1217+
if (exceededBatchTail.length > 0) {
1218+
await this.partitionRightRows(exceededBatchTail);
1219+
}
1220+
// Continue consuming remaining right-side batches
12131221
await this.consumeRemainingRight();
12141222
return;
12151223
}

src/r2-spill.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,17 @@ export function encodeColumnarRun(rows: Row[]): ArrayBuffer {
219219

220220
switch (dtype) {
221221
case DTYPE_F64: {
222-
const arr = new Float64Array(buf, offset, rowCount);
223222
for (let ri = 0; ri < rowCount; ri++) {
224223
const val = rows[ri][name];
225-
arr[ri] = typeof val === "number" ? val : 0;
224+
view.setFloat64(offset + ri * 8, typeof val === "number" ? val : 0, true);
226225
}
227226
offset += rowCount * 8;
228227
break;
229228
}
230229
case DTYPE_I64: {
231-
const arr = new BigInt64Array(buf, offset, rowCount);
232230
for (let ri = 0; ri < rowCount; ri++) {
233231
const val = rows[ri][name];
234-
arr[ri] = typeof val === "bigint" ? val : 0n;
232+
view.setBigInt64(offset + ri * 8, typeof val === "bigint" ? val : 0n, true);
235233
}
236234
offset += rowCount * 8;
237235
break;
@@ -257,14 +255,13 @@ export function encodeColumnarRun(rows: Row[]): ArrayBuffer {
257255

258256
view.setUint32(offset, totalLen, true); offset += 4;
259257

260-
// Offsets array
261-
const offsets = new Uint32Array(buf, offset, rowCount + 1);
258+
// Offsets array (use DataView to avoid alignment issues)
262259
let strOff = 0;
263260
for (let ri = 0; ri < rowCount; ri++) {
264-
offsets[ri] = strOff;
261+
view.setUint32(offset + ri * 4, strOff, true);
265262
strOff += encodedStrs[ri].length;
266263
}
267-
offsets[rowCount] = strOff;
264+
view.setUint32(offset + rowCount * 4, strOff, true);
268265
offset += (rowCount + 1) * 4;
269266

270267
// String data

vitest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ export default defineConfig({
1010
test: {
1111
environment: "node",
1212
setupFiles: ["./src/test-setup.ts"],
13+
hookTimeout: 300_000,
14+
testTimeout: 300_000,
1315
},
1416
});

0 commit comments

Comments
 (0)