Skip to content

Commit c6746dd

Browse files
Issue GoogleCloudDataproc#1126: Making SparkBigQueryConfig Kryo compatible (GoogleCloudDataproc#1243)
1 parent 2c1a865 commit c6746dd

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next
44

5+
* Issue #1126: Fixing Kryo serialization issues
56
* PR #1236: Fixing unshaded artifacts, added shading verification
67

78
## 0.39.0 - 2024-05-21

spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/SparkBigQueryConfig.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
import java.time.format.DateTimeFormatter;
6363
import java.time.format.DateTimeParseException;
6464
import java.util.Arrays;
65+
import java.util.Collections;
6566
import java.util.HashMap;
67+
import java.util.List;
6668
import java.util.Locale;
6769
import java.util.Map;
6870
import java.util.Optional;
@@ -207,8 +209,8 @@ public static WriteMethod from(@Nullable String writeMethod) {
207209
com.google.common.base.Optional<JobInfo.CreateDisposition> createDisposition = empty();
208210
boolean optimizedEmptyProjection = true;
209211
boolean useAvroLogicalTypes = false;
210-
ImmutableList<String> decimalTargetTypes = ImmutableList.of();
211-
ImmutableList<JobInfo.SchemaUpdateOption> loadSchemaUpdateOptions = ImmutableList.of();
212+
List<String> decimalTargetTypes = Collections.emptyList();
213+
List<JobInfo.SchemaUpdateOption> loadSchemaUpdateOptions = Collections.emptyList();
212214
int materializationExpirationTimeInMinutes;
213215
int maxReadRowsRetries = 3;
214216
boolean pushAllFilters = true;
@@ -233,8 +235,8 @@ public static WriteMethod from(@Nullable String writeMethod) {
233235
private int cacheExpirationTimeInMinutes = DEFAULT_CACHE_EXPIRATION_IN_MINUTES;
234236
// used to create BigQuery ReadSessions
235237
private com.google.common.base.Optional<String> traceId;
236-
private ImmutableMap<String, String> bigQueryJobLabels = ImmutableMap.of();
237-
private ImmutableMap<String, String> bigQueryTableLabels = ImmutableMap.of();
238+
private Map<String, String> bigQueryJobLabels = Collections.emptyMap();
239+
private Map<String, String> bigQueryTableLabels = Collections.emptyMap();
238240
private com.google.common.base.Optional<Long> createReadSessionTimeoutInSeconds;
239241
private QueryJobConfiguration.Priority queryJobPriority = DEFAULT_JOB_PRIORITY;
240242

@@ -464,11 +466,11 @@ public static SparkBigQueryConfig from(
464466
if (allowFieldRelaxation) {
465467
loadSchemaUpdateOptions.add(JobInfo.SchemaUpdateOption.ALLOW_FIELD_RELAXATION);
466468
}
467-
config.loadSchemaUpdateOptions = loadSchemaUpdateOptions.build();
469+
config.loadSchemaUpdateOptions = Collections.unmodifiableList(loadSchemaUpdateOptions.build());
468470
com.google.common.base.Optional<String[]> decimalTargetTypes =
469471
getOption(options, "decimalTargetTypes").transform(s -> s.split(","));
470472
if (decimalTargetTypes.isPresent()) {
471-
config.decimalTargetTypes = ImmutableList.copyOf(decimalTargetTypes.get());
473+
config.decimalTargetTypes = Arrays.asList(decimalTargetTypes.get());
472474
}
473475
config.bigQueryStorageGrpcEndpoint =
474476
getAnyOption(globalOptions, options, "bigQueryStorageGrpcEndpoint");
@@ -630,7 +632,7 @@ private static com.google.common.base.Optional<String> stripPrefix(
630632
// takes only the options with the BIGQUERY_JOB_LABEL_PREFIX prefix, and strip them of this
631633
// prefix.
632634
// The `options` map overrides the `globalOptions` map.
633-
static ImmutableMap<String, String> parseBigQueryLabels(
635+
static Map<String, String> parseBigQueryLabels(
634636
ImmutableMap<String, String> globalOptions,
635637
ImmutableMap<String, String> options,
636638
String labelPrefix) {
@@ -650,7 +652,7 @@ static ImmutableMap<String, String> parseBigQueryLabels(
650652
}
651653
}
652654

653-
return result.build();
655+
return Collections.unmodifiableMap(result.build());
654656
}
655657

656658
private static ImmutableMap<String, String> toLowerCaseKeysMap(Map<String, String> map) {
@@ -859,7 +861,7 @@ public boolean isUseAvroLogicalTypes() {
859861
}
860862

861863
public ImmutableList<String> getDecimalTargetTypes() {
862-
return decimalTargetTypes;
864+
return ImmutableList.copyOf(decimalTargetTypes);
863865
}
864866

865867
public boolean isViewsEnabled() {
@@ -925,7 +927,7 @@ public boolean isOptimizedEmptyProjection() {
925927
}
926928

927929
public ImmutableList<JobInfo.SchemaUpdateOption> getLoadSchemaUpdateOptions() {
928-
return loadSchemaUpdateOptions;
930+
return ImmutableList.copyOf(loadSchemaUpdateOptions);
929931
}
930932

931933
public int getMaterializationExpirationTimeInMinutes() {
@@ -1049,7 +1051,7 @@ public Optional<String> getTraceId() {
10491051

10501052
@Override
10511053
public ImmutableMap<String, String> getBigQueryJobLabels() {
1052-
return bigQueryJobLabels;
1054+
return ImmutableMap.copyOf(bigQueryJobLabels);
10531055
}
10541056

10551057
public boolean getAllowMapTypeConversion() {
@@ -1061,7 +1063,7 @@ public long getBigQueryJobTimeoutInMinutes() {
10611063
}
10621064

10631065
public ImmutableMap<String, String> getBigQueryTableLabels() {
1064-
return bigQueryTableLabels;
1066+
return ImmutableMap.copyOf(bigQueryTableLabels);
10651067
}
10661068

10671069
public Optional<String> getGpn() {

spark-bigquery-connector-common/src/test/java/com/google/cloud/spark/bigquery/SparkBigQueryConfigTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public void testJobLabelOverride() {
497497
.put("bigQueryJobLabel.foo", "2")
498498
.put("bigQueryJobLabel.baz", "2")
499499
.build();
500-
ImmutableMap<String, String> labels =
500+
Map<String, String> labels =
501501
SparkBigQueryConfig.parseBigQueryLabels(globalOptions, options, BIGQUERY_JOB_LABEL_PREFIX);
502502
assertThat(labels).hasSize(3);
503503
assertThat(labels).containsEntry("foo", "2");
@@ -518,7 +518,7 @@ public void testTableLabelOverride() {
518518
.put("bigQueryTableLabel.foo", "2")
519519
.put("bigQueryTableLabel.baz", "2")
520520
.build();
521-
ImmutableMap<String, String> labels =
521+
Map<String, String> labels =
522522
SparkBigQueryConfig.parseBigQueryLabels(
523523
globalOptions, options, BIGQUERY_TABLE_LABEL_PREFIX);
524524
assertThat(labels).hasSize(3);

0 commit comments

Comments
 (0)