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

suibianwanwan edited comment on CALCITE-6852 at 2/23/25 4:25 PM:
-----------------------------------------------------------------

Hi, [~jensen]. I don't fully agree that CALCITE-6580 cannot be reproduced 
without this PR. I briefly tried a writing that might give you some help.
{code:java}
@Test void testProjectRemoveRule() {
  final Function<RelBuilder, RelNode> relFn = b -> {
    RelNode r = b.scan("DEPT")
        .project(b.call(SqlStdOperatorTable.PLUS, ImmutableList.of(b.field(0), 
b.literal(1))))
        .build();
    b.push(r);
    return LogicalProject.create(r, ImmutableList.of(), 
ImmutableList.of(b.field(0)), (List<String>) null, ImmutableSet.of());
  };
  fixture().withRelBuilderConfig(a -> a.withBloat(-1))
          .relFn(relFn).withRule(CoreRules.PROJECT_REMOVE).check();
} {code}


was (Author: JIRAUSER301334):
Hi, [~jensen]. I don't fully agree that [CALCITE-6580] cannot be reproduced 
without this PR. I briefly tried a writing that might give you some help.
{code:java}
@Test void testProjectRemoveRule() {
  final Function<RelBuilder, RelNode> relFn = b -> {
    RelNode r = b.scan("DEPT")
        .project(b.call(SqlStdOperatorTable.PLUS, ImmutableList.of(b.field(0), 
b.literal(1))))
        .build();
    b.push(r);
    return LogicalProject.create(r, ImmutableList.of(), 
ImmutableList.of(b.field(0)), (List<String>) null, ImmutableSet.of());
  };
  fixture().withRelBuilderConfig(a -> a.withBloat(-1))
          .relFn(relFn).withRule(CoreRules.PROJECT_REMOVE).check();
} {code}
 

> Project's digest calculation error, should include FieldNames in rowType 
> -------------------------------------------------------------------------
>
>                 Key: CALCITE-6852
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6852
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.39.0
>            Reporter: Zhen Chen
>            Assignee: Zhen Chen
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.39.0
>
>         Attachments: image-2025-02-22-17-19-46-706.png, 
> image-2025-02-23-16-47-22-367.png, image-2025-02-23-16-53-03-724.png
>
>
> When I was building test cases for CALCITE-6850, I found that the results did 
> not meet my expectations. When debugging the code, I discovered that the 
> project's digest calculation did not include column names, This leads to the 
> inability to correctly find the correct project during the findBestExp 
> process.
> debug picture:
> !image-2025-02-22-17-19-46-706.png|width=553,height=245!
> I think we need to add column names in computing project's degist like this:
> {code:java}
> // code now
> protected int deepHashCode0() {
>   return Objects.hash(traitSet, input.deepHashCode(), exps, hints);
> }
> // should change to 
> protected int deepHashCode0() {
>   return Objects.hash(traitSet, input.deepHashCode(),
>     exps, hints, getRowType().getFieldNames()); 
> }{code}
> This change will affect some cases and the results of these cases need to be 
> fixed.
>  
> If calcite need this change, I can pull a pr. If this issue is not fixed, 
> there will be no way to find a case for issue CALCITE-6850. 
>  
> supplement:
> !image-2025-02-23-16-47-22-367.png|width=518,height=274!
> !image-2025-02-23-16-53-03-724.png|width=521,height=284!
> If project fields is not nested, then it wil use field name as pw key, and 
> expr as pw value,but in deepHashCode(), only use pw value to compute hash 
> code. So other operators has no effect. Such as Agg, it use the aggCalls as 
> pw value.



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

Reply via email to