Path: blob/main/crates/polars-io/src/catalog/unity/models.rs
6939 views
use polars_core::prelude::PlHashMap;1use polars_utils::pl_str::PlSmallStr;23#[derive(Debug, serde::Deserialize)]4pub struct CatalogInfo {5pub name: String,67pub comment: Option<String>,89#[serde(default)]10pub storage_location: Option<String>,1112#[serde(default, deserialize_with = "null_to_default")]13pub properties: PlHashMap<PlSmallStr, String>,1415#[serde(default, deserialize_with = "null_to_default")]16pub options: PlHashMap<PlSmallStr, String>,1718#[serde(with = "chrono::serde::ts_milliseconds_option")]19pub created_at: Option<chrono::DateTime<chrono::Utc>>,2021pub created_by: Option<String>,2223#[serde(with = "chrono::serde::ts_milliseconds_option")]24pub updated_at: Option<chrono::DateTime<chrono::Utc>>,2526pub updated_by: Option<String>,27}2829#[derive(Debug, serde::Deserialize)]30pub struct NamespaceInfo {31pub name: String,32pub comment: Option<String>,3334#[serde(default, deserialize_with = "null_to_default")]35pub properties: PlHashMap<PlSmallStr, String>,3637#[serde(default)]38pub storage_location: Option<String>,3940#[serde(with = "chrono::serde::ts_milliseconds_option")]41pub created_at: Option<chrono::DateTime<chrono::Utc>>,4243pub created_by: Option<String>,4445#[serde(with = "chrono::serde::ts_milliseconds_option")]46pub updated_at: Option<chrono::DateTime<chrono::Utc>>,4748pub updated_by: Option<String>,49}5051#[derive(Debug, serde::Deserialize)]52pub struct TableInfo {53pub name: String,54pub table_id: String,55pub table_type: TableType,5657#[serde(default)]58pub comment: Option<String>,5960#[serde(default)]61pub storage_location: Option<String>,6263#[serde(default)]64pub data_source_format: Option<DataSourceFormat>,6566#[serde(default)]67pub columns: Option<Vec<ColumnInfo>>,6869#[serde(default, deserialize_with = "null_to_default")]70pub properties: PlHashMap<PlSmallStr, String>,7172#[serde(with = "chrono::serde::ts_milliseconds_option")]73pub created_at: Option<chrono::DateTime<chrono::Utc>>,7475pub created_by: Option<String>,7677#[serde(with = "chrono::serde::ts_milliseconds_option")]78pub updated_at: Option<chrono::DateTime<chrono::Utc>>,7980pub updated_by: Option<String>,81}8283#[derive(84Debug, strum_macros::Display, strum_macros::EnumString, serde::Serialize, serde::Deserialize,85)]86#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]87#[serde(rename_all = "SCREAMING_SNAKE_CASE")]88pub enum TableType {89Managed,90External,91View,92MaterializedView,93StreamingTable,94ManagedShallowClone,95Foreign,96ExternalShallowClone,97}9899#[derive(100Debug, strum_macros::Display, strum_macros::EnumString, serde::Serialize, serde::Deserialize,101)]102#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]103#[serde(rename_all = "SCREAMING_SNAKE_CASE")]104pub enum DataSourceFormat {105Delta,106Csv,107Json,108Avro,109Parquet,110Orc,111Text,112113// Databricks-specific114UnityCatalog,115Deltasharing,116DatabricksFormat,117MysqlFormat,118PostgresqlFormat,119RedshiftFormat,120SnowflakeFormat,121SqldwFormat,122SqlserverFormat,123SalesforceFormat,124BigqueryFormat,125NetsuiteFormat,126WorkdayRaasFormat,127HiveSerde,128HiveCustom,129VectorIndexFormat,130}131132#[derive(Debug, serde::Serialize, serde::Deserialize)]133pub struct ColumnInfo {134pub name: PlSmallStr,135pub type_name: PlSmallStr,136pub type_text: PlSmallStr,137pub type_json: String,138pub position: Option<u32>,139pub comment: Option<String>,140pub partition_index: Option<u32>,141}142143/// Note: This struct contains all the field names for a few different possible type / field presence144/// combinations. We use serde(default) and skip_serializing_if to get the desired serialization145/// output.146///147/// E.g.:148///149/// ```text150/// {151/// "name": "List",152/// "type": {"type": "array", "elementType": "long", "containsNull": True},153/// "nullable": True,154/// "metadata": {},155/// }156/// {157/// "name": "Struct",158/// "type": {159/// "type": "struct",160/// "fields": [{"name": "x", "type": "long", "nullable": True, "metadata": {}}],161/// },162/// "nullable": True,163/// "metadata": {},164/// }165/// {166/// "name": "ListStruct",167/// "type": {168/// "type": "array",169/// "elementType": {170/// "type": "struct",171/// "fields": [{"name": "x", "type": "long", "nullable": True, "metadata": {}}],172/// },173/// "containsNull": True,174/// },175/// "nullable": True,176/// "metadata": {},177/// }178/// {179/// "name": "Map",180/// "type": {181/// "type": "map",182/// "keyType": "string",183/// "valueType": "string",184/// "valueContainsNull": True,185/// },186/// "nullable": True,187/// "metadata": {},188/// }189/// ```190#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]191pub struct ColumnTypeJson {192#[serde(default, skip_serializing_if = "Option::is_none")]193pub name: Option<PlSmallStr>,194195#[serde(rename = "type")]196pub type_: ColumnTypeJsonType,197198#[serde(default, skip_serializing_if = "Option::is_none")]199pub nullable: Option<bool>,200201#[serde(default, skip_serializing_if = "Option::is_none")]202pub metadata: Option<PlHashMap<String, String>>,203204// Used for List types205#[serde(206default,207rename = "elementType",208skip_serializing_if = "Option::is_none"209)]210pub element_type: Option<ColumnTypeJsonType>,211212#[serde(213default,214rename = "containsNull",215skip_serializing_if = "Option::is_none"216)]217pub contains_null: Option<bool>,218219// Used for Struct types220#[serde(default, skip_serializing_if = "Option::is_none")]221pub fields: Option<Vec<ColumnTypeJson>>,222223// Used for Map types224#[serde(default, rename = "keyType", skip_serializing_if = "Option::is_none")]225pub key_type: Option<ColumnTypeJsonType>,226227#[serde(default, rename = "valueType", skip_serializing_if = "Option::is_none")]228pub value_type: Option<ColumnTypeJsonType>,229230#[serde(231default,232rename = "valueContainsNull",233skip_serializing_if = "Option::is_none"234)]235pub value_contains_null: Option<bool>,236}237238#[derive(Debug, serde::Serialize, serde::Deserialize)]239#[serde(untagged)]240pub enum ColumnTypeJsonType {241/// * `{"type": "name", ..}``242TypeName(PlSmallStr),243/// * `{"type": {"type": "name", ..}}`244TypeJson(Box<ColumnTypeJson>),245}246247impl Default for ColumnTypeJsonType {248fn default() -> Self {249Self::TypeName(PlSmallStr::EMPTY)250}251}252253impl ColumnTypeJsonType {254pub const fn from_static_type_name(type_name: &'static str) -> Self {255Self::TypeName(PlSmallStr::from_static(type_name))256}257}258259#[derive(Debug, serde::Deserialize)]260pub struct TableCredentials {261pub aws_temp_credentials: Option<TableCredentialsAws>,262pub azure_user_delegation_sas: Option<TableCredentialsAzure>,263pub gcp_oauth_token: Option<TableCredentialsGcp>,264pub expiration_time: i64,265}266267impl TableCredentials {268pub fn into_enum(self) -> Option<TableCredentialsVariants> {269if let v @ Some(_) = self.aws_temp_credentials {270v.map(TableCredentialsVariants::Aws)271} else if let v @ Some(_) = self.azure_user_delegation_sas {272v.map(TableCredentialsVariants::Azure)273} else if let v @ Some(_) = self.gcp_oauth_token {274v.map(TableCredentialsVariants::Gcp)275} else {276None277}278}279}280281pub enum TableCredentialsVariants {282Aws(TableCredentialsAws),283Azure(TableCredentialsAzure),284Gcp(TableCredentialsGcp),285}286287#[derive(Debug, serde::Deserialize)]288pub struct TableCredentialsAws {289pub access_key_id: String,290pub secret_access_key: String,291pub session_token: Option<String>,292293#[serde(default)]294pub access_point: Option<String>,295}296297#[derive(Debug, serde::Deserialize)]298pub struct TableCredentialsAzure {299pub sas_token: String,300}301302#[derive(Debug, serde::Deserialize)]303pub struct TableCredentialsGcp {304pub oauth_token: String,305}306307fn null_to_default<'de, T, D>(d: D) -> Result<T, D::Error>308where309T: Default + serde::de::Deserialize<'de>,310D: serde::de::Deserializer<'de>,311{312use serde::Deserialize;313let opt_val = Option::<T>::deserialize(d)?;314Ok(opt_val.unwrap_or_default())315}316317318