This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new ec51af81cf [common] Keep escaped characters in StringToMapCastRule
entry splitting (#9620)
ec51af81cf is described below
commit ec51af81cf9175718829f8e99e7dc7b61b9f0987
Author: YangJie <[email protected]>
AuthorDate: Thu Sep 10 02:53:12 2026 -0400
[common] Keep escaped characters in StringToMapCastRule entry splitting
(#9620)
---
.../apache/paimon/casting/StringToMapCastRule.java | 3 +++
.../apache/paimon/casting/CastExecutorTest.java | 25 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git
a/paimon-common/src/main/java/org/apache/paimon/casting/StringToMapCastRule.java
b/paimon-common/src/main/java/org/apache/paimon/casting/StringToMapCastRule.java
index 2183a67d77..d700e9c6d8 100644
---
a/paimon-common/src/main/java/org/apache/paimon/casting/StringToMapCastRule.java
+++
b/paimon-common/src/main/java/org/apache/paimon/casting/StringToMapCastRule.java
@@ -181,7 +181,10 @@ class StringToMapCastRule extends
AbstractCastRule<BinaryString, InternalMap> {
for (char c : content.toCharArray()) {
if (escaped) {
+ // an escaped character is taken literally: it must survive in
the
+ // entry instead of being dropped together with its backslash
escaped = false;
+ current.append(c);
continue;
} else if (c == '\\') {
escaped = true;
diff --git
a/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
b/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
index a1cf992a2f..31a776c87d 100644
---
a/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
+++
b/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
@@ -982,6 +982,31 @@ public class CastExecutorTest {
assertThat(result).containsExactly("1", "abc");
}
+ @Test
+ public void testSplitMapEntriesWithEscapes() {
+ // the escaped separator must survive as a literal instead of vanishing
+ assertThat(StringToMapCastRule.INSTANCE.splitMapEntries("a\\,b, c"))
+ .containsExactly("a,b", "c");
+ // an escaped backslash yields one literal backslash
+ assertThat(StringToMapCastRule.INSTANCE.splitMapEntries("x\\\\y, z"))
+ .containsExactly("x\\y", "z");
+ // an escaped quote is a literal and does not toggle quote state
+ assertThat(StringToMapCastRule.INSTANCE.splitMapEntries("\"q\\\"z,
w\""))
+ .containsExactly("q\"z, w");
+ }
+
+ @Test
+ public void testStringToMapPreservesEscapedCharacters() {
+ Map<Object, Object> expected = new HashMap<>();
+ expected.put(BinaryString.fromString("a,b"),
BinaryString.fromString("v\\1"));
+ compareCastResult(
+ CastExecutors.resolve(
+ VarCharType.STRING_TYPE,
+ new MapType(DataTypes.STRING(), DataTypes.STRING())),
+ BinaryString.fromString("{a\\,b -> v\\\\1}"),
+ new GenericMap(expected));
+ }
+
@SuppressWarnings("rawtypes")
private void compareCastResult(CastExecutor<?, ?> cast, Object input,
Object output) {
assertThat(((CastExecutor) cast).cast(input)).isEqualTo(output);