Skip to content

Commit 8ded948

Browse files
committed
PCO decode error workaround
1 parent 7b93de1 commit 8ded948

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

src/mem_store/column.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ impl Column {
132132
self.data[0] = self.data[0].lz4_decode(decoded_type, self.len);
133133
trace!("lz4_decode after: {:?}", self);
134134
}
135-
if let Some(CodecOp::Pco(decoded_type, ..)) = self.codec.ops().first().copied() {
135+
if let Some(CodecOp::Pco(decoded_type, length, ..)) = self.codec.ops().first().copied() {
136136
trace!("lz4_decode before: {:?}", self);
137137
self.codec = self.codec.without_pco();
138-
self.data[0] = self.data[0].pco_decode(decoded_type);
138+
self.data[0] = self.data[0].pco_decode(decoded_type, length);
139139
trace!("lz4_decode after: {:?}", self);
140140
}
141141
}
@@ -462,7 +462,7 @@ impl DataSection {
462462
}
463463
}
464464

465-
pub fn pco_decode(&self, decoded_type: EncodingType) -> DataSection {
465+
pub fn pco_decode(&self, decoded_type: EncodingType, length: usize) -> DataSection {
466466
match self {
467467
DataSection::Pco { data, is_fp32, .. } => match decoded_type {
468468
EncodingType::U8 => DataSection::U8(
@@ -482,13 +482,19 @@ impl DataSection {
482482
EncodingType::U32 => DataSection::U32(simple_decompress(data).unwrap()),
483483
EncodingType::U64 => DataSection::U64(simple_decompress(data).unwrap()),
484484
EncodingType::I64 => DataSection::I64(simple_decompress(data).unwrap()),
485-
EncodingType::F64 if *is_fp32 => DataSection::F64(
486-
simple_decompress::<f32>(data)
487-
.unwrap()
488-
.into_iter()
489-
.map(|v| OrderedFloat(v as f64))
490-
.collect(),
491-
),
485+
EncodingType::F64 if *is_fp32 => match simple_decompress::<f32>(data) {
486+
Ok(decompressed) => DataSection::F64(
487+
decompressed
488+
.into_iter()
489+
.map(|v| OrderedFloat(v as f64))
490+
.collect(),
491+
),
492+
Err(e) => {
493+
log::error!("Error decompressing PCO f32 data section: {:?}", e);
494+
log::error!("PCO data section (hex): {:02x?}", data);
495+
DataSection::F64(vec![OrderedFloat(0.0); length])
496+
}
497+
},
492498
EncodingType::F64 if !is_fp32 => DataSection::F64(unsafe {
493499
std::mem::transmute::<Vec<f64>, Vec<of64>>(
494500
simple_decompress::<f64>(data).unwrap(),
@@ -736,26 +742,24 @@ fn decode<'a>(codec: &Codec, sections: &[&'a dyn Data<'a>]) -> BoxedData<'a> {
736742
}
737743
Box::new(output) as BoxedData
738744
}
739-
CodecOp::LZ4(encoding_type, count) => {
740-
match encoding_type {
741-
EncodingType::U8 => {
742-
let mut decoded = vec![0; *count];
743-
lz4::decode::<u8>(&mut lz4::decoder(arg0.cast_ref_u8()), &mut decoded);
744-
Box::new(decoded) as BoxedData
745-
}
746-
EncodingType::I64 => {
747-
let mut decoded = vec![0; *count];
748-
lz4::decode::<i64>(&mut lz4::decoder(arg0.cast_ref_u8()), &mut decoded);
749-
Box::new(decoded)
750-
}
751-
EncodingType::F64 => {
752-
let mut decoded = vec![0.0; *count];
753-
lz4::decode::<f64>(&mut lz4::decoder(arg0.cast_ref_u8()), &mut decoded);
754-
Box::new(vec_f64_to_vec_of64(decoded))
755-
}
756-
other => panic!("Unsupported encoding type for CodecOp::LZ4: {:?}", other),
745+
CodecOp::LZ4(encoding_type, count) => match encoding_type {
746+
EncodingType::U8 => {
747+
let mut decoded = vec![0; *count];
748+
lz4::decode::<u8>(&mut lz4::decoder(arg0.cast_ref_u8()), &mut decoded);
749+
Box::new(decoded) as BoxedData
757750
}
758-
}
751+
EncodingType::I64 => {
752+
let mut decoded = vec![0; *count];
753+
lz4::decode::<i64>(&mut lz4::decoder(arg0.cast_ref_u8()), &mut decoded);
754+
Box::new(decoded)
755+
}
756+
EncodingType::F64 => {
757+
let mut decoded = vec![0.0; *count];
758+
lz4::decode::<f64>(&mut lz4::decoder(arg0.cast_ref_u8()), &mut decoded);
759+
Box::new(vec_f64_to_vec_of64(decoded))
760+
}
761+
other => panic!("Unsupported encoding type for CodecOp::LZ4: {:?}", other),
762+
},
759763
CodecOp::Pco(encoding_type, _, is_fp32) => {
760764
let encoded_data = arg0.cast_ref_u8();
761765
match encoding_type {

0 commit comments

Comments
 (0)