1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use parquet2::statistics::{FixedLenStatistics, Statistics as ParquetStatistics};

use crate::array::*;
use crate::error::Result;
use crate::types::days_ms;

use super::super::{convert_days_ms, convert_i128};

pub(super) fn push_i128(
    from: Option<&dyn ParquetStatistics>,
    n: usize,
    min: &mut dyn MutableArray,
    max: &mut dyn MutableArray,
) -> Result<()> {
    let min = min
        .as_mut_any()
        .downcast_mut::<MutablePrimitiveArray<i128>>()
        .unwrap();
    let max = max
        .as_mut_any()
        .downcast_mut::<MutablePrimitiveArray<i128>>()
        .unwrap();
    let from = from.map(|s| s.as_any().downcast_ref::<FixedLenStatistics>().unwrap());

    min.push(from.and_then(|s| s.min_value.as_deref().map(|x| convert_i128(x, n))));
    max.push(from.and_then(|s| s.max_value.as_deref().map(|x| convert_i128(x, n))));

    Ok(())
}

pub(super) fn push(
    from: Option<&dyn ParquetStatistics>,
    min: &mut dyn MutableArray,
    max: &mut dyn MutableArray,
) -> Result<()> {
    let min = min
        .as_mut_any()
        .downcast_mut::<MutableFixedSizeBinaryArray>()
        .unwrap();
    let max = max
        .as_mut_any()
        .downcast_mut::<MutableFixedSizeBinaryArray>()
        .unwrap();
    let from = from.map(|s| s.as_any().downcast_ref::<FixedLenStatistics>().unwrap());
    min.push(from.and_then(|s| s.min_value.as_ref()));
    max.push(from.and_then(|s| s.max_value.as_ref()));
    Ok(())
}

fn convert_year_month(value: &[u8]) -> i32 {
    i32::from_le_bytes(value[..4].try_into().unwrap())
}

pub(super) fn push_year_month(
    from: Option<&dyn ParquetStatistics>,
    min: &mut dyn MutableArray,
    max: &mut dyn MutableArray,
) -> Result<()> {
    let min = min
        .as_mut_any()
        .downcast_mut::<MutablePrimitiveArray<i32>>()
        .unwrap();
    let max = max
        .as_mut_any()
        .downcast_mut::<MutablePrimitiveArray<i32>>()
        .unwrap();
    let from = from.map(|s| s.as_any().downcast_ref::<FixedLenStatistics>().unwrap());

    min.push(from.and_then(|s| s.min_value.as_deref().map(convert_year_month)));
    max.push(from.and_then(|s| s.max_value.as_deref().map(convert_year_month)));

    Ok(())
}

pub(super) fn push_days_ms(
    from: Option<&dyn ParquetStatistics>,
    min: &mut dyn MutableArray,
    max: &mut dyn MutableArray,
) -> Result<()> {
    let min = min
        .as_mut_any()
        .downcast_mut::<MutablePrimitiveArray<days_ms>>()
        .unwrap();
    let max = max
        .as_mut_any()
        .downcast_mut::<MutablePrimitiveArray<days_ms>>()
        .unwrap();
    let from = from.map(|s| s.as_any().downcast_ref::<FixedLenStatistics>().unwrap());

    min.push(from.and_then(|s| s.min_value.as_deref().map(convert_days_ms)));
    max.push(from.and_then(|s| s.max_value.as_deref().map(convert_days_ms)));

    Ok(())
}