Skip to content

interval array #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions tests/ffi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,40 @@ describe("duration", (t) => {
it("copy=true", () => test(true));
});


describe("interval", (t) => {
function test(copy: boolean) {
let columnIndex = TEST_TABLE.schema.fields.findIndex(
(field) => field.name == "interval"
);

const originalField = TEST_TABLE.schema.fields[columnIndex];
// declare it's not null
const originalVector = TEST_TABLE.getChildAt(columnIndex) as arrow.Vector;
const fieldPtr = FFI_TABLE.schemaAddr(columnIndex);
const field = parseField(WASM_MEMORY.buffer, fieldPtr);

expect(field.name).toStrictEqual(originalField.name);
expect(field.typeId).toStrictEqual(originalField.typeId);
expect(field.nullable).toStrictEqual(originalField.nullable);

const arrayPtr = FFI_TABLE.arrayAddr(0, columnIndex);
const wasmVector = parseVector(
WASM_MEMORY.buffer,
arrayPtr,
field.type,
copy
);

for (let i = 0; i < 3; i++) {
expect(originalVector.get(i), wasmVector.get(i));
}
}

it("copy=false", () => test(false));
it("copy=true", () => test(true));
});

describe("nullable int", (t) => {
function test(copy: boolean) {
let columnIndex = TEST_TABLE.schema.fields.findIndex(
Expand Down
14 changes: 12 additions & 2 deletions tests/pyarrow_generate_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime
from datetime import date, datetime, timedelta
from decimal import Decimal

import numpy as np
Expand Down Expand Up @@ -130,6 +130,16 @@ def duration_array() -> pa.Array:
return arr


def interval_array() -> pa.Array:
val = timedelta(
days=1, seconds=1, microseconds=1, milliseconds=1, minutes=1, hours=1, weeks=1
)
arr = pa.array([val, val, val], pa.month_day_nano_interval())

assert isinstance(arr, pa.MonthDayNanoIntervalArray)
return arr


def nullable_int() -> pa.Array:
# True means null
mask = [True, False, True]
Expand Down Expand Up @@ -243,10 +253,10 @@ def table() -> pa.Table:
"sparse_union": sparse_union_array(),
"dense_union": dense_union_array(),
"duration": duration_array(),
"interval": interval_array(),
}
)


def large_table() -> pa.Table:
# Important: the order of these columns cannot change
return pa.table(
Expand Down
72 changes: 60 additions & 12 deletions tests/rust-arrow-ffi/Cargo.lock

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

2 changes: 1 addition & 1 deletion tests/rust-arrow-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ wasm-bindgen = "0.2.63"
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = "0.1.6"
arrow2 = { version = "0.13.1", features = ["io_ipc"] }
arrow2 = { version = "0.17.4", features = ["io_ipc"] }
thiserror = "1.0"

[dev-dependencies]
Expand Down
Binary file modified tests/table.arrow
Binary file not shown.