gortiz commented on code in PR #13666: URL: https://github.com/apache/pinot/pull/13666#discussion_r1684442201
########## pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotRelDistributionTraitRule.java: ########## @@ -110,10 +117,22 @@ private static RelDistribution deriveDistribution(RelNode node) { LogicalProject project = (LogicalProject) node; try { if (inputRelDistribution != null) { - return inputRelDistribution.apply(project.getMapping()); + Mappings.TargetMapping mapping = + Project.getPartialMapping(input.getRowType().getFieldCount(), project.getProjects()); + // Note(gonzalo): In Calcite 1.37 mapping.getTargetOpt will fail in what it looks like a Calcite bug. + // Therefore here we apply a workaround and create a new map where the same elements (extracted with + // iterator, which actually work) are added to the new mapping. + // See https://lists.apache.org/thread/qz18qxrfp5bqldnoln2tg4582g402zyv + Mapping actualMapping = Mappings.create(MappingType.PARTIAL_FUNCTION, input.getRowType().getFieldCount(), + project.getRowType().getFieldCount()); + for (IntPair intPair : mapping) { + actualMapping.set(intPair.source, intPair.target); + } + return inputRelDistribution.apply(actualMapping); } } catch (Exception e) { // ... skip; + LOGGER.debug("Failed to derive distribution from input for node: {}", node, e); Review Comment: This is a useful log to have. In general the tried code should not fail, but in this case it was failing and a log would have been useful while I was debuging the issue. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org