You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Ruben Q L (Jira)" <ji...@apache.org> on 2022/12/23 08:59:00 UTC

[jira] [Commented] (CALCITE-5456) Hints on Tablescan will lost when plannerImpl execute flattenTypes

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

Ruben Q L commented on CALCITE-5456:
------------------------------------

[~grandfisher] thanks for reporting the issue, do you think you could provide a unit tests showing the error?

It is a bit strange, because {{RelStructuredTypeFlattener#setNewForOldRel}} contains the code that should copy the hints from the "old" to the "new":
{code}
  protected void setNewForOldRel(RelNode oldRel, RelNode newRel) {
    newRel = RelOptUtil.copyRelHints(oldRel, newRel);
    oldToNewRelMap.put(oldRel, newRel);
  }
{code}

https://github.com/apache/calcite/blob/273d33dd61e0f1ec6b58e3b6381d6531608ee5e7/core/src/main/java/org/apache/calcite/sql2rel/RelStructuredTypeFlattener.java#L276

> Hints on Tablescan will lost  when plannerImpl execute flattenTypes
> -------------------------------------------------------------------
>
>                 Key: CALCITE-5456
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5456
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.32.0
>            Reporter: grandfisher
>            Priority: Major
>
> I want to use some hints on tablescan for extra processing. But hints wll lost after  `flattenTypes` 
> In PlannerImpl#rel(SqlNode sql) 
> {code:java}
> // if hint apply on tablescan here
> RelRoot root =
>     sqlToRelConverter.convertQuery(validatedSqlNode, false, true);
> //  flattenTypes will make hints on tablescan lost
> root = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true));{code}
> This is due to `RelStructuredTypeFlattener` use `ImmutableList.of()` to initialize context, and `RelStructuredTypeFlattener`  recreate a new `tablescan` relnode with this  context
> {code:java}
> // PlannerImpl#flattenTypes
> public RelNode flattenTypes(
>     RelNode rootRel,
>     boolean restructure) {
>   RelStructuredTypeFlattener typeFlattener =
>       new RelStructuredTypeFlattener(relBuilder,
>           rexBuilder, createToRelContext(ImmutableList.of()), restructure);
>   return typeFlattener.rewrite(rootRel);
> } {code}
> {code:java}
> // RelStructuredTypeFlattener#rewriteRel
> public void rewriteRel(TableScan rel) {
>   RelNode newRel = rel.getTable().toRel(toRelContext);
>   if (!SqlTypeUtil.isFlat(rel.getRowType())) {
>     newRel = coverNewRelByFlatteningProjection(rel, newRel);
>   }
>   setNewForOldRel(rel, newRel);
> } {code}



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