[
https://issues.apache.org/jira/browse/CALCITE-4055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17130393#comment-17130393
]
Ruben Q L edited comment on CALCITE-4055 at 6/10/20, 8:21 AM:
--------------------------------------------------------------
Thanks for your feedback [~danny0405].
My first intention was to apply the change not just to Join, but to all
Hintable (i.e. Aggregate and Project as well), but this seems not so
straightforward.
Unlike {{RelBuilder#join}} (which always pushes a Join on top of the RelBuilder
stack, so we know it is there and we can safely call {{RelBuilder#hints}}
afterwards), we cannot know what will be on top of RelBuilder's stack after
calling {{RelBuilder#aggregate}} or {{RelBuilder#project}}, due to some
optimizations inside these methods. If I am not mistaken:
- {{RelBuilder#project}} can push: a Project, or nothing at all.
- {{RelBuilder#aggregate}} can push: an Aggregate, an Aggregate + a Project,
just a Project, or nothing at all.
So trying to propagate the hints in
{{RelFielTrimmer#trimFields(Aggregate,...)}} and
{{RelFielTrimmer#trimFields(Project,...)}} can lead to:
{code}
java.lang.AssertionError: The top relational expression is not a Hintable
at org.apache.calcite.tools.RelBuilder.hints(RelBuilder.java:2723)
{code}
Not sure how we could solve this issue for these operations.
was (Author: rubenql):
Thanks for your feedback [~danny0405].
My first intention was to apply the change not just to Join, but to all
Hintable (i.e. Aggregate and Project as well), but this seems not so
straightforward.
Unlike {{RelBuilder#join}} (which always pushes a Join on top of the RelBuilder
stack, so we know it is there and we can safely call {{RelBuilder#hints}}
afterwards), we cannot know what will be on top of RelBuilder's stack after
calling {{RelBuilder#aggregate}} or {{RelBuilder#project}}, due to some
optimizations inside these methods. If I am not mistaken:
- {{RelBuilder#project}} can push: a Project, or nothing at all.
- {{RelBuilder#aggregate}} can push: an Aggregate, an Aggregate + a Project,
just a Project, or nothing at all.
Not sure how we could solve this issue for these operations.
> RelFieldTrimmer loses join hints
> --------------------------------
>
> Key: CALCITE-4055
> URL: https://issues.apache.org/jira/browse/CALCITE-4055
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.23.0
> Reporter: Ruben Q L
> Assignee: Ruben Q L
> Priority: Major
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The trimmed plan generated by RelFieldTrimmer can lose the hints that might
> be present in the input plan.
> The issue can be reproduced with the following test (to be added to
> RelFieldTrimmerTest):
> {code:java}
> @Test void testJoinWithHints() {
> final RelHint noHashJoinHint =
> RelHint.builder("NO_HASH_JOIN").inheritPath(0).build();
> final RelBuilder builder = RelBuilder.create(config().build());
> final RelNode original =
> builder.scan("EMP")
> .scan("DEPT")
> .join(JoinRelType.INNER,
> builder.equals(
> builder.field(2, 0, "DEPTNO"),
> builder.field(2, 1, "DEPTNO")))
> .hints(noHashJoinHint)
> .project(
> builder.field("ENAME"),
> builder.field("DNAME"))
> .build();
> final RelFieldTrimmer fieldTrimmer = new RelFieldTrimmer(null, builder);
> final RelNode trimmed = fieldTrimmer.trim(original);
> final String expected = ""
> + "LogicalProject(ENAME=[$1], DNAME=[$4])\n"
> + " LogicalJoin(condition=[=($2, $3)], joinType=[inner])\n"
> + " LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$7])\n"
> + " LogicalTableScan(table=[[scott, EMP]])\n"
> + " LogicalProject(DEPTNO=[$0], DNAME=[$1])\n"
> + " LogicalTableScan(table=[[scott, DEPT]])\n";
> assertThat(trimmed, hasTree(expected));
> assertTrue(original.getInput(0) instanceof Join);
> final Join originalJoin = (Join) original.getInput(0);
> assertTrue(originalJoin.getHints().contains(noHashJoinHint));
> assertTrue(trimmed.getInput(0) instanceof Join);
> final Join join = (Join) trimmed.getInput(0);
> assertTrue(join.getHints().contains(noHashJoinHint));
> }
> {code}
> which fails in the last line:
> {{assertTrue(join.getHints().contains(noHashJoinHint));}}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)