swuferhong commented on code in PR #21489: URL: https://github.com/apache/flink/pull/21489#discussion_r1064235043
########## flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/utils/DynamicPartitionPruningUtils.java: ########## @@ -45,153 +52,177 @@ import org.apache.calcite.rel.core.JoinRelType; import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.core.TableScan; +import org.apache.calcite.rel.core.Union; +import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexInputRef; import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexProgram; import org.apache.calcite.util.ImmutableIntList; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; /** Planner utils for Dynamic partition Pruning. */ public class DynamicPartitionPruningUtils { - /** - * For the input join node, judge whether the join left side and join right side meet the - * requirements of dynamic partition pruning. Fact side in left or right join is not clear. - */ - public static boolean supportDynamicPartitionPruning(Join join) { - return supportDynamicPartitionPruning(join, true) - || supportDynamicPartitionPruning(join, false); - } - - /** - * For the input join node, judge whether the join left side and join right side meet the - * requirements of dynamic partition pruning. Fact side in left or right is clear. If meets the - * requirements, return true. - */ - public static boolean supportDynamicPartitionPruning(Join join, boolean factInLeft) { - if (!ShortcutUtils.unwrapContext(join) - .getTableConfig() - .get(OptimizerConfigOptions.TABLE_OPTIMIZER_DYNAMIC_FILTERING_ENABLED)) { - return false; - } - // Now dynamic partition pruning supports left/right join, inner and semi join. but now semi - // join can not join reorder. - if (join.getJoinType() == JoinRelType.LEFT) { - if (factInLeft) { - return false; - } - } else if (join.getJoinType() == JoinRelType.RIGHT) { - if (!factInLeft) { - return false; - } - } else if (join.getJoinType() != JoinRelType.INNER - && join.getJoinType() != JoinRelType.SEMI) { - return false; - } - - JoinInfo joinInfo = join.analyzeCondition(); - if (joinInfo.leftKeys.isEmpty()) { - return false; - } - RelNode left = join.getLeft(); - RelNode right = join.getRight(); - - // TODO Now fact side and dim side don't support many complex patterns, like join inside - // fact/dim side, agg inside fact/dim side etc. which will support next. - return factInLeft - ? isDynamicPartitionPruningPattern(left, right, joinInfo.leftKeys) - : isDynamicPartitionPruningPattern(right, left, joinInfo.rightKeys); - } - - private static boolean isDynamicPartitionPruningPattern( - RelNode factSide, RelNode dimSide, ImmutableIntList factSideJoinKey) { - return isDimSide(dimSide) && isFactSide(factSide, factSideJoinKey); - } - - /** make a dpp fact side factor to recurrence in fact side. */ - private static boolean isFactSide(RelNode rel, ImmutableIntList joinKeys) { - DppFactSideFactors factSideFactors = new DppFactSideFactors(); - visitFactSide(rel, factSideFactors, joinKeys); - return factSideFactors.isFactSide(); - } - /** * Judge whether input RelNode meets the conditions of dimSide. If joinKeys is null means we * need not consider the join keys in dim side, which already deal by dynamic partition pruning * rule. If joinKeys not null means we need to judge whether joinKeys changed in dim side, if * changed, this RelNode is not dim side. */ - private static boolean isDimSide(RelNode rel) { + public static boolean isDimSide(RelNode rel) { DppDimSideFactors dimSideFactors = new DppDimSideFactors(); visitDimSide(rel, dimSideFactors); return dimSideFactors.isDimSide(); } - /** - * Visit fact side to judge whether fact side has partition table, partition table source meets - * the condition of dpp table source and dynamic filtering keys changed in fact side. - */ - private static void visitFactSide( - RelNode rel, DppFactSideFactors factSideFactors, ImmutableIntList joinKeys) { + public static Tuple2<Boolean, RelNode> canConvertAndConvertDppFactSide( + RelNode rel, + ImmutableIntList joinKeys, + RelNode dimSide, + ImmutableIntList dimSideJoinKey) { + DppFactSideFactors factSideFactors = new DppFactSideFactors(); Review Comment: > ditto Done! -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org