unitycatalog_delta_api/column.rs
1//! Portable UC column model used by the managed-table contract.
2//!
3//! The Delta business logic derives UC columns from the Delta wire schema
4//! (`delta_columns_to_uc`) and reconstructs the wire schema from stored columns
5//! (`uc_columns_to_delta`). To keep this crate self-contained — free of
6//! `unitycatalog-common` and its generated proto types — it owns a small
7//! [`Column`] / [`ColumnTypeName`] pair mirroring the fields the contract needs.
8//!
9//! [`ColumnTypeName`]'s discriminants are identical to the generated
10//! `unitycatalog_common::models::tables::v1::ColumnTypeName`, so `as i32`
11//! round-trips across the boundary and each server's adapter can map between the
12//! two by value. The adapter is where the mapping to the server's own column type
13//! lives; the crate never sees it.
14
15/// A Unity Catalog column, the portable shape exchanged with the backend port.
16///
17/// This is the subset of the UC `Column` message the managed-table contract
18/// produces and consumes. The backend adapter maps between this and its own
19/// column representation.
20#[derive(Clone, Debug, Default, PartialEq, Eq)]
21pub struct Column {
22 /// Name of the column.
23 pub name: String,
24 /// Full data type specification as SQL / catalog-string text.
25 pub type_text: String,
26 /// Full data type specification, JSON-serialized (the original Delta type).
27 pub type_json: String,
28 /// Ordinal position of the column (starting at 0).
29 pub position: Option<i32>,
30 /// Data type name.
31 pub type_name: ColumnTypeName,
32 /// User-provided free-form description.
33 pub comment: Option<String>,
34 /// Whether the field may be null.
35 pub nullable: Option<bool>,
36 /// Partition index for the column, if it is a partition column.
37 pub partition_index: Option<i32>,
38}
39
40/// UC column data-type name.
41///
42/// Discriminants match the generated
43/// `unitycatalog_common::models::tables::v1::ColumnTypeName` so `as i32` values
44/// are interchangeable across the port boundary.
45#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
46#[repr(i32)]
47pub enum ColumnTypeName {
48 #[default]
49 Unspecified = 0,
50 Boolean = 1,
51 Byte = 2,
52 Short = 3,
53 Int = 4,
54 Long = 5,
55 Float = 6,
56 Double = 7,
57 Date = 8,
58 Timestamp = 9,
59 String = 10,
60 Binary = 11,
61 Decimal = 12,
62 Interval = 13,
63 Array = 14,
64 Struct = 15,
65 Map = 16,
66 Char = 17,
67 Null = 18,
68 UserDefinedType = 19,
69 TimestampNtz = 20,
70 Variant = 21,
71 TableType = 22,
72}
73
74impl From<i32> for ColumnTypeName {
75 /// The inverse of `as i32`. Unknown discriminants map to
76 /// [`Unspecified`](Self::Unspecified), matching prost's open-enum behavior.
77 fn from(v: i32) -> Self {
78 match v {
79 1 => Self::Boolean,
80 2 => Self::Byte,
81 3 => Self::Short,
82 4 => Self::Int,
83 5 => Self::Long,
84 6 => Self::Float,
85 7 => Self::Double,
86 8 => Self::Date,
87 9 => Self::Timestamp,
88 10 => Self::String,
89 11 => Self::Binary,
90 12 => Self::Decimal,
91 13 => Self::Interval,
92 14 => Self::Array,
93 15 => Self::Struct,
94 16 => Self::Map,
95 17 => Self::Char,
96 18 => Self::Null,
97 19 => Self::UserDefinedType,
98 20 => Self::TimestampNtz,
99 21 => Self::Variant,
100 22 => Self::TableType,
101 _ => Self::Unspecified,
102 }
103 }
104}