Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion tests/unit/kernel/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FakeNativeStatement implements KernelStatement {
// Mirrors the kernel `Statement.statementId` getter.
public readonly statementId = '01ef-fake-statement-id';

public async fetchNextBatch() {
public async fetchNextBatch(): Promise<{ ipcBytes: Buffer } | null> {
return null;
}

Expand Down Expand Up @@ -1894,3 +1894,36 @@ describe('DBSQLSession / DBSQLOperation over kernel backends — Symbol.asyncDis
expect(closeSpy.callCount).to.equal(1);
});
});

describe('DBSQLSession / DBSQLOperation over kernel backends — maxRows', () => {
it('ignores executeStatement maxRows and slices fetchChunk maxRows exactly over kernel batches', async () => {
const ipc = (from: number, count: number) =>
Buffer.from(
tableToIPC(tableFromArrays({ id: Int32Array.from({ length: count }, (_, i) => from + i) }), 'stream'),
);
const batches = [ipc(0, 4096), ipc(4096, 781)];
const connection = new FakeNativeConnection();
connection.statementToReturn.schema = () => ({ ipcBytes: ipc(0, 0) });
connection.statementToReturn.fetchNextBatch = async () => {
const ipcBytes = batches.shift();
return ipcBytes ? { ipcBytes } : null;
};
const context = makeContext();
const session = new DBSQLSession({ backend: new KernelSessionBackend({ connection, context }), context });

const operation = await session.executeStatement('SELECT id FROM range(4877)', { maxRows: 1000 });
expect(connection.lastOptions, 'maxRows is not forwarded to the kernel').to.equal(undefined);

const sizes: number[] = [];
const ids: unknown[] = [];
do {
// eslint-disable-next-line no-await-in-loop
const chunk = (await operation.fetchChunk({ maxRows: 1000 })) as Array<{ id: unknown }>;
sizes.push(chunk.length);
ids.push(...chunk.map((row) => row.id));
} while (await operation.hasMoreRows()); // eslint-disable-line no-await-in-loop

expect(sizes).to.deep.equal([1000, 1000, 1000, 1000, 877]);
expect(ids).to.deep.equal(Array.from({ length: 4877 }, (_, i) => i));
});
});
Loading