diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionItem.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionItem.java index d4e781322e186a..0e5cacfcdec5f2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionItem.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionItem.java @@ -200,10 +200,7 @@ public String toString() { public String toSql() { StringBuilder sb = new StringBuilder(); - int size = partitionKeys.size(); - if (size > 1) { - sb.append("("); - } + sb.append("("); int i = 0; for (PartitionKey partitionKey : partitionKeys) { @@ -214,9 +211,7 @@ public String toSql() { i++; } - if (size > 1) { - sb.append(")"); - } + sb.append(")"); return sb.toString(); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/ListPartitionInfoTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/ListPartitionInfoTest.java index fe5f2fa0070830..2caee8e7b68956 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/ListPartitionInfoTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/ListPartitionInfoTest.java @@ -248,4 +248,61 @@ public void testMultiAutotoSql() throws AnalysisException, DdlException { String expected = "AUTO PARTITION BY LIST (`k1`, `k2`)"; Assert.assertTrue("got: " + sql + ", should have: " + expected, sql.contains(expected)); } + + @Test + public void testListPartitionNullMax() throws AnalysisException, DdlException { + PartitionItem partitionItem = null; + Column k1 = new Column("k1", new ScalarType(PrimitiveType.INT), true, null, "", ""); + Column k2 = new Column("k2", new ScalarType(PrimitiveType.INT), true, null, "", ""); + partitionColumns.add(k1); + partitionColumns.add(k2); + partitionInfo = new ListPartitionInfo(partitionColumns); + + List> inValues = new ArrayList<>(); + inValues.add(Lists.newArrayList(new PartitionValue("", true), PartitionValue.MAX_VALUE)); + SinglePartitionDesc singlePartitionDesc = new SinglePartitionDesc(false, "p1", + PartitionKeyDesc.createIn(inValues), null); + singlePartitionDesc.analyze(2, null); + partitionItem = partitionInfo.handleNewSinglePartitionDesc(singlePartitionDesc, 20000L, false); + + Assert.assertEquals("((NULL, MAXVALUE))", ((ListPartitionItem) partitionItem).toSql()); + + inValues = new ArrayList<>(); + inValues.add(Lists.newArrayList(new PartitionValue("", true), new PartitionValue("", true))); + singlePartitionDesc = new SinglePartitionDesc(false, "p2", + PartitionKeyDesc.createIn(inValues), null); + singlePartitionDesc.analyze(2, null); + partitionItem = partitionInfo.handleNewSinglePartitionDesc(singlePartitionDesc, 20000L, false); + + Assert.assertEquals("((NULL, NULL))", ((ListPartitionItem) partitionItem).toSql()); + + inValues = new ArrayList<>(); + inValues.add(Lists.newArrayList(PartitionValue.MAX_VALUE, new PartitionValue("", true))); + singlePartitionDesc = new SinglePartitionDesc(false, "p3", + PartitionKeyDesc.createIn(inValues), null); + singlePartitionDesc.analyze(2, null); + partitionItem = partitionInfo.handleNewSinglePartitionDesc(singlePartitionDesc, 20000L, false); + + Assert.assertEquals("((MAXVALUE, NULL))", ((ListPartitionItem) partitionItem).toSql()); + + inValues = new ArrayList<>(); + inValues.add(Lists.newArrayList(PartitionValue.MAX_VALUE, PartitionValue.MAX_VALUE)); + singlePartitionDesc = new SinglePartitionDesc(false, "p4", + PartitionKeyDesc.createIn(inValues), null); + singlePartitionDesc.analyze(2, null); + partitionItem = partitionInfo.handleNewSinglePartitionDesc(singlePartitionDesc, 20000L, false); + + Assert.assertEquals("((MAXVALUE, MAXVALUE))", ((ListPartitionItem) partitionItem).toSql()); + + inValues = new ArrayList<>(); + inValues.add(Lists.newArrayList(new PartitionValue("", true), new PartitionValue("", true))); + inValues.add(Lists.newArrayList(PartitionValue.MAX_VALUE, new PartitionValue("", true))); + inValues.add(Lists.newArrayList(new PartitionValue("", true), PartitionValue.MAX_VALUE)); + singlePartitionDesc = new SinglePartitionDesc(false, "p5", + PartitionKeyDesc.createIn(inValues), null); + singlePartitionDesc.analyze(2, null); + partitionItem = partitionInfo.handleNewSinglePartitionDesc(singlePartitionDesc, 20000L, false); + + Assert.assertEquals("((NULL, NULL),(MAXVALUE, NULL),(NULL, MAXVALUE))", ((ListPartitionItem) partitionItem).toSql()); + } }