sqlparser/ast/helpers/
stmt_data_loading.rs1#[cfg(not(feature = "std"))]
23use alloc::string::String;
24use core::fmt;
25
26#[cfg(feature = "serde")]
27use serde::{Deserialize, Serialize};
28
29use crate::ast::helpers::key_value_options::KeyValueOptions;
30use crate::ast::{Ident, ObjectName, SelectItem};
31#[cfg(feature = "visitor")]
32use sqlparser_derive::{Visit, VisitMut};
33
34#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
35#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
36#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
37pub struct StageParamsObject {
39 pub url: Option<String>,
41 pub encryption: KeyValueOptions,
43 pub endpoint: Option<String>,
45 pub storage_integration: Option<String>,
47 pub credentials: KeyValueOptions,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
54#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
55#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
56pub enum StageLoadSelectItemKind {
57 SelectItem(SelectItem),
59 StageLoadSelectItem(StageLoadSelectItem),
61}
62
63impl fmt::Display for StageLoadSelectItemKind {
64 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65 match &self {
66 StageLoadSelectItemKind::SelectItem(item) => write!(f, "{item}"),
67 StageLoadSelectItemKind::StageLoadSelectItem(item) => write!(f, "{item}"),
68 }
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
73#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
74#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
75pub struct StageLoadSelectItem {
77 pub alias: Option<Ident>,
79 pub file_col_num: i32,
81 pub element: Option<Ident>,
83 pub item_as: Option<Ident>,
85}
86
87impl fmt::Display for StageParamsObject {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 let url = &self.url.as_ref();
90 let storage_integration = &self.storage_integration.as_ref();
91 let endpoint = &self.endpoint.as_ref();
92
93 if url.is_some() {
94 write!(f, " URL='{}'", url.unwrap())?;
95 }
96 if storage_integration.is_some() {
97 write!(f, " STORAGE_INTEGRATION={}", storage_integration.unwrap())?;
98 }
99 if endpoint.is_some() {
100 write!(f, " ENDPOINT='{}'", endpoint.unwrap())?;
101 }
102 if !self.credentials.options.is_empty() {
103 write!(f, " CREDENTIALS=({})", self.credentials)?;
104 }
105 if !self.encryption.options.is_empty() {
106 write!(f, " ENCRYPTION=({})", self.encryption)?;
107 }
108
109 Ok(())
110 }
111}
112
113impl fmt::Display for StageLoadSelectItem {
114 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
115 if let Some(alias) = &self.alias {
116 write!(f, "{alias}.")?;
117 }
118 write!(f, "${}", self.file_col_num)?;
119 if let Some(element) = &self.element {
120 write!(f, ":{element}")?;
121 }
122 if let Some(item_as) = &self.item_as {
123 write!(f, " AS {item_as}")?;
124 }
125 Ok(())
126 }
127}
128
129#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
130#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
131#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
132pub struct FileStagingCommand {
134 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
136 pub stage: ObjectName,
137 pub pattern: Option<String>,
139}
140
141impl fmt::Display for FileStagingCommand {
142 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
143 write!(f, "{}", self.stage)?;
144 if let Some(pattern) = self.pattern.as_ref() {
145 write!(f, " PATTERN='{pattern}'")?;
146 }
147 Ok(())
148 }
149}