@@ -78,7 +78,8 @@ public class SparkBigQueryConfig
78
78
79
79
public enum WriteMethod {
80
80
DIRECT ,
81
- INDIRECT ;
81
+ INDIRECT ,
82
+ OLD_INDIRECT ;
82
83
83
84
public static WriteMethod from (@ Nullable String writeMethod ) {
84
85
try {
@@ -96,6 +97,7 @@ public static WriteMethod from(@Nullable String writeMethod) {
96
97
public static final String VALIDATE_SPARK_AVRO_PARAM = "validateSparkAvroInternalParam" ;
97
98
public static final String ENABLE_LIST_INFERENCE = "enableListInference" ;
98
99
public static final String INTERMEDIATE_FORMAT_OPTION = "intermediateFormat" ;
100
+ public static final String WRITE_METHOD_PARAM = "writeMethod" ;
99
101
@ VisibleForTesting static final DataFormat DEFAULT_READ_DATA_FORMAT = DataFormat .ARROW ;
100
102
101
103
@ VisibleForTesting
@@ -186,6 +188,7 @@ public static WriteMethod from(@Nullable String writeMethod) {
186
188
// the catalog ones
187
189
public static SparkBigQueryConfig from (
188
190
Map <String , String > options ,
191
+ ImmutableMap <String , String > customDefaults ,
189
192
DataSourceVersion dataSourceVersion ,
190
193
SparkSession spark ,
191
194
Optional <StructType > schema ,
@@ -196,6 +199,7 @@ public static SparkBigQueryConfig from(
196
199
ImmutableMap .copyOf (optionsMap ),
197
200
ImmutableMap .copyOf (mapAsJavaMap (spark .conf ().getAll ())),
198
201
spark .sparkContext ().hadoopConfiguration (),
202
+ customDefaults ,
199
203
spark .sparkContext ().defaultParallelism (),
200
204
spark .sqlContext ().conf (),
201
205
spark .version (),
@@ -208,6 +212,7 @@ public static SparkBigQueryConfig from(
208
212
Map <String , String > optionsInput ,
209
213
ImmutableMap <String , String > originalGlobalOptions ,
210
214
Configuration hadoopConfiguration ,
215
+ ImmutableMap <String , String > customDefaults ,
211
216
int defaultParallelism ,
212
217
SQLConf sqlConf ,
213
218
String sparkVersion ,
@@ -375,10 +380,14 @@ public static SparkBigQueryConfig from(
375
380
.transform (String ::toUpperCase )
376
381
.or (DEFAULT_ARROW_COMPRESSION_CODEC .toString ());
377
382
383
+ WriteMethod writeMethodDefault =
384
+ Optional .ofNullable (customDefaults .get (WRITE_METHOD_PARAM ))
385
+ .map (WriteMethod ::from )
386
+ .orElse (DEFAULT_WRITE_METHOD );
378
387
config .writeMethod =
379
- getAnyOption (globalOptions , options , "writeMethod" )
388
+ getAnyOption (globalOptions , options , WRITE_METHOD_PARAM )
380
389
.transform (WriteMethod ::from )
381
- .or (DEFAULT_WRITE_METHOD );
390
+ .or (writeMethodDefault );
382
391
383
392
try {
384
393
config .arrowCompressionCodec = CompressionCodec .valueOf (arrowCompressionCodecParam );
@@ -844,8 +853,8 @@ static boolean isSpark24OrAbove(String sparkVersion) {
844
853
}
845
854
846
855
// could not load the spark-avro data source
847
- private static IllegalStateException missingAvroException (
848
- String sparkVersion , Exception cause ) {
856
+ @ VisibleForTesting
857
+ static IllegalStateException missingAvroException ( String sparkVersion , Exception cause ) {
849
858
String avroPackage ;
850
859
if (isSpark24OrAbove (sparkVersion )) {
851
860
String scalaVersion = scala .util .Properties .versionNumberString ();
0 commit comments