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 if let Some(ref url) = self.url {
90 write!(f, " URL='{url}'")?;
91 }
92 if let Some(ref storage_integration) = self.storage_integration {
93 write!(f, " STORAGE_INTEGRATION={storage_integration}")?;
94 }
95 if let Some(ref endpoint) = self.endpoint {
96 write!(f, " ENDPOINT='{endpoint}'")?;
97 }
98 if !self.credentials.options.is_empty() {
99 write!(f, " CREDENTIALS=({})", self.credentials)?;
100 }
101 if !self.encryption.options.is_empty() {
102 write!(f, " ENCRYPTION=({})", self.encryption)?;
103 }
104
105 Ok(())
106 }
107}
108
109impl fmt::Display for StageLoadSelectItem {
110 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111 if let Some(alias) = &self.alias {
112 write!(f, "{alias}.")?;
113 }
114 write!(f, "${}", self.file_col_num)?;
115 if let Some(element) = &self.element {
116 write!(f, ":{element}")?;
117 }
118 if let Some(item_as) = &self.item_as {
119 write!(f, " AS {item_as}")?;
120 }
121 Ok(())
122 }
123}
124
125#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
126#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
127#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
128pub struct FileStagingCommand {
130 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
132 pub stage: ObjectName,
133 pub pattern: Option<String>,
135}
136
137impl fmt::Display for FileStagingCommand {
138 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
139 write!(f, "{}", self.stage)?;
140 if let Some(pattern) = self.pattern.as_ref() {
141 write!(f, " PATTERN='{pattern}'")?;
142 }
143 Ok(())
144 }
145}