Skip to content

Commit af41056

Browse files
authored
Fix nested types (#18)
1 parent 9e69163 commit af41056

File tree

7 files changed

+1386
-1012
lines changed

7 files changed

+1386
-1012
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lib/
2+
.yarn
23

34
# Logs
45
logs

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

src/vector.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function parseData<T extends DataType>(
3535
}
3636

3737
const ptrToChildrenPtrs = dataView.getUint32(ptr + 44, true);
38-
const children = new Array(Number(nChildren));
38+
const children: arrow.Vector[] = new Array(Number(nChildren));
3939
for (let i = 0; i < nChildren; i++) {
4040
children[i] = parseVector(
4141
buffer,
@@ -273,41 +273,55 @@ function parseData<T extends DataType>(
273273
copyBuffer(dataView.buffer, offsetsPtr, (length + 1) * 4)
274274
)
275275
: new Int32Array(dataView.buffer, offsetsPtr, length + 1);
276+
277+
assert(children[0].data.length === 1);
278+
let childData = children[0].data[0];
279+
276280
return arrow.makeData({
277281
type: dataType,
278282
offset,
279283
length,
280284
nullCount,
281285
nullBitmap,
282286
valueOffsets,
283-
child: children[0],
287+
child: childData,
284288
});
285289
}
286290

287291
if (DataType.isFixedSizeList(dataType)) {
288292
assert(nChildren === 1);
289293
const [validityPtr] = bufferPtrs;
290294
const nullBitmap = parseNullBitmap(dataView.buffer, validityPtr, copy);
295+
296+
assert(children[0].data.length === 1);
297+
let childData = children[0].data[0];
298+
291299
return arrow.makeData({
292300
type: dataType,
293301
offset,
294302
length,
295303
nullCount,
296304
nullBitmap,
297-
child: children[0],
305+
child: childData,
298306
});
299307
}
300308

301309
if (DataType.isStruct(dataType)) {
302310
const [validityPtr] = bufferPtrs;
303311
const nullBitmap = parseNullBitmap(dataView.buffer, validityPtr, copy);
312+
313+
let childData = children.map(child => {
314+
assert(child.data.length === 1);
315+
return child.data[0];
316+
})
317+
304318
return arrow.makeData({
305319
type: dataType,
306320
offset,
307321
length,
308322
nullCount,
309323
nullBitmap,
310-
children,
324+
children: childData,
311325
});
312326
}
313327

tests/ffi.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { parseField, parseVector } from "../src";
77
wasm.setPanicHook();
88

99
// @ts-expect-error
10-
const WASM_MEMORY = wasm.__wasm.memory;
10+
const WASM_MEMORY: WebAssembly.Memory = wasm.__wasm.memory;
1111

1212
interface FixtureType {
1313
data: any;
@@ -121,7 +121,7 @@ test("primitive types non-null with copy", (t) => {
121121
t.end();
122122
});
123123

124-
test.skip("fixed size list", (t) => {
124+
test("fixed size list", (t) => {
125125
const table = loadIPCTableFromDisk("tests/fixed_size_list.arrow");
126126
const originalField = table.schema.fields[0];
127127
const originalVector = table.getChildAt(0);
@@ -130,11 +130,18 @@ test.skip("fixed size list", (t) => {
130130
const fieldPtr = ffiTable.schemaAddr(0);
131131
const field = parseField(WASM_MEMORY.buffer, fieldPtr);
132132

133-
t.equals(field.name, originalField.name);
134-
t.equals(field.typeId, originalField.typeId);
135-
// t.equals(field.nullable, originalField.nullable);
133+
t.equals(field.name, originalField.name, "Field name should be equal.");
134+
t.equals(field.typeId, originalField.typeId, "Type id should be equal.");
136135

137-
console.log("field", field);
136+
const arrayPtr = ffiTable.arrayAddr(0, 0);
137+
const wasmVector = parseVector(WASM_MEMORY.buffer, arrayPtr, field.type);
138+
139+
t.equals(wasmVector.get(0).get(0), 1);
140+
t.equals(wasmVector.get(0).get(1), 2);
141+
t.equals(wasmVector.get(1).get(0), 3);
142+
t.equals(wasmVector.get(1).get(1), 4);
143+
t.equals(wasmVector.get(2).get(0), 5);
144+
t.equals(wasmVector.get(2).get(1), 6);
138145

139146
t.end();
140147
});

tests/rust-arrow-ffi/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
bin/
44
pkg/
55
wasm-pack.log
6+
.yarn

tests/rust-arrow-ffi/yarn.lock

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 6
6+
7+
"root-workspace-0b6124@workspace:.":
8+
version: 0.0.0-use.local
9+
resolution: "root-workspace-0b6124@workspace:."
10+
languageName: unknown
11+
linkType: soft

0 commit comments

Comments
 (0)