diff --git a/vortex-fastlanes/src/bitpacking/compress.rs b/vortex-fastlanes/src/bitpacking/compress.rs index a45504d73b..e55f029287 100644 --- a/vortex-fastlanes/src/bitpacking/compress.rs +++ b/vortex-fastlanes/src/bitpacking/compress.rs @@ -90,26 +90,30 @@ fn bitpacked_compressor(array: &dyn Array, like: Option<&dyn Array>, ctx: Compre .unwrap_or_else(|| best_bit_width(parray.ptype(), &bit_width_freq)); let num_exceptions = count_exceptions(bit_width, &bit_width_freq); - // If we pack into zero bits, then just return the sparse array. - // TODO(ngates): this breaks our rule of returning ourselves. But we can't really do that - // unless we create an empty bitpacked array? - if bit_width == 0 { - return bitpack_patches(parray, bit_width, num_exceptions); - } + // If we pack into zero bits, then we have an empty byte array. + let packed = if bit_width == 0 { + PrimitiveArray::from_vec(Vec::::new()).boxed() + } else { + bitpack(parray, bit_width) + }; + + let validity = parray + .validity() + .map(|v| ctx.compress(v.as_ref(), like_bp.and_then(|bp| bp.validity()))); + + let patches = if num_exceptions > 0 { + Some(ctx.compress( + bitpack_patches(parray, bit_width, num_exceptions).as_ref(), + like_bp.and_then(|bp| bp.patches()), + )) + } else { + None + }; return BitPackedArray::try_new( - bitpack(parray, bit_width), - parray - .validity() - .map(|v| ctx.compress(v.as_ref(), like_bp.and_then(|bp| bp.validity()))), - if num_exceptions > 0 { - Some(ctx.compress( - bitpack_patches(parray, bit_width, num_exceptions).as_ref(), - like_bp.and_then(|bp| bp.patches()), - )) - } else { - None - }, + packed, + validity, + patches, bit_width, parray.dtype().clone(), parray.len(), diff --git a/vortex-fastlanes/src/bitpacking/mod.rs b/vortex-fastlanes/src/bitpacking/mod.rs index d2d0811e7e..f94dabc26c 100644 --- a/vortex-fastlanes/src/bitpacking/mod.rs +++ b/vortex-fastlanes/src/bitpacking/mod.rs @@ -1,3 +1,17 @@ +// (c) Copyright 2024 Fulcrum Technologies, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use std::any::Any; use std::collections::HashMap; use std::sync::{Arc, RwLock}; diff --git a/vortex-fastlanes/src/for/mod.rs b/vortex-fastlanes/src/for/mod.rs index b2d16db139..05aa2dee80 100644 --- a/vortex-fastlanes/src/for/mod.rs +++ b/vortex-fastlanes/src/for/mod.rs @@ -1,3 +1,17 @@ +// (c) Copyright 2024 Fulcrum Technologies, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use std::any::Any; use std::collections::HashMap; use std::sync::{Arc, RwLock};