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

grandfisher commented on CALCITE-5456:
--------------------------------------

I found the reason for this issue is that  myTableScan doesn't  overridden 
`withHints` method.

The default implementation return Relnode self directly.
{code:java}
// Hintable#withHints
default RelNode withHints(List<RelHint> hintList) {
  return (RelNode) this;
} {code}
 

 

> 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)

Reply via email to