Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](mtmv) Fix partition trace wrong when partition name is same from both side of join #40485

Merged
merged 3 commits into from
Sep 13, 2024
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 number Diff line number Diff line change
Expand Up @@ -429,6 +429,20 @@ public Void visitLogicalRelation(LogicalRelation relation, IncrementCheckerConte
+ "but now is %s", relation.getClass().getSimpleName()));
return null;
}
SlotReference contextPartitionColumn = getContextPartitionColumn(context);
if (contextPartitionColumn == null) {
context.addFailReason(String.format("mv partition column is not from table when relation check, "
+ "mv partition column is %s", context.getMvPartitionColumn()));
return null;
}
// Check the table which mv partition column belonged to is same as the current check relation or not
if (!((LogicalCatalogRelation) relation).getTable().getFullQualifiers().equals(
contextPartitionColumn.getTable().map(TableIf::getFullQualifiers).orElse(ImmutableList.of()))) {
context.addFailReason(String.format("mv partition column name is not belonged to current check , "
+ "table, current table is %s",
((LogicalCatalogRelation) relation).getTable().getFullQualifiers()));
return null;
}
LogicalCatalogRelation logicalCatalogRelation = (LogicalCatalogRelation) relation;
TableIf table = logicalCatalogRelation.getTable();
// if self join, self join can not partition track now, remove the partition column correspondingly
Expand Down Expand Up @@ -457,10 +471,6 @@ public Void visitLogicalRelation(LogicalRelation relation, IncrementCheckerConte
return null;
}
Set<Column> partitionColumnSet = new HashSet<>(relatedTable.getPartitionColumns());
SlotReference contextPartitionColumn = getContextPartitionColumn(context);
if (contextPartitionColumn == null) {
return null;
}
Column mvReferenceColumn = contextPartitionColumn.getColumn().get();
Expr definExpr = mvReferenceColumn.getDefineExpr();
if (definExpr instanceof SlotRef) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ private void analyzeExpressions(Plan plan, Map<String, String> mvProperties) {
List<Expression> functionCollectResult = MaterializedViewUtils.extractNondeterministicFunction(plan);
if (!CollectionUtils.isEmpty(functionCollectResult)) {
throw new AnalysisException(String.format(
"can not contain invalid expression, the expression is %s",
"can not contain nonDeterministic expression, the expression is %s. "
+ "Should add 'enable_nondeterministic_function' = 'true' property "
+ "when create materialized view if you know the property real meaning entirely",
functionCollectResult.stream().map(Expression::toString).collect(Collectors.joining(","))));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,6 @@ public void computeUniform(DataTrait.Builder builder) {

@Override
public void computeEqualSet(DataTrait.Builder builder) {
if (getTable() instanceof MTMV && getTable().getName().equals("mv1")) {
System.out.println();
}
if (getTable() instanceof MTMV) {
MTMV mtmv = (MTMV) getTable();
MTMVCache cache = mtmv.getCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,26 @@ protected void runBeforeAll() throws Exception {
connectContext.getSessionVariable().setDisableNereidsRules("OLAP_SCAN_PARTITION_PRUNE,PRUNE_EMPTY_PARTITION");
}

// Test when join both side are all partition table and partition column name is same
@Test
public void joinPartitionNameSameTest() {
PlanChecker.from(connectContext)
.checkExplain("select t1.upgrade_day, t2.batch_no, count(*) "
+ "from test2 t2 join test1 t1 on "
+ "t1.upgrade_day = t2.upgrade_day "
+ "group by t1.upgrade_day, t2.batch_no;",
nereidsPlanner -> {
Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan();
RelatedTableInfo relatedTableInfo =
MaterializedViewUtils.getRelatedTableInfo("upgrade_day", null,
rewrittenPlan, nereidsPlanner.getCascadesContext());
checkRelatedTableInfo(relatedTableInfo,
"test1",
"upgrade_day",
true);
});
}

@Test
public void getRelatedTableInfoWhenAutoPartitionTest() {
PlanChecker.from(connectContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ suite("test_enable_date_non_deterministic_function_mtmv","mtmv") {
Assert.fail();
} catch (Exception e) {
logger.info(e.getMessage())
assertTrue(e.getMessage().contains("can not contain invalid expression"));
assertTrue(e.getMessage().contains("can not contain nonDeterministic expression"));
}
sql """drop materialized view if exists ${mvName};"""

Expand All @@ -75,7 +75,7 @@ suite("test_enable_date_non_deterministic_function_mtmv","mtmv") {
Assert.fail();
} catch (Exception e) {
logger.info(e.getMessage())
assertTrue(e.getMessage().contains("can not contain invalid expression"));
assertTrue(e.getMessage().contains("can not contain nonDeterministic expression"));
}
sql """drop materialized view if exists ${mvName};"""

Expand Down Expand Up @@ -128,7 +128,7 @@ suite("test_enable_date_non_deterministic_function_mtmv","mtmv") {
Assert.fail();
} catch (Exception e) {
logger.info(e.getMessage())
assertTrue(e.getMessage().contains("can not contain invalid expression"));
assertTrue(e.getMessage().contains("can not contain nonDeterministic expression"));
}

sql """drop table if exists `${tableName}`"""
Expand Down
Loading