From daa04c081f214fedba28ba1c3e5c92be7c664ecb Mon Sep 17 00:00:00 2001 From: connor Date: Tue, 1 Dec 2026 22:41:46 +0000 Subject: [PATCH] Extract temporal types and operations into vortex-temporal Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Signed-off-by: connor Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Signed-off-by: connor Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- Cargo.lock | 37 ++- Cargo.toml | 2 + encodings/datetime-parts/Cargo.toml | 1 + .../benches/date_time_parts_decode.rs | 6 +- .../datetime-parts/benches/split_temporal.rs | 11 +- encodings/datetime-parts/src/array/mod.rs | 2 +- encodings/datetime-parts/src/block.rs | 8 +- encodings/datetime-parts/src/canonical.rs | 10 +- encodings/datetime-parts/src/compress.rs | 8 +- encodings/datetime-parts/src/compute/cast.rs | 4 +- .../datetime-parts/src/compute/compare.rs | 10 +- .../datetime-parts/src/compute/filter.rs | 4 +- encodings/datetime-parts/src/compute/mask.rs | 4 +- encodings/datetime-parts/src/compute/mod.rs | 4 +- encodings/datetime-parts/src/compute/rules.rs | 8 +- encodings/datetime-parts/src/compute/take.rs | 4 +- encodings/datetime-parts/src/ops.rs | 4 +- encodings/datetime-parts/src/timestamp.rs | 2 +- encodings/parquet-variant/Cargo.toml | 1 + encodings/parquet-variant/src/operations.rs | 8 +- encodings/sparse/Cargo.toml | 1 + encodings/sparse/src/canonical.rs | 4 +- fuzz/Cargo.toml | 1 + fuzz/fuzz_targets/arrow_roundtrip.rs | 8 +- scripts/codspeed_bench_counts.json | 5 +- vortex-array/Cargo.toml | 1 - vortex-array/benches/compare_sorted.rs | 12 - .../src/aggregate_fn/fns/min_max/mod.rs | 26 -- .../fns/uncompressed_size_in_bytes/mod.rs | 6 +- vortex-array/src/aggregate_fn/session.rs | 13 +- .../src/aggregate_fn/storage_pushdown.rs | 286 +----------------- .../src/arrays/constant/vtable/canonical.rs | 15 +- .../src/arrays/constant/vtable/mod.rs | 9 +- .../src/arrays/extension/compute/cast.rs | 147 +++++---- .../src/arrays/extension/compute/compare.rs | 3 +- .../src/arrays/extension/compute/fill_null.rs | 21 +- .../src/arrays/extension/compute/mod.rs | 48 +-- vortex-array/src/arrays/mod.rs | 3 - vortex-array/src/arrays/repeated/tests.rs | 11 +- .../src/arrays/runend/array/to_dict.rs | 16 +- .../src/arrays/runend/compute/cast.rs | 15 +- vortex-array/src/builders/extension.rs | 28 +- vortex-array/src/builders/tests.rs | 41 +-- vortex-array/src/canonical.rs | 8 +- vortex-array/src/dtype/dtype_impl.rs | 39 ++- vortex-array/src/dtype/extension/tests.rs | 69 ----- vortex-array/src/dtype/extension/typed.rs | 11 - vortex-array/src/dtype/serde/mod.rs | 102 +++---- vortex-array/src/dtype/serde/proto.rs | 26 +- vortex-array/src/dtype/session.rs | 22 +- vortex-array/src/extension/mod.rs | 2 - vortex-array/src/extension/tests/mod.rs | 22 ++ vortex-array/src/optimizer/kernels.rs | 16 +- vortex-array/src/scalar/display.rs | 119 -------- vortex-array/src/scalar/tests/nullability.rs | 25 +- vortex-array/src/scalar/tests/primitives.rs | 11 +- vortex-array/src/scalar/validate.rs | 8 +- .../src/scalar_fn/builtin/cast/kernel.rs | 21 +- .../src/scalar_fn/builtin/compare/tests.rs | 146 +-------- .../src/scalar_fn/builtin/fill_null/kernel.rs | 14 +- .../src/scalar_fn/unstable/row/batch/tests.rs | 9 +- .../unstable/row/types/element/tuple/tests.rs | 9 +- vortex-arrow/Cargo.toml | 1 + vortex-arrow/src/convert.rs | 18 +- vortex-arrow/src/dtype.rs | 14 +- vortex-arrow/src/executor/dictionary.rs | 10 +- vortex-arrow/src/executor/mod.rs | 14 +- vortex-arrow/src/executor/run_end.rs | 5 +- vortex-arrow/src/executor/temporal.rs | 6 +- vortex-arrow/src/ext_metadata.rs | 4 +- vortex-arrow/src/scalar.rs | 16 +- vortex-arrow/src/session.rs | 2 +- vortex-arrow/src/test_harness/temporal.rs | 16 +- vortex-arrow/tests/integration/vortex_id.rs | 9 +- vortex-btrblocks/Cargo.toml | 1 + vortex-btrblocks/src/schemes/temporal.rs | 6 +- vortex-btrblocks/src/tests.rs | 5 +- vortex-btrblocks/tests/golden.rs | 12 +- vortex-compressor/Cargo.toml | 1 + .../src/compressor/constant/tests.rs | 10 +- vortex-cuda/src/arrow/canonical.rs | 8 +- vortex-cuda/src/hybrid_dispatch/mod.rs | 6 +- .../src/kernel/encodings/date_time_parts.rs | 10 +- vortex-duckdb/src/convert/vector.rs | 8 +- vortex-duckdb/src/exporter/extension.rs | 6 +- vortex-duckdb/src/exporter/temporal.rs | 4 +- vortex-expr/src/tests/fill_null.rs | 18 +- vortex-extensions/vortex-temporal/Cargo.toml | 43 +++ .../benches/timestamp_compare.rs | 81 +++++ .../vortex-temporal/src/arrays/mod.rs | 10 + .../src/arrays/temporal}/mod.rs | 41 +-- .../src/arrays/temporal}/tests.rs | 28 +- .../vortex-temporal}/src/change_time_unit.rs | 37 +-- .../vortex-temporal}/src/convert_time_zone.rs | 11 +- .../vortex-temporal}/src/date_to_timestamp.rs | 24 +- .../vortex-temporal/src}/datetime/counts.rs | 34 +-- .../vortex-temporal/src}/datetime/date.rs | 72 +++-- .../vortex-temporal/src}/datetime/duration.rs | 34 +-- .../vortex-temporal/src}/datetime/matcher.rs | 16 +- .../vortex-temporal/src}/datetime/mod.rs | 24 +- .../vortex-temporal/src}/datetime/rounding.rs | 2 +- .../vortex-temporal/src}/datetime/time.rs | 53 ++-- .../src}/datetime/timestamp.rs | 68 +++-- .../vortex-temporal/src}/datetime/unit.rs | 0 vortex-extensions/vortex-temporal/src/expr.rs | 128 ++++++++ vortex-extensions/vortex-temporal/src/lib.rs | 65 ++++ .../vortex-temporal}/src/replace_time_zone.rs | 15 +- .../vortex-temporal/src/tests/aggregate.rs | 249 +++++++++++++++ .../vortex-temporal/src/tests/common.rs | 39 +++ .../vortex-temporal/src/tests/compare.rs | 164 ++++++++++ .../vortex-temporal/src/tests/mod.rs | 11 + .../src/tests/scalar_display.rs | 117 +++++++ .../vortex-temporal}/src/timestamp_to_date.rs | 36 +-- .../vortex-temporal}/src/timestamp_to_time.rs | 36 +-- vortex-extensions/vortex-uuid/Cargo.toml | 1 + vortex-extensions/vortex-uuid/src/text.rs | 4 +- vortex-ffi/src/scalar.rs | 4 +- vortex-file/Cargo.toml | 1 + vortex-file/src/tests.rs | 9 +- vortex-file/src/v2/file_stats_reader.rs | 5 +- vortex-file/src/writer.rs | 7 +- vortex-functions/Cargo.toml | 2 +- vortex-functions/benches/zip_dtypes.rs | 5 +- vortex-functions/src/expr/mod.rs | 107 ------- vortex-functions/src/ext_storage.rs | 4 +- vortex-functions/src/lib.rs | 32 +- vortex-functions/src/tests/mod.rs | 30 -- vortex-functions/src/zip/extension.rs | 5 +- vortex-layout/Cargo.toml | 1 + .../bloom_filter/canonical/extension.rs | 4 +- .../zoned/aggregates/bloom_filter/constant.rs | 4 +- vortex-layout/src/layouts/zoned/schema.rs | 11 +- vortex-layout/src/layouts/zoned/writer.rs | 4 +- vortex-python/src/expr/mod.rs | 2 +- vortex-row/Cargo.toml | 1 + vortex-row/src/tests.rs | 10 +- vortex-test/compat-gen/Cargo.toml | 1 + .../arrays/synthetic/arrays/datetime.rs | 4 +- .../arrays/synthetic/encodings/constant.rs | 4 +- .../synthetic/encodings/datetimeparts.rs | 4 +- vortex-test/e2e-cuda/src/lib.rs | 8 +- vortex/Cargo.toml | 8 +- .../common_encoding_tree_throughput.rs | 2 +- vortex/src/editions/tests.rs | 6 +- vortex/src/editions/unstable_tests.rs | 4 +- vortex/src/lib.rs | 16 +- 146 files changed, 1931 insertions(+), 1564 deletions(-) create mode 100644 vortex-extensions/vortex-temporal/Cargo.toml create mode 100644 vortex-extensions/vortex-temporal/benches/timestamp_compare.rs create mode 100644 vortex-extensions/vortex-temporal/src/arrays/mod.rs rename {vortex-array/src/arrays/datetime => vortex-extensions/vortex-temporal/src/arrays/temporal}/mod.rs (85%) rename {vortex-array/src/arrays/datetime => vortex-extensions/vortex-temporal/src/arrays/temporal}/tests.rs (90%) rename {vortex-functions => vortex-extensions/vortex-temporal}/src/change_time_unit.rs (96%) rename {vortex-functions => vortex-extensions/vortex-temporal}/src/convert_time_zone.rs (97%) rename {vortex-functions => vortex-extensions/vortex-temporal}/src/date_to_timestamp.rs (95%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/counts.rs (87%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/date.rs (75%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/duration.rs (90%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/matcher.rs (92%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/mod.rs (80%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/rounding.rs (97%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/time.rs (86%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/timestamp.rs (88%) rename {vortex-array/src/extension => vortex-extensions/vortex-temporal/src}/datetime/unit.rs (100%) create mode 100644 vortex-extensions/vortex-temporal/src/expr.rs create mode 100644 vortex-extensions/vortex-temporal/src/lib.rs rename {vortex-functions => vortex-extensions/vortex-temporal}/src/replace_time_zone.rs (98%) create mode 100644 vortex-extensions/vortex-temporal/src/tests/aggregate.rs create mode 100644 vortex-extensions/vortex-temporal/src/tests/common.rs create mode 100644 vortex-extensions/vortex-temporal/src/tests/compare.rs create mode 100644 vortex-extensions/vortex-temporal/src/tests/mod.rs create mode 100644 vortex-extensions/vortex-temporal/src/tests/scalar_display.rs rename {vortex-functions => vortex-extensions/vortex-temporal}/src/timestamp_to_date.rs (88%) rename {vortex-functions => vortex-extensions/vortex-temporal}/src/timestamp_to_time.rs (88%) diff --git a/Cargo.lock b/Cargo.lock index 56052e50db4..f149bea971e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11077,6 +11077,7 @@ dependencies = [ "vortex-sequence", "vortex-session", "vortex-sparse", + "vortex-temporal", "vortex-utils", "vortex-uuid", "vortex-zigzag", @@ -11131,7 +11132,6 @@ dependencies = [ "insta", "inventory", "itertools 0.14.0", - "jiff 1.0.3", "mimalloc", "num-traits", "num_enum", @@ -11209,6 +11209,7 @@ dependencies = [ "vortex-onpair", "vortex-scan", "vortex-session", + "vortex-temporal", "vortex-zstd", ] @@ -11317,6 +11318,7 @@ dependencies = [ "vortex-sequence", "vortex-session", "vortex-sparse", + "vortex-temporal", "vortex-utils", "vortex-zigzag", "vortex-zstd", @@ -11413,6 +11415,7 @@ dependencies = [ "vortex-buffer", "vortex-error", "vortex-session", + "vortex-temporal", ] [[package]] @@ -11433,6 +11436,7 @@ dependencies = [ "vortex-error", "vortex-mask", "vortex-session", + "vortex-temporal", "vortex-utils", ] @@ -11596,6 +11600,7 @@ dependencies = [ "vortex-mask", "vortex-session", "vortex-sparse", + "vortex-temporal", ] [[package]] @@ -11824,6 +11829,7 @@ dependencies = [ "vortex-sequence", "vortex-session", "vortex-sparse", + "vortex-temporal", "vortex-tensor", "vortex-utils", "vortex-zigzag", @@ -11861,7 +11867,6 @@ dependencies = [ "hegeltest", "insta", "itertools 0.14.0", - "jiff 1.0.3", "memchr", "mimalloc", "num-traits", @@ -11880,6 +11885,7 @@ dependencies = [ "vortex-expr", "vortex-mask", "vortex-session", + "vortex-temporal", "vortex-utils", ] @@ -11918,6 +11924,7 @@ dependencies = [ "vortex-row", "vortex-session", "vortex-spatial", + "vortex-temporal", "vortex-tensor", "vortex-utils", "vortex-uuid", @@ -12077,6 +12084,7 @@ dependencies = [ "vortex-scan", "vortex-sequence", "vortex-session", + "vortex-temporal", "vortex-utils", ] @@ -12164,6 +12172,7 @@ dependencies = [ "vortex-layout", "vortex-mask", "vortex-session", + "vortex-temporal", "vortex-uuid", ] @@ -12253,6 +12262,7 @@ dependencies = [ "vortex-error", "vortex-mask", "vortex-session", + "vortex-temporal", ] [[package]] @@ -12335,6 +12345,7 @@ dependencies = [ "vortex-functions", "vortex-mask", "vortex-session", + "vortex-temporal", ] [[package]] @@ -12413,6 +12424,27 @@ dependencies = [ "vortex-utils", ] +[[package]] +name = "vortex-temporal" +version = "0.1.0" +dependencies = [ + "codspeed-divan-compat", + "hegeltest", + "jiff 1.0.3", + "mimalloc", + "num_enum", + "prost 0.14.6", + "rstest", + "serde", + "serde_json", + "vortex-array", + "vortex-buffer", + "vortex-error", + "vortex-expr", + "vortex-mask", + "vortex-session", +] + [[package]] name = "vortex-tensor" version = "0.1.0" @@ -12510,6 +12542,7 @@ dependencies = [ "vortex-error", "vortex-expr", "vortex-session", + "vortex-temporal", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8ca2693d7d4..8630f18c59a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ members = [ "vortex-array", "vortex-functions", "vortex-expr", + "vortex-extensions/vortex-temporal", "vortex-arrow", "vortex-row", "vortex-compressor", @@ -339,6 +340,7 @@ vortex-sequence = { version = "0.1.0", path = "encodings/sequence", default-feat vortex-session = { version = "0.1.0", path = "./vortex-session", default-features = false } vortex-sparse = { version = "0.1.0", path = "./encodings/sparse", default-features = false } vortex-spatial = { version = "0.1.0", path = "./vortex-extensions/vortex-spatial", default-features = false } +vortex-temporal = { version = "0.1.0", path = "./vortex-extensions/vortex-temporal", default-features = false } vortex-tensor = { version = "0.1.0", path = "./vortex-extensions/vortex-tensor", default-features = false } vortex-utils = { version = "0.1.0", path = "./vortex-utils", default-features = false } vortex-uuid = { version = "0.1.0", path = "./vortex-extensions/vortex-uuid", default-features = false } diff --git a/encodings/datetime-parts/Cargo.toml b/encodings/datetime-parts/Cargo.toml index baf13d17ac1..d2c010386f0 100644 --- a/encodings/datetime-parts/Cargo.toml +++ b/encodings/datetime-parts/Cargo.toml @@ -25,6 +25,7 @@ vortex-error = { workspace = true } vortex-functions = { workspace = true } vortex-mask = { workspace = true } vortex-session = { workspace = true } +vortex-temporal = { workspace = true } [dev-dependencies] divan = { workspace = true } diff --git a/encodings/datetime-parts/benches/date_time_parts_decode.rs b/encodings/datetime-parts/benches/date_time_parts_decode.rs index 18c32405082..3b13bfbf56c 100644 --- a/encodings/datetime-parts/benches/date_time_parts_decode.rs +++ b/encodings/datetime-parts/benches/date_time_parts_decode.rs @@ -18,13 +18,10 @@ use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::ConstantArray; use vortex_array::arrays::PrimitiveArray; -use vortex_array::arrays::TemporalArray; use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; use vortex_array::dtype::PType; -use vortex_array::extension::datetime::TimeUnit; -use vortex_array::extension::datetime::Timestamp; use vortex_array::scalar::Scalar; use vortex_array::session::ArraySession; use vortex_datetime_parts::DateTimeParts; @@ -33,6 +30,9 @@ use vortex_fastlanes::FoR; use vortex_fastlanes::bitpack_compress::bitpack_encode; use vortex_session::VortexSession; use vortex_sparse::Sparse; +use vortex_temporal::arrays::TemporalArray; +use vortex_temporal::datetime::TimeUnit; +use vortex_temporal::datetime::Timestamp; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; diff --git a/encodings/datetime-parts/benches/split_temporal.rs b/encodings/datetime-parts/benches/split_temporal.rs index 9349969a5de..19bd685b01e 100644 --- a/encodings/datetime-parts/benches/split_temporal.rs +++ b/encodings/datetime-parts/benches/split_temporal.rs @@ -13,14 +13,14 @@ use rand::rngs::StdRng; use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; -use vortex_array::arrays::TemporalArray; -use vortex_array::extension::datetime::TimeUnit; use vortex_array::optimizer::kernels::KernelSession; use vortex_array::test_harness::mark_optimized; use vortex_array::validity::Validity; use vortex_buffer::Buffer; use vortex_datetime_parts::split_temporal; use vortex_session::VortexSession; +use vortex_temporal::arrays::TemporalArray; +use vortex_temporal::datetime::TimeUnit; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; @@ -30,8 +30,11 @@ fn main() { divan::main(); } -static SESSION: LazyLock = - LazyLock::new(|| VortexSession::empty().with::()); +static SESSION: LazyLock = LazyLock::new(|| { + let session = VortexSession::empty().with::(); + vortex_temporal::initialize(&session); + session +}); const BENCH_ARGS: &[(usize, TimeUnit)] = &[ (8_192, TimeUnit::Seconds), diff --git a/encodings/datetime-parts/src/array/mod.rs b/encodings/datetime-parts/src/array/mod.rs index 38f69be12a5..ecb0c9ef8ce 100644 --- a/encodings/datetime-parts/src/array/mod.rs +++ b/encodings/datetime-parts/src/array/mod.rs @@ -20,7 +20,6 @@ use vortex_array::ExecutionResult; use vortex_array::IntoArray; use vortex_array::array_slots; use vortex_array::arrays::Primitive; -use vortex_array::arrays::TemporalArray; use vortex_array::block::BlockOp; use vortex_array::buffer::BufferHandle; use vortex_array::dtype::DType; @@ -37,6 +36,7 @@ use vortex_error::vortex_ensure_eq; use vortex_error::vortex_err; use vortex_error::vortex_panic; use vortex_session::registry::CachedId; +use vortex_temporal::arrays::TemporalArray; use crate::TemporalParts; use crate::block::days_block_op; diff --git a/encodings/datetime-parts/src/block.rs b/encodings/datetime-parts/src/block.rs index 8f849b71ee6..c3ef98bfcdd 100644 --- a/encodings/datetime-parts/src/block.rs +++ b/encodings/datetime-parts/src/block.rs @@ -18,13 +18,13 @@ use vortex_array::dtype::DType; use vortex_array::dtype::NativePType; use vortex_array::dtype::Nullability; use vortex_array::dtype::PType; -use vortex_array::extension::datetime::TimeUnit; -use vortex_array::extension::datetime::Timestamp; use vortex_array::match_each_integer_ptype; use vortex_buffer::Buffer; use vortex_compute::lane_kernels::Repeat; use vortex_error::VortexResult; use vortex_error::vortex_bail; +use vortex_temporal::datetime::TimeUnit; +use vortex_temporal::datetime::Timestamp; use crate::canonical::combine_parts; use crate::timestamp::SECONDS_PER_DAY; @@ -224,10 +224,8 @@ mod tests { use vortex_array::arrays::ConstantArray; use vortex_array::arrays::DictArray; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::assert_arrays_eq; use vortex_array::dtype::DType; - use vortex_array::extension::datetime::TimeUnit; use vortex_array::match_each_integer_ptype; use vortex_array::scalar::Scalar; use vortex_array::test_harness::fusion::fusion_trace; @@ -236,6 +234,8 @@ mod tests { use vortex_fastlanes::FoR; use vortex_fastlanes::bitpack_compress::bitpack_encode; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; use crate::array::DateTimePartsArraySlotsExt; diff --git a/encodings/datetime-parts/src/canonical.rs b/encodings/datetime-parts/src/canonical.rs index 9f2a2c64db1..4d15fd6c11a 100644 --- a/encodings/datetime-parts/src/canonical.rs +++ b/encodings/datetime-parts/src/canonical.rs @@ -9,14 +9,11 @@ use vortex_array::ExecutionCtx; use vortex_array::IntoArray; use vortex_array::arrays::Primitive; use vortex_array::arrays::PrimitiveArray; -use vortex_array::arrays::TemporalArray; use vortex_array::arrays::primitive::PrimitiveArrayExt; use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; use vortex_array::dtype::PType; -use vortex_array::extension::datetime::TimeUnit; -use vortex_array::extension::datetime::Timestamp; use vortex_array::match_each_integer_ptype; use vortex_buffer::BufferMut; use vortex_compute::lane_kernels::IndexedSource; @@ -26,6 +23,9 @@ use vortex_compute::lane_kernels::Repeat; use vortex_error::VortexExpect as _; use vortex_error::VortexResult; use vortex_error::vortex_panic; +use vortex_temporal::arrays::TemporalArray; +use vortex_temporal::datetime::TimeUnit; +use vortex_temporal::datetime::Timestamp; use crate::array::DateTimePartsParts; use crate::timestamp::SECONDS_PER_DAY; @@ -171,14 +171,14 @@ mod test { use vortex_array::VortexSessionExecute; use vortex_array::arrays::ConstantArray; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::arrays::extension::ExtensionArrayExt; use vortex_array::assert_arrays_eq; - use vortex_array::extension::datetime::TimeUnit; use vortex_array::validity::Validity; use vortex_buffer::buffer; use vortex_error::VortexResult; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; use crate::array::DateTimePartsArraySlotsExt; diff --git a/encodings/datetime-parts/src/compress.rs b/encodings/datetime-parts/src/compress.rs index 81d22925652..128cd792028 100644 --- a/encodings/datetime-parts/src/compress.rs +++ b/encodings/datetime-parts/src/compress.rs @@ -19,15 +19,15 @@ use vortex_array::aggregate_fn::fns::min_max::MinMaxResult; use vortex_array::aggregate_fn::fns::min_max::min_max; use vortex_array::arrays::ConstantArray; use vortex_array::arrays::PrimitiveArray; -use vortex_array::arrays::TemporalArray; use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::PType; -use vortex_array::extension::datetime::TimeUnit; use vortex_buffer::Buffer; use vortex_buffer::BufferMut; use vortex_error::VortexResult; use vortex_error::vortex_bail; +use vortex_temporal::arrays::TemporalArray; +use vortex_temporal::datetime::TimeUnit; use crate::timestamp; @@ -277,10 +277,8 @@ mod tests { use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::assert_arrays_eq; use vortex_array::dtype::PType; - use vortex_array::extension::datetime::TimeUnit; use vortex_array::serde::SerializeOptions; use vortex_array::serde::SerializedArray; use vortex_array::validity::Validity; @@ -290,6 +288,8 @@ mod tests { use vortex_error::VortexResult; use vortex_session::VortexSession; use vortex_session::registry::ReadContext; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use super::day_offset; use crate::DateTimeParts; diff --git a/encodings/datetime-parts/src/compute/cast.rs b/encodings/datetime-parts/src/compute/cast.rs index e49b0bdc853..9dabe60a3a7 100644 --- a/encodings/datetime-parts/src/compute/cast.rs +++ b/encodings/datetime-parts/src/compute/cast.rs @@ -41,14 +41,14 @@ mod tests { use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; - use vortex_array::extension::datetime::TimeUnit; use vortex_array::validity::Validity; use vortex_buffer::buffer; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; use crate::DateTimePartsArray; diff --git a/encodings/datetime-parts/src/compute/compare.rs b/encodings/datetime-parts/src/compute/compare.rs index e49e70db6b3..510f9d552d2 100644 --- a/encodings/datetime-parts/src/compute/compare.rs +++ b/encodings/datetime-parts/src/compute/compare.rs @@ -16,7 +16,6 @@ use vortex_array::arrays::bool::BoolArrayExt; use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::Nullability; -use vortex_array::extension::datetime::Timestamp; use vortex_array::scalar::Scalar; use vortex_array::scalar_fn::builtin::compare::CompareKernel; use vortex_array::scalar_fn::builtin::operators::BooleanOperator; @@ -26,6 +25,7 @@ use vortex_array::validity::Validity; use vortex_error::VortexResult; use vortex_error::vortex_ensure; use vortex_mask::AllOr; +use vortex_temporal::datetime::Timestamp; use crate::array::DateTimeParts; use crate::array::DateTimePartsArraySlotsExt; @@ -326,17 +326,17 @@ mod tests { use vortex_array::arrays::BoolArray; use vortex_array::arrays::ConstantArray; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::assert_arrays_eq; use vortex_array::dtype::IntegerPType; - use vortex_array::extension::datetime::TimeUnit; - use vortex_array::extension::datetime::Timestamp; - use vortex_array::extension::datetime::TimestampOptions; use vortex_array::scalar::Scalar; use vortex_array::scalar_fn::builtin::compare::CompareKernel; use vortex_array::validity::Validity; use vortex_buffer::buffer; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; + use vortex_temporal::datetime::Timestamp; + use vortex_temporal::datetime::TimestampOptions; use super::*; use crate::DateTimeParts; diff --git a/encodings/datetime-parts/src/compute/filter.rs b/encodings/datetime-parts/src/compute/filter.rs index 1c3f04764f9..b47f14b716d 100644 --- a/encodings/datetime-parts/src/compute/filter.rs +++ b/encodings/datetime-parts/src/compute/filter.rs @@ -31,11 +31,11 @@ mod test { use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::compute::conformance::filter::test_filter_conformance; - use vortex_array::extension::datetime::TimeUnit; use vortex_buffer::buffer; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; diff --git a/encodings/datetime-parts/src/compute/mask.rs b/encodings/datetime-parts/src/compute/mask.rs index 51e0b365c5f..1d211964a3e 100644 --- a/encodings/datetime-parts/src/compute/mask.rs +++ b/encodings/datetime-parts/src/compute/mask.rs @@ -34,13 +34,13 @@ mod tests { use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::compute::conformance::mask::test_mask_conformance; - use vortex_array::extension::datetime::TimeUnit; use vortex_array::optimizer::ArrayOptimizer; use vortex_buffer::buffer; use vortex_error::VortexResult; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; use crate::DateTimePartsArray; diff --git a/encodings/datetime-parts/src/compute/mod.rs b/encodings/datetime-parts/src/compute/mod.rs index 9afa114da5f..01cdb7f494a 100644 --- a/encodings/datetime-parts/src/compute/mod.rs +++ b/encodings/datetime-parts/src/compute/mod.rs @@ -19,11 +19,11 @@ mod tests { use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::compute::conformance::consistency::test_array_consistency; - use vortex_array::extension::datetime::TimeUnit; use vortex_buffer::buffer; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; use crate::DateTimePartsArray; diff --git a/encodings/datetime-parts/src/compute/rules.rs b/encodings/datetime-parts/src/compute/rules.rs index 652e421f5fe..3b34add5cdd 100644 --- a/encodings/datetime-parts/src/compute/rules.rs +++ b/encodings/datetime-parts/src/compute/rules.rs @@ -15,7 +15,6 @@ use vortex_array::arrays::scalar_fn::ScalarFn; use vortex_array::arrays::scalar_fn::ScalarFnArrayExt; use vortex_array::arrays::slice::SliceReduceAdaptor; use vortex_array::dtype::DType; -use vortex_array::extension::datetime::Timestamp; use vortex_array::optimizer::kernels::ArrayKernelsExt; use vortex_array::optimizer::rules::ArrayParentReduceRule; use vortex_array::scalar::Scalar; @@ -28,6 +27,7 @@ use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_functions::between::Between; use vortex_session::VortexSession; +use vortex_temporal::datetime::Timestamp; use crate::DateTimeParts; use crate::array::DateTimePartsArraySlotsExt; @@ -219,11 +219,8 @@ mod tests { use vortex_array::arrays::BoolArray; use vortex_array::arrays::FilterArray; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::assert_arrays_eq; use vortex_array::dtype::Nullability; - use vortex_array::extension::datetime::TimeUnit; - use vortex_array::extension::datetime::TimestampOptions; use vortex_array::optimizer::ArrayOptimizer; use vortex_array::scalar::Scalar; use vortex_array::scalar_fn::builtin::operators::CompareMode; @@ -234,6 +231,9 @@ mod tests { use vortex_functions::between::StrictComparison; use vortex_mask::Mask; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; + use vortex_temporal::datetime::TimestampOptions; use super::*; use crate::DateTimeParts; diff --git a/encodings/datetime-parts/src/compute/take.rs b/encodings/datetime-parts/src/compute/take.rs index 6d33c4a0150..319a5e906c0 100644 --- a/encodings/datetime-parts/src/compute/take.rs +++ b/encodings/datetime-parts/src/compute/take.rs @@ -100,11 +100,11 @@ mod tests { use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::PrimitiveArray; - use vortex_array::arrays::TemporalArray; use vortex_array::compute::conformance::take::test_take_conformance; - use vortex_array::extension::datetime::TimeUnit; use vortex_buffer::buffer; use vortex_session::VortexSession; + use vortex_temporal::arrays::TemporalArray; + use vortex_temporal::datetime::TimeUnit; use crate::DateTimeParts; use crate::DateTimePartsArray; diff --git a/encodings/datetime-parts/src/ops.rs b/encodings/datetime-parts/src/ops.rs index 92e8cf4a60e..56f83b2aabf 100644 --- a/encodings/datetime-parts/src/ops.rs +++ b/encodings/datetime-parts/src/ops.rs @@ -6,12 +6,12 @@ use vortex_array::ExecutionCtx; use vortex_array::ProbeState; use vortex_array::dtype::DType; use vortex_array::dtype::IntegerPType; -use vortex_array::extension::datetime::Timestamp; use vortex_array::scalar::Scalar; use vortex_array::vtable::OperationsVTable; use vortex_error::VortexResult; use vortex_error::vortex_err; use vortex_error::vortex_panic; +use vortex_temporal::datetime::Timestamp; use crate::DateTimeParts; use crate::DateTimePartsSlots; @@ -107,9 +107,9 @@ mod tests { use vortex_array::VortexSessionExecute; use vortex_array::arrays::ConstantArray; use vortex_array::dtype::Nullability; - use vortex_array::extension::datetime::TimeUnit; use vortex_buffer::buffer; use vortex_session::VortexSession; + use vortex_temporal::datetime::TimeUnit; use super::*; diff --git a/encodings/datetime-parts/src/timestamp.rs b/encodings/datetime-parts/src/timestamp.rs index 76c379a518f..1d8e00bb9d4 100644 --- a/encodings/datetime-parts/src/timestamp.rs +++ b/encodings/datetime-parts/src/timestamp.rs @@ -7,10 +7,10 @@ //! narrow the days component when the values fit. use num_traits::AsPrimitive; -use vortex_array::extension::datetime::TimeUnit; use vortex_error::VortexResult; use vortex_error::vortex_bail; use vortex_error::vortex_err; +use vortex_temporal::datetime::TimeUnit; pub const SECONDS_PER_DAY: i64 = 86_400; // 24 * 60 * 60 diff --git a/encodings/parquet-variant/Cargo.toml b/encodings/parquet-variant/Cargo.toml index 1c63ec2fade..56e66eee21b 100644 --- a/encodings/parquet-variant/Cargo.toml +++ b/encodings/parquet-variant/Cargo.toml @@ -32,6 +32,7 @@ vortex-functions = { workspace = true } vortex-json = { workspace = true } vortex-mask = { workspace = true } vortex-session = { workspace = true } +vortex-temporal = { workspace = true } [dev-dependencies] divan = { workspace = true } diff --git a/encodings/parquet-variant/src/operations.rs b/encodings/parquet-variant/src/operations.rs index 4ae8df3e5ae..54b13c0943e 100644 --- a/encodings/parquet-variant/src/operations.rs +++ b/encodings/parquet-variant/src/operations.rs @@ -14,10 +14,6 @@ use vortex_array::dtype::FieldName; use vortex_array::dtype::FieldNames; use vortex_array::dtype::Nullability; use vortex_array::dtype::StructFields; -use vortex_array::extension::datetime::Date; -use vortex_array::extension::datetime::Time; -use vortex_array::extension::datetime::TimeUnit; -use vortex_array::extension::datetime::Timestamp; use vortex_array::scalar::PValue; use vortex_array::scalar::Scalar; use vortex_array::scalar::ScalarValue; @@ -26,6 +22,10 @@ use vortex_error::VortexExpect; use vortex_error::VortexResult; use vortex_error::vortex_bail; use vortex_error::vortex_err; +use vortex_temporal::datetime::Date; +use vortex_temporal::datetime::Time; +use vortex_temporal::datetime::TimeUnit; +use vortex_temporal::datetime::Timestamp; use crate::array::ParquetVariantSlots; use crate::vtable::ParquetVariant; diff --git a/encodings/sparse/Cargo.toml b/encodings/sparse/Cargo.toml index ba5f267f660..d667873783b 100644 --- a/encodings/sparse/Cargo.toml +++ b/encodings/sparse/Cargo.toml @@ -34,6 +34,7 @@ mimalloc = { workspace = true } rstest = { workspace = true } vortex-array = { workspace = true, features = ["_test-harness"] } vortex-arrow = { workspace = true } +vortex-temporal = { workspace = true } [[bench]] name = "sparse_canonical" diff --git a/encodings/sparse/src/canonical.rs b/encodings/sparse/src/canonical.rs index 4a6a7090ee7..0f416530272 100644 --- a/encodings/sparse/src/canonical.rs +++ b/encodings/sparse/src/canonical.rs @@ -926,8 +926,6 @@ mod test { use vortex_array::dtype::Nullability::Nullable; use vortex_array::dtype::PType; use vortex_array::dtype::StructFields; - use vortex_array::extension::datetime::TimeUnit; - use vortex_array::extension::datetime::Timestamp; use vortex_array::scalar::DecimalValue; use vortex_array::scalar::Scalar; use vortex_array::validity::Validity; @@ -940,6 +938,8 @@ mod test { use vortex_error::VortexResult; use vortex_mask::Mask; use vortex_session::VortexSession; + use vortex_temporal::datetime::TimeUnit; + use vortex_temporal::datetime::Timestamp; use crate::Sparse; diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index eb8a8af0a94..ad83b98779f 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -85,6 +85,7 @@ vortex-cuda = { workspace = true, optional = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } +vortex-temporal = { workspace = true } [lints] workspace = true diff --git a/fuzz/fuzz_targets/arrow_roundtrip.rs b/fuzz/fuzz_targets/arrow_roundtrip.rs index 011839b396a..d46593b0057 100644 --- a/fuzz/fuzz_targets/arrow_roundtrip.rs +++ b/fuzz/fuzz_targets/arrow_roundtrip.rs @@ -34,10 +34,6 @@ use vortex_array::dtype::Nullability; use vortex_array::dtype::PType; use vortex_array::dtype::extension::ExtDType; use vortex_array::dtype::extension::ExtDTypeRef; -use vortex_array::extension::datetime::Date; -use vortex_array::extension::datetime::Time; -use vortex_array::extension::datetime::TimeUnit; -use vortex_array::extension::datetime::Timestamp; use vortex_array::validity::Validity; use vortex_arrow::test_harness::check_containers; use vortex_buffer::Buffer; @@ -55,6 +51,10 @@ use vortex_spatial::extension::Polygon; use vortex_spatial::extension::Rect; use vortex_spatial::extension::SpatialMetadata; use vortex_spatial::extension::WellKnownBinary; +use vortex_temporal::datetime::Date; +use vortex_temporal::datetime::Time; +use vortex_temporal::datetime::TimeUnit; +use vortex_temporal::datetime::Timestamp; use vortex_tensor::fixed_shape_tensor::FixedShapeTensor; use vortex_tensor::fixed_shape_tensor::FixedShapeTensorMetadata; use vortex_tensor::vector::Vector; diff --git a/scripts/codspeed_bench_counts.json b/scripts/codspeed_bench_counts.json index 4c6b09520bd..694c5ddae37 100644 --- a/scripts/codspeed_bench_counts.json +++ b/scripts/codspeed_bench_counts.json @@ -28,7 +28,7 @@ "chunked_fsl_canonicalize": 6, "chunked_nested_canonicalize": 10, "compare": 9, - "compare_sorted": 3, + "compare_sorted": 2, "copy_to_canonical_width": 0, "dict_compare": 16, "dict_compress": 31, @@ -215,6 +215,9 @@ "inner_product": 6, "l2_norm": 6 }, + "vortex-temporal": { + "timestamp_compare": 1 + }, "vortex-zigzag": { "zigzag_decode": 1 } diff --git a/vortex-array/Cargo.toml b/vortex-array/Cargo.toml index fec3b56d6eb..60c40da3aee 100644 --- a/vortex-array/Cargo.toml +++ b/vortex-array/Cargo.toml @@ -40,7 +40,6 @@ hegeltest = { workspace = true, optional = true } humansize = { workspace = true } inventory = { workspace = true } itertools = { workspace = true } -jiff = { workspace = true } num-traits = { workspace = true } num_enum = { workspace = true } parking_lot = { workspace = true } diff --git a/vortex-array/benches/compare_sorted.rs b/vortex-array/benches/compare_sorted.rs index 9489c67ca62..3a5ecee92a3 100644 --- a/vortex-array/benches/compare_sorted.rs +++ b/vortex-array/benches/compare_sorted.rs @@ -13,12 +13,8 @@ use vortex_array::Canonical; use vortex_array::IntoArray; use vortex_array::VortexSessionExecute; use vortex_array::arrays::ConstantArray; -use vortex_array::arrays::ExtensionArray; use vortex_array::arrays::VarBinViewArray; use vortex_array::builtins::ArrayBuiltins; -use vortex_array::dtype::Nullability; -use vortex_array::extension::datetime::TimeUnit; -use vortex_array::extension::datetime::Timestamp; use vortex_array::memory::MemorySession; use vortex_array::optimizer::kernels::KernelSession; use vortex_array::scalar::Scalar; @@ -83,14 +79,6 @@ fn i64_lt(bencher: Bencher) { ); } -#[divan::bench] -fn timestamp_gte(bencher: Bencher) { - let dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); - let array = ExtensionArray::new(dtype.clone(), ints().into_array()).into_array(); - let constant = Scalar::extension_ref(dtype, needle().into()); - bench_compare(bencher, array, constant, CompareOperator::Gte); -} - #[divan::bench] fn utf8_lt(bencher: Bencher) { let array = diff --git a/vortex-array/src/aggregate_fn/fns/min_max/mod.rs b/vortex-array/src/aggregate_fn/fns/min_max/mod.rs index f8e51d31abe..876fcea980a 100644 --- a/vortex-array/src/aggregate_fn/fns/min_max/mod.rs +++ b/vortex-array/src/aggregate_fn/fns/min_max/mod.rs @@ -575,7 +575,6 @@ mod tests { use crate::arrays::ListArray; use crate::arrays::NullArray; use crate::arrays::PrimitiveArray; - use crate::arrays::TemporalArray; use crate::arrays::VarBinArray; use crate::dtype::BigCast; use crate::dtype::DType; @@ -585,7 +584,6 @@ mod tests { use crate::dtype::extension::ExtDType; use crate::dtype::extension::ExtId; use crate::dtype::extension::ExtVTable; - use crate::extension::datetime::TimeUnit; use crate::match_each_decimal_value_type; use crate::scalar::DecimalValue; use crate::scalar::Scalar; @@ -611,30 +609,6 @@ mod tests { Ok(()) } - #[test] - fn test_timestamp_min_max_beyond_jiff_range() -> VortexResult<()> { - // Midnight on 9999-12-31 UTC. - const END_OF_9999_US: i64 = 253_402_214_400_000_000; - let timestamps = TemporalArray::new_timestamp( - PrimitiveArray::from_iter([0i64, END_OF_9999_US]).into_array(), - TimeUnit::Microseconds, - None, - ) - .into_array(); - let mut ctx = SESSION.create_execution_ctx(); - let MinMaxResult { min, max } = - min_max(×tamps, &mut ctx, NumericalAggregateOpts::default())? - .vortex_expect("two non-null timestamps have min and max"); - - assert_eq!(min.as_extension().to_storage_scalar(), 0i64.into()); - assert_eq!( - max.as_extension().to_storage_scalar(), - END_OF_9999_US.into() - ); - - Ok(()) - } - #[test] fn test_prim_min_max_multiple_null_runs() -> VortexResult<()> { // Several disjoint valid runs separated by nulls exercise the per-run fold; the extrema diff --git a/vortex-array/src/aggregate_fn/fns/uncompressed_size_in_bytes/mod.rs b/vortex-array/src/aggregate_fn/fns/uncompressed_size_in_bytes/mod.rs index 09133b2ab3b..f348775adfc 100644 --- a/vortex-array/src/aggregate_fn/fns/uncompressed_size_in_bytes/mod.rs +++ b/vortex-array/src/aggregate_fn/fns/uncompressed_size_in_bytes/mod.rs @@ -414,8 +414,7 @@ mod tests { use crate::dtype::Nullability; use crate::dtype::PType; use crate::dtype::UnionVariants; - use crate::extension::datetime::Date; - use crate::extension::datetime::TimeUnit; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; use crate::scalar::ScalarValue; use crate::stats::Precision; @@ -772,7 +771,8 @@ mod tests { #[test] fn extension_matches_materialized_size() -> VortexResult<()> { let storage = PrimitiveArray::from_option_iter([Some(1i32), None, Some(3)]).into_array(); - let ext_dtype = Date::new(TimeUnit::Days, Nullability::Nullable).erased(); + let ext_dtype = + extension_dtype(vec![0], DType::Primitive(PType::I32, Nullability::Nullable))?; let array = ExtensionArray::new(ext_dtype, storage).into_array(); assert_eq!( diff --git a/vortex-array/src/aggregate_fn/session.rs b/vortex-array/src/aggregate_fn/session.rs index 98bb8855e2e..d74ef6a4b86 100644 --- a/vortex-array/src/aggregate_fn/session.rs +++ b/vortex-array/src/aggregate_fn/session.rs @@ -59,10 +59,6 @@ use crate::arrays::runend::compute::min_max::RunEndMinMaxKernel; use crate::arrays::runend::compute::sum::RunEndSumKernel; use crate::arrays::widen::compute::aggregate::WidenArrayAggregate; use crate::dtype::extension::ExtVTable; -use crate::extension::datetime::Date; -use crate::extension::datetime::Duration; -use crate::extension::datetime::Time; -use crate::extension::datetime::Timestamp; /// Session state for aggregate functions and encoding-specific aggregate kernels. /// @@ -133,13 +129,6 @@ impl Default for AggregateFnSession { this.register(SumV2); this.register(UncompressedSizeInBytes); - // Temporal extension types compare like their integer storage, so comparison-based - // aggregates are pushed down into it. - this.register_storage_ordered(Date); - this.register_storage_ordered(Duration); - this.register_storage_ordered(Time); - this.register_storage_ordered(Timestamp); - // Register the built-in aggregate kernels. this.register_aggregate_kernel(Chunked.id(), None::, &ChunkedArrayAggregate); this.register_aggregate_kernel(Dict.id(), Some(MinMax.id()), &DictMinMaxKernel); @@ -197,7 +186,7 @@ impl AggregateFnSession { /// extension type `ext`, through [`ExtensionStoragePushdown`]. /// /// Only call this when comparing two values of `ext` is the same as comparing their storage, - /// as for the temporal types and for UUIDs, which are stored big-endian. See + /// as for types whose storage preserves their value ordering. See /// [`ExtensionStoragePushdown`] for how to check. pub fn register_storage_ordered(&self, ext: E) { self.register(ExtensionStoragePushdown::new(IsSorted, ext.clone())); diff --git a/vortex-array/src/aggregate_fn/storage_pushdown.rs b/vortex-array/src/aggregate_fn/storage_pushdown.rs index faa4f6fd54d..b8e349d11e5 100644 --- a/vortex-array/src/aggregate_fn/storage_pushdown.rs +++ b/vortex-array/src/aggregate_fn/storage_pushdown.rs @@ -46,68 +46,20 @@ use crate::scalar::Scalar; /// of the logical aggregate result. This requires storage to preserve whichever properties `A` /// relies on, such as ordering, equality, arithmetic, or NaN classification. /// -/// For example, minimum is defined for timestamps, and their integer storage preserves their -/// ordering, so both conditions hold. Summing timestamps fails the first condition even though -/// their storage supports addition. +/// For example, an extension type whose logical values preserve the order of their integer +/// storage can register minimum and maximum. Other operations may not be defined for that type, +/// even when their storage supports the operation. /// /// These conditions are not checked. An invalid registration can silently return incorrect results. /// /// # Results and partials /// /// Results and partial states are those of `A` over the storage dtype. Results are not converted -/// back to `E`. For example, the minimum and maximum of a timestamp column are raw `i64` values -/// in the column's time unit. +/// back to `E`; for primitive storage, they are values of the storage type. /// /// Partial states can only be combined when the aggregate, options, and full input dtype match. -/// This includes extension metadata, so timestamp partials with different time units must not be -/// combined even if their storage dtypes match. -/// -/// # Example -/// -/// Timestamps compare like their `i64` storage, so `is_sorted` can be pushed down. Register the -/// pair once on the session, then bind it like any other aggregate: -/// -/// ``` -/// # use vortex_array::IntoArray; -/// # use vortex_session::VortexSession; -/// # use vortex_array::VortexSessionExecute; -/// # use vortex_array::aggregate_fn::Accumulator; -/// # use vortex_array::aggregate_fn::DynAccumulator; -/// # use vortex_array::aggregate_fn::ExtensionStoragePushdown; -/// # use vortex_array::aggregate_fn::fns::is_sorted::IsSorted; -/// # use vortex_array::aggregate_fn::fns::is_sorted::IsSortedOptions; -/// # use vortex_array::aggregate_fn::session::AggregateFnSessionExt; -/// # use vortex_array::arrays::ExtensionArray; -/// # use vortex_array::arrays::PrimitiveArray; -/// # use vortex_array::dtype::DType; -/// # use vortex_array::dtype::Nullability; -/// # use vortex_array::extension::datetime::TimeUnit; -/// # use vortex_array::extension::datetime::Timestamp; -/// # fn main() -> vortex_error::VortexResult<()> { -/// let session = VortexSession::empty(); -/// -/// // Register `vortex.is_sorted[vortex.timestamp]`. -/// let is_sorted = ExtensionStoragePushdown::new(IsSorted, Timestamp); -/// session.aggregate_fns().register(is_sorted.clone()); -/// -/// // Aggregate a timestamp column through its storage. -/// let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); -/// let column = ExtensionArray::new( -/// ext_dtype.clone(), -/// PrimitiveArray::from_iter([1_000i64, 2_000, 3_000]).into_array(), -/// ) -/// .into_array(); -/// -/// let mut acc = Accumulator::try_new( -/// is_sorted, -/// IsSortedOptions { strict: true }, -/// DType::Extension(ext_dtype), -/// )?; -/// acc.accumulate(&column, &mut session.create_execution_ctx())?; -/// assert!(bool::try_from(&acc.finish()?)?); -/// # Ok(()) -/// # } -/// ``` +/// This includes extension metadata, so partials with different metadata must not be combined even +/// if their storage dtypes match. #[derive(Clone, Debug)] pub struct ExtensionStoragePushdown { aggregate: A, @@ -313,229 +265,3 @@ impl AggregateFnVTable for ExtensionStorageP .finalize_scalar(self.storage_args(args)?, partial) } } - -#[cfg(test)] -mod tests { - use std::sync::LazyLock; - - use rstest::rstest; - use vortex_error::VortexResult; - use vortex_session::VortexSession; - - use super::ExtensionStoragePushdown; - use crate::IntoArray; - use crate::VortexSessionExecute; - use crate::aggregate_fn::Accumulator; - use crate::aggregate_fn::AggregateFnVTable; - use crate::aggregate_fn::DynAccumulator; - use crate::aggregate_fn::NumericalAggregateOpts; - use crate::aggregate_fn::fns::is_sorted::IsSorted; - use crate::aggregate_fn::fns::is_sorted::IsSortedOptions; - use crate::aggregate_fn::fns::min_max::MinMax; - use crate::aggregate_fn::session::AggregateFnSessionExt; - use crate::arrays::ConstantArray; - use crate::arrays::ExtensionArray; - use crate::arrays::PrimitiveArray; - use crate::dtype::DType; - use crate::dtype::Nullability; - use crate::extension::datetime::Date; - use crate::extension::datetime::Duration; - use crate::extension::datetime::Time; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; - use crate::scalar::Scalar; - - static SESSION: LazyLock = LazyLock::new(VortexSession::empty); - - #[test] - fn pushes_down_into_storage() -> VortexResult<()> { - let session = VortexSession::empty(); - let aggregate = ExtensionStoragePushdown::new(MinMax, Timestamp); - session.aggregate_fns().register(aggregate.clone()); - assert!( - session - .aggregate_fns() - .find_plugin(&aggregate.id()) - .is_some() - ); - - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::Nullable).erased(); - let storage = - PrimitiveArray::from_option_iter([Some(3_000i64), None, Some(1_000)]).into_array(); - let array = ExtensionArray::new(ext_dtype.clone(), storage.clone()).into_array(); - - let mut ctx = session.create_execution_ctx(); - let mut acc = Accumulator::try_new( - aggregate, - NumericalAggregateOpts::default(), - DType::Extension(ext_dtype), - )?; - acc.accumulate(&array, &mut ctx)?; - - let mut expected = Accumulator::try_new( - MinMax, - NumericalAggregateOpts::default(), - storage.dtype().clone(), - )?; - expected.accumulate(&storage, &mut ctx)?; - - assert_eq!(acc.finish()?, expected.finish()?); - Ok(()) - } - - #[test] - fn combines_flushed_partials() -> VortexResult<()> { - let mut ctx = SESSION.create_execution_ctx(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::Nullable).erased(); - let batch = |values: [Option; 2]| { - ExtensionArray::new( - ext_dtype.clone(), - PrimitiveArray::from_option_iter(values).into_array(), - ) - .into_array() - }; - let accumulator = || { - Accumulator::try_new( - ExtensionStoragePushdown::new(MinMax, Timestamp), - NumericalAggregateOpts::default(), - DType::Extension(ext_dtype.clone()), - ) - }; - - let mut first = accumulator()?; - first.accumulate(&batch([Some(3_000), None]), &mut ctx)?; - let mut second = accumulator()?; - second.accumulate(&batch([Some(1_000), Some(500)]), &mut ctx)?; - first.combine_partials(&second.flush()?)?; - - let mut expected = accumulator()?; - expected.accumulate(&batch([Some(3_000), None]), &mut ctx)?; - expected.accumulate(&batch([Some(1_000), Some(500)]), &mut ctx)?; - - assert_eq!(first.finish()?, expected.finish()?); - Ok(()) - } - - #[test] - fn accumulates_constant_batches() -> VortexResult<()> { - let mut ctx = SESSION.create_execution_ctx(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::Nullable).erased(); - let constant = |value: i64| { - ConstantArray::new( - Scalar::extension_ref( - ext_dtype.clone(), - Scalar::primitive(value, Nullability::Nullable), - ), - 3, - ) - .into_array() - }; - - let mut acc = Accumulator::try_new( - ExtensionStoragePushdown::new(MinMax, Timestamp), - NumericalAggregateOpts::default(), - DType::Extension(ext_dtype.clone()), - )?; - acc.accumulate(&constant(2_000), &mut ctx)?; - acc.accumulate(&constant(1_000), &mut ctx)?; - - let mut expected = Accumulator::try_new( - MinMax, - NumericalAggregateOpts::default(), - ext_dtype.storage_dtype().clone(), - )?; - expected.accumulate( - &PrimitiveArray::from_option_iter([Some(2_000i64), Some(1_000)]).into_array(), - &mut ctx, - )?; - - assert_eq!(acc.finish()?, expected.finish()?); - Ok(()) - } - - #[test] - fn rejects_other_extension_types() { - let date = DType::Extension(Date::new(TimeUnit::Days, Nullability::Nullable).erased()); - assert!( - ExtensionStoragePushdown::new(MinMax, Timestamp) - .return_dtype(&NumericalAggregateOpts::default(), &date) - .is_none() - ); - } - - #[test] - fn default_session_registers_temporal_order_aggregates() { - let session = VortexSession::empty(); - let aggregate_fns = session.aggregate_fns(); - for id in [ - ExtensionStoragePushdown::new(IsSorted, Date).id(), - ExtensionStoragePushdown::new(IsSorted, Duration).id(), - ExtensionStoragePushdown::new(IsSorted, Time).id(), - ExtensionStoragePushdown::new(IsSorted, Timestamp).id(), - ExtensionStoragePushdown::new(MinMax, Date).id(), - ExtensionStoragePushdown::new(MinMax, Duration).id(), - ExtensionStoragePushdown::new(MinMax, Time).id(), - ExtensionStoragePushdown::new(MinMax, Timestamp).id(), - ] { - assert!( - aggregate_fns.find_plugin(&id).is_some(), - "{id} is not registered" - ); - } - } - - #[rstest] - // Nulls sort first. - #[case::sorted([None, Some(1_000), Some(2_000), Some(2_000)], false, true)] - #[case::unsorted([Some(2_000), Some(1_000), None, Some(3_000)], false, false)] - #[case::strict_with_duplicates([None, Some(1_000), Some(2_000), Some(2_000)], true, false)] - fn is_sorted_over_timestamps( - #[case] values: [Option; 4], - #[case] strict: bool, - #[case] expected: bool, - ) -> VortexResult<()> { - let mut ctx = SESSION.create_execution_ctx(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::Nullable).erased(); - let array = ExtensionArray::new( - ext_dtype.clone(), - PrimitiveArray::from_option_iter(values).into_array(), - ) - .into_array(); - - let mut acc = Accumulator::try_new( - ExtensionStoragePushdown::new(IsSorted, Timestamp), - IsSortedOptions { strict }, - DType::Extension(ext_dtype), - )?; - acc.accumulate(&array, &mut ctx)?; - - assert_eq!(bool::try_from(&acc.finish()?)?, expected); - Ok(()) - } - - #[test] - fn min_max_over_dates_matches_storage() -> VortexResult<()> { - let mut ctx = SESSION.create_execution_ctx(); - let ext_dtype = Date::new(TimeUnit::Days, Nullability::Nullable).erased(); - let storage = - PrimitiveArray::from_option_iter([Some(20i32), None, Some(-3), Some(7)]).into_array(); - let array = ExtensionArray::new(ext_dtype.clone(), storage.clone()).into_array(); - - let mut acc = Accumulator::try_new( - ExtensionStoragePushdown::new(MinMax, Date), - NumericalAggregateOpts::default(), - DType::Extension(ext_dtype), - )?; - acc.accumulate(&array, &mut ctx)?; - - let mut expected = Accumulator::try_new( - MinMax, - NumericalAggregateOpts::default(), - storage.dtype().clone(), - )?; - expected.accumulate(&storage, &mut ctx)?; - - assert_eq!(acc.finish()?, expected.finish()?); - Ok(()) - } -} diff --git a/vortex-array/src/arrays/constant/vtable/canonical.rs b/vortex-array/src/arrays/constant/vtable/canonical.rs index 05d5cfef90e..dcbed7e438f 100644 --- a/vortex-array/src/arrays/constant/vtable/canonical.rs +++ b/vortex-array/src/arrays/constant/vtable/canonical.rs @@ -585,8 +585,7 @@ mod tests { use crate::dtype::Nullability; use crate::dtype::PType; use crate::dtype::half::f16; - use crate::extension::datetime::Date; - use crate::extension::datetime::TimeUnit; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; use crate::stats::Stat; use crate::stats::StatsProvider; @@ -1240,7 +1239,11 @@ mod tests { /// `[date(42), null]` as a list scalar. fn date_list() -> Scalar { - let date = Scalar::extension::(TimeUnit::Days, Scalar::from(Some(42i32))); + let date = Scalar::extension_ref( + extension_dtype(vec![0], DType::Primitive(PType::I32, Nullability::Nullable)) + .expect("build foreign extension dtype"), + Scalar::from(Some(42i32)), + ); let dtype = date.dtype().clone(); Scalar::list( Arc::new(dtype.clone()), @@ -1251,7 +1254,11 @@ mod tests { /// The elements of [`date_list`] as an array. fn date_elements() -> ArrayRef { - let date = Scalar::extension::(TimeUnit::Days, Scalar::from(Some(42i32))); + let date = Scalar::extension_ref( + extension_dtype(vec![0], DType::Primitive(PType::I32, Nullability::Nullable)) + .expect("build foreign extension dtype"), + Scalar::from(Some(42i32)), + ); let DType::Extension(ext_dtype) = date.dtype().clone() else { vortex_panic!("a date is an extension value"); }; diff --git a/vortex-array/src/arrays/constant/vtable/mod.rs b/vortex-array/src/arrays/constant/vtable/mod.rs index 9aef0b2ac69..c7380021788 100644 --- a/vortex-array/src/arrays/constant/vtable/mod.rs +++ b/vortex-array/src/arrays/constant/vtable/mod.rs @@ -406,8 +406,7 @@ mod tests { use crate::dtype::Nullability; use crate::dtype::PType; use crate::dtype::StructFields; - use crate::extension::datetime::Date; - use crate::extension::datetime::TimeUnit; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); @@ -746,7 +745,8 @@ mod tests { #[test] fn test_extension_constant_append() -> VortexResult<()> { - let scalar = Scalar::extension::(TimeUnit::Days, Scalar::from(Some(42i32))); + let dtype = extension_dtype(vec![0], DType::Primitive(PType::I32, Nullability::Nullable))?; + let scalar = Scalar::extension_ref(dtype, Scalar::from(Some(42i32))); assert_append_matches_canonical(ConstantArray::new(scalar, 5)) } @@ -755,7 +755,8 @@ mod tests { #[test] fn test_extension_constant_append_keeps_storage_constant() -> VortexResult<()> { let mut ctx = SESSION.create_execution_ctx(); - let scalar = Scalar::extension::(TimeUnit::Days, Scalar::from(Some(42i32))); + let dtype = extension_dtype(vec![0], DType::Primitive(PType::I32, Nullability::Nullable))?; + let scalar = Scalar::extension_ref(dtype, Scalar::from(Some(42i32))); let array = ConstantArray::new(scalar.clone(), 1_000); let mut builder = builder_with_capacity_in( diff --git a/vortex-array/src/arrays/extension/compute/cast.rs b/vortex-array/src/arrays/extension/compute/cast.rs index 2d95d506a4f..a8c951f0360 100644 --- a/vortex-array/src/arrays/extension/compute/cast.rs +++ b/vortex-array/src/arrays/extension/compute/cast.rs @@ -86,10 +86,10 @@ mod tests { use crate::dtype::Nullability; use crate::dtype::PType; use crate::dtype::StructFields; + use crate::dtype::extension::ExtDTypeRef; use crate::executor::VortexSessionExecute; - use crate::extension::datetime::Duration; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::extension::tests::extension_dtype as make_extension_dtype; + use crate::extension::tests::extension_dtype_with_id as make_extension_dtype_with_id; use crate::scalar::Scalar; use crate::scalar_fn::ScalarFnVTableExt; use crate::scalar_fn::builtin::cast::Cast; @@ -101,7 +101,7 @@ mod tests { #[test] fn cast_same_ext_dtype() { - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); + let ext_dtype = first_extension_ext_dtype(0, Nullability::NonNullable); let storage = Buffer::::empty().into_array(); let arr = ExtensionArray::new(ext_dtype.clone(), storage); @@ -118,7 +118,7 @@ mod tests { #[test] fn cast_same_ext_dtype_differet_nullability() { - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); + let ext_dtype = first_extension_ext_dtype(0, Nullability::NonNullable); let storage = Buffer::::empty().into_array(); let arr = ExtensionArray::new(ext_dtype.clone(), storage); @@ -134,53 +134,55 @@ mod tests { #[rstest] #[case::to_storage( - create_timestamp_array(TimeUnit::Milliseconds, false).into_array(), + create_first_extension_array(0, false).into_array(), DType::Primitive(PType::I64, Nullability::NonNullable), )] #[case::from_storage( buffer![1_000i64, 2_000].into_array(), - timestamp_dtype(TimeUnit::Milliseconds, Nullability::NonNullable), + first_extension_dtype(0, Nullability::NonNullable), )] #[case::coarser_unit( - create_timestamp_array(TimeUnit::Nanoseconds, false).into_array(), - timestamp_dtype(TimeUnit::Milliseconds, Nullability::NonNullable), + create_first_extension_array(1, false).into_array(), + first_extension_dtype(0, Nullability::NonNullable), )] #[case::different_zone( - create_timestamp_array(TimeUnit::Milliseconds, false).into_array(), - DType::Extension(Timestamp::new_with_tz( - TimeUnit::Milliseconds, - Some("+01:00".into()), - Nullability::NonNullable, - ).erased()), + create_first_extension_array(0, false).into_array(), + DType::Extension( + make_extension_dtype( + vec![0, 1], + DType::Primitive(PType::I64, Nullability::NonNullable), + ) + .expect("build foreign extension dtype"), + ), )] #[case::nullable_to_storage( - create_timestamp_array(TimeUnit::Milliseconds, true).into_array(), + create_first_extension_array(0, true).into_array(), DType::Primitive(PType::I64, Nullability::Nullable), )] - #[case::null_to_non_nullable_timestamp( + #[case::null_to_non_nullable_extension( NullArray::new(2).into_array(), - timestamp_dtype(TimeUnit::Milliseconds, Nullability::NonNullable), + first_extension_dtype(0, Nullability::NonNullable), )] - #[case::typed_null_to_timestamp( + #[case::typed_null_to_extension( PrimitiveArray::from_option_iter([None::, None]).into_array(), - timestamp_dtype(TimeUnit::Milliseconds, Nullability::Nullable), + first_extension_dtype(0, Nullability::Nullable), )] #[case::nested_in_struct( - in_struct(create_timestamp_array(TimeUnit::Milliseconds, false).into_array()), + in_struct(create_first_extension_array(0, false).into_array()), struct_dtype(DType::Primitive(PType::I64, Nullability::NonNullable)), )] #[case::nested_rescale( - in_struct(create_timestamp_array(TimeUnit::Milliseconds, false).into_array()), - struct_dtype(timestamp_dtype(TimeUnit::Nanoseconds, Nullability::NonNullable)), + in_struct(create_first_extension_array(0, false).into_array()), + struct_dtype(first_extension_dtype(1, Nullability::NonNullable)), )] #[case::nested_in_list( - in_list(create_timestamp_array(TimeUnit::Milliseconds, false).into_array()), + in_list(create_first_extension_array(0, false).into_array()), list_dtype(DType::Primitive(PType::I64, Nullability::NonNullable), Nullability::NonNullable), )] #[case::null_list_constant( ConstantArray::new( Scalar::null(list_dtype( - timestamp_dtype(TimeUnit::Milliseconds, Nullability::NonNullable), + first_extension_dtype(0, Nullability::NonNullable), Nullability::Nullable, )), 2, @@ -191,7 +193,7 @@ mod tests { #[case::empty_list_constant( ConstantArray::new( Scalar::list_empty( - Arc::new(timestamp_dtype(TimeUnit::Milliseconds, Nullability::NonNullable)), + Arc::new(first_extension_dtype(0, Nullability::NonNullable)), Nullability::NonNullable, ), 2, @@ -199,21 +201,21 @@ mod tests { .into_array(), list_dtype(DType::Primitive(PType::I64, Nullability::NonNullable), Nullability::NonNullable), )] - #[case::duration_to_storage( - create_duration_array(TimeUnit::Milliseconds, false).into_array(), + #[case::second_extension_to_storage( + create_second_extension_array(0, false).into_array(), DType::Primitive(PType::I64, Nullability::NonNullable), )] - #[case::storage_to_duration( + #[case::storage_to_second_extension( buffer![1_000i64, 2_000].into_array(), - duration_dtype(TimeUnit::Milliseconds, Nullability::NonNullable), + second_extension_dtype(0, Nullability::NonNullable), )] - #[case::duration_coarser_unit( - create_duration_array(TimeUnit::Milliseconds, false).into_array(), - duration_dtype(TimeUnit::Seconds, Nullability::NonNullable), + #[case::different_extension_metadata( + create_second_extension_array(0, false).into_array(), + second_extension_dtype(2, Nullability::NonNullable), )] - #[case::duration_to_timestamp( - create_duration_array(TimeUnit::Milliseconds, false).into_array(), - timestamp_dtype(TimeUnit::Milliseconds, Nullability::NonNullable), + #[case::extension_type_change( + create_second_extension_array(0, false).into_array(), + first_extension_dtype_with_id("test.first", 0, Nullability::NonNullable), )] fn cast_never_reinterprets_storage(#[case] input: ArrayRef, #[case] target: DType) { assert!( @@ -232,8 +234,8 @@ mod tests { } #[test] - fn untyped_null_casts_to_nullable_timestamp_on_every_path() { - let target = timestamp_dtype(TimeUnit::Milliseconds, Nullability::Nullable); + fn untyped_null_casts_to_nullable_extension_on_every_path() { + let target = first_extension_dtype(0, Nullability::Nullable); let expected = ExtensionArray::new( target.as_extension().clone(), PrimitiveArray::from_option_iter([None::, None]).into_array(), @@ -248,8 +250,8 @@ mod tests { } #[test] - fn cast_timestamp_nullability_on_every_path() { - let input = create_timestamp_array(TimeUnit::Milliseconds, false); + fn cast_extension_nullability_on_every_path() { + let input = create_first_extension_array(0, false); let target = input.dtype().as_nullable(); let expected = ExtensionArray::new( target.as_extension().clone(), @@ -274,7 +276,7 @@ mod tests { #[test] fn same_type_cast_returns_the_storage_error() -> VortexResult<()> { let mut ctx = SESSION.create_execution_ctx(); - let input = create_timestamp_array(TimeUnit::Milliseconds, true); + let input = create_first_extension_array(0, true); let storage = input.storage_array(); let storage_error = storage .cast(storage.dtype().as_nonnullable()) @@ -288,7 +290,7 @@ mod tests { .cast(target) .and_then(|cast| cast.execute::(&mut ctx)) .err() - .expect("timestamp with nulls cannot cast to non-nullable"); + .expect("extension with nulls cannot cast to non-nullable"); assert_eq!( error.to_string().lines().next(), @@ -298,24 +300,24 @@ mod tests { } #[rstest] - #[case(create_timestamp_array(TimeUnit::Milliseconds, false))] - #[case(create_timestamp_array(TimeUnit::Microseconds, true))] - #[case(create_timestamp_array(TimeUnit::Nanoseconds, false))] - #[case(create_timestamp_array(TimeUnit::Seconds, true))] - #[case(create_duration_array(TimeUnit::Milliseconds, false))] - #[case(create_duration_array(TimeUnit::Microseconds, true))] - #[case(create_duration_array(TimeUnit::Nanoseconds, false))] - #[case(create_duration_array(TimeUnit::Seconds, true))] + #[case(create_first_extension_array(0, false))] + #[case(create_first_extension_array(3, true))] + #[case(create_first_extension_array(1, false))] + #[case(create_first_extension_array(2, true))] + #[case(create_second_extension_array(0, false))] + #[case(create_second_extension_array(3, true))] + #[case(create_second_extension_array(1, false))] + #[case(create_second_extension_array(2, true))] fn test_cast_extension_conformance(#[case] array: ExtensionArray) { test_cast_conformance(&array.into_array(), &mut SESSION.create_execution_ctx()); } - fn create_timestamp_array(time_unit: TimeUnit, nullable: bool) -> ExtensionArray { - let dtype = timestamp_dtype(time_unit, nullable.into()); + fn create_first_extension_array(metadata_byte: u8, nullable: bool) -> ExtensionArray { + let dtype = first_extension_dtype(metadata_byte, nullable.into()); let storage = if nullable { PrimitiveArray::from_option_iter([ - Some(1_000_000i64), // 1 second in microseconds + Some(1_000_000i64), None, Some(2_000_000), Some(3_000_000), @@ -358,14 +360,35 @@ mod tests { DType::List(Arc::new(element), nullability) } - fn timestamp_dtype(time_unit: TimeUnit, nullability: Nullability) -> DType { + fn first_extension_ext_dtype(metadata_byte: u8, nullability: Nullability) -> ExtDTypeRef { + make_extension_dtype( + vec![metadata_byte, 0], + DType::Primitive(PType::I64, nullability), + ) + .expect("build foreign extension dtype") + } + + fn first_extension_dtype(metadata_byte: u8, nullability: Nullability) -> DType { + DType::Extension(first_extension_ext_dtype(metadata_byte, nullability)) + } + + fn first_extension_dtype_with_id( + id: &str, + metadata_byte: u8, + nullability: Nullability, + ) -> DType { DType::Extension( - Timestamp::new_with_tz(time_unit, Some("UTC".into()), nullability).erased(), + make_extension_dtype_with_id( + id, + vec![metadata_byte, 0], + DType::Primitive(PType::I64, nullability), + ) + .expect("build foreign extension dtype"), ) } - fn create_duration_array(time_unit: TimeUnit, nullable: bool) -> ExtensionArray { - let dtype = duration_dtype(time_unit, nullable.into()); + fn create_second_extension_array(metadata_byte: u8, nullable: bool) -> ExtensionArray { + let dtype = second_extension_dtype(metadata_byte, nullable.into()); let storage = if nullable { PrimitiveArray::from_option_iter([ @@ -383,7 +406,13 @@ mod tests { ExtensionArray::new(dtype.as_extension().clone(), storage) } - fn duration_dtype(time_unit: TimeUnit, nullability: Nullability) -> DType { - DType::Extension(Duration::new(time_unit, nullability).erased()) + fn second_extension_dtype(metadata_byte: u8, nullability: Nullability) -> DType { + DType::Extension( + make_extension_dtype( + vec![metadata_byte, 1], + DType::Primitive(PType::I64, nullability), + ) + .expect("build foreign extension dtype"), + ) } } diff --git a/vortex-array/src/arrays/extension/compute/compare.rs b/vortex-array/src/arrays/extension/compute/compare.rs index b4fbfff725c..557aa3f55ea 100644 --- a/vortex-array/src/arrays/extension/compute/compare.rs +++ b/vortex-array/src/arrays/extension/compute/compare.rs @@ -22,8 +22,7 @@ impl CompareKernel for Extension { operator: CompareOperator, _ctx: &mut ExecutionCtx, ) -> VortexResult> { - // Storage values are only comparable when both sides share the same extension dtype - // (e.g. timestamps in different units must not compare their raw storage). + // Storage values are only comparable when both sides share the same extension dtype. if !lhs.dtype().eq_ignore_nullability(rhs.dtype()) { return Ok(None); } diff --git a/vortex-array/src/arrays/extension/compute/fill_null.rs b/vortex-array/src/arrays/extension/compute/fill_null.rs index e6a52bdd5b2..46bf670d29a 100644 --- a/vortex-array/src/arrays/extension/compute/fill_null.rs +++ b/vortex-array/src/arrays/extension/compute/fill_null.rs @@ -66,29 +66,32 @@ mod tests { use crate::builtins::ArrayBuiltins; use crate::dtype::Nullability; use crate::dtype::extension::ExtDTypeRef; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; use crate::validity::Validity; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); - fn timestamp(nullability: Nullability) -> ExtDTypeRef { - Timestamp::new(TimeUnit::Milliseconds, nullability).erased() + fn foreign_extension(nullability: Nullability) -> ExtDTypeRef { + extension_dtype( + vec![0], + crate::dtype::DType::Primitive(crate::dtype::PType::I64, nullability), + ) + .expect("build foreign extension dtype") } - /// Null timestamps take the fill timestamp, and the result has the fill's nullability. + /// Null extension values take the fill values, and the result has the fill's nullability. #[rstest] #[case::non_nullable_fill(Nullability::NonNullable)] #[case::nullable_fill(Nullability::Nullable)] - fn fill_null_timestamps(#[case] nullability: Nullability) -> VortexResult<()> { + fn fill_null_extension_values(#[case] nullability: Nullability) -> VortexResult<()> { let input = ExtensionArray::new( - timestamp(Nullability::Nullable), + foreign_extension(Nullability::Nullable), PrimitiveArray::from_option_iter([Some(10i64), None, Some(30), None]).into_array(), ) .into_array(); let fill = Scalar::extension_ref( - timestamp(nullability), + foreign_extension(nullability), Scalar::primitive(99i64, nullability), ); @@ -96,7 +99,7 @@ mod tests { let result = input.fill_null(fill)?; let expected = ExtensionArray::new( - timestamp(nullability), + foreign_extension(nullability), PrimitiveArray::new(buffer![10i64, 99, 30, 99], Validity::from(nullability)) .into_array(), ); diff --git a/vortex-array/src/arrays/extension/compute/mod.rs b/vortex-array/src/arrays/extension/compute/mod.rs index 475f1bbd3a2..f106675c815 100644 --- a/vortex-array/src/arrays/extension/compute/mod.rs +++ b/vortex-array/src/arrays/extension/compute/mod.rs @@ -24,16 +24,22 @@ mod test { use crate::arrays::PrimitiveArray; use crate::compute::conformance::filter::test_filter_conformance; use crate::compute::conformance::take::test_take_conformance; + use crate::dtype::DType; use crate::dtype::Nullability; - use crate::extension::datetime::Date; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::dtype::PType; + use crate::dtype::extension::ExtDTypeRef; + use crate::extension::tests::extension_dtype as build_extension_dtype; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); + fn extension_dtype(ptype: PType, nullability: Nullability) -> ExtDTypeRef { + build_extension_dtype(vec![0], DType::Primitive(ptype, nullability)) + .expect("build foreign extension dtype") + } + #[test] fn test_filter_extension_array() { - let ext_dtype = Date::new(TimeUnit::Days, Nullability::NonNullable).erased(); + let ext_dtype = extension_dtype(PType::I32, Nullability::NonNullable); // Create storage array let storage = buffer![1i32, 2, 3, 4, 5].into_array(); @@ -52,35 +58,26 @@ mod test { #[case({ // Simple extension type (non-nullable i64) let storage = buffer![1i64, 2, 3, 4, 5].into_array(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); + let ext_dtype = extension_dtype(PType::I64, Nullability::NonNullable); ExtensionArray::new(ext_dtype, storage) })] #[case({ // Nullable extension type let storage = PrimitiveArray::from_option_iter([Some(1i64), None, Some(3), Some(4), None]) .into_array(); - let ext_dtype_nullable = Timestamp::new( - TimeUnit::Milliseconds, - Nullability::Nullable, - ).erased(); + let ext_dtype_nullable = extension_dtype(PType::I64, Nullability::Nullable); ExtensionArray::new(ext_dtype_nullable, storage) })] #[case({ // Single element let storage = buffer![42i64].into_array(); - let ext_dtype_single = Timestamp::new( - TimeUnit::Milliseconds, - Nullability::NonNullable, - ).erased(); + let ext_dtype_single = extension_dtype(PType::I64, Nullability::NonNullable); ExtensionArray::new(ext_dtype_single, storage) })] #[case({ // Larger array for edge cases let storage = buffer![0i64..100].into_array(); - let ext_dtype_large = Timestamp::new( - TimeUnit::Milliseconds, - Nullability::NonNullable, - ).erased(); + let ext_dtype_large = extension_dtype(PType::I64, Nullability::NonNullable); ExtensionArray::new(ext_dtype_large, storage) })] fn test_take_extension_array_conformance(#[case] array: ExtensionArray) { @@ -101,29 +98,36 @@ mod tests { use crate::arrays::ExtensionArray; use crate::arrays::PrimitiveArray; use crate::compute::conformance::consistency::test_array_consistency; + use crate::dtype::DType; use crate::dtype::Nullability; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::dtype::PType; + use crate::dtype::extension::ExtDTypeRef; + use crate::extension::tests::extension_dtype as build_extension_dtype; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); + fn extension_dtype(nullability: Nullability) -> ExtDTypeRef { + build_extension_dtype(vec![0], DType::Primitive(PType::I64, nullability)) + .expect("build foreign extension dtype") + } + #[rstest] // Note: The original test_all_consistency cases for extension arrays caused errors // because of unsupported extension type "uuid". We'll use simpler test cases. #[case::extension_simple({ let storage = buffer![1i64, 2, 3, 4, 5].into_array(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); + let ext_dtype = extension_dtype(Nullability::NonNullable); ExtensionArray::new(ext_dtype, storage) })] #[case::extension_nullable({ let storage = PrimitiveArray::from_option_iter([Some(1i64), None, Some(3), Some(4), None]) .into_array(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::Nullable).erased(); + let ext_dtype = extension_dtype(Nullability::Nullable); ExtensionArray::new(ext_dtype, storage) })] #[case::extension_large({ let storage = buffer![0..100i64].into_array(); - let ext_dtype = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); + let ext_dtype = extension_dtype(Nullability::NonNullable); ExtensionArray::new(ext_dtype, storage) })] fn test_extension_consistency(#[case] array: ExtensionArray) { diff --git a/vortex-array/src/arrays/mod.rs b/vortex-array/src/arrays/mod.rs index 23611e03dc5..755dc416511 100644 --- a/vortex-array/src/arrays/mod.rs +++ b/vortex-array/src/arrays/mod.rs @@ -42,9 +42,6 @@ pub mod constant; pub use constant::Constant; pub use constant::ConstantArray; -pub mod datetime; -pub use datetime::TemporalArray; - pub mod decimal; pub use decimal::Decimal; pub use decimal::DecimalArray; diff --git a/vortex-array/src/arrays/repeated/tests.rs b/vortex-array/src/arrays/repeated/tests.rs index a1d5c539f9c..149a6ff2f52 100644 --- a/vortex-array/src/arrays/repeated/tests.rs +++ b/vortex-array/src/arrays/repeated/tests.rs @@ -43,8 +43,7 @@ use crate::builders::VariantBuilder; use crate::builders::builder_with_capacity_in; use crate::dtype::DType; use crate::dtype::Nullability; -use crate::extension::datetime::TimeUnit; -use crate::extension::datetime::Timestamp; +use crate::extension::tests::extension_dtype; use crate::optimizer::ArrayOptimizer; use crate::scalar::Scalar; use crate::validity::Validity; @@ -319,10 +318,14 @@ fn list_view_child() -> ArrayRef { .into_array() } -/// Three timestamps. +/// Three extension values. fn extension_child() -> ArrayRef { ExtensionArray::new( - Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(), + extension_dtype( + vec![0], + DType::Primitive(crate::dtype::PType::I64, Nullability::NonNullable), + ) + .expect("build foreign extension dtype"), buffer![1i64, 2, 3].into_array(), ) .into_array() diff --git a/vortex-array/src/arrays/runend/array/to_dict.rs b/vortex-array/src/arrays/runend/array/to_dict.rs index 511cb479bbd..d065d6e75a8 100644 --- a/vortex-array/src/arrays/runend/array/to_dict.rs +++ b/vortex-array/src/arrays/runend/array/to_dict.rs @@ -106,8 +106,7 @@ mod tests { use crate::dtype::DType; use crate::dtype::Nullability; use crate::dtype::PType; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; #[track_caller] @@ -143,14 +142,13 @@ mod tests { ) } - fn timestamp_values(storage: ArrayRef) -> VortexResult { - let ext_dtype = Timestamp::try_new_with_tz( - TimeUnit::Microseconds, - Some("UTC".into()), - storage.dtype().nullability(), + fn extension_values(storage: ArrayRef) -> VortexResult { + let ext_dtype = extension_dtype( + vec![0], + DType::Primitive(PType::I64, storage.dtype().nullability()), )?; - Ok(ExtensionArray::try_new(ext_dtype.erased(), storage)?.into_array()) + Ok(ExtensionArray::try_new(ext_dtype, storage)?.into_array()) } #[rstest] @@ -248,7 +246,7 @@ mod tests { #[rstest] #[case::structure(struct_values)] #[case::fixed_size_list(fixed_size_list_values)] - #[case::extension(timestamp_values)] + #[case::extension(extension_values)] fn fallback_preserves_dtype( #[case] wrap: fn(ArrayRef) -> VortexResult, #[values(false, true)] empty: bool, diff --git a/vortex-array/src/arrays/runend/compute/cast.rs b/vortex-array/src/arrays/runend/compute/cast.rs index b145fffe838..95a0ad8dc2d 100644 --- a/vortex-array/src/arrays/runend/compute/cast.rs +++ b/vortex-array/src/arrays/runend/compute/cast.rs @@ -54,19 +54,19 @@ mod tests { use crate::dtype::DType; use crate::dtype::Nullability; use crate::dtype::PType; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::extension::tests::extension_dtype; use crate::test_harness::ExpectedOutcome; use crate::test_harness::assert_execution_paths; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); #[test] - fn test_cast_runend_ignores_unreferenced_null_timestamp() -> VortexResult<()> { + fn test_cast_runend_ignores_unreferenced_null_extension() -> VortexResult<()> { let mut ctx = SESSION.create_execution_ctx(); - let timestamp = Timestamp::new(TimeUnit::Milliseconds, Nullability::Nullable).erased(); + let ext_dtype = + extension_dtype(vec![0], DType::Primitive(PType::I64, Nullability::Nullable))?; let values = ExtensionArray::try_new( - timestamp, + ext_dtype, PrimitiveArray::from_option_iter([None, Some(5i64)]).into_array(), )?; let runs = RunEnd::try_new_offset_length( @@ -76,7 +76,10 @@ mod tests { 1, &mut ctx, )?; - let target = Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(); + let target = extension_dtype( + vec![0], + DType::Primitive(PType::I64, Nullability::NonNullable), + )?; let expected = ExtensionArray::try_new(target.clone(), buffer![5i64].into_array())?; assert_execution_paths( &[runs.into_array()], diff --git a/vortex-array/src/builders/extension.rs b/vortex-array/src/builders/extension.rs index a8a73e9b983..ab9e2ff610d 100644 --- a/vortex-array/src/builders/extension.rs +++ b/vortex-array/src/builders/extension.rs @@ -150,6 +150,7 @@ impl ArrayBuilder for ExtensionBuilder { mod tests { use std::sync::LazyLock; + use vortex_error::VortexResult; use vortex_session::VortexSession; use super::*; @@ -158,37 +159,35 @@ mod tests { use crate::assert_arrays_eq; use crate::builders::ArrayBuilder; use crate::dtype::Nullability; - use crate::extension::datetime::Date; - use crate::extension::datetime::TimeUnit; + use crate::dtype::PType; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); #[test] - fn test_append_scalar() { + fn test_append_scalar() -> VortexResult<()> { let mut ctx = SESSION.create_execution_ctx(); - let ext_dtype = Date::new(TimeUnit::Days, Nullability::Nullable).erased(); + let ext_dtype = + extension_dtype(vec![0], DType::Primitive(PType::I32, Nullability::Nullable))?; let mut builder = ExtensionBuilder::new_in(ext_dtype.clone(), BufferAllocatorRef::static_ref()); // Test appending a valid extension value. let storage1 = Scalar::from(Some(42i32)); - let ext_scalar1 = Scalar::extension::(TimeUnit::Days, storage1); - builder.append_scalar(&ext_scalar1).unwrap(); + let ext_scalar1 = Scalar::extension_ref(ext_dtype.clone(), storage1); + builder.append_scalar(&ext_scalar1)?; // Test appending another value. let storage2 = Scalar::from(Some(84i32)); - let ext_scalar2 = Scalar::extension::(TimeUnit::Days, storage2); - builder.append_scalar(&ext_scalar2).unwrap(); + let ext_scalar2 = Scalar::extension_ref(ext_dtype.clone(), storage2); + builder.append_scalar(&ext_scalar2)?; // Test appending null value. - let null_storage = Scalar::null(DType::Primitive( - crate::dtype::PType::I32, - Nullability::Nullable, - )); - let null_scalar = Scalar::extension::(TimeUnit::Days, null_storage); - builder.append_scalar(&null_scalar).unwrap(); + let null_storage = Scalar::null(DType::Primitive(PType::I32, Nullability::Nullable)); + let null_scalar = Scalar::extension_ref(ext_dtype.clone(), null_storage); + builder.append_scalar(&null_scalar)?; let array = builder.finish_into_extension(); let expected = ExtensionArray::new( @@ -203,5 +202,6 @@ mod tests { let mut builder = ExtensionBuilder::new_in(ext_dtype, BufferAllocatorRef::static_ref()); let wrong_scalar = Scalar::from(true); assert!(builder.append_scalar(&wrong_scalar).is_err()); + Ok(()) } } diff --git a/vortex-array/src/builders/tests.rs b/vortex-array/src/builders/tests.rs index 79903b35136..3649f850b18 100644 --- a/vortex-array/src/builders/tests.rs +++ b/vortex-array/src/builders/tests.rs @@ -59,14 +59,21 @@ use crate::dtype::PType; use crate::dtype::StructFields; use crate::dtype::extension::ExtDTypeRef; use crate::dtype::half::f16; -use crate::extension::datetime::TimeUnit; -use crate::extension::datetime::Timestamp; +use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; use crate::scalar::ScalarValue; use crate::validity::Validity; static SESSION: LazyLock = LazyLock::new(VortexSession::empty); +fn extension_i64() -> ExtDTypeRef { + extension_dtype( + vec![0], + DType::Primitive(PType::I64, Nullability::NonNullable), + ) + .expect("build foreign extension dtype") +} + #[derive(Debug)] struct CountingAllocator { allocations: Arc, @@ -219,9 +226,7 @@ fn builder_reuses_its_allocator_after_finish() { 3, Nullability::NonNullable ))] -#[case::extension(DType::Extension( - Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased() -))] +#[case::extension(DType::Extension(extension_i64()))] fn test_append_zeros_matches_default_value(#[case] dtype: DType) { let num_elements = 5; @@ -324,14 +329,8 @@ fn test_append_zeros_matches_default_value(#[case] dtype: DType) { ]), Nullability::NonNullable ), 3)] -#[case::extension( - DType::Extension(Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased()), - 1 -)] -#[case::extension_multiple( - DType::Extension(Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased()), - 3 -)] +#[case::extension(DType::Extension(extension_i64()), 1)] +#[case::extension_multiple(DType::Extension(extension_i64()), 3)] #[should_panic(expected = "non-nullable")] fn test_append_nulls_panics_on_non_nullable(#[case] dtype: DType, #[case] count: usize) { let mut builder = builder_with_capacity_in(&dtype, count, BufferAllocatorRef::static_ref()); @@ -577,15 +576,9 @@ fn test_to_canonical_struct() { #[test] fn test_to_canonical_extension() { let mut ctx = SESSION.create_execution_ctx(); - let dtype = - DType::Extension(Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased()); + let dtype = DType::Extension(extension_i64()); let expected = [0i64, 1, 2, 3, 4] - .map(|value| { - Scalar::extension_ref( - Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(), - Scalar::from(value), - ) - }) + .map(|value| Scalar::extension_ref(extension_i64(), Scalar::from(value))) .to_vec(); compare_to_canonical_methods(&dtype, &expected, &mut ctx, |builder| { let ext_dtype = match &dtype { @@ -730,9 +723,7 @@ fn test_to_canonical_f32() { 3, Nullability::Nullable ))] -#[case::extension_non_nullable(DType::Extension( - Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased() -))] +#[case::extension_non_nullable(DType::Extension(extension_i64()))] fn test_append_scalar_comprehensive(#[case] dtype: DType) { let num_elements = 3; let mut builder = @@ -1088,7 +1079,7 @@ fn test_append_scalar_repeated_same_instance() { )] #[case::extension_storage( ExtensionArray::new( - Timestamp::new(TimeUnit::Milliseconds, Nullability::NonNullable).erased(), + extension_i64(), ConstantArray::new( Scalar::primitive(0i64, Nullability::NonNullable), CHUNK_LEN, diff --git a/vortex-array/src/canonical.rs b/vortex-array/src/canonical.rs index fd93fff01c5..4961753271e 100644 --- a/vortex-array/src/canonical.rs +++ b/vortex-array/src/canonical.rs @@ -1357,8 +1357,7 @@ mod tests { use crate::dtype::PType; use crate::dtype::StructFields; use crate::dtype::UnionVariants; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::extension::tests::extension_dtype; use crate::scalar::Scalar; /// A shared session for these canonical tests, used to create execution contexts. @@ -1400,7 +1399,10 @@ mod tests { nullability, ), DType::Variant(nullability), - DType::Extension(Timestamp::new(TimeUnit::Microseconds, nullability).erased()), + DType::Extension(extension_dtype( + vec![0], + DType::Primitive(PType::I64, nullability), + )?), ]; let arrays: Vec<_> = dtypes .iter() diff --git a/vortex-array/src/dtype/dtype_impl.rs b/vortex-array/src/dtype/dtype_impl.rs index 3528ca0cba1..6d70e3344ac 100644 --- a/vortex-array/src/dtype/dtype_impl.rs +++ b/vortex-array/src/dtype/dtype_impl.rs @@ -596,10 +596,7 @@ mod tests { use crate::dtype::PType; use crate::dtype::UnionVariants; use crate::dtype::decimal::DecimalDType; - use crate::extension::datetime::Date; - use crate::extension::datetime::Time; - use crate::extension::datetime::TimeUnit; - use crate::extension::datetime::Timestamp; + use crate::extension::tests::extension_dtype; fn hash_ignore_nullability(dtype: &DType) -> u64 { let mut hasher = DefaultHasher::new(); @@ -608,19 +605,27 @@ mod tests { } #[test] - fn test_ext_dtype_eq_ignore_nullability() { - let d1 = DType::Extension(Time::new(TimeUnit::Seconds, Nullable).erased()); - let d2 = DType::Extension(Time::new(TimeUnit::Seconds, NonNullable).erased()); + fn test_ext_dtype_eq_ignore_nullability() -> VortexResult<()> { + let d1 = DType::Extension(extension_dtype( + vec![0], + DType::Primitive(PType::I64, Nullable), + )?); + let d2 = DType::Extension(extension_dtype( + vec![0], + DType::Primitive(PType::I64, NonNullable), + )?); assert!(d1.eq_ignore_nullability(&d2)); - let t1 = DType::Extension( - Timestamp::new_with_tz(TimeUnit::Seconds, Some("UTC".into()), Nullable).erased(), - ); - let t2 = DType::Extension( - Timestamp::new_with_tz(TimeUnit::Seconds, Some("America/New_York".into()), Nullable) - .erased(), - ); + let t1 = DType::Extension(extension_dtype( + vec![1], + DType::Primitive(PType::I64, Nullable), + )?); + let t2 = DType::Extension(extension_dtype( + vec![2], + DType::Primitive(PType::I64, Nullable), + )?); assert!(!t1.eq_ignore_nullability(&t2)); + Ok(()) } #[test] @@ -753,7 +758,11 @@ mod tests { #[test] fn element_size_extension() { assert_eq!( - DType::Extension(Date::new(TimeUnit::Days, NonNullable).erased()).element_size(), + DType::Extension( + extension_dtype(vec![], DType::Primitive(PType::I32, NonNullable),) + .expect("build foreign extension dtype"), + ) + .element_size(), Some(4) ); } diff --git a/vortex-array/src/dtype/extension/tests.rs b/vortex-array/src/dtype/extension/tests.rs index 2aa5c9350f8..d03140a3caa 100644 --- a/vortex-array/src/dtype/extension/tests.rs +++ b/vortex-array/src/dtype/extension/tests.rs @@ -17,7 +17,6 @@ use vortex_session::registry::CachedId; use super::ExtDType; use super::ExtDTypePlugin; -use super::ExtDTypeRef; use super::ExtId; use super::ExtVTable; use super::ForeignExtDType; @@ -29,10 +28,6 @@ use crate::dtype::Nullability; use crate::dtype::Nullability::NonNullable; use crate::dtype::Nullability::Nullable; use crate::dtype::PType; -use crate::extension::datetime::Date; -use crate::extension::datetime::Time; -use crate::extension::datetime::TimeUnit; -use crate::extension::datetime::Timestamp; use crate::scalar::Scalar; use crate::scalar::ScalarValue; @@ -207,33 +202,6 @@ fn test_read_of_storage_without_non_nullable_form(#[case] declared: DType, #[cas assert!(result.is_err_and(|error| error.to_string().contains(expected))); } -/// [`ExtDType::try_with_vtable`] validates the metadata before it asks for the storage -/// declaration, so a time unit that [`Date`] or [`Time`] does not support returns an error -/// instead of a panic. -#[rstest] -#[case::date_seconds( - Date::try_new(TimeUnit::Seconds, NonNullable).map(ExtDType::erased), - "Date time unit must be days or milliseconds, got s" -)] -#[case::date_microseconds( - Date::try_new(TimeUnit::Microseconds, NonNullable).map(ExtDType::erased), - "Date time unit must be days or milliseconds, got µs" -)] -#[case::date_nanoseconds( - Date::try_new(TimeUnit::Nanoseconds, NonNullable).map(ExtDType::erased), - "Date time unit must be days or milliseconds, got ns" -)] -#[case::time_days( - Time::try_new(TimeUnit::Days, NonNullable).map(ExtDType::erased), - "Time time unit must be finer than days, got days" -)] -fn test_unsupported_time_unit_returns_error( - #[case] result: VortexResult, - #[case] expected: &str, -) { - assert!(result.is_err_and(|error| error.to_string().contains(expected))); -} - /// Foreign metadata normalizes outer nullability and preserves nested nullability, so equality /// and hashing that ignore nullability still distinguish different nested storage declarations. #[rstest] @@ -265,43 +233,6 @@ fn test_foreign_dtype_ignores_only_top_level_nullability( Ok(()) } -#[rstest] -#[case::compact(false)] -#[case::pretty(true)] -fn test_debug_preserves_metadata(#[case] pretty: bool) -> VortexResult<()> { - let dtype = - Timestamp::try_new_with_tz(TimeUnit::Milliseconds, Some("UTC".into()), Nullable)?.erased(); - let output = if pretty { - format!("{dtype:#?}") - } else { - format!("{dtype:?}") - }; - - assert!(output.starts_with("ExtDType {"), "{output}"); - assert!(output.contains("metadata: TimestampOptions {"), "{output}"); - assert!(output.contains("unit: Milliseconds"), "{output}"); - assert_eq!( - output.contains("metadata: TimestampOptions {\n"), - pretty, - "{output}" - ); - assert_eq!(output.matches("UTC").count(), 1, "{output}"); - - Ok(()) -} - -#[test] -fn storage_construction_validates_before_declaration() { - let storage = DType::Primitive(PType::I32, NonNullable); - let error = ExtDType::::try_from_storage(TimeUnit::Seconds, storage) - .expect_err("Date rejects seconds before requesting its storage declaration"); - assert!( - error - .to_string() - .contains("Date time unit must be days or milliseconds") - ); -} - /// Null storage supports nullable construction and rejects non-nullable requests without panicking. #[rstest] #[case::null(DType::Null)] diff --git a/vortex-array/src/dtype/extension/typed.rs b/vortex-array/src/dtype/extension/typed.rs index bd63202ca3f..28864e0ec6d 100644 --- a/vortex-array/src/dtype/extension/typed.rs +++ b/vortex-array/src/dtype/extension/typed.rs @@ -50,17 +50,6 @@ impl ExtDType { /// Reconstructs a dtype from stored metadata and its complete storage dtype. /// /// See [`try_from_storage_with_vtable`](Self::try_from_storage_with_vtable) for the checks. - /// - /// ``` - /// use vortex_array::dtype::{DType, Nullability, PType}; - /// use vortex_array::dtype::extension::ExtDType; - /// use vortex_array::extension::datetime::{Time, TimeUnit}; - /// - /// let storage = DType::Primitive(PType::I32, Nullability::Nullable); - /// let dtype = ExtDType::