Skip to content

Commit

Permalink
add rewrite rule
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhseh committed Feb 3, 2024
1 parent 33f49b8 commit 2d2f412
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/binder/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl Binder {
);

if constant_case_when_flag {
return Ok(FunctionCall::new(ExprType::ConstantCaseWhenEval, constant_case_when_eval_inputs)?.into());
return Ok(FunctionCall::new(ExprType::ConstantLookup, constant_case_when_eval_inputs)?.into());
}

// See if the case-when expression can be optimized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::expr::{ExprImpl, ExprRewriter, FunctionCall};
use risingwave_common::error::RwError;

pub struct ConstCaseWhenRewriter {}
use crate::expr::{ExprImpl, ExprRewriter, FunctionCall, ExprType};

pub struct ConstCaseWhenRewriter {
pub error: Option<RwError>,
}

impl ExprRewriter for ConstCaseWhenRewriter {
fn rewrite_function_call(&mut self, func_call: FunctionCall) -> ExprImpl {
println!("Current func_call: {:#?}", func_call);
todo!()
if func_call.func_type() != ExprType::ConstantLookup {
return func_call.into();
}
if func_call.inputs().len() != 1 {
// Normal constant lookup pass
return func_call.into();
}
func_call.inputs()[0].clone().into()
}
}
6 changes: 2 additions & 4 deletions src/frontend/src/optimizer/rule/const_case_when_eval_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ use crate::optimizer::plan_expr_rewriter::ConstCaseWhenRewriter;
pub struct ConstCaseWhenEvalRule {}
impl Rule for ConstCaseWhenEvalRule {
fn apply(&self, plan: PlanRef) -> Option<PlanRef> {
println!("Current plan: {:#?}", plan);
let values: &LogicalValues = plan.as_logical_values()?;
println!("Current values: {:#?}", values);
let _const_case_when_rewriter = ConstCaseWhenRewriter {};
todo!()
let mut const_case_when_rewriter = ConstCaseWhenRewriter { error: None };
Some(values.rewrite_exprs(&mut const_case_when_rewriter))
}
}

Expand Down

0 comments on commit 2d2f412

Please sign in to comment.