[fix](mtmv)fix generate partition name illegality when partition value contains colon (#31282)

This commit is contained in:
zhangdong
2024-02-23 17:59:44 +08:00
committed by yiguolei
parent 30ef9b70c3
commit bb31f4adb6
2 changed files with 8 additions and 5 deletions

View File

@ -45,9 +45,13 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MTMVPartitionUtil {
private static final Logger LOG = LogManager.getLogger(MTMVPartitionUtil.class);
private static final Pattern PARTITION_NAME_PATTERN = Pattern.compile("[^a-zA-Z0-9,]");
private static final String PARTITION_NAME_PREFIX = "p_";
/**
* Determine whether the partition is sync with retated partition and other baseTables
@ -286,9 +290,8 @@ public class MTMVPartitionUtil {
* @return
*/
public static String generatePartitionName(PartitionKeyDesc desc) {
String partitionName = "p_";
partitionName += desc.toSql().trim().replaceAll("\\(|\\)|\\-|\\[|\\]|'|\\s+", "")
.replaceAll("\\(|\\)|\\,|\\[|\\]", "_");
Matcher matcher = PARTITION_NAME_PATTERN.matcher(desc.toSql());
String partitionName = PARTITION_NAME_PREFIX + matcher.replaceAll("").replaceAll("\\,", "_");
if (partitionName.length() > 50) {
partitionName = partitionName.substring(0, 30) + Math.abs(Objects.hash(partitionName))
+ "_" + System.currentTimeMillis();