[Bug](partition) fix auto list partition erros of incorrect partition name (#27974)

the partition name need limit it's length and can't have negative "-"
This commit is contained in:
zhangstar333
2023-12-05 12:54:06 +08:00
committed by GitHub
parent 2f63999066
commit ca6949ee3e
2 changed files with 50 additions and 4 deletions

View File

@ -120,8 +120,8 @@ public class PartitionExprUtil {
Map<String, AddPartitionClause> result = Maps.newHashMap();
ArrayList<Expr> partitionExprs = partitionInfo.getPartitionExprs();
PartitionType partitionType = partitionInfo.getType();
List<Column> partiitonColumn = partitionInfo.getPartitionColumns();
Type partitionColumnType = partiitonColumn.get(0).getType();
List<Column> partitionColumn = partitionInfo.getPartitionColumns();
boolean hasStringType = partitionColumn.stream().anyMatch(column -> column.getType().isStringType());
FunctionIntervalInfo intervalInfo = getFunctionIntervalInfo(partitionExprs, partitionType);
Set<String> filterPartitionValues = new HashSet<String>();
@ -141,6 +141,7 @@ public class PartitionExprUtil {
filterPartitionValues.add(filterStr);
if (partitionType == PartitionType.RANGE) {
String beginTime = curPartitionValues.get(0); // have check range type size must be 1
Type partitionColumnType = partitionColumn.get(0).getType();
DateLiteral beginDateTime = new DateLiteral(beginTime, partitionColumnType);
partitionName += String.format(DATETIME_NAME_FORMATTER,
beginDateTime.getYear(), beginDateTime.getMonth(), beginDateTime.getDay(),
@ -157,9 +158,9 @@ public class PartitionExprUtil {
partitionKeyDesc = PartitionKeyDesc.createIn(
listValues);
partitionName += getFormatPartitionValue(filterStr);
if (partitionColumnType.isStringType()) {
if (hasStringType) {
if (partitionName.length() > 50) {
partitionName = partitionName.substring(40) + Objects.hash(partitionName)
partitionName = partitionName.substring(0, 30) + Math.abs(Objects.hash(partitionName))
+ "_" + System.currentTimeMillis();
}
}