This is an automated email from the ASF dual-hosted git repository.
yihua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new ad221c449ecf fix(common): escape dots in single-level hive-style
partition column names (#19751)
ad221c449ecf is described below
commit ad221c449ecf30967d21ff352b1862e1e3f8f4ef
Author: Lokesh Jain <[email protected]>
AuthorDate: Thu Aug 27 04:49:55 2026 +0530
fix(common): escape dots in single-level hive-style partition column names
(#19751)
---
.../hudi/common/util/PartitionPathEncodeUtils.java | 20 ++++++
.../common/util/TestPartitionPathEncodeUtils.java | 83 ++++++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/common/util/PartitionPathEncodeUtils.java
b/hudi-common/src/main/java/org/apache/hudi/common/util/PartitionPathEncodeUtils.java
index b3499fd75f26..a1c45d316740 100644
---
a/hudi-common/src/main/java/org/apache/hudi/common/util/PartitionPathEncodeUtils.java
+++
b/hudi-common/src/main/java/org/apache/hudi/common/util/PartitionPathEncodeUtils.java
@@ -79,6 +79,10 @@ public class PartitionPathEncodeUtils {
return c >= 0 && c < charToEscapeFilename.size() &&
charToEscapeFilename.get(c);
}
+ static boolean needsEscapingFilenameWithDot(char c) {
+ return c == '.' || needsEscapingFilename(c);
+ }
+
public static String escapePathName(String path) {
return escapePathName(path, null);
}
@@ -118,10 +122,26 @@ public class PartitionPathEncodeUtils {
return sb.toString();
}
+ /**
+ * Escapes a filename derived from a partition path for use in
metadata-table file ids.
+ * For a single-level hive-style segment (like "fare.currency=USD"), dots in
the column name
+ * (before the first '=') are escaped, since a literal dot there makes the
metadata log file
+ * name unparseable by the log-file pattern. Dots in the partition value
(after '=') are left
+ * as-is. Partition values that contain dots, and nested or non-hive-style
dotted paths, are
+ * not handled here.
+ */
public static String escapeFileName(String filename) {
if (filename == null || filename.length() == 0) {
return filename;
}
+ int eqIdx = filename.indexOf('=');
+ if (eqIdx > 0) {
+ // Hive-style partition path: escape dots only in the column name
(before '=')
+ String columnName = filename.substring(0, eqIdx);
+ String value = filename.substring(eqIdx); // includes '='
+ return doEscape(columnName,
PartitionPathEncodeUtils::needsEscapingFilenameWithDot)
+ + doEscape(value, PartitionPathEncodeUtils::needsEscapingFilename);
+ }
return doEscape(filename, PartitionPathEncodeUtils::needsEscapingFilename);
}
diff --git
a/hudi-common/src/test/java/org/apache/hudi/common/util/TestPartitionPathEncodeUtils.java
b/hudi-common/src/test/java/org/apache/hudi/common/util/TestPartitionPathEncodeUtils.java
new file mode 100644
index 000000000000..84e754a475a7
--- /dev/null
+++
b/hudi-common/src/test/java/org/apache/hudi/common/util/TestPartitionPathEncodeUtils.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Tests for {@link PartitionPathEncodeUtils}.
+ */
+public class TestPartitionPathEncodeUtils {
+
+ @Test
+ public void testEscapeFileNameWithDotInColumnName() {
+ // Dot in column name should be escaped
+ assertEquals("fare%2Ecurrency%3DUSD",
PartitionPathEncodeUtils.escapeFileName("fare.currency=USD"));
+ }
+
+ @Test
+ public void testEscapeFileNamePreservesDotInValue() {
+ // Dot in partition value should NOT be escaped (backward compatibility)
+ assertEquals("date%3D2024.01.01",
PartitionPathEncodeUtils.escapeFileName("date=2024.01.01"));
+ assertEquals("version%3D1.2.3",
PartitionPathEncodeUtils.escapeFileName("version=1.2.3"));
+ }
+
+ @Test
+ public void testEscapeFileNameWithDotInBothColumnAndValue() {
+ // Dot in column name escaped, dot in value preserved
+ assertEquals("col%2Ename%3Dval.ue",
PartitionPathEncodeUtils.escapeFileName("col.name=val.ue"));
+ }
+
+ @Test
+ public void testEscapeFileNameWithoutEquals() {
+ // No '=' means no hive-style partitioning; dots are NOT escaped (no
column name to protect)
+ assertEquals("simple", PartitionPathEncodeUtils.escapeFileName("simple"));
+ assertEquals("path.with.dots",
PartitionPathEncodeUtils.escapeFileName("path.with.dots"));
+ }
+
+ @Test
+ public void testEscapeFileNameNullAndEmpty() {
+ assertNull(PartitionPathEncodeUtils.escapeFileName(null));
+ assertEquals("", PartitionPathEncodeUtils.escapeFileName(""));
+ }
+
+ @Test
+ public void testEscapeFileNameNoDotsHiveStyle() {
+ // Standard hive-style without dots
+ assertEquals("country%3DUS",
PartitionPathEncodeUtils.escapeFileName("country=US"));
+ }
+
+ @Test
+ public void testUnescapeRoundTrip() {
+ String original = "fare.currency=USD";
+ String escaped = PartitionPathEncodeUtils.escapeFileName(original);
+ assertEquals("fare%2Ecurrency%3DUSD", escaped);
+ assertEquals(original, PartitionPathEncodeUtils.unescapePathName(escaped));
+ }
+
+ @Test
+ public void testUnescapeRoundTripWithDotInValue() {
+ String original = "date=2024.01.01";
+ String escaped = PartitionPathEncodeUtils.escapeFileName(original);
+ assertEquals("date%3D2024.01.01", escaped);
+ assertEquals(original, PartitionPathEncodeUtils.unescapePathName(escaped));
+ }
+}