polars_parquet/parquet/metadata/
sort.rs#[cfg(feature = "serde_types")]
use serde::{Deserialize, Serialize};
use crate::parquet::schema::types::{
IntegerType, PhysicalType, PrimitiveConvertedType, PrimitiveLogicalType,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde_types", derive(Deserialize, Serialize))]
pub enum SortOrder {
Signed,
Unsigned,
Undefined,
}
pub fn get_sort_order(
logical_type: &Option<PrimitiveLogicalType>,
converted_type: &Option<PrimitiveConvertedType>,
physical_type: &PhysicalType,
) -> SortOrder {
if let Some(logical_type) = logical_type {
return get_logical_sort_order(logical_type);
};
if let Some(converted_type) = converted_type {
return get_converted_sort_order(converted_type);
};
get_physical_sort_order(physical_type)
}
fn get_logical_sort_order(logical_type: &PrimitiveLogicalType) -> SortOrder {
use PrimitiveLogicalType::*;
match logical_type {
String | Enum | Json | Bson => SortOrder::Unsigned,
Integer(t) => match t {
IntegerType::Int8 | IntegerType::Int16 | IntegerType::Int32 | IntegerType::Int64 => {
SortOrder::Signed
},
_ => SortOrder::Unsigned,
},
Decimal(_, _) => SortOrder::Signed,
Date => SortOrder::Signed,
Time { .. } => SortOrder::Signed,
Timestamp { .. } => SortOrder::Signed,
Unknown => SortOrder::Undefined,
Uuid => SortOrder::Unsigned,
Float16 => SortOrder::Unsigned,
}
}
fn get_converted_sort_order(converted_type: &PrimitiveConvertedType) -> SortOrder {
use PrimitiveConvertedType::*;
match converted_type {
Utf8 | Json | Bson | Enum => SortOrder::Unsigned,
Int8 | Int16 | Int32 | Int64 => SortOrder::Signed,
Uint8 | Uint16 | Uint32 | Uint64 => SortOrder::Unsigned,
Decimal(_, _) => SortOrder::Signed,
Date => SortOrder::Signed,
TimeMillis | TimeMicros | TimestampMillis | TimestampMicros => SortOrder::Signed,
Interval => SortOrder::Undefined,
}
}
fn get_physical_sort_order(physical_type: &PhysicalType) -> SortOrder {
use PhysicalType::*;
match physical_type {
Boolean => SortOrder::Unsigned,
Int32 | Int64 => SortOrder::Signed,
Int96 => SortOrder::Undefined,
Float | Double => SortOrder::Signed,
ByteArray | FixedLenByteArray(_) => SortOrder::Unsigned,
}
}