[ 
https://issues.apache.org/jira/browse/CALCITE-6998?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zhen Chen updated CALCITE-6998:
-------------------------------
    Description: 
Problem Description:

For example, ExpandDisjunctionForJoinInputsRule contains two Configs, FILTER 
and JOIN.
@Value.Immutable(singleton = false)
public interface Config extends RelRule.Config {
  Config FILTER = ImmutableExpandDisjunctionForJoinInputsRule.Config.builder()
    .withDescription("ExpandDisjunctionForJoinInputsRule(Filter)")
    .withMatchHandler(ExpandDisjunctionForJoinInputsRule::matchFilter)
    .build()
    .withOperandSupplier(b0 ->
        b0.operand(Filter.class).oneInput(b1 ->
            b1.operand(Join.class).anyInputs()));
​
  Config JOIN = ImmutableExpandDisjunctionForJoinInputsRule.Config.builder()
    .withDescription("ExpandDisjunctionForJoinInputsRule(Join)")
    .withMatchHandler(ExpandDisjunctionForJoinInputsRule::matchJoin)
    .build()
    .withOperandSupplier(b -> b.operand(Join.class).anyInputs());
​
  ......
}
When using reflection to load rules in CoreRules, the following rules cannot be 
instantiated correctly.
public static final ExpandDisjunctionForJoinInputsRule 
EXPAND_FILTER_DISJUNCTION_LOCAL 
  = ExpandDisjunctionForJoinInputsRule.Config.FILTER.toRule();
​
public static final ExpandDisjunctionForJoinInputsRule 
EXPAND_JOIN_DISJUNCTION_LOCAL 
  = ExpandDisjunctionForJoinInputsRule.Config.JOIN.toRule();
If both rules are loaded simultaneously, they both end up using 
{{ExpandDisjunctionForJoinInputsRule.Config.FILTER.toRule()}}.

Solution:

Add an annotation {{@RuleConfig(value="XXX")}} to each rule in CoreRules, where 
the {{value}} identifies the name of the Config used by the rule. For example:
@RuleConfig(value = "JOIN")
public static final ExpandDisjunctionForJoinInputsRule 
EXPAND_JOIN_DISJUNCTION_LOCAL =
      ExpandDisjunctionForJoinInputsRule.Config.JOIN.toRule();
This indicates that the rule uses the {{JOIN}} Config.

If a rule has only one Config named {{DEFAULT}}, the annotation is not required.

This way, during reflection, the correct rule instance can be obtained based on 
the {{@RuleConfig}} annotation.

  was:For example, ExpandDisjunctionForJoinInputsRule, which contains multiple 
Config, including Filter and JOIN. Unable to recognize different Config when 
loading such rules through reflection.


> The command !set planner-rules does not support rules with multiple Config
> --------------------------------------------------------------------------
>
>                 Key: CALCITE-6998
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6998
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Zhen Chen
>            Assignee: Zhen Chen
>            Priority: Major
>              Labels: pull-request-available
>
> Problem Description:
> For example, ExpandDisjunctionForJoinInputsRule contains two Configs, FILTER 
> and JOIN.
> @Value.Immutable(singleton = false)
> public interface Config extends RelRule.Config {
>   Config FILTER = ImmutableExpandDisjunctionForJoinInputsRule.Config.builder()
>     .withDescription("ExpandDisjunctionForJoinInputsRule(Filter)")
>     .withMatchHandler(ExpandDisjunctionForJoinInputsRule::matchFilter)
>     .build()
>     .withOperandSupplier(b0 ->
>         b0.operand(Filter.class).oneInput(b1 ->
>             b1.operand(Join.class).anyInputs()));
> ​
>   Config JOIN = ImmutableExpandDisjunctionForJoinInputsRule.Config.builder()
>     .withDescription("ExpandDisjunctionForJoinInputsRule(Join)")
>     .withMatchHandler(ExpandDisjunctionForJoinInputsRule::matchJoin)
>     .build()
>     .withOperandSupplier(b -> b.operand(Join.class).anyInputs());
> ​
>   ......
> }
> When using reflection to load rules in CoreRules, the following rules cannot 
> be instantiated correctly.
> public static final ExpandDisjunctionForJoinInputsRule 
> EXPAND_FILTER_DISJUNCTION_LOCAL 
>   = ExpandDisjunctionForJoinInputsRule.Config.FILTER.toRule();
> ​
> public static final ExpandDisjunctionForJoinInputsRule 
> EXPAND_JOIN_DISJUNCTION_LOCAL 
>   = ExpandDisjunctionForJoinInputsRule.Config.JOIN.toRule();
> If both rules are loaded simultaneously, they both end up using 
> {{ExpandDisjunctionForJoinInputsRule.Config.FILTER.toRule()}}.
> Solution:
> Add an annotation {{@RuleConfig(value="XXX")}} to each rule in CoreRules, 
> where the {{value}} identifies the name of the Config used by the rule. For 
> example:
> @RuleConfig(value = "JOIN")
> public static final ExpandDisjunctionForJoinInputsRule 
> EXPAND_JOIN_DISJUNCTION_LOCAL =
>       ExpandDisjunctionForJoinInputsRule.Config.JOIN.toRule();
> This indicates that the rule uses the {{JOIN}} Config.
> If a rule has only one Config named {{DEFAULT}}, the annotation is not 
> required.
> This way, during reflection, the correct rule instance can be obtained based 
> on the {{@RuleConfig}} annotation.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to