databend_common_ast/ast/statements/
principal.rs1use std::fmt::Display;
16use std::fmt::Formatter;
17
18use derive_visitor::Drive;
19use derive_visitor::DriveMut;
20
21use crate::ast::quote::QuotedString;
22use crate::ast::Identifier;
23
24#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
25pub struct ShareNameIdent {
26 pub tenant: Identifier,
27 pub share: Identifier,
28}
29
30impl Display for ShareNameIdent {
31 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
32 write!(f, "{}.{}", self.tenant, self.share)
33 }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
37pub struct UserIdentity {
38 pub username: String,
39 pub hostname: String,
40}
41
42impl Display for UserIdentity {
43 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
44 write!(
45 f,
46 "{}@{}",
47 QuotedString(&self.username, '\''),
48 QuotedString(&self.hostname, '\''),
49 )
50 }
51}
52
53#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
54pub enum PrincipalIdentity {
55 User(UserIdentity),
56 Role(String),
57}
58
59impl Display for PrincipalIdentity {
60 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
61 match self {
62 PrincipalIdentity::User(u) => write!(f, " USER {u}"),
63 PrincipalIdentity::Role(r) => write!(f, " ROLE '{r}'"),
64 }
65 }
66}
67
68#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
69pub enum CreateOption {
70 Create,
71 CreateIfNotExists,
72 CreateOrReplace,
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
76pub enum AuthType {
77 NoPassword,
78 Sha256Password,
79 DoubleSha1Password,
80 JWT,
81}
82
83impl Display for AuthType {
84 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
85 write!(f, "{}", match self {
86 AuthType::NoPassword => "no_password",
87 AuthType::Sha256Password => "sha256_password",
88 AuthType::DoubleSha1Password => "double_sha1_password",
89 AuthType::JWT => "jwt",
90 })
91 }
92}
93
94#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
95pub enum CatalogType {
96 Default,
97 Hive,
98 Iceberg,
99}
100
101impl Display for CatalogType {
102 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
103 match self {
104 CatalogType::Default => write!(f, "DEFAULT"),
105 CatalogType::Hive => write!(f, "HIVE"),
106 CatalogType::Iceberg => write!(f, "ICEBERG"),
107 }
108 }
109}
110
111#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
112pub enum UserPrivilegeType {
113 Usage,
115 Select,
117 Insert,
119 Update,
121 Delete,
123 Create,
125 Drop,
127 Alter,
129 Super,
131 CreateUser,
133 CreateRole,
135 Grant,
137 CreateStage,
139 DropRole,
141 DropUser,
143 CreateDataMask,
145 Ownership,
147 Read,
149 Write,
151 CreateDatabase,
153 CreateWarehouse,
155 AccessConnection,
157 CreateConnection,
159 AccessSequence,
161 CreateSequence,
163 Set,
165}
166
167impl Display for UserPrivilegeType {
168 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
169 write!(f, "{}", match self {
170 UserPrivilegeType::Usage => "USAGE",
171 UserPrivilegeType::Create => "CREATE",
172 UserPrivilegeType::Update => "UPDATE",
173 UserPrivilegeType::Select => "SELECT",
174 UserPrivilegeType::Insert => "INSERT",
175 UserPrivilegeType::Delete => "DELETE",
176 UserPrivilegeType::Drop => "DROP",
177 UserPrivilegeType::Alter => "ALTER",
178 UserPrivilegeType::Super => "SUPER",
179 UserPrivilegeType::CreateUser => "CREATE USER",
180 UserPrivilegeType::DropUser => "DROP USER",
181 UserPrivilegeType::CreateRole => "CREATE ROLE",
182 UserPrivilegeType::DropRole => "DROP ROLE",
183 UserPrivilegeType::CreateStage => "CREATE STAGE",
184 UserPrivilegeType::Grant => "GRANT",
185 UserPrivilegeType::Set => "SET",
186 UserPrivilegeType::CreateDataMask => "CREATE DATAMASK",
187 UserPrivilegeType::Ownership => "OWNERSHIP",
188 UserPrivilegeType::Read => "Read",
189 UserPrivilegeType::Write => "Write",
190 UserPrivilegeType::CreateDatabase => "CREATE DATABASE",
191 UserPrivilegeType::CreateWarehouse => "CREATE WAREHOUSE",
192 UserPrivilegeType::CreateConnection => "CREATE CONNECTION",
193 UserPrivilegeType::AccessConnection => "ACCESS CONNECTION",
194 UserPrivilegeType::CreateSequence => "CREATE SEQUENCE",
195 UserPrivilegeType::AccessSequence => "ACCESS SEQUENCE",
196 })
197 }
198}
199
200#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
201pub enum ShareGrantObjectPrivilege {
202 Usage,
204 ReferenceUsage,
206 Select,
208}
209
210impl Display for ShareGrantObjectPrivilege {
211 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
212 match *self {
213 ShareGrantObjectPrivilege::Usage => write!(f, "USAGE"),
214 ShareGrantObjectPrivilege::ReferenceUsage => write!(f, "REFERENCE_USAGE"),
215 ShareGrantObjectPrivilege::Select => write!(f, "SELECT"),
216 }
217 }
218}