Custom state-full rule not working with Volcano Planner after calcite upgrade from 1.21.0 to 1.32.0/1.34.0

huangapple go评论121阅读模式
英文:

Custom state-full rule not working with Volcano Planner after calcite upgrade from 1.21.0 to 1.32.0/1.34.0

问题

The above rule fails with AssertionError: null whenever the matches function returns false. here's the stacktrace

java.lang.AssertionError: null
	at org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:57) ~[calcite-core-1.34.0.jar:1.34.0]
	at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:523) ~[calcite-core-1.34.0.jar:1.34.0]

Is it like, it is no longer allowed to return false from Calcite Rule now? Since I could see the assert over matches call in IterativeRuleDriver.java as well as TopDownRuleDriver.java.

I have also tried implementing the TransformationRule interface but no luck.

Note the same rule was working calcite version 1.21.0 as there were no such assertions back then.

英文:
public class StateFullRule extends RelOptRule {

    // *** some state
    //private boolean isProccessed = false;
    //private Map<RelNodeKey, Object> ancestorsMap;

    public StateFullRule() {
        super(operand(LogicalUnion.class, operand(LogicalProject.class, any()), new RelOptRuleOperand[]{operand(LogicalProject.class, any())}), "StateFullRule");
    }

    @Override
    public boolean matches(RelOptRuleCall call) {
            // Build intermediate state:subsetAncestorsMap using input call
            Boolean matches = determineIfRuleMatches();  // can return true or false
            if(matches) {
                //*** updateState
                //ancestorsMap = subsetAncestorsMap;
            }
            return matches;
    }

    private Boolean determineIfRuleMatches() {
        // using intermediate and actual state determine if the rule matches.
        return false;
    }
    

    public void onMatch(RelOptRuleCall call)   {
        // Transformation logic using state.
    }
}

The above rule fails with AssertionError: null whenever the matches function returns false.
here's the stacktrace

java.lang.AssertionError: null
	at org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:57) ~[calcite-core-1.34.0.jar:1.34.0]
	at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:523) ~[calcite-core-1.34.0.jar:1.34.0]

Is it like , it is no longer allowed to return false from Calcite Rule now? Since I could see the assert over matches call in IterativeRuleDriver.java as well as TopDownRuleDriver.java.

I have also tried implementing the TransformationRule interface but no luck.
Note the same rule was working calcite version 1.21.0 as there were no such assertions back then.

答案1

得分: 1

Calcite不支持有状态的规则。如果您要使规则具有状态,Calcite无法阻止您,但必须使这些规则符合Calcite的假设之一,即规则是否匹配仅取决于其RelNode参数。

我犹豫是否推荐解决方法,但也许您可以更改规则,使matches()方法返回true,直到调用onMatch(RelOptRuleCall)方法为止。

英文:

Calcite doesn't support stateful rules. If you are going to make rules stateful, Calcite can't stop you, but must make those rules comply with Calcite's assumptions. One of which is that whether a rule matches depends only on its RelNode arguments.

I hesitate to recommend workarounds, but maybe you can change your rule so that matches() returns true until the onMatch(RelOptRuleCall) method has been called.

huangapple
  • 本文由 发表于 2023年6月6日 16:18:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定