NGA-TRAN commented on issue #4426: URL: https://github.com/apache/arrow-datafusion/issues/4426#issuecomment-1332754679
I have tried to parse `PREPARE` and `EXECUTE` statements. They both works
well
<details>
<summary>Here is the test and output of `PREPARE`. sqlparser has enum
Value::Placeholder to store the parameter. I will use that in LogicalPlan
</summary>
```rust
fn create_prepared_statement() -> Result<(), ParserError> {
// positive case
let sql = "PREPARE my_plan(TIME, INT) AS SELECT region FROM cpu
WHERE time = $1 and usage_user > $2";
let statements = DFParser::parse_sql(sql)?;
println!("{:#?}", statements[0]);
assert_eq!(statements.len(), 1);
Ok(())
}
```
```
Statement(
Prepare {
name: Ident {
value: "my_plan",
quote_style: None,
},
data_types: [
Time(
None,
None,
),
Int(
None,
),
],
statement: Query(
Query {
with: None,
body: Select(
Select {
distinct: false,
top: None,
projection: [
UnnamedExpr(
Identifier(
Ident {
value: "region",
quote_style: None,
},
),
),
],
into: None,
from: [
TableWithJoins {
relation: Table {
name: ObjectName(
[
Ident {
value: "cpu",
quote_style: None,
},
],
),
alias: None,
args: None,
with_hints: [],
},
joins: [],
},
],
lateral_views: [],
selection: Some(
BinaryOp {
left: BinaryOp {
left: Identifier(
Ident {
value: "time",
quote_style: None,
},
),
op: Eq,
right: Value(
Placeholder(
"$1",
),
),
},
op: And,
right: BinaryOp {
left: Identifier(
Ident {
value: "usage_user",
quote_style: None,
},
),
op: Gt,
right: Value(
Placeholder(
"$2",
),
),
},
},
),
group_by: [],
cluster_by: [],
distribute_by: [],
sort_by: [],
having: None,
qualify: None,
},
),
order_by: [],
limit: None,
offset: None,
fetch: None,
lock: None,
},
),
},
)
```
</details>
<details>
<summary>Here is the test and output of `EXECUTE`</summary>
```rust
#[test]
fn execute_statement() -> Result<(), ParserError> {
// positive case
let sql = "EXECUTE my_plan(1, '2022-11-30')";
let statements = DFParser::parse_sql(sql)?;
println!("{:#?}", statements[0]);
assert_eq!(statements.len(), 1);
Ok(())
}
```
```
Statement(
Execute {
name: Ident {
value: "my_plan",
quote_style: None,
},
parameters: [
Value(
Number(
"1",
false,
),
),
Value(
SingleQuotedString(
"2022-11-30",
),
),
],
},
)
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
