mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 06:54:07 +00:00
Replace parallel condition/result vectors with single CaseWhen vector in Expr::Case (#1733)
This commit is contained in:
parent
7fc37a76e5
commit
72312ba82a
5 changed files with 160 additions and 50 deletions
|
@ -83,6 +83,71 @@ fn test_databricks_exists() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_databricks_lambdas() {
|
||||
#[rustfmt::skip]
|
||||
let sql = concat!(
|
||||
"SELECT array_sort(array('Hello', 'World'), ",
|
||||
"(p1, p2) -> CASE WHEN p1 = p2 THEN 0 ",
|
||||
"WHEN reverse(p1) < reverse(p2) THEN -1 ",
|
||||
"ELSE 1 END)",
|
||||
);
|
||||
pretty_assertions::assert_eq!(
|
||||
SelectItem::UnnamedExpr(call(
|
||||
"array_sort",
|
||||
[
|
||||
call(
|
||||
"array",
|
||||
[
|
||||
Expr::Value(Value::SingleQuotedString("Hello".to_owned())),
|
||||
Expr::Value(Value::SingleQuotedString("World".to_owned()))
|
||||
]
|
||||
),
|
||||
Expr::Lambda(LambdaFunction {
|
||||
params: OneOrManyWithParens::Many(vec![Ident::new("p1"), Ident::new("p2")]),
|
||||
body: Box::new(Expr::Case {
|
||||
operand: None,
|
||||
conditions: vec![
|
||||
CaseWhen {
|
||||
condition: Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("p1"))),
|
||||
op: BinaryOperator::Eq,
|
||||
right: Box::new(Expr::Identifier(Ident::new("p2")))
|
||||
},
|
||||
result: Expr::Value(number("0"))
|
||||
},
|
||||
CaseWhen {
|
||||
condition: Expr::BinaryOp {
|
||||
left: Box::new(call(
|
||||
"reverse",
|
||||
[Expr::Identifier(Ident::new("p1"))]
|
||||
)),
|
||||
op: BinaryOperator::Lt,
|
||||
right: Box::new(call(
|
||||
"reverse",
|
||||
[Expr::Identifier(Ident::new("p2"))]
|
||||
)),
|
||||
},
|
||||
result: Expr::UnaryOp {
|
||||
op: UnaryOperator::Minus,
|
||||
expr: Box::new(Expr::Value(number("1")))
|
||||
}
|
||||
},
|
||||
],
|
||||
else_result: Some(Box::new(Expr::Value(number("1"))))
|
||||
})
|
||||
})
|
||||
]
|
||||
)),
|
||||
databricks().verified_only_select(sql).projection[0]
|
||||
);
|
||||
|
||||
databricks().verified_expr(
|
||||
"map_zip_with(map(1, 'a', 2, 'b'), map(1, 'x', 2, 'y'), (k, v1, v2) -> concat(v1, v2))",
|
||||
);
|
||||
databricks().verified_expr("transform(array(1, 2, 3), x -> x + 1)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_values_clause() {
|
||||
let values = Values {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue