-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathscheme_selection_tests.rs
More file actions
122 lines (108 loc) · 4.2 KB
/
Copy pathscheme_selection_tests.rs
File metadata and controls
122 lines (108 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Tests to verify that each string compression scheme produces the expected encoding.
use std::sync::LazyLock;
use vortex_array::IntoArray;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::Constant;
use vortex_array::arrays::Dict;
use vortex_array::arrays::VarBinViewArray;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability;
use vortex_error::VortexResult;
use vortex_fsst::FSST;
use vortex_session::VortexSession;
use crate::BtrBlocksCompressor;
static SESSION: LazyLock<VortexSession> = LazyLock::new(vortex_array::array_session);
#[test]
fn test_constant_compressed() -> VortexResult<()> {
let strings: Vec<Option<&str>> = vec![Some("constant_value"); 100];
let array = VarBinViewArray::from_iter(strings, DType::Utf8(Nullability::NonNullable));
let array_ref = array.into_array();
let compressed =
BtrBlocksCompressor::default().compress(&array_ref, &mut SESSION.create_execution_ctx())?;
assert!(compressed.is::<Constant>());
Ok(())
}
#[test]
fn test_dict_compressed() -> VortexResult<()> {
let distinct_values = ["apple", "banana", "cherry"];
let mut strings = Vec::with_capacity(1000);
for i in 0..1000 {
strings.push(Some(distinct_values[i % 3]));
}
let array = VarBinViewArray::from_iter(strings, DType::Utf8(Nullability::NonNullable));
let array_ref = array.into_array();
let compressed =
BtrBlocksCompressor::default().compress(&array_ref, &mut SESSION.create_execution_ctx())?;
assert!(compressed.is::<Dict>());
Ok(())
}
#[cfg(feature = "unstable_encodings")]
#[test]
fn test_unstable_all_schemes_includes_onpair() {
use crate::SchemeExt;
use crate::schemes::string::onpair::OnPairScheme;
let ids: Vec<_> = crate::ALL_SCHEMES.iter().map(|s| s.id()).collect();
assert!(
ids.contains(&OnPairScheme.id()),
"OnPairScheme not registered in ALL_SCHEMES"
);
}
#[cfg(feature = "unstable_encodings")]
#[test]
fn test_unstable_default_btrblocks_compressor_selects_onpair() -> VortexResult<()> {
// Dictionary-style string corpus: high lexical overlap, short rows.
// OnPair beats FSST on this corpus, so it wins the sample-based
// comparison even though both are registered when `unstable_encodings`
// is enabled.
let mut strings = Vec::with_capacity(1000);
for i in 0..1000 {
strings.push(Some(format!(
"this_is_a_common_prefix_with_some_variation_{i}_and_a_common_suffix_pattern"
)));
}
let array = VarBinViewArray::from_iter(strings, DType::Utf8(Nullability::NonNullable));
let array_ref = array.into_array();
let compressed =
BtrBlocksCompressor::default().compress(&array_ref, &mut SESSION.create_execution_ctx())?;
assert!(
compressed.is::<vortex_onpair::OnPair>(),
"expected OnPair, got {}",
compressed.encoding_id()
);
Ok(())
}
/// FSST is registered in the default scheme list, and an FSST-only builder
/// still produces an FSST array.
#[test]
fn test_fsst_in_default_scheme_list() -> VortexResult<()> {
use crate::BtrBlocksCompressorBuilder;
use crate::SchemeExt;
use crate::schemes::string::FSSTScheme;
// FSST is registered by default.
assert!(
crate::ALL_SCHEMES.iter().any(|s| s.id() == FSSTScheme.id()),
"FSSTScheme should be in ALL_SCHEMES",
);
// An FSST-only builder still produces an FSST array for FSST-favourable
// input.
let mut strings = Vec::with_capacity(1000);
for i in 0..1000 {
strings.push(Some(format!(
"this_is_a_common_prefix_with_some_variation_{i}_and_a_common_suffix_pattern"
)));
}
let array = VarBinViewArray::from_iter(strings, DType::Utf8(Nullability::NonNullable));
let array_ref = array.into_array();
let compressor = BtrBlocksCompressorBuilder::empty()
.with_new_scheme(&FSSTScheme)
.build();
let compressed = compressor.compress(&array_ref, &mut SESSION.create_execution_ctx())?;
assert!(
compressed.is::<FSST>(),
"expected FSST when only FSSTScheme is registered, got {}",
compressed.encoding_id()
);
Ok(())
}