Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcasale committed Apr 24, 2024
1 parent 08807ad commit 3dbf337
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions vortex-zigzag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linkme = { workspace = true }
vortex-alloc = { path = "../vortex-alloc" }
vortex-array = { path = "../vortex-array" }
vortex-error = { path = "../vortex-error" }
vortex-fastlanes = { path = "../vortex-fastlanes" }
vortex-schema = { path = "../vortex-schema" }
zigzag = { workspace = true }
paste = { workspace = true }
Expand Down
39 changes: 33 additions & 6 deletions vortex-zigzag/src/compress.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use vortex::array::primitive::PrimitiveArray;
use vortex::array::primitive::{Primitive, PrimitiveArray};
use vortex::compress::{CompressConfig, CompressCtx, EncodingCompression};
use vortex::ptype::{NativePType, PType};
use vortex::stats::{ArrayStatistics, Stat};
Expand All @@ -8,7 +8,7 @@ use vortex_alloc::{AlignedVec, ALIGNED_ALLOCATOR};
use vortex_error::VortexResult;
use zigzag::ZigZag as ExternalZigZag;

use crate::{OwnedZigZagArray, ZigZag, ZigZagEncoding};
use crate::{OwnedZigZagArray, ZigZagEncoding};

impl EncodingCompression for ZigZagEncoding {
fn can_compress(
Expand All @@ -17,7 +17,7 @@ impl EncodingCompression for ZigZagEncoding {
_config: &CompressConfig,
) -> Option<&dyn EncodingCompression> {
// Only support primitive arrays
let parray = array.as_primitive();
let parray = PrimitiveArray::try_from(array).ok()?;

// Only supports signed integers
if !parray.ptype().is_signed_int() {
Expand All @@ -33,17 +33,17 @@ impl EncodingCompression for ZigZagEncoding {
.map(|_| self as &dyn EncodingCompression)
}

#[allow(unused_variables)]
fn compress(
&self,
array: &Array,
like: Option<&Array>,
ctx: CompressCtx,
) -> VortexResult<OwnedArray> {
let zigzag_like = like.map(|like_arr| like_arr.as_array_ref());
let encoded = if array.encoding().id() == ZigZag::ID {
let encoded = if array.encoding().id() == Primitive::ID {
zigzag_encode(&array.as_primitive())?
} else {
println!("{}", array.encoding().id());
unreachable!("This array kind should have been filtered out")
};

Expand Down Expand Up @@ -116,4 +116,31 @@ where
} else {
PrimitiveArray::from(encoded.to_vec())
}
}
}

#[cfg(test)]
mod test {
use std::sync::Arc;

use vortex::encoding::{ArrayEncoding, EncodingRef};
use vortex_fastlanes::BitPackedEncoding;

// use vortex::ToArray;
use super::*;

#[test]
fn test_compress() {
let cfg = CompressConfig::new()
.with_enabled([&ZigZagEncoding as EncodingRef, &BitPackedEncoding])
.with_disabled(vec![]);
let ctx = CompressCtx::new(Arc::new(cfg));

let compressed = ctx
.compress(
PrimitiveArray::from(Vec::from_iter((-10_000..10_000).map(|i| i as i64))).array(),
None,
)
.unwrap();
assert_eq!(compressed.encoding().id(), ZigZagEncoding.id());
}
}
3 changes: 2 additions & 1 deletion vortex-zigzag/src/zigzag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use vortex::array::primitive::Primitive;
use vortex::stats::ArrayStatisticsCompute;
use vortex::validity::{ArrayValidity, LogicalValidity};
use vortex::visitor::{AcceptArrayVisitor, ArrayVisitor};
Expand Down Expand Up @@ -36,7 +37,7 @@ impl ZigZagArray<'_> {
}

pub fn encode<'a>(array: &'a Array<'a>) -> VortexResult<Array<'a>> {
if array.encoding().id() == ZigZag::ID {
if array.encoding().id() == Primitive::ID {
Ok(zigzag_encode(&array.as_primitive())?.into_array())
} else {
Err(vortex_err!("ZigZag can only encoding primitive arrays"))
Expand Down

0 comments on commit 3dbf337

Please sign in to comment.