Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -973,7 +973,9 @@ private Set<Set<Slot>> getShuttledRequireNoNullableViewSlots(Set<Set<Slot>> requ
for (Set<Slot> requireNullableSlots : requireNoNullableViewSlot) {
shuttledRequireNoNullableViewSlot.add(
ExpressionUtils.shuttleExpressionWithLineage(new ArrayList<>(requireNullableSlots),
viewStructInfo.getTopPlan()).stream().map(Slot.class::cast)
viewStructInfo.getTopPlan()).stream()
.filter(Slot.class::isInstance)
.map(Slot.class::cast)
.collect(Collectors.toSet()));
}
return shuttledRequireNoNullableViewSlot;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,53 @@ void testNullRejectCompensationForInnerJoinFullJoinRewriteOnRightSide() {
.anyMatch(expression -> isNotNullOnSlot(expression, "o_orderdate")));
}

@Test
void testNullRejectCompensationWithCastJoinConditionFallsBack() {
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
CascadesContext queryContext = createCascadesContext(
"select lineitem.l_orderkey, orders.o_orderkey, orders.o_orderdate from lineitem "
+ "inner join orders on cast(lineitem.l_orderkey as bigint) "
+ "= cast(orders.o_orderkey as bigint)",
connectContext
);
Plan queryPlan = PlanChecker.from(queryContext)
.analyze()
.rewrite()
.applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
.getAllPlan().get(0).child(0);

CascadesContext viewContext = createCascadesContext(
"select lineitem.l_orderkey, orders.o_orderkey, orders.o_orderdate from lineitem "
+ "left outer join orders on cast(lineitem.l_orderkey as bigint) "
+ "= cast(orders.o_orderkey as bigint)",
connectContext
);
Plan viewPlan = PlanChecker.from(viewContext)
.analyze()
.rewrite()
.applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
.getAllPlan().get(0).child(0);

StructInfo queryStructInfo = StructInfo.of(queryPlan, queryPlan, queryContext);
StructInfo viewStructInfo = StructInfo.of(viewPlan, viewPlan, viewContext);
RelationMapping relationMapping = RelationMapping.generate(
queryStructInfo.getRelations(), viewStructInfo.getRelations(), 8).get(0);
SlotMapping queryToView = SlotMapping.generate(relationMapping);
SlotMapping viewToQuery = queryToView.inverse();
LogicalCompatibilityContext compatibilityContext = LogicalCompatibilityContext.from(
relationMapping, viewToQuery, queryStructInfo, viewStructInfo);
ComparisonResult comparisonResult = StructInfo.isGraphLogicalEquals(
queryStructInfo, viewStructInfo, compatibilityContext);

Assertions.assertFalse(comparisonResult.isInvalid());
Assertions.assertFalse(comparisonResult.getViewNoNullableSlot().isEmpty());

SplitPredicate compensatePredicates = Assertions.assertDoesNotThrow(
() -> TEST_RULE.predicatesCompensateForTest(
queryStructInfo, viewStructInfo, viewToQuery, comparisonResult, queryContext));
Assertions.assertTrue(compensatePredicates.isInvalid());
}

private static boolean isNotNullOnSlot(Expression expression, String slotName) {
if (!(expression instanceof Not) || ((Not) expression).isGeneratedIsNotNull()
|| !(((Not) expression).child() instanceof IsNull)) {
Expand Down
Loading