use std::collections::HashMap;
use crate::compiler::fact_table::{FilterColumn, SqlType};
#[must_use]
pub fn pg_type_to_cast(data_type: &str) -> &'static str {
match data_type.to_lowercase().as_str() {
"uuid" => "uuid",
"integer" | "int" | "int4" => "int4",
"bigint" | "int8" => "int8",
"smallint" | "int2" => "int2",
"boolean" | "bool" => "bool",
"numeric" | "decimal" => "numeric",
"double precision" | "float8" => "float8",
"real" | "float4" => "float4",
"timestamp without time zone" | "timestamp" => "timestamp",
"timestamp with time zone" | "timestamptz" => "timestamptz",
"date" => "date",
"time without time zone" | "time" => "time",
_ => "",
}
}
#[must_use]
pub const fn sql_type_to_pg_cast(sql_type: &SqlType) -> &'static str {
match sql_type {
SqlType::Uuid => "uuid",
SqlType::Int => "int4",
SqlType::BigInt => "int8",
SqlType::Decimal => "numeric",
SqlType::Float => "float8",
SqlType::Boolean => "bool",
SqlType::Timestamp => "timestamptz",
SqlType::Date => "date",
SqlType::Text | SqlType::Jsonb | SqlType::Json | SqlType::Other(_) => "",
}
}
#[must_use]
pub fn filter_columns_to_native_map(filters: &[FilterColumn]) -> HashMap<String, String> {
filters
.iter()
.map(|f| (f.name.clone(), sql_type_to_pg_cast(&f.sql_type).to_string()))
.collect()
}