This is an automated email from the ASF dual-hosted git repository.
w41ter pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new b085e94a5e2 branch-2.1: [fix](sql) Wrong result for partition item
tosql #45918 (#45960)
b085e94a5e2 is described below
commit b085e94a5e2f616492f301fe491a8f976fc7b572
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Dec 30 10:09:58 2024 +0800
branch-2.1: [fix](sql) Wrong result for partition item tosql #45918 (#45960)
Cherry-picked from #45918
Co-authored-by: Uniqueyou <[email protected]>
---
.../apache/doris/catalog/ListPartitionItem.java | 9 +---
.../doris/catalog/ListPartitionInfoTest.java | 57 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 7 deletions(-)
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 d4e781322e1..0e5cacfcdec 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 class ListPartitionItem extends PartitionItem {
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 class ListPartitionItem extends PartitionItem {
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 fe5f2fa0070..2caee8e7b68 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 class ListPartitionInfoTest {
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<List<PartitionValue>> 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());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]