1use std::collections::BTreeMap;
16use std::fmt::Display;
17use std::fmt::Formatter;
18
19use derive_visitor::Drive;
20use derive_visitor::DriveMut;
21
22use crate::ast::Identifier;
23
24#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
25pub struct ShowOnlineNodesStmt {}
26
27impl Display for ShowOnlineNodesStmt {
28 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29 write!(f, "SHOW ONLINE NODES")
30 }
31}
32
33#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
34pub struct ShowWarehousesStmt {}
35
36impl Display for ShowWarehousesStmt {
37 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
38 write!(f, "SHOW WAREHOUSES")
39 }
40}
41
42#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
43pub struct UseWarehouseStmt {
44 pub warehouse: Identifier,
45}
46
47impl Display for UseWarehouseStmt {
48 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49 write!(f, "USE WAREHOUSE {}", self.warehouse)
50 }
51}
52
53#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
54pub struct CreateWarehouseStmt {
55 pub warehouse: Identifier,
56 pub node_list: Vec<(Option<String>, u64)>,
57 pub options: BTreeMap<String, String>,
58}
59
60impl Display for CreateWarehouseStmt {
61 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
62 write!(f, "CREATE WAREHOUSE {}", self.warehouse)?;
63
64 if !self.node_list.is_empty() {
65 write!(f, "(")?;
66
67 for (idx, (node_group, nodes)) in self.node_list.iter().enumerate() {
68 if idx != 0 {
69 write!(f, ",")?;
70 }
71
72 write!(f, " ASSIGN {} NODES", nodes)?;
73
74 if let Some(node_group) = node_group {
75 write!(f, " FROM '{}'", node_group)?;
76 }
77 }
78
79 write!(f, ")")?;
80 }
81
82 if !self.options.is_empty() {
83 write!(f, " WITH ")?;
84
85 for (idx, (key, value)) in self.options.iter().enumerate() {
86 if idx != 0 {
87 write!(f, ",")?;
88 }
89
90 write!(f, " {} = '{}'", key, value)?;
91 }
92 }
93
94 Ok(())
95 }
96}
97
98#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
99pub struct DropWarehouseStmt {
100 pub warehouse: Identifier,
101}
102
103impl Display for DropWarehouseStmt {
104 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
105 write!(f, "DROP WAREHOUSE {}", self.warehouse)
106 }
107}
108
109#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
110pub struct SuspendWarehouseStmt {
111 pub warehouse: Identifier,
112}
113
114impl Display for SuspendWarehouseStmt {
115 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
116 write!(f, "SUSPEND WAREHOUSE {}", self.warehouse)
117 }
118}
119
120#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
121pub struct ResumeWarehouseStmt {
122 pub warehouse: Identifier,
123}
124
125impl Display for ResumeWarehouseStmt {
126 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
127 write!(f, "RESUME WAREHOUSE {}", self.warehouse)
128 }
129}
130
131#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
132pub struct RenameWarehouseStmt {
133 pub warehouse: Identifier,
134 pub new_warehouse: Identifier,
135}
136
137impl Display for RenameWarehouseStmt {
138 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
139 write!(
140 f,
141 "RENAME WAREHOUSE {} TO {}",
142 self.warehouse, self.new_warehouse
143 )
144 }
145}
146
147#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
148pub struct InspectWarehouseStmt {
149 pub warehouse: Identifier,
150}
151
152impl Display for InspectWarehouseStmt {
153 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
154 write!(f, "INSPECT WAREHOUSE {}", self.warehouse)
155 }
156}
157
158#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
159pub struct AddWarehouseClusterStmt {
160 pub warehouse: Identifier,
161 pub cluster: Identifier,
162 pub node_list: Vec<(Option<String>, u64)>,
163 pub options: BTreeMap<String, String>,
164}
165
166impl Display for AddWarehouseClusterStmt {
167 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
168 write!(
169 f,
170 "ALTER WAREHOUSE {} ADD CLUSTER {}",
171 self.warehouse, self.cluster
172 )?;
173
174 if !self.node_list.is_empty() {
175 write!(f, "(")?;
176
177 for (idx, (node_group, nodes)) in self.node_list.iter().enumerate() {
178 if idx != 0 {
179 write!(f, ",")?;
180 }
181
182 write!(f, " ASSIGN {} NODES", nodes)?;
183
184 if let Some(node_group) = node_group {
185 write!(f, " FROM '{}'", node_group)?;
186 }
187 }
188
189 write!(f, ")")?;
190 }
191
192 if !self.options.is_empty() {
193 write!(f, " WITH ")?;
194
195 for (idx, (key, value)) in self.options.iter().enumerate() {
196 if idx != 0 {
197 write!(f, ",")?;
198 }
199
200 write!(f, " {} = '{}'", key, value)?;
201 }
202 }
203
204 Ok(())
205 }
206}
207
208#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
209pub struct DropWarehouseClusterStmt {
210 pub cluster: Identifier,
211 pub warehouse: Identifier,
212}
213
214impl Display for DropWarehouseClusterStmt {
215 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
216 write!(
217 f,
218 "ALTER WAREHOUSE {} DROP CLUSTER {}",
219 self.warehouse, self.cluster
220 )
221 }
222}
223
224#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
225pub struct RenameWarehouseClusterStmt {
226 pub warehouse: Identifier,
227 pub cluster: Identifier,
228 pub new_cluster: Identifier,
229}
230
231impl Display for RenameWarehouseClusterStmt {
232 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
233 write!(
234 f,
235 "ALTER WAREHOUSE {} RENAME CLUSTER {} TO {}",
236 self.warehouse, self.cluster, self.new_cluster
237 )
238 }
239}
240
241#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
242pub struct AssignWarehouseNodesStmt {
243 pub warehouse: Identifier,
244 pub node_list: Vec<(Identifier, Option<String>, u64)>,
245}
246
247impl Display for AssignWarehouseNodesStmt {
248 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
249 write!(f, "ALTER WAREHOUSE {} ASSIGN NODES (", self.warehouse)?;
250
251 for (idx, (cluster, group, nodes)) in self.node_list.iter().enumerate() {
252 if idx != 0 {
253 write!(f, ", ")?;
254 }
255
256 write!(f, "ASSIGN {} NODES", nodes)?;
257
258 if let Some(group) = group {
259 write!(f, " FROM '{}'", group)?;
260 }
261
262 write!(f, " FOR {}", cluster)?;
263 }
264
265 write!(f, ")")?;
266
267 Ok(())
268 }
269}
270
271#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
272pub struct UnassignWarehouseNodesStmt {
273 pub warehouse: Identifier,
274 pub node_list: Vec<(Identifier, Option<String>, u64)>,
275}
276
277impl Display for UnassignWarehouseNodesStmt {
278 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
279 write!(f, "ALTER WAREHOUSE {} UNASSIGN NODES (", self.warehouse)?;
280
281 for (idx, (cluster, group, nodes)) in self.node_list.iter().enumerate() {
282 if idx != 0 {
283 write!(f, ", ")?;
284 }
285
286 write!(f, "UNASSIGN {} NODES", nodes)?;
287
288 if let Some(group) = group {
289 write!(f, " FROM '{}'", group)?;
290 }
291
292 write!(f, " FOR {}", cluster)?;
293 }
294
295 write!(f, ")")?;
296
297 Ok(())
298 }
299}