From a48e73866c0ffdbfb29c362353300e64c552652e Mon Sep 17 00:00:00 2001 From: wuwenchi Date: Thu, 6 Jun 2024 15:54:24 +0800 Subject: [PATCH] fix --- .../doris/nereids/parser/PartitionTableInfo.java | 6 +++--- .../trees/plans/CreateTableCommandTest.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/PartitionTableInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/PartitionTableInfo.java index ceef99a1bce8e4..38601ba6d8045a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/PartitionTableInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/PartitionTableInfo.java @@ -204,10 +204,10 @@ public void validatePartitionInfo( } List partitionInSchema = columns.subList( columns.size() - partitionColumns.size(), columns.size()); + if (partitionInSchema.stream().anyMatch(p -> !partitionColumns.contains(p.getName()))) { + throw new AnalysisException("The partition field must be at the end of the schema."); + } for (int i = 0; i < partitionInSchema.size(); i++) { - if (!partitionColumns.contains(partitionInSchema.get(i).getName())) { - throw new AnalysisException("The partition field must be at the end of the schema."); - } if (!partitionInSchema.get(i).getName().equals(partitionColumns.get(i))) { throw new AnalysisException("The order of partition fields in the schema " + "must be consistent with the order defined in `PARTITIONED BY LIST()`"); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateTableCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateTableCommandTest.java index fbd60f4744c6e5..dc45e3de0fe8c1 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateTableCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateTableCommandTest.java @@ -884,5 +884,19 @@ public void testPartitionCheckForHive() { } catch (Exception e) { Assertions.assertEquals("partition key par1 is not exists", e.getMessage()); } + + try { + getCreateTableStmt("CREATE TABLE `tb11`(\n" + + " `c1` bigint,\n" + + " `par1` int,\n" + + " `par2` int,\n" + + " `par3` int\n" + + ") ENGINE = hive PARTITION BY LIST (\n" + + " par1, par2\n" + + ")();"); + Assertions.assertTrue(false); + } catch (Exception e) { + Assertions.assertEquals("The partition field must be at the end of the schema.", e.getMessage()); + } } }