Skip to content

Zdenko/snowflake parse trim with second param #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use alloc::{
vec::Vec,
};

use core::fmt::{self, Display};
use core::borrow::Borrow;
use core::fmt::{self, Display};
use std::ops::Deref;

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -48,7 +48,6 @@ pub use self::value::{
escape_quoted_string, DateTimeField, DollarQuotedString, TrimWhereField, Value,
};


use crate::ast::helpers::stmt_data_loading::{
DataLoadingOptions, StageLoadSelectItem, StageParamsObject,
};
Expand Down Expand Up @@ -176,14 +175,13 @@ impl fmt::Display for ObjectName {
}
}


#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct EngineSpec {
pub name: String,
pub options: Option<Vec<Expr>>,
}
}

impl fmt::Display for EngineSpec {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -584,12 +582,14 @@ pub enum Expr {
/// ```sql
/// TRIM([BOTH | LEADING | TRAILING] [<expr> FROM] <expr>)
/// TRIM(<expr>)
/// TRIM(<expr>, [, characters]) -- Snowflake
/// ```
Trim {
expr: Box<Expr>,
// ([BOTH | LEADING | TRAILING]
trim_where: Option<TrimWhereField>,
trim_what: Option<Box<Expr>>,
trim_characters: Option<Vec<Expr>>,
},
/// ```sql
/// OVERLAY(<expr> PLACING <expr> FROM <expr>[ FOR <expr> ]
Expand Down Expand Up @@ -831,27 +831,39 @@ impl fmt::Display for Expr {
write!(f, "{op}{expr}")
}
}
Expr::Cast { expr, data_type, format } => {
Expr::Cast {
expr,
data_type,
format,
} => {
if let Some(format) = format {
write!(f, "CAST({expr} AS {data_type} FORMAT {format})")
} else {
write!(f, "CAST({expr} AS {data_type})")
}
},
Expr::TryCast { expr, data_type, format } => {
}
Expr::TryCast {
expr,
data_type,
format,
} => {
if let Some(format) = format {
write!(f, "TRY_CAST({expr} AS {data_type} FORMAT {format})")
} else {
write!(f, "TRY_CAST({expr} AS {data_type})")
}
},
Expr::SafeCast { expr, data_type, format } => {
}
Expr::SafeCast {
expr,
data_type,
format,
} => {
if let Some(format) = format {
write!(f, "SAFE_CAST({expr} AS {data_type} FORMAT {format})")
} else {
write!(f, "SAFE_CAST({expr} AS {data_type})")
}
},
}
Expr::Extract { field, expr } => write!(f, "EXTRACT({field} FROM {expr})"),
Expr::Ceil { expr, field } => {
if field == &DateTimeField::NoDateTime {
Expand Down Expand Up @@ -984,6 +996,7 @@ impl fmt::Display for Expr {
expr,
trim_where,
trim_what,
trim_characters,
} => {
write!(f, "TRIM(")?;
if let Some(ident) = trim_where {
Expand All @@ -993,6 +1006,9 @@ impl fmt::Display for Expr {
write!(f, "{trim_char} FROM {expr}")?;
} else {
write!(f, "{expr}")?;
if let Some(characters) = trim_characters {
write!(f, ", {}", display_comma_separated(characters))?;
}
}

write!(f, ")")
Expand Down Expand Up @@ -2232,7 +2248,7 @@ impl fmt::Display for Statement {
cluster_by,
destination_table,
columns_with_types,
late_binding
late_binding,
} => {
write!(
f,
Expand All @@ -2259,7 +2275,7 @@ impl fmt::Display for Statement {
write!(f, " CLUSTER BY ({})", display_comma_separated(cluster_by))?;
}
write!(f, " AS {query}")?;
if *late_binding{
if *late_binding {
write!(f, " WITH NO SCHEMA BINDING")?;
}
Ok(())
Expand Down
Loading