[CALCITE-3868] Remove redundant ruleSet and ruleNames in VolcanoPlanner#1869
[CALCITE-3868] Remove redundant ruleSet and ruleNames in VolcanoPlanner#1869hsyuan merged 1 commit intoapache:masterfrom hsyuan:remove_ruleset
Conversation
| : "Rule's description should not contain '$': " | ||
| + description; | ||
| assert !INTEGER_PATTERN.matcher(description).matches() | ||
| : "Rule's description should not be an integer: " |
There was a problem hiding this comment.
How should we validate the rule description pattern now ?
| * are unique. | ||
| */ | ||
| private final Map<String, RelOptRule> mapDescToRule = new HashMap<>(); | ||
| protected final Map<String, RelOptRule> mapDescToRule = new HashMap<>(); |
There was a problem hiding this comment.
With this change the map becomes the main data structure holding the rules so I think the Javadoc should be updated to reflect this. Increasing the visibility of the field makes it public API; it might be better to keep this private and rely on public/protected methods to recover the necessary info.
There was a problem hiding this comment.
I think we may need to change it to LinkedHashMap to be consistent with the requirement of HepPlanner.
There was a problem hiding this comment.
It turns out we still need it to be protected to avoid copying.
There was a problem hiding this comment.
I think that in most cases the number of rules is not very big so I was thinking that copying vs. mapDescToRule.values() is not going to have significant performance overhead in the planning phase, thus, I tend to prefer better encapsulation. Having that said, I do not have any concrete measures to support my claims (just instinct that could be wrong) :)
There was a problem hiding this comment.
I agree the rules is not very big. But in onNewClass, every time we add a new logical/physical operator we have to copy it. It will copy N times depends on how many operators you have. Though not a significant overhead, but I think we still need to avoid multiple times copy.
There was a problem hiding this comment.
I'm fine with any option so I am leaving the final decision up to you :)
| // Check that there isn't a rule with the same description, | ||
| // also validating description string. | ||
|
|
||
| protected boolean mapRuleDescription(RelOptRule rule) { |
There was a problem hiding this comment.
The method now basically registers the rule to the planner so it might be better to rename this entirely to addRule.
| * @return the rule that is removed, or null if no rule is removed | ||
| */ | ||
| protected void unmapRuleDescription(RelOptRule rule) { | ||
| protected RelOptRule unmapRuleDescription(RelOptRule rule) { |
There was a problem hiding this comment.
Rename this to removeRule and update the Javadoc?
There was a problem hiding this comment.
The parameter of this method is weird, should be string description of the rule, like removeRule(String desc) ?
| this.provenanceMap.clear(); | ||
| } | ||
|
|
||
| public List<RelOptRule> getRules() { |
There was a problem hiding this comment.
Would it be a good idea to move the method to AbstractRelOptPlanner? This would allow us to keep mapDescToRule private and replace calls to mapDescToRule.values() with calls to this method.
| return ImmutableList.copyOf(mapDescToRule.values()); | ||
| } | ||
|
|
||
| public boolean addRule(RelOptRule rule) { |
There was a problem hiding this comment.
If we choose to add this method to the superclass (instead of having mapRuleDescription) then here we can ovverride.
There was a problem hiding this comment.
@zabetak I have addressed your comments. Thanks.
| if (instruction.ruleSet == null) { | ||
| instruction.ruleSet = new LinkedHashSet<>(); | ||
| for (RelOptRule rule : allRules) { | ||
| for (RelOptRule rule : mapDescToRule.values()) { |
There was a problem hiding this comment.
If we already know the size of mapDescToRule, we can create a set with exact size, which will eliminate capacity expansion overhead and space waste when creating. Even though this is trivial update, I think it is always a good manner to create collection in such way if possible.
instruction.ruleSet = Sets.newHashSetWithExpectedSize(mapDescToRule.size());
There was a problem hiding this comment.
It turns out the size instruction.ruleSet is undetermined, we don't know the exact size. So I will leave as it is.
There was a problem hiding this comment.
I agree, there is "if" check to determine what to be added. I didn't find that out clearly, sorry about the false alert.
JIRA: https://issues.apache.org/jira/browse/CALCITE-3868