pub use thrift::protocol::TCompactOutputProtocol;
use thrift::protocol::{TInputProtocol, TOutputProtocol};
pub trait TSerializable: Sized {
fn read_from_in_protocol<T: TInputProtocol>(i_prot: &mut T) -> thrift::Result<Self>;
fn write_to_out_protocol<T: TOutputProtocol>(&self, o_prot: &mut T) -> thrift::Result<()>;
}
#[cfg(test)]
mod tests {
use crate::{
basic::Type,
file::page_index::{column_index::ColumnIndexMetaData, index_reader::decode_column_index},
};
#[test]
#[allow(deprecated)]
fn legacy_statistics_reject_oversized_binary_before_allocation() {
use crate::{format::Statistics, thrift::TSerializable};
use thrift::{Error, ProtocolErrorKind, protocol::TCompactInputProtocol};
let bytes = [0x18, 0x81, 0x80, 0x80, 0x32];
let mut input = TCompactInputProtocol::new(bytes.as_slice());
let error = Statistics::read_from_in_protocol(&mut input).unwrap_err();
assert!(
matches!(error, Error::Protocol(error) if error.kind == ProtocolErrorKind::SizeLimit)
);
}
#[test]
#[allow(deprecated)]
fn legacy_statistics_compact_protocol_roundtrip() {
use crate::{format::Statistics, thrift::TSerializable};
use thrift::protocol::{TCompactInputProtocol, TCompactOutputProtocol};
let expected = Statistics {
min_value: Some(vec![0, 1, 255]),
max_value: Some(vec![255, 0, 1]),
null_count: Some(7),
..Default::default()
};
let mut bytes = Vec::new();
expected
.write_to_out_protocol(&mut TCompactOutputProtocol::new(&mut bytes))
.unwrap();
let actual =
Statistics::read_from_in_protocol(&mut TCompactInputProtocol::new(bytes.as_slice()))
.unwrap();
assert_eq!(actual, expected);
}
#[test]
pub fn read_boolean_list_field_type() {
let bytes = vec![
0x19, 0x21, 2, 1, 0x19, 0x28, 1, 0, 0, 0x19, 0x28, 1, 1, 0, 0x15, 0, 0,
];
let index = decode_column_index(&bytes, Type::BOOLEAN).unwrap();
let index = match index {
ColumnIndexMetaData::BOOLEAN(index) => index,
_ => panic!("expected boolean column index"),
};
assert!(!index.is_null_page(0));
assert!(index.is_null_page(1));
assert!(!index.min_value(0).unwrap()); assert!(index.max_value(0).unwrap()); assert!(index.min_value(1).is_none());
assert!(index.max_value(1).is_none());
}
#[test]
pub fn read_boolean_list_alternative_encoding() {
let bytes = vec![
0x19, 0x22, 0, 1, 0x19, 0x28, 1, 0, 0, 0x19, 0x28, 1, 1, 0, 0x15, 0, 0,
];
let index = decode_column_index(&bytes, Type::BOOLEAN).unwrap();
let index = match index {
ColumnIndexMetaData::BOOLEAN(index) => index,
_ => panic!("expected boolean column index"),
};
assert!(!index.is_null_page(0));
assert!(index.is_null_page(1));
assert!(!index.min_value(0).unwrap()); assert!(index.max_value(0).unwrap()); assert!(index.min_value(1).is_none());
assert!(index.max_value(1).is_none());
}
}