[ 
https://issues.apache.org/jira/browse/CALCITE-5391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17636938#comment-17636938
 ] 

Scott Reynolds commented on CALCITE-5391:
-----------------------------------------

I am worried my application – which depends on field names – is going to break 
in other ways because of this. I did some exploration and identified a few 
other places where the field names change – some in meaningful ways. I found 
Rules that rewrote all the names and ignoring all the aliases the user 
provided. And I found – I believe mostly caused by ambiguous {{{}RexNode{}}}s – 
field changes from {{Something}} to {{{}Something0{}}}.

How *should* applications code against the result set? Should applications keep 
their own map of field names to ordinals instead of relying on the field names 
from the root {{RelNode}} ?
h3. How I ran the Tests

I updated {{RelOptFixture#check()}} to compare the before and after plan's 
{{RelDataType}}
{code:none}
diff --git a/testkit/src/main/java/org/apache/calcite/test/RelOptFixture.java 
b/testkit/src/main/java/org/apache/calcite/test/RelOptFixture.java
index ecb474a9e..ed99437c7 100644
--- a/testkit/src/main/java/org/apache/calcite/test/RelOptFixture.java
+++ b/testkit/src/main/java/org/apache/calcite/test/RelOptFixture.java
@@ -400,6 +400,8 @@ private void checkPlanning(boolean unchanged) {
       }
     }
     assertThat(relAfter, relIsValid());
+
+    assertThat(relAfter.getRowType(), is(relBefore.getRowType()));
   }
{code}
And then ran {{./gradlew :core:test --tests 
org.apache.calcite.test.RelOptRulesTest}}
h3. What I found
h4. Tests that rewrote all the column names
 # testWithinDistinctCountDistinct
 # testProjectToWindowRuleForMultipleWindows
 # testReduceConstantsWindow
 # testExpressionInWindowFunction
 # testProjectWindowTransposeRuleWithConstants
 # testProjectAggregateMergeSum0

h4. Column Names changed from {{Something}} to {{Something0}}
 # testPushAggregateThroughOuterJoin2
 # testPushAggregateThroughOuterJoin3
 # testAggregateJoinRemove6

h4. Plans with expressions without an alias

There where a few plans that have expressions without a name so they get a name 
change through the planning process. These seemed harmless.

> JoinOnUniqueToSemiJoinRule should preserve field names, if possible
> -------------------------------------------------------------------
>
>                 Key: CALCITE-5391
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5391
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.32.0
>            Reporter: Scott Reynolds
>            Assignee: Scott Reynolds
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.33.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The new rule pushes a copy of the [original project without the alias 
> names|https://github.com/apache/calcite/pull/2848/files#r1026959819] 
> {code:java}
> builder.project(project.getProjects());
> {code}
> This results in a new SQL plan without the name fields -- they become {{$fN}} 
> fields in different plans. 
> Small change is required to put the names from the {{RelDataType}} of the 
> {{Project}} similar to the other {{Semijoin}} rule.



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

Reply via email to