You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/02/23 11:05:53 UTC
(doris) 13/13: [fix](mtmv)fix generate partition name illegality when partition value contains colon (#31282)
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
commit bb31f4adb6bd5c32156d2e2c8af3e88e5c27e709
Author: zhangdong <49...@qq.com>
AuthorDate: Fri Feb 23 17:59:44 2024 +0800
[fix](mtmv)fix generate partition name illegality when partition value contains colon (#31282)
---
.../src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java | 9 ++++++---
.../test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java | 4 ++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
index a4f3f4cb53e..6657b3d243f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
@@ -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();
diff --git a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
index 4bb74bfd448..62f2fd5ff58 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java
@@ -171,11 +171,11 @@ public class MTMVPartitionUtilTest {
@Test
public void testGeneratePartitionName() {
List<List<PartitionValue>> inValues = Lists.newArrayList();
- inValues.add(Lists.newArrayList(new PartitionValue("value11"), new PartitionValue("value12")));
+ inValues.add(Lists.newArrayList(new PartitionValue("20201010 01:01:01"), new PartitionValue("value12")));
inValues.add(Lists.newArrayList(new PartitionValue("value21"), new PartitionValue("value22")));
PartitionKeyDesc inDesc = PartitionKeyDesc.createIn(inValues);
String inName = MTMVPartitionUtil.generatePartitionName(inDesc);
- Assert.assertEquals("p_value11_value12_value21_value22", inName);
+ Assert.assertEquals("p_20201010010101_value12_value21_value22", inName);
PartitionKeyDesc rangeDesc = PartitionKeyDesc.createFixed(
Lists.newArrayList(new PartitionValue(1L)),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org