Skip to content

Commit

Permalink
[fix](sql) Wrong result for partition item tosql (#45918)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyxxxcat authored and Your Name committed Dec 25, 2024
1 parent bccfb04 commit f8bbb2e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -214,9 +211,7 @@ public String toSql() {
i++;
}

if (size > 1) {
sb.append(")");
}
sb.append(")");

return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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());
}
}

0 comments on commit f8bbb2e

Please sign in to comment.