mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Support procedure argmode (#1901)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
This commit is contained in:
parent
44f3be38e5
commit
b9365b3853
4 changed files with 87 additions and 5 deletions
|
@ -30,7 +30,7 @@ use sqlparser_derive::{Visit, VisitMut};
|
||||||
|
|
||||||
use crate::ast::value::escape_single_quote_string;
|
use crate::ast::value::escape_single_quote_string;
|
||||||
use crate::ast::{
|
use crate::ast::{
|
||||||
display_comma_separated, display_separated, CommentDef, CreateFunctionBody,
|
display_comma_separated, display_separated, ArgMode, CommentDef, CreateFunctionBody,
|
||||||
CreateFunctionUsing, DataType, Expr, FunctionBehavior, FunctionCalledOnNull,
|
CreateFunctionUsing, DataType, Expr, FunctionBehavior, FunctionCalledOnNull,
|
||||||
FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn, MySQLColumnPosition,
|
FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn, MySQLColumnPosition,
|
||||||
ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect, SequenceOptions, SqlOption, Tag,
|
ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect, SequenceOptions, SqlOption, Tag,
|
||||||
|
@ -1367,11 +1367,16 @@ impl fmt::Display for NullsDistinctOption {
|
||||||
pub struct ProcedureParam {
|
pub struct ProcedureParam {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub data_type: DataType,
|
pub data_type: DataType,
|
||||||
|
pub mode: Option<ArgMode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ProcedureParam {
|
impl fmt::Display for ProcedureParam {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{} {}", self.name, self.data_type)
|
if let Some(mode) = &self.mode {
|
||||||
|
write!(f, "{mode} {} {}", self.name, self.data_type)
|
||||||
|
} else {
|
||||||
|
write!(f, "{} {}", self.name, self.data_type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7624,9 +7624,22 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_procedure_param(&mut self) -> Result<ProcedureParam, ParserError> {
|
pub fn parse_procedure_param(&mut self) -> Result<ProcedureParam, ParserError> {
|
||||||
|
let mode = if self.parse_keyword(Keyword::IN) {
|
||||||
|
Some(ArgMode::In)
|
||||||
|
} else if self.parse_keyword(Keyword::OUT) {
|
||||||
|
Some(ArgMode::Out)
|
||||||
|
} else if self.parse_keyword(Keyword::INOUT) {
|
||||||
|
Some(ArgMode::InOut)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let name = self.parse_identifier()?;
|
let name = self.parse_identifier()?;
|
||||||
let data_type = self.parse_data_type()?;
|
let data_type = self.parse_data_type()?;
|
||||||
Ok(ProcedureParam { name, data_type })
|
Ok(ProcedureParam {
|
||||||
|
name,
|
||||||
|
data_type,
|
||||||
|
mode,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
|
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
|
||||||
|
|
|
@ -15356,3 +15356,65 @@ fn check_enforced() {
|
||||||
"CREATE TABLE t (a INT, b INT, c INT, CHECK (a > 0) NOT ENFORCED, CHECK (b > 0) ENFORCED, CHECK (c > 0))",
|
"CREATE TABLE t (a INT, b INT, c INT, CHECK (a > 0) NOT ENFORCED, CHECK (b > 0) ENFORCED, CHECK (c > 0))",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_create_procedure_with_parameter_modes() {
|
||||||
|
let sql = r#"CREATE PROCEDURE test_proc (IN a INTEGER, OUT b TEXT, INOUT c TIMESTAMP, d BOOL) AS BEGIN SELECT 1; END"#;
|
||||||
|
match verified_stmt(sql) {
|
||||||
|
Statement::CreateProcedure {
|
||||||
|
or_alter,
|
||||||
|
name,
|
||||||
|
params,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
assert_eq!(or_alter, false);
|
||||||
|
assert_eq!(name.to_string(), "test_proc");
|
||||||
|
let fake_span = Span {
|
||||||
|
start: Location { line: 0, column: 0 },
|
||||||
|
end: Location { line: 0, column: 0 },
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
params,
|
||||||
|
Some(vec![
|
||||||
|
ProcedureParam {
|
||||||
|
name: Ident {
|
||||||
|
value: "a".into(),
|
||||||
|
quote_style: None,
|
||||||
|
span: fake_span,
|
||||||
|
},
|
||||||
|
data_type: DataType::Integer(None),
|
||||||
|
mode: Some(ArgMode::In)
|
||||||
|
},
|
||||||
|
ProcedureParam {
|
||||||
|
name: Ident {
|
||||||
|
value: "b".into(),
|
||||||
|
quote_style: None,
|
||||||
|
span: fake_span,
|
||||||
|
},
|
||||||
|
data_type: DataType::Text,
|
||||||
|
mode: Some(ArgMode::Out)
|
||||||
|
},
|
||||||
|
ProcedureParam {
|
||||||
|
name: Ident {
|
||||||
|
value: "c".into(),
|
||||||
|
quote_style: None,
|
||||||
|
span: fake_span,
|
||||||
|
},
|
||||||
|
data_type: DataType::Timestamp(None, TimezoneInfo::None),
|
||||||
|
mode: Some(ArgMode::InOut)
|
||||||
|
},
|
||||||
|
ProcedureParam {
|
||||||
|
name: Ident {
|
||||||
|
value: "d".into(),
|
||||||
|
quote_style: None,
|
||||||
|
span: fake_span,
|
||||||
|
},
|
||||||
|
data_type: DataType::Bool,
|
||||||
|
mode: None
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -153,7 +153,8 @@ fn parse_create_procedure() {
|
||||||
quote_style: None,
|
quote_style: None,
|
||||||
span: Span::empty(),
|
span: Span::empty(),
|
||||||
},
|
},
|
||||||
data_type: DataType::Int(None)
|
data_type: DataType::Int(None),
|
||||||
|
mode: None,
|
||||||
},
|
},
|
||||||
ProcedureParam {
|
ProcedureParam {
|
||||||
name: Ident {
|
name: Ident {
|
||||||
|
@ -164,7 +165,8 @@ fn parse_create_procedure() {
|
||||||
data_type: DataType::Varchar(Some(CharacterLength::IntegerLength {
|
data_type: DataType::Varchar(Some(CharacterLength::IntegerLength {
|
||||||
length: 256,
|
length: 256,
|
||||||
unit: None
|
unit: None
|
||||||
}))
|
})),
|
||||||
|
mode: None,
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
name: ObjectName::from(vec![Ident {
|
name: ObjectName::from(vec![Ident {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue