Skip to content

[CALCITE-3997] Logical rules matched with physical operators but failed to handle traits#1976

Closed
hsyuan wants to merge 1 commit intoapache:masterfrom
hsyuan:CALCITE-3997
Closed

[CALCITE-3997] Logical rules matched with physical operators but failed to handle traits#1976
hsyuan wants to merge 1 commit intoapache:masterfrom
hsyuan:CALCITE-3997

Conversation

@hsyuan
Copy link
Member

@hsyuan hsyuan commented May 13, 2020

Logical transformation rule, only logical operator can be rule operand, and
only generate logical alternatives. It is only visible to VolcanoPlanner,
HepPlanner will ignore this interface. That means, in HepPlanner, the rule that
implements TransformationRule can still match with physical operator of
PhysicalNode and generate physical alternatives. But in VolcanoPlanner,
TransformationRule doesn't match with physical operator that implements
PhysicalNode. It is highly discouraged to generate physical operators in
TransformationRule, unless you are using it in HepPlanner.

This will also fix issue CALCITE-3968.

@hsyuan hsyuan changed the title Add TransformationRule interface [CALCITE-3997] Logical rules matched with physical operators but failed to handle traits May 13, 2020
@hsyuan hsyuan added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label May 14, 2020
@eolivelli
Copy link
Contributor

@hsyuan thank you !

@vlsi
Do you know how to build locally this branch and put the jars into local Maven repository ?
this way I can test this branch against my branch on HerdDB

@eolivelli
Copy link
Contributor

@hsyuan it looks like you modified 92 files...
IMHO it would be better to narrow down the patch to the minimal set of changes, in order to prevent conflicts with other patches

…ed to handle traits

Logical transformation rule, only logical operator can be rule operand, and
only generate logical alternatives. It is only visible to VolcanoPlanner,
HepPlanner will ignore this interface. That means, in HepPlanner, the rule that
implements TransformationRule can still match with physical operator of
PhysicalNode and generate physical alternatives.  But in VolcanoPlanner,
TransformationRule doesn't match with physical operator that implements
PhysicalNode. It is highly discouraged to generate physical operators in
TransformationRule, unless you are using it in HepPlanner.

Close #1976
@eolivelli
Copy link
Contributor

btw I see now that you added a marker interface.
It is a big change.
But I don't have enough context in order to give a suggestion

@hsyuan
Copy link
Member Author

hsyuan commented May 14, 2020

There won't be conflicts. It is the thorough fix.

@xndai
Copy link
Contributor

xndai commented May 14, 2020

How do you guarantee only logical nodes are generated in transformation rule? Also please make sure to include this in the release note as a potential breaking change.

@hsyuan
Copy link
Member Author

hsyuan commented May 14, 2020

How do you guarantee only logical nodes are generated in transformation rule?

It is allowed, but not encouraged. Just a contract, unless we add a check inside call.transformTo, which can be added in next version.

Also please make sure to include this in the release note as a potential breaking change.

What do you think it will break?

@xndai
Copy link
Contributor

xndai commented May 14, 2020

If this's something we believe should be enforced, why don't we just add such check?

There are a number of rules you can be applied to both logical and physical nodes today (matching the base rel class instead of the logical rel). Those rules won't fire anymore with your change. Certain scenarios could break due to this.

@hsyuan
Copy link
Member Author

hsyuan commented May 14, 2020

If it can match physical operators, that means it is already matches with logical operators, it just generates redundant operators. What scenario will it break?

@xndai
Copy link
Contributor

xndai commented May 14, 2020

If one physical node is created by a rule, rather than being converted from a logical node, then there's no logical counterpart and won't be processed by your transformation rule. We don't have such rule in Calcite, but it doesn't mean the user cannot create one.

@hsyuan
Copy link
Member Author

hsyuan commented May 14, 2020

The only possible case is the user's special rule creates a physical operator that is a sub-class of Enumerable operator, at the same use Calcite's built-in logical rule to process it.
Sounds rare but fare, I will add it in the release notes.

@hsyuan hsyuan closed this in 7be30db May 14, 2020
@xndai
Copy link
Contributor

xndai commented May 14, 2020

Not necessarily a sub-class of Enumerable. It could be a sub-class of the base RelNode, such as Project or Aggregate.

@hsyuan
Copy link
Member Author

hsyuan commented May 14, 2020

The restriction only applies operator that implements PhysicalNode, which is a newly introduced interface, no one has the chance to implement it until 1.23.0 is released.
see 7be30db#diff-70d5035797baebe157bab8cbf860e456R415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left. slow-tests-needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants