Skip to content

Commit 0d35e66

Browse files
authored
chore: add a test case for variable packed struct (#5384)
This PR adds a new test case for variable packed struct with utf8. --- **This PR was primarily authored with Codex using GPT-5-Codex-Max and then hand-reviewed by me. I AM responsible for every change made in this PR. I aimed to keep it aligned with our goals, though I may have missed minor issues. Please flag anything that feels off, I'll fix it quickly.** --------- Signed-off-by: Xuanwo <[email protected]>
1 parent 28a01d3 commit 0d35e66

File tree

1 file changed

+47
-0
lines changed
  • rust/lance-encoding/src/encodings/physical

1 file changed

+47
-0
lines changed

rust/lance-encoding/src/encodings/physical/packed.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,17 @@ mod tests {
735735
use crate::{
736736
compression::CompressionStrategy,
737737
compression::{DefaultCompressionStrategy, DefaultDecompressionStrategy},
738+
constants::PACKED_STRUCT_META_KEY,
738739
statistics::ComputeStat,
740+
testing::{check_round_trip_encoding_of_data, TestCases},
739741
version::LanceFileVersion,
740742
};
741743
use arrow_array::{
742744
Array, ArrayRef, BinaryArray, Int32Array, Int64Array, LargeStringArray, StringArray,
745+
StructArray, UInt32Array,
743746
};
744747
use arrow_schema::{DataType, Field as ArrowField, Fields};
748+
use std::collections::HashMap;
745749
use std::sync::Arc;
746750

747751
fn fixed_block_from_array(array: Int64Array) -> FixedWidthDataBlock {
@@ -947,6 +951,49 @@ mod tests {
947951
Ok(())
948952
}
949953

954+
#[tokio::test]
955+
async fn variable_packed_struct_utf8_round_trip() {
956+
// schema: Struct<id: UInt32, uri: Utf8, long_text: LargeUtf8>
957+
let fields = Fields::from(vec![
958+
Arc::new(ArrowField::new("id", DataType::UInt32, false)),
959+
Arc::new(ArrowField::new("uri", DataType::Utf8, false)),
960+
Arc::new(ArrowField::new("long_text", DataType::LargeUtf8, false)),
961+
]);
962+
963+
// mark struct as packed
964+
let mut meta = HashMap::new();
965+
meta.insert(PACKED_STRUCT_META_KEY.to_string(), "true".to_string());
966+
967+
let array = Arc::new(StructArray::from(vec![
968+
(
969+
fields[0].clone(),
970+
Arc::new(UInt32Array::from(vec![1, 2, 3])) as ArrayRef,
971+
),
972+
(
973+
fields[1].clone(),
974+
Arc::new(StringArray::from(vec![
975+
Some("a"),
976+
Some("b"),
977+
Some("/tmp/x"),
978+
])) as ArrayRef,
979+
),
980+
(
981+
fields[2].clone(),
982+
Arc::new(LargeStringArray::from(vec![
983+
Some("alpha"),
984+
Some("a considerably longer payload for testing"),
985+
Some("mid"),
986+
])) as ArrayRef,
987+
),
988+
]));
989+
990+
let test_cases = TestCases::default()
991+
.with_min_file_version(LanceFileVersion::V2_2)
992+
.with_expected_encoding("variable_packed_struct");
993+
994+
check_round_trip_encoding_of_data(vec![array], &test_cases, meta).await;
995+
}
996+
950997
#[test]
951998
fn variable_packed_struct_multi_variable_round_trip() -> Result<()> {
952999
let arrow_fields: Fields = vec![

0 commit comments

Comments
 (0)