[branch-2.1](DDL) Fix wrong show create table stmt for auto list multi-columns partition (#43967) (#44007)
pick https://github.com/apache/doris/pull/43967
This commit is contained in:
@ -24,7 +24,6 @@ import org.apache.doris.analysis.PartitionDesc;
|
||||
import org.apache.doris.analysis.PartitionKeyDesc;
|
||||
import org.apache.doris.analysis.PartitionValue;
|
||||
import org.apache.doris.analysis.SinglePartitionDesc;
|
||||
import org.apache.doris.analysis.SlotRef;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.common.DdlException;
|
||||
import org.apache.doris.common.util.ListUtil;
|
||||
@ -196,31 +195,19 @@ public class ListPartitionInfo extends PartitionInfo {
|
||||
@Override
|
||||
public String toSql(OlapTable table, List<Long> partitionId) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int idx = 0;
|
||||
if (enableAutomaticPartition()) {
|
||||
sb.append("AUTO PARTITION BY LIST ");
|
||||
for (Expr e : partitionExprs) {
|
||||
boolean isSlotRef = (e instanceof SlotRef);
|
||||
if (isSlotRef) {
|
||||
sb.append("(");
|
||||
}
|
||||
sb.append(e.toSql());
|
||||
if (isSlotRef) {
|
||||
sb.append(")");
|
||||
}
|
||||
}
|
||||
sb.append("\n(");
|
||||
} else {
|
||||
sb.append("PARTITION BY LIST(");
|
||||
for (Column column : partitionColumns) {
|
||||
if (idx != 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append("`").append(column.getName()).append("`");
|
||||
idx++;
|
||||
}
|
||||
sb.append(")\n(");
|
||||
sb.append("AUTO ");
|
||||
}
|
||||
sb.append("PARTITION BY LIST (");
|
||||
int idx = 0;
|
||||
for (Column column : partitionColumns) {
|
||||
if (idx != 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append("`").append(column.getName()).append("`");
|
||||
idx++;
|
||||
}
|
||||
sb.append(")\n(");
|
||||
|
||||
// sort list
|
||||
List<Map.Entry<Long, PartitionItem>> entries = new ArrayList<>(this.idToItem.entrySet());
|
||||
|
||||
@ -476,7 +476,7 @@ public class CreateTableAsSelectStmtTest extends TestWithFeService {
|
||||
+ " `username` varchar(255) NOT NULL\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "DUPLICATE KEY(`userId`)\n"
|
||||
+ "PARTITION BY LIST(`userId`)\n"
|
||||
+ "PARTITION BY LIST (`userId`)\n"
|
||||
+ "(PARTITION p1 VALUES IN (\"CA\",\"GB\",\"US\",\"ZH\"))\n"
|
||||
+ "DISTRIBUTED BY HASH(`userId`) BUCKETS 10\n"
|
||||
+ "PROPERTIES (\n"
|
||||
|
||||
@ -17,9 +17,12 @@
|
||||
|
||||
package org.apache.doris.catalog;
|
||||
|
||||
import org.apache.doris.analysis.Expr;
|
||||
import org.apache.doris.analysis.PartitionKeyDesc;
|
||||
import org.apache.doris.analysis.PartitionValue;
|
||||
import org.apache.doris.analysis.SinglePartitionDesc;
|
||||
import org.apache.doris.analysis.SlotRef;
|
||||
import org.apache.doris.analysis.TableName;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.common.DdlException;
|
||||
|
||||
@ -223,4 +226,26 @@ public class ListPartitionInfoTest {
|
||||
Assert.assertEquals("beijing", ((ListPartitionItem) partitionItem).getItems().get(0).getKeys().get(0).getRealValue());
|
||||
Assert.assertEquals(100, ((ListPartitionItem) partitionItem).getItems().get(0).getKeys().get(1).getLongValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiAutotoSql() throws AnalysisException, DdlException {
|
||||
Column k1 = new Column("k1", new ScalarType(PrimitiveType.VARCHAR), true, null, "", "");
|
||||
Column k2 = new Column("k2", new ScalarType(PrimitiveType.INT), true, null, "", "");
|
||||
partitionColumns.add(k1);
|
||||
partitionColumns.add(k2);
|
||||
|
||||
ArrayList<Expr> partitionExprs = new ArrayList<>();
|
||||
SlotRef s1 = new SlotRef(new TableName("tbl"), "k1");
|
||||
SlotRef s2 = new SlotRef(new TableName("tbl"), "k2");
|
||||
partitionExprs.add(s1);
|
||||
partitionExprs.add(s2);
|
||||
|
||||
partitionInfo = new ListPartitionInfo(true, partitionExprs, partitionColumns);
|
||||
OlapTable table = new OlapTable();
|
||||
|
||||
String sql = partitionInfo.toSql(table, null);
|
||||
|
||||
String expected = "AUTO PARTITION BY LIST (`k1`, `k2`)";
|
||||
Assert.assertTrue("got: " + sql + ", should have: " + expected, sql.contains(expected));
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,14 +17,20 @@
|
||||
|
||||
package org.apache.doris.catalog;
|
||||
|
||||
import org.apache.doris.analysis.Expr;
|
||||
import org.apache.doris.analysis.FunctionCallExpr;
|
||||
import org.apache.doris.analysis.PartitionKeyDesc;
|
||||
import org.apache.doris.analysis.PartitionKeyDesc.PartitionKeyValueType;
|
||||
import org.apache.doris.analysis.PartitionValue;
|
||||
import org.apache.doris.analysis.SinglePartitionDesc;
|
||||
import org.apache.doris.analysis.SlotRef;
|
||||
import org.apache.doris.analysis.StringLiteral;
|
||||
import org.apache.doris.analysis.TableName;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.common.DdlException;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -442,4 +448,28 @@ public class RangePartitionInfoTest {
|
||||
partitionInfo.handleNewSinglePartitionDesc(singlePartitionDesc, partitionId++, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutotoSql() throws AnalysisException, DdlException {
|
||||
Column k1 = new Column("k1", new ScalarType(PrimitiveType.DATEV2), true, null, "", "");
|
||||
partitionColumns.add(k1);
|
||||
|
||||
ArrayList<Expr> params = new ArrayList<>();
|
||||
SlotRef s1 = new SlotRef(new TableName("tbl"), "k1");
|
||||
params.add(s1);
|
||||
params.add(new StringLiteral("day"));
|
||||
|
||||
FunctionCallExpr f1 = new FunctionCallExpr("date_trunc", params);
|
||||
|
||||
ArrayList<Expr> partitionExprs = new ArrayList<>();
|
||||
partitionExprs.add(f1);
|
||||
|
||||
partitionInfo = new RangePartitionInfo(true, partitionExprs, partitionColumns);
|
||||
OlapTable table = new OlapTable();
|
||||
|
||||
String sql = partitionInfo.toSql(table, null);
|
||||
|
||||
String expected = "AUTO PARTITION BY RANGE (date_trunc(`tbl`.`k1`, 'day'))";
|
||||
Assert.assertTrue("got: " + sql + ", should have: " + expected, sql.contains(expected));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user