Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private Object parseValue(String valueStr, CastExecutor<BinaryString, Object> ca
: castExecutor.cast(BinaryString.fromString(valueStr));
}

private List<String> splitMapEntries(String content) {
public List<String> splitMapEntries(String content) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can introduce something like Spark CollationAwareUTF8String.splitSQL.

Copy link
Contributor Author

@YannByron YannByron Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's research it, but can we deal with it with this tiny change?

List<String> entries = new ArrayList<>();
StringBuilder current = new StringBuilder();
Stack<Character> bracketStack = new Stack<>();
Expand All @@ -186,10 +186,13 @@ private List<String> splitMapEntries(String content) {
for (char c : content.toCharArray()) {
if (escaped) {
escaped = false;
continue;
} else if (c == '\\') {
escaped = true;
continue;
} else if (c == '"') {
inQuotes = !inQuotes;
continue;
} else if (!inQuotes) {
if (StringUtils.isOpenBracket(c)) {
bracketStack.push(c);
Expand All @@ -209,7 +212,7 @@ private List<String> splitMapEntries(String content) {

private void addCurrentEntry(List<String> entries, StringBuilder current) {
if (current.length() > 0) {
entries.add(current.toString());
entries.add(current.toString().trim());
current.setLength(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

Expand Down Expand Up @@ -898,6 +899,13 @@ public void testRowToString() {
BinaryString.fromString("{1, {2025-01-06, {1 -> [1, null, 2]}, null}}"));
}

@Test
public void testSplitMapEntriesWithQuotes() {
String content = "1, \"abc\"";
List<String> result = StringToMapCastRule.INSTANCE.splitMapEntries(content);
assertThat(result).containsExactly("1", "abc");
}

@SuppressWarnings("rawtypes")
private void compareCastResult(CastExecutor<?, ?> cast, Object input, Object output) {
assertThat(((CastExecutor) cast).cast(input)).isEqualTo(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,43 @@ class DefaultValueTest extends PaimonSparkTestBase {
}
}

test("Default Value: map type with string element") {
withTable("t") {
spark.sql("""CREATE TABLE IF NOT EXISTS t (
| id BIGINT NOT NULL,
| col1 MAP<BIGINT, STRING> DEFAULT NULL,
| col2 MAP<BIGINT, STRING> DEFAULT map(),
| col3 MAP<BIGINT, STRING> DEFAULT map(9999, "hello")
|) using paimon;
|""".stripMargin)

spark.sql("""
|INSERT INTO t VALUES
| (1, map(1, "a", 11, "aa"), map(2, "b"), map(3, "c")),
| (2, null, map(5, "e", 55, "ee"), map(6, "f")),
| (3, map(7, "g"), null, map(9, "i", 99, "ii")),
| (4, map(10, "j"), map(11, "k"), null),
| (5, null, null, map(15, "o")),
| (6, null, map(17, "q"), null),
| (7, map(19, "r"), null, null),
| (8, null, null, null)
|""".stripMargin)

checkAnswer(
spark.sql("SELECT * FROM t ORDER BY id"),
Row(1, Map(1 -> "a", 11 -> "aa"), Map(2 -> "b"), Map(3 -> "c"))
:: Row(2, null, Map(5 -> "e", 55 -> "ee"), Map(6 -> "f"))
:: Row(3, Map(7 -> "g"), Map(), Map(9 -> "i", 99 -> "ii"))
:: Row(4, Map(10 -> "j"), Map(11 -> "k"), Map(9999 -> "hello"))
:: Row(5, null, Map(), Map(15 -> "o"))
:: Row(6, null, Map(17 -> "q"), Map(9999 -> "hello"))
:: Row(7, Map(19 -> "r"), Map(), Map(9999 -> "hello"))
:: Row(8, null, Map(), Map(9999 -> "hello"))
:: Nil
)
}
}

test("Default Value: unsupported default value") {
withTimeZone("Asia/Shanghai") {
withTable("t") {
Expand Down
Loading