unitycatalog_common/models/
object.rs1use crate::Error;
2use crate::models::{
3 ObjectLabel, Resource, ResourceExt, ResourceIdent, ResourceName, ResourceRef, Table,
4};
5
6use super::tables::v1::TableSummary;
7
8pub 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 }
45 }
46
47 fn resource_ref(&self) -> ResourceRef {
48 match self {
49 Resource::Agent(obj) => obj.resource_ref(),
50 Resource::AgentSkill(obj) => obj.resource_ref(),
51 Resource::Share(obj) => obj.resource_ref(),
52 Resource::Credential(obj) => obj.resource_ref(),
53 Resource::Catalog(obj) => obj.resource_ref(),
54 Resource::Schema(obj) => obj.resource_ref(),
55 Resource::Table(obj) => obj.resource_ref(),
56 Resource::ExternalLocation(obj) => obj.resource_ref(),
57 Resource::Recipient(obj) => obj.resource_ref(),
58 Resource::Provider(obj) => obj.resource_ref(),
59 Resource::Column(obj) => obj.resource_ref(),
60 Resource::Volume(obj) => obj.resource_ref(),
61 Resource::Function(obj) => obj.resource_ref(),
62 Resource::TagPolicy(obj) => obj.resource_ref(),
63 Resource::StagingTable(obj) => obj.resource_ref(),
64 Resource::PolicyInfo(obj) => obj.resource_ref(),
65 }
66 }
67
68 fn resource_ident(&self) -> ResourceIdent {
69 match self {
70 Resource::Agent(obj) => obj.resource_ident(),
71 Resource::AgentSkill(obj) => obj.resource_ident(),
72 Resource::Share(obj) => obj.resource_ident(),
73 Resource::Credential(obj) => obj.resource_ident(),
74 Resource::Catalog(obj) => obj.resource_ident(),
75 Resource::Schema(obj) => obj.resource_ident(),
76 Resource::Table(obj) => obj.resource_ident(),
77 Resource::ExternalLocation(obj) => obj.resource_ident(),
78 Resource::Recipient(obj) => obj.resource_ident(),
79 Resource::Provider(obj) => obj.resource_ident(),
80 Resource::Column(obj) => obj.resource_ident(),
81 Resource::Volume(obj) => obj.resource_ident(),
82 Resource::Function(obj) => obj.resource_ident(),
83 Resource::TagPolicy(obj) => obj.resource_ident(),
84 Resource::StagingTable(obj) => obj.resource_ident(),
85 Resource::PolicyInfo(obj) => obj.resource_ident(),
86 }
87 }
88}
89
90impl TryFrom<Resource> for Object {
91 type Error = Error;
92
93 fn try_from(resource: Resource) -> Result<Self, Self::Error> {
94 match resource {
95 Resource::Agent(obj) => obj.try_into(),
96 Resource::AgentSkill(obj) => obj.try_into(),
97 Resource::Share(obj) => obj.try_into(),
98 Resource::Credential(obj) => obj.try_into(),
99 Resource::Catalog(obj) => obj.try_into(),
100 Resource::Schema(obj) => obj.try_into(),
101 Resource::Table(obj) => obj.try_into(),
102 Resource::ExternalLocation(obj) => obj.try_into(),
103 Resource::Recipient(obj) => obj.try_into(),
104 Resource::Provider(obj) => obj.try_into(),
105 Resource::Column(obj) => obj.try_into(),
106 Resource::Volume(obj) => obj.try_into(),
107 Resource::Function(obj) => obj.try_into(),
108 Resource::TagPolicy(obj) => obj.try_into(),
109 Resource::StagingTable(obj) => obj.try_into(),
110 Resource::PolicyInfo(obj) => obj.try_into(),
111 }
112 }
113}
114
115impl TryFrom<Object> for Resource {
116 type Error = Error;
117
118 fn try_from(obj: Object) -> Result<Self, Self::Error> {
119 match obj.label {
120 ObjectLabel::Agent => Ok(Resource::Agent(obj.try_into()?)),
121 ObjectLabel::AgentSkill => Ok(Resource::AgentSkill(obj.try_into()?)),
122 ObjectLabel::Share => Ok(Resource::Share(obj.try_into()?)),
123 ObjectLabel::Credential => Ok(Resource::Credential(obj.try_into()?)),
124 ObjectLabel::Catalog => Ok(Resource::Catalog(obj.try_into()?)),
125 ObjectLabel::Schema => Ok(Resource::Schema(obj.try_into()?)),
126 ObjectLabel::Table => Ok(Resource::Table(obj.try_into()?)),
127 ObjectLabel::ExternalLocation => Ok(Resource::ExternalLocation(obj.try_into()?)),
128 ObjectLabel::Recipient => Ok(Resource::Recipient(obj.try_into()?)),
129 ObjectLabel::Provider => Ok(Resource::Provider(obj.try_into()?)),
130 ObjectLabel::Column => Ok(Resource::Column(obj.try_into()?)),
131 ObjectLabel::Volume => Ok(Resource::Volume(obj.try_into()?)),
132 ObjectLabel::Function => Ok(Resource::Function(obj.try_into()?)),
133 ObjectLabel::TagPolicy => Ok(Resource::TagPolicy(obj.try_into()?)),
134 ObjectLabel::StagingTable => Ok(Resource::StagingTable(obj.try_into()?)),
135 ObjectLabel::PolicyInfo => Ok(Resource::PolicyInfo(obj.try_into()?)),
136 }
137 }
138}
139
140impl From<Table> for TableSummary {
141 fn from(table: Table) -> Self {
142 TableSummary {
143 table_type: table.table_type,
144 full_name: table.full_name,
145 }
146 }
147}