grandfisher created CALCITE-5456:
------------------------------------

             Summary: 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


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