Skip to content

Commit 9b8e9cc

Browse files
committed
fix
1 parent 3e86955 commit 9b8e9cc

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed

src/query/storages/common/table_meta/src/meta/utils.rs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,22 @@ pub fn trim_object_prefix(key: &str) -> &str {
185185
#[cfg(test)]
186186
#[allow(clippy::items_after_test_module)]
187187
mod tests {
188+
use std::io::Cursor;
189+
use std::io::Error;
190+
use std::io::ErrorKind;
191+
188192
use chrono::Duration;
189193
use databend_common_base::base::uuid::Uuid;
194+
use databend_common_exception::Result;
195+
use databend_common_io::prelude::bincode_deserialize_from_slice;
196+
use databend_common_io::prelude::bincode_serialize_into_buf;
190197

191198
use crate::meta::trim_object_prefix;
192199
use crate::meta::try_extract_uuid_str_from_path;
200+
use crate::meta::AdditionalStatsMeta;
201+
use crate::meta::Location;
202+
use crate::meta::RawBlockHLL;
203+
use crate::meta::TableSnapshotV4;
193204
use crate::meta::VACUUM2_OBJECT_KEY_PREFIX;
194205

195206
#[test]
@@ -244,4 +255,153 @@ mod tests {
244255
assert_order_preserved(now, ts);
245256
assert_order_preserved(ts - Duration::milliseconds(1), ts);
246257
}
258+
259+
#[test]
260+
fn test_decode_snapshot() -> Result<()> {
261+
let data = [
262+
4, 0, 0, 0, 0, 0, 0, 0, 2, 1, 197, 2, 0, 0, 0, 0, 0, 0, 40, 181, 47, 253, 0, 88, 229,
263+
21, 0, 230, 233, 147, 72, 240, 144, 184, 13, 204, 131, 11, 131, 51, 218, 138, 145, 68,
264+
106, 164, 89, 117, 78, 234, 63, 184, 126, 97, 248, 95, 245, 97, 186, 123, 211, 51, 118,
265+
61, 149, 125, 8, 255, 94, 55, 123, 101, 31, 136, 161, 78, 145, 123, 224, 25, 185, 229,
266+
169, 61, 131, 219, 176, 66, 191, 145, 72, 187, 22, 93, 124, 234, 77, 97, 84, 22, 136,
267+
132, 4, 135, 0, 123, 0, 125, 0, 247, 138, 36, 45, 212, 135, 167, 46, 103, 159, 213,
268+
245, 218, 161, 233, 101, 191, 226, 4, 191, 162, 152, 38, 30, 207, 188, 146, 146, 226,
269+
245, 190, 5, 89, 27, 38, 126, 18, 229, 172, 143, 7, 50, 104, 170, 7, 149, 14, 161, 163,
270+
244, 129, 196, 42, 21, 51, 98, 225, 185, 252, 251, 205, 46, 75, 191, 67, 24, 10, 31,
271+
16, 23, 226, 105, 35, 26, 104, 36, 180, 69, 8, 113, 32, 158, 6, 2, 226, 52, 174, 69,
272+
136, 103, 231, 143, 109, 119, 145, 114, 204, 168, 145, 2, 7, 141, 23, 59, 48, 100, 128,
273+
193, 218, 49, 34, 19, 16, 163, 90, 217, 53, 137, 135, 51, 115, 151, 143, 172, 45, 223,
274+
95, 146, 125, 226, 173, 65, 152, 14, 1, 37, 153, 173, 59, 253, 146, 138, 250, 125, 127,
275+
41, 91, 153, 215, 220, 163, 44, 177, 214, 247, 139, 9, 208, 169, 49, 125, 205, 182,
276+
229, 0, 128, 26, 22, 21, 254, 196, 114, 249, 253, 244, 201, 250, 156, 255, 14, 177,
277+
166, 89, 164, 193, 100, 167, 15, 238, 15, 101, 56, 38, 84, 223, 207, 165, 211, 179,
278+
168, 169, 188, 160, 183, 11, 196, 105, 79, 140, 69, 206, 178, 145, 221, 244, 25, 70,
279+
195, 236, 179, 206, 254, 184, 149, 141, 178, 221, 189, 132, 245, 213, 239, 98, 136, 53,
280+
125, 193, 170, 149, 25, 139, 87, 83, 23, 247, 233, 185, 193, 137, 253, 31, 22, 73, 88,
281+
168, 191, 223, 12, 252, 169, 173, 217, 178, 140, 40, 227, 243, 61, 195, 18, 214, 136,
282+
26, 51, 148, 113, 195, 99, 196, 178, 154, 113, 2, 214, 99, 244, 204, 140, 8, 18, 96,
283+
55, 238, 37, 173, 176, 18, 169, 172, 109, 159, 84, 223, 22, 246, 39, 150, 175, 112,
284+
152, 253, 177, 156, 89, 219, 110, 107, 157, 51, 175, 253, 157, 139, 151, 190, 116, 10,
285+
116, 50, 20, 198, 225, 47, 222, 89, 146, 160, 150, 157, 102, 219, 185, 173, 43, 20,
286+
156, 182, 198, 143, 101, 182, 48, 216, 189, 98, 110, 161, 166, 137, 87, 83, 4, 42, 91,
287+
188, 74, 201, 80, 120, 159, 157, 203, 171, 169, 235, 245, 39, 150, 223, 41, 246, 109,
288+
3, 47, 201, 169, 237, 220, 246, 217, 93, 188, 78, 111, 18, 35, 250, 190, 218, 121, 159,
289+
173, 227, 66, 223, 127, 218, 244, 186, 26, 18, 121, 148, 106, 19, 36, 34, 242, 241, 60,
290+
17, 229, 54, 77, 235, 232, 247, 205, 13, 12, 85, 207, 3, 69, 31, 38, 33, 14, 233, 74,
291+
178, 3, 81, 80, 228, 125, 168, 123, 13, 124, 207, 19, 105, 93, 13, 213, 80, 221, 42,
292+
221, 64, 79, 180, 105, 36, 207, 136, 75, 15, 136, 243, 108, 155, 141, 148, 138, 247,
293+
252, 120, 244, 188, 5, 65, 66, 253, 95, 128, 109, 56, 155, 140, 147, 169, 140, 157, 50,
294+
248, 24, 80, 25, 177, 44, 219, 168, 70, 214, 232, 128, 192, 0, 213, 24, 42, 32, 96,
295+
194, 67, 103, 30, 61, 68, 144, 251, 36, 150, 161, 205, 214, 223, 213, 239, 8, 33, 126,
296+
76, 116, 131, 66, 49, 55, 102, 224, 24, 62, 251, 222, 76, 104, 185, 129, 238, 225, 158,
297+
92, 103, 200, 231, 177, 43, 131, 29, 123, 136, 113, 3, 136, 156, 13, 185, 121, 183,
298+
112, 9, 75, 121, 242, 220, 176, 16, 220, 192, 25, 148, 67, 228, 200, 89, 162, 67, 225,
299+
152, 209, 129, 198, 62, 12, 30, 216, 10, 64, 23, 14, 54, 203, 93, 85, 57, 212, 255, 24,
300+
45, 87, 178, 13, 198, 185, 158, 25,
301+
];
302+
303+
let val = TableSnapshotV4::from_slice(&data)?;
304+
println!("val: {:?}", val);
305+
let mut buffer = Cursor::new(Vec::new());
306+
bincode_serialize_into_buf(&mut buffer, &val).unwrap();
307+
let slice = buffer.get_ref().as_slice();
308+
let deserialized: TableSnapshotV4 = bincode_deserialize_from_slice(slice).unwrap();
309+
assert_eq!(val.summary, deserialized.summary);
310+
Ok(())
311+
}
312+
313+
#[test]
314+
fn test_additional_stats_meta_compatibility() -> Result<()> {
315+
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq, Default)]
316+
struct AdditionalStatsMeta803 {
317+
/// The size of the stats data in bytes.
318+
size: u64,
319+
/// The file location of the stats data.
320+
location: Location,
321+
/// An optional HyperLogLog data structure.
322+
hll: Option<RawBlockHLL>,
323+
/// The count of the stats rows.
324+
#[serde(default)]
325+
row_count: u64,
326+
}
327+
328+
// 790 and 797 have the same definition as 801
329+
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq, Default)]
330+
struct AdditionalStatsMeta801 {
331+
/// The size of the stats data in bytes.
332+
size: u64,
333+
/// The file location of the stats data.
334+
location: Location,
335+
}
336+
337+
// Simulate using current PR read data of v803
338+
{
339+
let v803 = AdditionalStatsMeta803::default();
340+
let bytes = rmp_serde::to_vec_named(&v803)
341+
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
342+
let current: std::result::Result<AdditionalStatsMeta, Error> =
343+
rmp_serde::from_slice(&bytes).map_err(|e| Error::new(ErrorKind::InvalidData, e));
344+
// v803 is compatible with current PR
345+
assert!(current.is_ok());
346+
eprintln!("current {:#?}", current);
347+
}
348+
349+
// Simulate using v803 read data created by current PR when the location is none
350+
{
351+
let current = AdditionalStatsMeta {
352+
hll: Some(RawBlockHLL::default()),
353+
..Default::default()
354+
};
355+
let bytes = rmp_serde::to_vec_named(&current)
356+
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
357+
let v803: std::result::Result<AdditionalStatsMeta803, Error> =
358+
rmp_serde::from_slice(&bytes).map_err(|e| Error::new(ErrorKind::InvalidData, e));
359+
// v803 is not compatible with current PR when the location is none.
360+
assert!(v803.is_err());
361+
}
362+
363+
// Simulate using v803 read data created by current PR when the location is some
364+
{
365+
let current = AdditionalStatsMeta {
366+
hll: Some(RawBlockHLL::default()),
367+
location: Some(Location::default()),
368+
..Default::default()
369+
};
370+
let bytes = rmp_serde::to_vec_named(&current)
371+
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
372+
let v803: std::result::Result<AdditionalStatsMeta803, Error> =
373+
rmp_serde::from_slice(&bytes).map_err(|e| Error::new(ErrorKind::InvalidData, e));
374+
// v803 is compatible with current PR when the location is some.
375+
assert!(v803.is_ok());
376+
eprintln!("v803 {:#?}", v803);
377+
}
378+
379+
// v790, 797, 801 have been deployed, we MUST support them
380+
// Simulate using current PR read data of v790, 797, 801
381+
{
382+
let v801 = AdditionalStatsMeta801::default();
383+
let bytes = rmp_serde::to_vec_named(&v801)
384+
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
385+
let current: std::result::Result<AdditionalStatsMeta, Error> =
386+
rmp_serde::from_slice(&bytes).map_err(|e| Error::new(ErrorKind::InvalidData, e));
387+
assert!(current.is_ok());
388+
eprintln!("current {:#?}", current);
389+
}
390+
391+
// Simulate using v790, 797, 801 read data created by current PR
392+
{
393+
let current = AdditionalStatsMeta {
394+
hll: Some(RawBlockHLL::default()),
395+
..Default::default()
396+
};
397+
let bytes = rmp_serde::to_vec_named(&current)
398+
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
399+
let current: std::result::Result<AdditionalStatsMeta801, Error> =
400+
rmp_serde::from_slice(&bytes).map_err(|e| Error::new(ErrorKind::InvalidData, e));
401+
// current is not compatible with v801 PR when the location is none.
402+
assert!(current.is_err());
403+
}
404+
405+
Ok(())
406+
}
247407
}

src/query/storages/fuse/src/operations/analyze.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ impl SinkAnalyzeState {
222222
new_snapshot.summary.additional_stats_meta = Some(AdditionalStatsMeta {
223223
hll: Some(encode_column_hll(&self.ndv_states)?),
224224
row_count: snapshot.summary.row_count,
225+
location: Some(("".to_string(), 0u64)),
225226
..Default::default()
226227
});
227228

src/query/storages/fuse/src/statistics/table_statistics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl TableStatsGenerator {
5555
Some(AdditionalStatsMeta {
5656
hll,
5757
row_count: self.row_count,
58+
location: Some(("".to_string(), 0u64)),
5859
..Default::default()
5960
})
6061
}

0 commit comments

Comments
 (0)