Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): fix subquery writer in udf #15610

Merged
merged 3 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/query/sql/src/evaluator/cse.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use std::collections::HashMap;

use databend_common_expression::Expr;
use databend_common_functions::BUILTIN_FUNCTIONS;
use log::debug;

use super::BlockOperator;
@@ -117,6 +118,9 @@ pub fn apply_cse(
/// `count_expressions` recursively counts the occurrences of expressions in an expression tree
/// and stores the count in a HashMap.
fn count_expressions(expr: &Expr, counter: &mut HashMap<Expr, usize>) {
if !expr.is_deterministic(&BUILTIN_FUNCTIONS) {
return;
}
match expr {
Expr::FunctionCall { function, .. } if function.signature.name == "if" => {}
Expr::FunctionCall { function, .. } if function.signature.name == "is_not_error" => {}
Original file line number Diff line number Diff line change
@@ -168,17 +168,20 @@ impl SubqueryRewriter {
))
}

RelOperator::Limit(_) | RelOperator::Sort(_) => Ok(SExpr::create_unary(
RelOperator::Limit(_)
| RelOperator::Sort(_)
| RelOperator::Udf(_)
| RelOperator::AsyncFunction(_) => Ok(SExpr::create_unary(
Arc::new(s_expr.plan().clone()),
Arc::new(self.rewrite(s_expr.child(0)?)?),
)),

RelOperator::DummyTableScan(_)
| RelOperator::Scan(_)
| RelOperator::CteScan(_)
| RelOperator::ConstantTableScan(_) => Ok(s_expr.clone()),

_ => Err(ErrorCode::Internal("Invalid plan type")),
| RelOperator::ConstantTableScan(_)
| RelOperator::AddRowNumber(_)
| RelOperator::Exchange(_) => Ok(s_expr.clone()),
}
}

6 changes: 6 additions & 0 deletions tests/sqllogictests/suites/udf_server/udf_server_test.test
Original file line number Diff line number Diff line change
@@ -170,6 +170,12 @@ NULL
6
NULL

query I
SELECT gcd(a,b) d from (select number + 1 a, a * 2 b from numbers(3) where number in (select * from numbers(300))) order by d;
----
1
2
3


statement ok