fix(mito-codec): return the first field from dense decode_leftmost (#10090)

DensePrimaryKeyCodec::decode_leftmost decoded the whole key and popped
the last value, so codecs with more than one field returned the
rightmost primary key column. Decode only the first field instead,
which also removes the full-key decoding noted in the TODO.

Current callers build single-field codecs and are unaffected.

Fixes #10089

Signed-off-by: Aumnertic <hznuzc@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aum
2026-11-03 03:16:10 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent eef2d58a48
commit 5cecc99cbe
+43 -3
View File
@@ -730,9 +730,13 @@ impl PrimaryKeyCodec for DensePrimaryKeyCodec {
}
fn decode_leftmost(&self, bytes: &[u8]) -> Result<Option<Value>> {
// TODO(weny, yinwen): avoid decoding the whole primary key.
let mut values = self.decode_dense(bytes)?;
Ok(values.pop().map(|(_, v)| v))
// Dense keys store fields in primary key order, so only the first
// field needs to be decoded.
let Some((_, field)) = self.ordered_primary_key_columns.first() else {
return Ok(None);
};
let mut deserializer = Deserializer::new(bytes);
field.deserialize(&mut deserializer).map(Some)
}
}
@@ -1003,6 +1007,42 @@ mod tests {
)
}
#[test]
fn test_decode_leftmost_returns_first_field() {
let encoder = DensePrimaryKeyCodec::with_fields(vec![
(0, SortField::new(ConcreteDataType::string_datatype())),
(1, SortField::new(ConcreteDataType::int32_datatype())),
(2, SortField::new(ConcreteDataType::string_datatype())),
]);
let row = [
Value::String("first".into()),
Value::Int32(42),
Value::String("last".into()),
];
let encoded = encoder
.encode(row.iter().map(|v| v.as_value_ref()))
.unwrap();
assert_eq!(
encoder.decode_leftmost(&encoded).unwrap(),
Some(Value::String("first".into()))
);
let single = DensePrimaryKeyCodec::with_fields(vec![(
0,
SortField::new(ConcreteDataType::int32_datatype()),
)]);
let encoded = single
.encode([Value::Int32(7).as_value_ref()].into_iter())
.unwrap();
assert_eq!(
single.decode_leftmost(&encoded).unwrap(),
Some(Value::Int32(7))
);
let empty = DensePrimaryKeyCodec::with_fields(vec![]);
assert_eq!(empty.decode_leftmost(&[]).unwrap(), None);
}
#[test]
fn test_encoded_value_at() {
let data_types = [