Skip to content

Fixes for DF 54 upgrade #1771

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 12 commits into from
5 changes: 0 additions & 5 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ pub enum EnumMember {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum DataType {
/// Table type in [postgresql]. e.g. CREATE FUNCTION RETURNS TABLE(...)
///
/// [postgresql]: https://www.postgresql.org/docs/15/sql-createfunction.html
Table(Vec<ColumnDef>),
/// Fixed-length character type e.g. CHARACTER(10)
Character(Option<CharacterLength>),
/// Fixed-length char type e.g. CHAR(10)
Expand Down Expand Up @@ -634,7 +630,6 @@ impl fmt::Display for DataType {
DataType::Unspecified => Ok(()),
DataType::Trigger => write!(f, "TRIGGER"),
DataType::AnyType => write!(f, "ANY TYPE"),
DataType::Table(fields) => write!(f, "TABLE({})", display_comma_separated(fields)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/helpers/stmt_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ mod tests {

#[test]
pub fn test_from_valid_statement() {
let builder = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("table_name")]));
let builder = CreateTableBuilder::new(ObjectName(vec![Ident::new("table_name")]));

let stmt = builder.clone().build();

Expand Down
100 changes: 69 additions & 31 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,44 +268,14 @@ impl fmt::Display for Ident {
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct ObjectName(pub Vec<ObjectNamePart>);

impl From<Vec<Ident>> for ObjectName {
fn from(idents: Vec<Ident>) -> Self {
ObjectName(idents.into_iter().map(ObjectNamePart::Identifier).collect())
}
}
pub struct ObjectName(pub Vec<Ident>);

impl fmt::Display for ObjectName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", display_separated(&self.0, "."))
}
}

/// A single part of an ObjectName
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum ObjectNamePart {
Identifier(Ident),
}

impl ObjectNamePart {
pub fn as_ident(&self) -> Option<&Ident> {
match self {
ObjectNamePart::Identifier(ident) => Some(ident),
}
}
}

impl fmt::Display for ObjectNamePart {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ObjectNamePart::Identifier(ident) => write!(f, "{}", ident),
}
}
}

/// Represents an Array Expression, either
/// `ARRAY[..]`, or `[..]`
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
Expand Down Expand Up @@ -2697,6 +2667,17 @@ pub enum Statement {
operation: AlterPolicyOperation,
},
/// ```sql
/// ALTER SESSION SET sessionParam
/// ALTER SESSION UNSET <param_name> [ , <param_name> , ... ]
/// ```
/// See <https://docs.snowflake.com/en/sql-reference/sql/alter-session>
AlterSession {
/// true is to set for the session parameters, false is to unset
set: bool,
/// The session parameters to set or unset
session_params: DataLoadingOptions,
},
/// ```sql
/// ATTACH DATABASE 'path/to/file' AS alias
/// ```
/// (SQLite-specific)
Expand Down Expand Up @@ -2980,6 +2961,32 @@ pub enum Statement {
show_options: ShowStatementOptions,
},
/// ```sql
/// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ]
/// [ IN
/// {
/// ACCOUNT |
///
/// DATABASE |
/// DATABASE <database_name> |
///
/// SCHEMA |
/// SCHEMA <schema_name> |
/// <schema_name>
///
/// APPLICATION <application_name> |
/// APPLICATION PACKAGE <application_package_name> |
/// }
/// ]
/// [ STARTS WITH '<name_string>' ]
/// [ LIMIT <rows> [ FROM '<name_string>' ] ]
/// ```
/// Snowflake-specific statement
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
ShowObjects {
terse: bool,
show_options: ShowStatementOptions,
},
/// ```sql
/// SHOW TABLES
/// ```
ShowTables {
Expand Down Expand Up @@ -4411,6 +4418,26 @@ impl fmt::Display for Statement {
} => {
write!(f, "ALTER POLICY {name} ON {table_name}{operation}")
}
Statement::AlterSession {
set,
session_params,
} => {

write!( f, "ALTER SESSION {set}", set = if *set { "SET"} else { "UNSET" })?;
if !session_params.options.is_empty() {
if *set {
write!(f, " {}", session_params)?;
} else {
let options = session_params
.options
.iter()
.map(|p| p.option_name.clone())
.collect::<Vec<_>>() ;
write!(f, " {}", display_separated(&options, " "))?;
}
}
Ok(())
}
Statement::Drop {
object_type,
if_exists,
Expand Down Expand Up @@ -4642,6 +4669,17 @@ impl fmt::Display for Statement {
)?;
Ok(())
}
Statement::ShowObjects {
terse,
show_options,
} => {
write!(
f,
"SHOW {terse}OBJECTS{show_options}",
terse = if *terse { "TERSE " } else { "" },
)?;
Ok(())
}
Statement::ShowTables {
terse,
history,
Expand Down
2 changes: 1 addition & 1 deletion src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ impl fmt::Display for SelectItem {
SelectItem::UnnamedExpr(expr) => write!(f, "{expr}"),
SelectItem::ExprWithAlias { expr, alias } => write!(f, "{expr} AS {alias}"),
SelectItem::QualifiedWildcard(kind, additional_options) => {
write!(f, "{kind}")?;
write!(f, "{kind}.*")?;
write!(f, "{additional_options}")?;
Ok(())
}
Expand Down
42 changes: 18 additions & 24 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ use super::{
FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments,
GroupByExpr, HavingBound, IlikeSelectItem, Insert, Interpolate, InterpolateExpr, Join,
JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView, MatchRecognizePattern,
Measure, NamedWindowDefinition, ObjectName, ObjectNamePart, Offset, OnConflict,
OnConflictAction, OnInsert, OrderBy, OrderByExpr, Partition, PivotValueSource,
ProjectionSelect, Query, ReferentialAction, RenameSelectItem, ReplaceSelectElement,
ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption, Statement, Subscript,
SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint, TableFactor, TableObject,
TableOptionsClustered, TableWithJoins, UpdateTableFromKind, Use, Value, Values, ViewColumnDef,
WildcardAdditionalOptions, With, WithFill,
Measure, NamedWindowDefinition, ObjectName, Offset, OnConflict, OnConflictAction, OnInsert,
OrderBy, OrderByExpr, Partition, PivotValueSource, ProjectionSelect, Query, ReferentialAction,
RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem,
SetExpr, SqlOption, Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef,
TableConstraint, TableFactor, TableObject, TableOptionsClustered, TableWithJoins,
UpdateTableFromKind, Use, Value, Values, ViewColumnDef, WildcardAdditionalOptions, With,
WithFill,
};

/// Given an iterator of spans, return the [Span::union] of all spans.
Expand Down Expand Up @@ -424,6 +424,7 @@ impl Spanned for Statement {
),
// These statements need to be implemented
Statement::AlterRole { .. } => Span::empty(),
Statement::AlterSession { .. } => Span::empty(),
Statement::AttachDatabase { .. } => Span::empty(),
Statement::AttachDuckDBDatabase { .. } => Span::empty(),
Statement::DetachDuckDBDatabase { .. } => Span::empty(),
Expand Down Expand Up @@ -490,6 +491,7 @@ impl Spanned for Statement {
Statement::DropPolicy { .. } => Span::empty(),
Statement::ShowDatabases { .. } => Span::empty(),
Statement::ShowSchemas { .. } => Span::empty(),
Statement::ShowObjects { .. } => Span::empty(),
Statement::ShowViews { .. } => Span::empty(),
Statement::LISTEN { .. } => Span::empty(),
Statement::NOTIFY { .. } => Span::empty(),
Expand Down Expand Up @@ -1357,9 +1359,9 @@ impl Spanned for Expr {
.union(&overlay_what.span())
.union(&overlay_from.span())
.union_opt(&overlay_for.as_ref().map(|i| i.span())),
Expr::Collate { expr, collation } => expr
Expr::Collate { expr, collation } => expr
.span()
.union(&union_spans(collation.0.iter().map(|i| i.span()))),
.union(&union_spans(collation.0.iter().map(|i| i.span))),
Expr::Nested(expr) => expr.span(),
Expr::Value(value) => value.span(),
Expr::TypedString { value, .. } => value.span(),
Expand Down Expand Up @@ -1463,7 +1465,7 @@ impl Spanned for Expr {
object_name
.0
.iter()
.map(|i| i.span())
.map(|i| i.span)
.chain(iter::once(token.0.span)),
),
Expr::OuterJoin(expr) => expr.span(),
Expand Down Expand Up @@ -1508,15 +1510,7 @@ impl Spanned for ObjectName {
fn span(&self) -> Span {
let ObjectName(segments) = self;

union_spans(segments.iter().map(|i| i.span()))
}
}

impl Spanned for ObjectNamePart {
fn span(&self) -> Span {
match self {
ObjectNamePart::Identifier(ident) => ident.span,
}
union_spans(segments.iter().map(|i| i.span))
}
}

Expand Down Expand Up @@ -1547,7 +1541,7 @@ impl Spanned for Function {
union_spans(
name.0
.iter()
.map(|i| i.span())
.map(|i| i.span)
.chain(iter::once(args.span()))
.chain(iter::once(parameters.span()))
.chain(filter.iter().map(|i| i.span()))
Expand Down Expand Up @@ -1751,7 +1745,7 @@ impl Spanned for TableFactor {
} => union_spans(
name.0
.iter()
.map(|i| i.span())
.map(|i| i.span)
.chain(alias.as_ref().map(|alias| {
union_spans(
iter::once(alias.name.span)
Expand Down Expand Up @@ -1796,7 +1790,7 @@ impl Spanned for TableFactor {
} => union_spans(
name.0
.iter()
.map(|i| i.span())
.map(|i| i.span)
.chain(args.iter().map(|i| i.span()))
.chain(alias.as_ref().map(|alias| alias.span())),
),
Expand Down Expand Up @@ -1947,7 +1941,7 @@ impl Spanned for FunctionArgExpr {
match self {
FunctionArgExpr::Expr(expr) => expr.span(),
FunctionArgExpr::QualifiedWildcard(object_name) => {
union_spans(object_name.0.iter().map(|i| i.span()))
union_spans(object_name.0.iter().map(|i| i.span))
}
FunctionArgExpr::Wildcard => Span::empty(),
}
Expand Down Expand Up @@ -2160,7 +2154,7 @@ impl Spanned for TableObject {
fn span(&self) -> Span {
match self {
TableObject::TableName(ObjectName(segments)) => {
union_spans(segments.iter().map(|i| i.span()))
union_spans(segments.iter().map(|i| i.span))
}
TableObject::TableFunction(func) => func.span(),
}
Expand Down
Loading