Skip to content

Commit d4c2ef8

Browse files
authored
Spark 3.5: Support camel case session configs and options (apache#10310)
1 parent dd2197f commit d4c2ef8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkConfParser.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,23 @@ protected T parse(Function<String, T> conversion, T defaultValue) {
270270
if (optionValue != null) {
271271
return conversion.apply(optionValue);
272272
}
273+
274+
String sparkOptionValue = options.get(toCamelCase(optionName));
275+
if (sparkOptionValue != null) {
276+
return conversion.apply(sparkOptionValue);
277+
}
273278
}
274279

275280
if (sessionConfName != null) {
276281
String sessionConfValue = sessionConf.get(sessionConfName, null);
277282
if (sessionConfValue != null) {
278283
return conversion.apply(sessionConfValue);
279284
}
285+
286+
String sparkSessionConfValue = sessionConf.get(toCamelCase(sessionConfName), null);
287+
if (sparkSessionConfValue != null) {
288+
return conversion.apply(sparkSessionConfValue);
289+
}
280290
}
281291

282292
if (tablePropertyName != null) {
@@ -288,5 +298,23 @@ protected T parse(Function<String, T> conversion, T defaultValue) {
288298

289299
return defaultValue;
290300
}
301+
302+
private String toCamelCase(String key) {
303+
StringBuilder transformedKey = new StringBuilder();
304+
boolean capitalizeNext = false;
305+
306+
for (char character : key.toCharArray()) {
307+
if (character == '-') {
308+
capitalizeNext = true;
309+
} else if (capitalizeNext) {
310+
transformedKey.append(Character.toUpperCase(character));
311+
capitalizeNext = false;
312+
} else {
313+
transformedKey.append(character);
314+
}
315+
}
316+
317+
return transformedKey.toString();
318+
}
291319
}
292320
}

spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/TestSparkWriteConf.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ public void testOptionCaseInsensitive() {
8888
assertThat(parsedValue).isEqualTo("value");
8989
}
9090

91+
@TestTemplate
92+
public void testCamelCaseSparkSessionConf() {
93+
Table table = validationCatalog.loadTable(tableIdent);
94+
String confName = "spark.sql.iceberg.some-int-conf";
95+
String sparkConfName = "spark.sql.iceberg.someIntConf";
96+
97+
withSQLConf(
98+
ImmutableMap.of(sparkConfName, "1"),
99+
() -> {
100+
SparkConfParser parser = new SparkConfParser(spark, table, ImmutableMap.of());
101+
Integer value = parser.intConf().sessionConf(confName).parseOptional();
102+
assertThat(value).isEqualTo(1);
103+
});
104+
}
105+
106+
@TestTemplate
107+
public void testCamelCaseSparkOption() {
108+
Table table = validationCatalog.loadTable(tableIdent);
109+
String option = "some-int-option";
110+
String sparkOption = "someIntOption";
111+
Map<String, String> options = ImmutableMap.of(sparkOption, "1");
112+
SparkConfParser parser = new SparkConfParser(spark, table, options);
113+
Integer value = parser.intConf().option(option).parseOptional();
114+
assertThat(value).isEqualTo(1);
115+
}
116+
91117
@TestTemplate
92118
public void testDurationConf() {
93119
Table table = validationCatalog.loadTable(tableIdent);

0 commit comments

Comments
 (0)