fn extract_iox_statistics(
    parquet_stats: &ParquetStatistics,
    min_max_set: bool,
    iox_type: InfluxColumnType,
    total_count: u64,
    row_group_idx: usize,
    column_name: &str,
) -> Result<Statistics> {
    let null_count = parquet_stats.null_count();

    match (parquet_stats, iox_type) {
        (ParquetStatistics::Boolean(stats), InfluxColumnType::Field(InfluxFieldType::Boolean)) => {
            Ok(Statistics::Bool(StatValues {
                min: min_max_set.then(|| *stats.min()),
                max: min_max_set.then(|| *stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Int64(stats), InfluxColumnType::Field(InfluxFieldType::Integer)) => {
            Ok(Statistics::I64(StatValues {
                min: min_max_set.then(|| *stats.min()),
                max: min_max_set.then(|| *stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Int64(stats), InfluxColumnType::Field(InfluxFieldType::UInteger)) => {
            Ok(Statistics::U64(StatValues {
                min: min_max_set.then(|| *stats.min() as u64),
                max: min_max_set.then(|| *stats.max() as u64),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Double(stats), InfluxColumnType::Field(InfluxFieldType::Float)) => {
            Ok(Statistics::F64(StatValues {
                min: min_max_set.then(|| *stats.min()),
                max: min_max_set.then(|| *stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Int64(stats), InfluxColumnType::Timestamp) => {
            Ok(Statistics::I64(StatValues {
                min: Some(*stats.min()),
                max: Some(*stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::ByteArray(stats), InfluxColumnType::Tag)
        | (ParquetStatistics::ByteArray(stats), InfluxColumnType::Field(InfluxFieldType::String)) => {
            Ok(Statistics::String(StatValues {
                min: min_max_set
                    .then(|| {
                        stats
                            .min()
                            .as_utf8()
                            .context(StatisticsUtf8Snafu {
                                row_group: row_group_idx,
                                column: column_name.to_string(),
                            })
                            .map(|x| x.to_string())
                    })
                    .transpose()?,
                max: min_max_set
                    .then(|| {
                        stats
                            .max()
                            .as_utf8()
                            .context(StatisticsUtf8Snafu {
                                row_group: row_group_idx,
                                column: column_name.to_string(),
                            })
                            .map(|x| x.to_string())
                    })
                    .transpose()?,
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        _ => Err(Error::StatisticsTypeMismatch {
            row_group: row_group_idx,
            column: column_name.to_string(),
            expected: iox_type,
            actual: parquet_stats.clone(),
        }),
    }
}
/// Extract IOx statistics from parquet statistics.
///
/// This is required because upstream does not have a mapper from
/// parquet statistics back to arrow or Rust native types.
Extract IOx statistics from parquet statistics.
This is required because upstream does not have a mapper from
parquet statistics back to arrow or Rust native types.
Extract IOx statistics from parquet statistics . This is required because upstream does not have a mapper from parquet statistics back to arrow or Rust native types .
fn extract_iox_statistics(
    parquet_stats: &ParquetStatistics,
    min_max_set: bool,
    iox_type: InfluxColumnType,
    total_count: u64,
    row_group_idx: usize,
    column_name: &str,
) -> Result<Statistics> {
    let null_count = parquet_stats.null_count();
    match (parquet_stats, iox_type) {
        (ParquetStatistics::Boolean(stats), InfluxColumnType::Field(InfluxFieldType::Boolean)) => {
            Ok(Statistics::Bool(StatValues {
                min: min_max_set.then(|| *stats.min()),
                max: min_max_set.then(|| *stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Int64(stats), InfluxColumnType::Field(InfluxFieldType::Integer)) => {
            Ok(Statistics::I64(StatValues {
                min: min_max_set.then(|| *stats.min()),
                max: min_max_set.then(|| *stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Int64(stats), InfluxColumnType::Field(InfluxFieldType::UInteger)) => {
            Ok(Statistics::U64(StatValues {
                min: min_max_set.then(|| *stats.min() as u64),
                max: min_max_set.then(|| *stats.max() as u64),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Double(stats), InfluxColumnType::Field(InfluxFieldType::Float)) => {
            Ok(Statistics::F64(StatValues {
                min: min_max_set.then(|| *stats.min()),
                max: min_max_set.then(|| *stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::Int64(stats), InfluxColumnType::Timestamp) => {
            Ok(Statistics::I64(StatValues {
                min: Some(*stats.min()),
                max: Some(*stats.max()),
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        (ParquetStatistics::ByteArray(stats), InfluxColumnType::Tag)
        | (ParquetStatistics::ByteArray(stats), InfluxColumnType::Field(InfluxFieldType::String)) => {
            Ok(Statistics::String(StatValues {
                min: min_max_set
                    .then(|| {
                        stats
                            .min()
                            .as_utf8()
                            .context(StatisticsUtf8Snafu {
                                row_group: row_group_idx,
                                column: column_name.to_string(),
                            })
                            .map(|x| x.to_string())
                    })
                    .transpose()?,
                max: min_max_set
                    .then(|| {
                        stats
                            .max()
                            .as_utf8()
                            .context(StatisticsUtf8Snafu {
                                row_group: row_group_idx,
                                column: column_name.to_string(),
                            })
                            .map(|x| x.to_string())
                    })
                    .transpose()?,
                distinct_count: parquet_stats
                    .distinct_count()
                    .and_then(|x| x.try_into().ok()),
                null_count: Some(null_count),
                total_count,
            }))
        }
        _ => Err(Error::StatisticsTypeMismatch {
            row_group: row_group_idx,
            column: column_name.to_string(),
            expected: iox_type,
            actual: parquet_stats.clone(),
        }),
    }
}
fn extract_iox_statistics ( parquet_stats : & ParquetStatistics , min_max_set : bool , iox_type : InfluxColumnType , total_count : u64 , row_group_idx : usize , column_name : & str , ) -> Result < Statistics > { let null_count = parquet_stats . null_count ( ) ; match ( parquet_stats , iox_type ) { ( ParquetStatistics :: Boolean ( stats ) , InfluxColumnType :: Field ( InfluxFieldType :: Boolean ) ) => { Ok ( Statistics :: Bool ( StatValues { min : min_max_set . then ( | | * stats . min ( ) ) , max : min_max_set . then ( | | * stats . max ( ) ) , distinct_count : parquet_stats . distinct_count ( ) . and_then ( | x | x . try_into ( ) . ok ( ) ) , null_count : Some ( null_count ) , total_count , } ) ) } ( ParquetStatistics :: Int64 ( stats ) , InfluxColumnType :: Field ( InfluxFieldType :: Integer ) ) => { Ok ( Statistics :: I64 ( StatValues { min : min_max_set . then ( | | * stats . min ( ) ) , max : min_max_set . then ( | | * stats . max ( ) ) , distinct_count : parquet_stats . distinct_count ( ) . and_then ( | x | x . try_into ( ) . ok ( ) ) , null_count : Some ( null_count ) , total_count , } ) ) } ( ParquetStatistics :: Int64 ( stats ) , InfluxColumnType :: Field ( InfluxFieldType :: UInteger ) ) => { Ok ( Statistics :: U64 ( StatValues { min : min_max_set . then ( | | * stats . min ( ) as u64 ) , max : min_max_set . then ( | | * stats . max ( ) as u64 ) , distinct_count : parquet_stats . distinct_count ( ) . and_then ( | x | x . try_into ( ) . ok ( ) ) , null_count : Some ( null_count ) , total_count , } ) ) } ( ParquetStatistics :: Double ( stats ) , InfluxColumnType :: Field ( InfluxFieldType :: Float ) ) => { Ok ( Statistics :: F64 ( StatValues { min : min_max_set . then ( | | * stats . min ( ) ) , max : min_max_set . then ( | | * stats . max ( ) ) , distinct_count : parquet_stats . distinct_count ( ) . and_then ( | x | x . try_into ( ) . ok ( ) ) , null_count : Some ( null_count ) , total_count , } ) ) } ( ParquetStatistics :: Int64 ( stats ) , InfluxColumnType :: Timestamp ) => { Ok ( Statistics :: I64 ( StatValues { min : Some ( * stats . min ( ) ) , max : Some ( * stats . max ( ) ) , distinct_count : parquet_stats . distinct_count ( ) . and_then ( | x | x . try_into ( ) . ok ( ) ) , null_count : Some ( null_count ) , total_count , } ) ) } ( ParquetStatistics :: ByteArray ( stats ) , InfluxColumnType :: Tag ) | ( ParquetStatistics :: ByteArray ( stats ) , InfluxColumnType :: Field ( InfluxFieldType :: String ) ) => { Ok ( Statistics :: String ( StatValues { min : min_max_set . then ( | | { stats . min ( ) . as_utf8 ( ) . context ( StatisticsUtf8Snafu { row_group : row_group_idx , column : column_name . to_string ( ) , } ) . map ( | x | x . to_string ( ) ) } ) . transpose ( ) ? , max : min_max_set . then ( | | { stats . max ( ) . as_utf8 ( ) . context ( StatisticsUtf8Snafu { row_group : row_group_idx , column : column_name . to_string ( ) , } ) . map ( | x | x . to_string ( ) ) } ) . transpose ( ) ? , distinct_count : parquet_stats . distinct_count ( ) . and_then ( | x | x . try_into ( ) . ok ( ) ) , null_count : Some ( null_count ) , total_count , } ) ) } _ => Err ( Error :: StatisticsTypeMismatch { row_group : row_group_idx , column : column_name . to_string ( ) , expected : iox_type , actual : parquet_stats . clone ( ) , } ) , } }
Extract IOx statistics from parquet statistics.
Extract IOx statistics from parquet statistics .
parquet_stats
&ParquetStatistics
min_max_set
bool
iox_type
InfluxColumnType
total_count
u64
row_group_idx
usize
column_name
&str
parquet_stats
&ParquetStatistics
min_max_set
bool
iox_type
InfluxColumnType
total_count
u64
row_group_idx
usize
column_name
&str