Steve Carlin created IMPALA-14723:
-------------------------------------

             Summary: Calcite planner: Refactor TReduceExprShuttle
                 Key: IMPALA-14723
                 URL: https://issues.apache.org/jira/browse/IMPALA-14723
             Project: IMPALA
          Issue Type: Sub-task
            Reporter: Steve Carlin


>From code review:

This is not really related to this change and doesn't need to happen in this 
specific review. I think the code would benefit from a helper function. The 
collection of fields in ReduceShuttleObjects would be local variables in the 
helper function, and the tests wouldn't know about them at all. For example (I 
haven't compiled this, so it probably needs a couple fixes):

void verifyExprReduction(String expr, Map<String, TColumn> reductionMap, 
List<String> expectedReducedExprs) {
 CalciteAnalysisResult analysisResult =
 (CalciteAnalysisResult) parseAndAnalyze("SELECT " + query,
 feFixture_.createAnalysisCtx(), new CalciteCompilerFactory());

 CalciteRelNodeConverter relNodeConverter =
 new CalciteRelNodeConverter(analysisResult);
 RelNode rootNode = relNodeConverter.convert(analysisResult.getValidatedNode());

 Preconditions.checkState(rootNode instanceof Project);
 Project project = (Project) rootNode;

 Analyzer analyzer = analysisResult.getAnalyzer();
 TQueryCtx queryCtx = analyzer.getQueryCtx();
 TestReducerTmp testReducer = new TestReducerTmp(reductionMap);
 RexExecutor executor = new ImpalaRexExecutor(
 analyzer, queryCtx, testReducer);

 RexBuilder rexBuilder = new RexBuilder(
 new JavaTypeFactoryImpl(new ImpalaTypeSystemImpl()));
 List<RexNode> reducedExprs = new ArrayList<>();
 executor.reduce(rexBuilder, project.getProjects(), reducedExprs);

 assertEquals(expectedReducedExprs.size(), reducedExprs.size());
 for (int i = 0; i < expectedReducedExprs.size(); i++) {
 assertEquals(exectedReducedExprs.get(i), reducedExprs.get(i).toString());
 }
}



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

Reply via email to