diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java index 254297842b521e..235a84e596b837 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java @@ -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 @@ -457,10 +471,6 @@ public Void visitLogicalRelation(LogicalRelation relation, IncrementCheckerConte return null; } Set 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) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java index 0bee8dd1881e64..941a46fbad2bed 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java @@ -381,7 +381,9 @@ private void analyzeExpressions(Plan plan, Map mvProperties) { List 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(",")))); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java index ef3d4c43d8266f..15e06816c1a95b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java @@ -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(); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java index b44e1cc3ec681a..ccc759dff3de94 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java @@ -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) diff --git a/regression-test/suites/mtmv_p0/test_enable_date_non_deterministic_function_mtmv.groovy b/regression-test/suites/mtmv_p0/test_enable_date_non_deterministic_function_mtmv.groovy index c085779e707e3a..a8705c6ba9ed88 100644 --- a/regression-test/suites/mtmv_p0/test_enable_date_non_deterministic_function_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_enable_date_non_deterministic_function_mtmv.groovy @@ -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};""" @@ -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};""" @@ -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}`"""