mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-10 22:12:01 +00:00
Support PARALLEL ... and for
..ON NULL INPUT ... to
CREATE FUNCTION` (#1202)
This commit is contained in:
parent
14b33ac493
commit
2bf93a470c
4 changed files with 142 additions and 3 deletions
|
@ -5683,6 +5683,46 @@ impl fmt::Display for FunctionBehavior {
|
|||
}
|
||||
}
|
||||
|
||||
/// These attributes describe the behavior of the function when called with a null argument.
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum FunctionCalledOnNull {
|
||||
CalledOnNullInput,
|
||||
ReturnsNullOnNullInput,
|
||||
Strict,
|
||||
}
|
||||
|
||||
impl fmt::Display for FunctionCalledOnNull {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
FunctionCalledOnNull::CalledOnNullInput => write!(f, "CALLED ON NULL INPUT"),
|
||||
FunctionCalledOnNull::ReturnsNullOnNullInput => write!(f, "RETURNS NULL ON NULL INPUT"),
|
||||
FunctionCalledOnNull::Strict => write!(f, "STRICT"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If it is safe for PostgreSQL to call the function from multiple threads at once
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum FunctionParallel {
|
||||
Unsafe,
|
||||
Restricted,
|
||||
Safe,
|
||||
}
|
||||
|
||||
impl fmt::Display for FunctionParallel {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
FunctionParallel::Unsafe => write!(f, "PARALLEL UNSAFE"),
|
||||
FunctionParallel::Restricted => write!(f, "PARALLEL RESTRICTED"),
|
||||
FunctionParallel::Safe => write!(f, "PARALLEL SAFE"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
|
@ -5703,7 +5743,7 @@ impl fmt::Display for FunctionDefinition {
|
|||
|
||||
/// Postgres specific feature.
|
||||
///
|
||||
/// See [Postgresdocs](https://www.postgresql.org/docs/15/sql-createfunction.html)
|
||||
/// See [Postgres docs](https://www.postgresql.org/docs/15/sql-createfunction.html)
|
||||
/// for more details
|
||||
#[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
@ -5713,6 +5753,10 @@ pub struct CreateFunctionBody {
|
|||
pub language: Option<Ident>,
|
||||
/// IMMUTABLE | STABLE | VOLATILE
|
||||
pub behavior: Option<FunctionBehavior>,
|
||||
/// CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
|
||||
pub called_on_null: Option<FunctionCalledOnNull>,
|
||||
/// PARALLEL { UNSAFE | RESTRICTED | SAFE }
|
||||
pub parallel: Option<FunctionParallel>,
|
||||
/// AS 'definition'
|
||||
///
|
||||
/// Note that Hive's `AS class_name` is also parsed here.
|
||||
|
@ -5731,6 +5775,12 @@ impl fmt::Display for CreateFunctionBody {
|
|||
if let Some(behavior) = &self.behavior {
|
||||
write!(f, " {behavior}")?;
|
||||
}
|
||||
if let Some(called_on_null) = &self.called_on_null {
|
||||
write!(f, " {called_on_null}")?;
|
||||
}
|
||||
if let Some(parallel) = &self.parallel {
|
||||
write!(f, " {parallel}")?;
|
||||
}
|
||||
if let Some(definition) = &self.as_ {
|
||||
write!(f, " AS {definition}")?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue