Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch-2.1: [fix](sql) Wrong result for partition item tosql #45918 #45960

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading