Skip to content

Commit

Permalink
Return empty ArrayBuffer if returnRawBuffers is true (#58)
Browse files Browse the repository at this point in the history
* If there are no results for an attribute return empty ArrayBuffer if returnRawBuffers is true

* Build lib

* Add tests for empty attributes
  • Loading branch information
SarantopoulosKon authored Feb 10, 2023
1 parent 9c98415 commit d10352a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/utils/getResultsFromArrayBuffer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/utils/getResultsFromArrayBuffer.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 57 additions & 1 deletion src/utils/getResultsFromArrayBuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe("getResultsFromArrayBuffer()", () => {
nullableVarLengthAttrBufferHeaders,
varLenNullableAttributesSchema
);
// expect(results).toEqual("");

expect(results).toEqual({
a1: [100, null, null, 400],
Expand All @@ -53,4 +52,61 @@ describe("getResultsFromArrayBuffer()", () => {
rows: [1, 1, 2, 2],
});
});

it("Should return empty array if there are no results if attributebuffers are empty", async () => {
const file = path.join(__dirname, "../fixtures/nullable_buffer.raw");
const rawBuffer = readFileSync(file);
const arrayBufferOfFixedLengthAttributes =
convertToArrayBufferIfNodeBuffer(rawBuffer);

const attributeBufferHeaders = [
{
name: "cols",
fixedLenBufferSizeInBytes: 0,
varLenBufferSizeInBytes: 0,
validityLenBufferSizeInBytes: 0,
originalFixedLenBufferSizeInBytes: 0,
originalVarLenBufferSizeInBytes: 0,
originalValidityLenBufferSizeInBytes: 0,
}
]

const results = await getResultsFromArrayBuffer(
arrayBufferOfFixedLengthAttributes,
attributeBufferHeaders,
varLenNullableAttributesSchema
);

expect(results).toEqual({ cols: []});
});

it("Should return empty ArrayBuffer if no results and returnRawBuffers is true", async () => {
const file = path.join(__dirname, "../fixtures/nullable_buffer.raw");
const rawBuffer = readFileSync(file);
const arrayBufferOfFixedLengthAttributes =
convertToArrayBufferIfNodeBuffer(rawBuffer);

const attributeBufferHeaders = [
{
name: "cols",
fixedLenBufferSizeInBytes: 0,
varLenBufferSizeInBytes: 0,
validityLenBufferSizeInBytes: 0,
originalFixedLenBufferSizeInBytes: 0,
originalVarLenBufferSizeInBytes: 0,
originalValidityLenBufferSizeInBytes: 0,
}
]

const results = await getResultsFromArrayBuffer(
arrayBufferOfFixedLengthAttributes,
attributeBufferHeaders,
varLenNullableAttributesSchema,
{
returnRawBuffers: true
}
);

expect(results).toEqual({ cols: new ArrayBuffer(0)});
});
});
6 changes: 5 additions & 1 deletion src/utils/getResultsFromArrayBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const getResultsFromArrayBuffer = async (
const offset = await offsetPromise;

if (!totalNumberOfBytesOfAttribute) {
data[attribute.name] = [];
if (options.returnRawBuffers) {
data[attribute.name] = new ArrayBuffer(0);
} else {
data[attribute.name] = [];
}

return offset;
}
Expand Down

0 comments on commit d10352a

Please sign in to comment.