use crate::config::models::{ColumnConfig, EnvelopeField};
use crate::file_format::models::ParquetKind;
pub(crate) fn parquet_kind(column: &ColumnConfig) -> ParquetKind {
match column.field {
EnvelopeField::Partition => ParquetKind::Int32,
EnvelopeField::Offset | EnvelopeField::Timestamp | EnvelopeField::TimestampType => {
ParquetKind::Int64
}
EnvelopeField::ExportedAt => ParquetKind::Timestamp,
EnvelopeField::Date => ParquetKind::Date,
EnvelopeField::Topic
| EnvelopeField::Key
| EnvelopeField::Value
| EnvelopeField::Headers
| EnvelopeField::Null => ParquetKind::Text,
}
}
pub(crate) fn is_semi_structured(sql_type: &str) -> bool {
let upper = sql_type.trim().to_ascii_uppercase();
upper.starts_with("VARIANT") || upper.starts_with("OBJECT") || upper.starts_with("ARRAY")
}
pub(crate) fn timestamp_family(sql_type: &str) -> Option<&'static str> {
let upper = sql_type.trim().to_ascii_uppercase();
match upper.split(['(', ' ']).next().unwrap_or_default() {
"TIMESTAMP_TZ" => Some("TIMESTAMP_TZ"),
"TIMESTAMP_LTZ" => Some("TIMESTAMP_LTZ"),
"TIMESTAMP_NTZ" | "TIMESTAMP" | "DATETIME" => Some("TIMESTAMP_NTZ"),
_ => None,
}
}