Skip to content

Commit df0b9f2

Browse files
Merge branch 'main' into no-whitespace-parser
2 parents 2f8d5f6 + 4beea9a commit df0b9f2

File tree

10 files changed

+401
-105
lines changed

10 files changed

+401
-105
lines changed

src/ast/ddl.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,8 +3099,12 @@ impl fmt::Display for CreateFunction {
30993099
if let Some(remote_connection) = &self.remote_connection {
31003100
write!(f, " REMOTE WITH CONNECTION {remote_connection}")?;
31013101
}
3102-
if let Some(CreateFunctionBody::AsBeforeOptions(function_body)) = &self.function_body {
3103-
write!(f, " AS {function_body}")?;
3102+
if let Some(CreateFunctionBody::AsBeforeOptions { body, link_symbol }) = &self.function_body
3103+
{
3104+
write!(f, " AS {body}")?;
3105+
if let Some(link_symbol) = link_symbol {
3106+
write!(f, ", {link_symbol}")?;
3107+
}
31043108
}
31053109
if let Some(CreateFunctionBody::Return(function_body)) = &self.function_body {
31063110
write!(f, " RETURN {function_body}")?;
@@ -4188,3 +4192,62 @@ impl fmt::Display for OperatorPurpose {
41884192
}
41894193
}
41904194
}
4195+
4196+
/// `DROP OPERATOR` statement
4197+
/// See <https://www.postgresql.org/docs/current/sql-dropoperator.html>
4198+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4199+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4200+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4201+
pub struct DropOperator {
4202+
/// `IF EXISTS` clause
4203+
pub if_exists: bool,
4204+
/// One or more operators to drop with their signatures
4205+
pub operators: Vec<DropOperatorSignature>,
4206+
/// `CASCADE or RESTRICT`
4207+
pub drop_behavior: Option<DropBehavior>,
4208+
}
4209+
4210+
/// Operator signature for a `DROP OPERATOR` statement
4211+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4212+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4213+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4214+
pub struct DropOperatorSignature {
4215+
/// Operator name
4216+
pub name: ObjectName,
4217+
/// Left operand type
4218+
pub left_type: Option<DataType>,
4219+
/// Right operand type
4220+
pub right_type: DataType,
4221+
}
4222+
4223+
impl fmt::Display for DropOperatorSignature {
4224+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4225+
write!(f, "{} (", self.name)?;
4226+
if let Some(left_type) = &self.left_type {
4227+
write!(f, "{}", left_type)?;
4228+
} else {
4229+
write!(f, "NONE")?;
4230+
}
4231+
write!(f, ", {})", self.right_type)
4232+
}
4233+
}
4234+
4235+
impl fmt::Display for DropOperator {
4236+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4237+
write!(f, "DROP OPERATOR")?;
4238+
if self.if_exists {
4239+
write!(f, " IF EXISTS")?;
4240+
}
4241+
write!(f, " {}", display_comma_separated(&self.operators))?;
4242+
if let Some(drop_behavior) = &self.drop_behavior {
4243+
write!(f, " {}", drop_behavior)?;
4244+
}
4245+
Ok(())
4246+
}
4247+
}
4248+
4249+
impl Spanned for DropOperator {
4250+
fn span(&self) -> Span {
4251+
Span::empty()
4252+
}
4253+
}

src/ast/mod.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ pub use self::ddl::{
6767
ColumnPolicyProperty, ConstraintCharacteristics, CreateConnector, CreateDomain,
6868
CreateExtension, CreateFunction, CreateIndex, CreateOperator, CreateOperatorClass,
6969
CreateOperatorFamily, CreateTable, CreateTrigger, CreateView, Deduplicate, DeferrableInitial,
70-
DropBehavior, DropExtension, DropFunction, DropTrigger, GeneratedAs, GeneratedExpressionMode,
71-
IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind,
72-
IdentityPropertyOrder, IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, Msck,
73-
NullsDistinctOption, OperatorArgTypes, OperatorClassItem, OperatorPurpose, Owner, Partition,
74-
ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity, TagsColumnOption,
75-
TriggerObjectKind, Truncate, UserDefinedTypeCompositeAttributeDef,
76-
UserDefinedTypeInternalLength, UserDefinedTypeRangeOption, UserDefinedTypeRepresentation,
77-
UserDefinedTypeSqlDefinitionOption, UserDefinedTypeStorage, ViewColumnDef,
70+
DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorSignature, DropTrigger,
71+
GeneratedAs, GeneratedExpressionMode, IdentityParameters, IdentityProperty,
72+
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, IndexColumn,
73+
IndexOption, IndexType, KeyOrIndexDisplay, Msck, NullsDistinctOption, OperatorArgTypes,
74+
OperatorClassItem, OperatorPurpose, Owner, Partition, ProcedureParam, ReferentialAction,
75+
RenameTableNameKind, ReplicaIdentity, TagsColumnOption, TriggerObjectKind, Truncate,
76+
UserDefinedTypeCompositeAttributeDef, UserDefinedTypeInternalLength,
77+
UserDefinedTypeRangeOption, UserDefinedTypeRepresentation, UserDefinedTypeSqlDefinitionOption,
78+
UserDefinedTypeStorage, ViewColumnDef,
7879
};
7980
pub use self::dml::{Copy, Delete, Insert, Update};
8081
pub use self::operator::{BinaryOperator, UnaryOperator};
@@ -3560,6 +3561,12 @@ pub enum Statement {
35603561
/// <https://www.postgresql.org/docs/current/sql-dropextension.html>
35613562
DropExtension(DropExtension),
35623563
/// ```sql
3564+
/// DROP OPERATOR [ IF EXISTS ] name ( { left_type | NONE } , right_type ) [, ...] [ CASCADE | RESTRICT ]
3565+
/// ```
3566+
/// Note: this is a PostgreSQL-specific statement.
3567+
/// <https://www.postgresql.org/docs/current/sql-dropoperator.html>
3568+
DropOperator(DropOperator),
3569+
/// ```sql
35633570
/// FETCH
35643571
/// ```
35653572
/// Retrieve rows from a query using a cursor
@@ -4786,6 +4793,7 @@ impl fmt::Display for Statement {
47864793
Statement::CreateIndex(create_index) => create_index.fmt(f),
47874794
Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
47884795
Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
4796+
Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
47894797
Statement::CreateRole(create_role) => write!(f, "{create_role}"),
47904798
Statement::CreateSecret {
47914799
or_replace,
@@ -9050,7 +9058,20 @@ pub enum CreateFunctionBody {
90509058
/// ```
90519059
///
90529060
/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
9053-
AsBeforeOptions(Expr),
9061+
/// [PostgreSQL]: https://www.postgresql.org/docs/current/sql-createfunction.html
9062+
AsBeforeOptions {
9063+
/// The primary expression.
9064+
body: Expr,
9065+
/// Link symbol if the primary expression contains the name of shared library file.
9066+
///
9067+
/// Example:
9068+
/// ```sql
9069+
/// CREATE FUNCTION cas_in(input cstring) RETURNS cas
9070+
/// AS 'MODULE_PATHNAME', 'cas_in_wrapper'
9071+
/// ```
9072+
/// [PostgreSQL]: https://www.postgresql.org/docs/current/sql-createfunction.html
9073+
link_symbol: Option<Expr>,
9074+
},
90549075
/// A function body expression using the 'AS' keyword and shows up
90559076
/// after any `OPTIONS` clause.
90569077
///

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ impl Spanned for Statement {
368368
Statement::CreateRole(create_role) => create_role.span(),
369369
Statement::CreateExtension(create_extension) => create_extension.span(),
370370
Statement::DropExtension(drop_extension) => drop_extension.span(),
371+
Statement::DropOperator(drop_operator) => drop_operator.span(),
371372
Statement::CreateSecret { .. } => Span::empty(),
372373
Statement::CreateServer { .. } => Span::empty(),
373374
Statement::CreateConnector { .. } => Span::empty(),

src/dialect/snowflake.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl Dialect for SnowflakeDialect {
397397

398398
fn is_column_alias(&self, kw: &Keyword, parser: &mut Parser) -> bool {
399399
match kw {
400-
// The following keywords can be considered an alias as long as
400+
// The following keywords can be considered an alias as long as
401401
// they are not followed by other tokens that may change their meaning
402402
// e.g. `SELECT * EXCEPT (col1) FROM tbl`
403403
Keyword::EXCEPT
@@ -412,7 +412,7 @@ impl Dialect for SnowflakeDialect {
412412
Keyword::LIMIT | Keyword::OFFSET if peek_for_limit_options(parser) => false,
413413

414414
// `FETCH` can be considered an alias as long as it's not followed by `FIRST`` or `NEXT`
415-
// which would give it a different meanings, for example:
415+
// which would give it a different meanings, for example:
416416
// `SELECT 1 FETCH FIRST 10 ROWS` - not an alias
417417
// `SELECT 1 FETCH 10` - not an alias
418418
Keyword::FETCH if parser.peek_one_of_keywords(&[Keyword::FIRST, Keyword::NEXT]).is_some()
@@ -421,8 +421,8 @@ impl Dialect for SnowflakeDialect {
421421
false
422422
}
423423

424-
// Reserved keywords by the Snowflake dialect, which seem to be less strictive
425-
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
424+
// Reserved keywords by the Snowflake dialect, which seem to be less strictive
425+
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
426426
// keywords were tested with the this statement: `SELECT 1 <KW>`.
427427
Keyword::FROM
428428
| Keyword::GROUP
@@ -692,7 +692,7 @@ pub fn parse_create_table(
692692
.iceberg(iceberg)
693693
.global(global)
694694
.dynamic(dynamic)
695-
.hive_formats(Some(Default::default()));
695+
.hive_formats(None);
696696

697697
// Snowflake does not enforce order of the parameters in the statement. The parser needs to
698698
// parse the statement in a loop.

0 commit comments

Comments
 (0)