Skip to main content

unitycatalog_common/models/
object.rs

1use crate::Error;
2use crate::models::{
3    ObjectLabel, Resource, ResourceExt, ResourceIdent, ResourceName, ResourceRef, Table,
4};
5
6use super::tables::v1::TableSummary;
7
8/// Project-specific alias for `resource_store::Object` with our generated `ObjectLabel`.
9pub type Object = olai_store::Object<ObjectLabel>;
10
11impl ResourceExt for Object {
12    fn resource_name(&self) -> ResourceName {
13        self.name.clone()
14    }
15
16    fn resource_ref(&self) -> ResourceRef {
17        ResourceRef::Uuid(self.id)
18    }
19
20    fn resource_ident(&self) -> ResourceIdent {
21        self.label.to_ident(self.id)
22    }
23}
24
25impl ResourceExt for Resource {
26    fn resource_name(&self) -> ResourceName {
27        match self {
28            Resource::Agent(obj) => obj.resource_name(),
29            Resource::AgentSkill(obj) => obj.resource_name(),
30            Resource::Share(obj) => obj.resource_name(),
31            Resource::Credential(obj) => obj.resource_name(),
32            Resource::Catalog(obj) => obj.resource_name(),
33            Resource::Schema(obj) => obj.resource_name(),
34            Resource::Table(obj) => obj.resource_name(),
35            Resource::ExternalLocation(obj) => obj.resource_name(),
36            Resource::Recipient(obj) => obj.resource_name(),
37            Resource::Provider(obj) => obj.resource_name(),
38            Resource::Column(obj) => obj.resource_name(),
39            Resource::Volume(obj) => obj.resource_name(),
40            Resource::Function(obj) => obj.resource_name(),
41            Resource::TagPolicy(obj) => obj.resource_name(),
42            Resource::StagingTable(obj) => obj.resource_name(),
43            Resource::PolicyInfo(obj) => obj.resource_name(),
44            Resource::RegisteredModel(obj) => obj.resource_name(),
45            Resource::ModelVersion(obj) => obj.resource_name(),
46        }
47    }
48
49    fn resource_ref(&self) -> ResourceRef {
50        match self {
51            Resource::Agent(obj) => obj.resource_ref(),
52            Resource::AgentSkill(obj) => obj.resource_ref(),
53            Resource::Share(obj) => obj.resource_ref(),
54            Resource::Credential(obj) => obj.resource_ref(),
55            Resource::Catalog(obj) => obj.resource_ref(),
56            Resource::Schema(obj) => obj.resource_ref(),
57            Resource::Table(obj) => obj.resource_ref(),
58            Resource::ExternalLocation(obj) => obj.resource_ref(),
59            Resource::Recipient(obj) => obj.resource_ref(),
60            Resource::Provider(obj) => obj.resource_ref(),
61            Resource::Column(obj) => obj.resource_ref(),
62            Resource::Volume(obj) => obj.resource_ref(),
63            Resource::Function(obj) => obj.resource_ref(),
64            Resource::TagPolicy(obj) => obj.resource_ref(),
65            Resource::StagingTable(obj) => obj.resource_ref(),
66            Resource::PolicyInfo(obj) => obj.resource_ref(),
67            Resource::RegisteredModel(obj) => obj.resource_ref(),
68            Resource::ModelVersion(obj) => obj.resource_ref(),
69        }
70    }
71
72    fn resource_ident(&self) -> ResourceIdent {
73        match self {
74            Resource::Agent(obj) => obj.resource_ident(),
75            Resource::AgentSkill(obj) => obj.resource_ident(),
76            Resource::Share(obj) => obj.resource_ident(),
77            Resource::Credential(obj) => obj.resource_ident(),
78            Resource::Catalog(obj) => obj.resource_ident(),
79            Resource::Schema(obj) => obj.resource_ident(),
80            Resource::Table(obj) => obj.resource_ident(),
81            Resource::ExternalLocation(obj) => obj.resource_ident(),
82            Resource::Recipient(obj) => obj.resource_ident(),
83            Resource::Provider(obj) => obj.resource_ident(),
84            Resource::Column(obj) => obj.resource_ident(),
85            Resource::Volume(obj) => obj.resource_ident(),
86            Resource::Function(obj) => obj.resource_ident(),
87            Resource::TagPolicy(obj) => obj.resource_ident(),
88            Resource::StagingTable(obj) => obj.resource_ident(),
89            Resource::PolicyInfo(obj) => obj.resource_ident(),
90            Resource::RegisteredModel(obj) => obj.resource_ident(),
91            Resource::ModelVersion(obj) => obj.resource_ident(),
92        }
93    }
94}
95
96impl TryFrom<Resource> for Object {
97    type Error = Error;
98
99    fn try_from(resource: Resource) -> Result<Self, Self::Error> {
100        match resource {
101            Resource::Agent(obj) => obj.try_into(),
102            Resource::AgentSkill(obj) => obj.try_into(),
103            Resource::Share(obj) => obj.try_into(),
104            Resource::Credential(obj) => obj.try_into(),
105            Resource::Catalog(obj) => obj.try_into(),
106            Resource::Schema(obj) => obj.try_into(),
107            Resource::Table(obj) => obj.try_into(),
108            Resource::ExternalLocation(obj) => obj.try_into(),
109            Resource::Recipient(obj) => obj.try_into(),
110            Resource::Provider(obj) => obj.try_into(),
111            Resource::Column(obj) => obj.try_into(),
112            Resource::Volume(obj) => obj.try_into(),
113            Resource::Function(obj) => obj.try_into(),
114            Resource::TagPolicy(obj) => obj.try_into(),
115            Resource::StagingTable(obj) => obj.try_into(),
116            Resource::PolicyInfo(obj) => obj.try_into(),
117            Resource::RegisteredModel(obj) => obj.try_into(),
118            Resource::ModelVersion(obj) => obj.try_into(),
119        }
120    }
121}
122
123impl TryFrom<Object> for Resource {
124    type Error = Error;
125
126    fn try_from(obj: Object) -> Result<Self, Self::Error> {
127        match obj.label {
128            ObjectLabel::Agent => Ok(Resource::Agent(obj.try_into()?)),
129            ObjectLabel::AgentSkill => Ok(Resource::AgentSkill(obj.try_into()?)),
130            ObjectLabel::Share => Ok(Resource::Share(obj.try_into()?)),
131            ObjectLabel::Credential => Ok(Resource::Credential(obj.try_into()?)),
132            ObjectLabel::Catalog => Ok(Resource::Catalog(obj.try_into()?)),
133            ObjectLabel::Schema => Ok(Resource::Schema(obj.try_into()?)),
134            ObjectLabel::Table => Ok(Resource::Table(obj.try_into()?)),
135            ObjectLabel::ExternalLocation => Ok(Resource::ExternalLocation(obj.try_into()?)),
136            ObjectLabel::Recipient => Ok(Resource::Recipient(obj.try_into()?)),
137            ObjectLabel::Provider => Ok(Resource::Provider(obj.try_into()?)),
138            ObjectLabel::Column => Ok(Resource::Column(obj.try_into()?)),
139            ObjectLabel::Volume => Ok(Resource::Volume(obj.try_into()?)),
140            ObjectLabel::Function => Ok(Resource::Function(obj.try_into()?)),
141            ObjectLabel::TagPolicy => Ok(Resource::TagPolicy(obj.try_into()?)),
142            ObjectLabel::StagingTable => Ok(Resource::StagingTable(obj.try_into()?)),
143            ObjectLabel::PolicyInfo => Ok(Resource::PolicyInfo(obj.try_into()?)),
144            ObjectLabel::RegisteredModel => Ok(Resource::RegisteredModel(obj.try_into()?)),
145            ObjectLabel::ModelVersion => Ok(Resource::ModelVersion(obj.try_into()?)),
146        }
147    }
148}
149
150impl From<Table> for TableSummary {
151    fn from(table: Table) -> Self {
152        TableSummary {
153            table_type: table.table_type,
154            full_name: table.full_name,
155            ..Default::default()
156        }
157    }
158}