forked from googleapis/java-bigquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadJobConfiguration.java
808 lines (724 loc) · 29.7 KB
/
LoadJobConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
* Copyright 2016 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigquery;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.api.services.bigquery.model.JobConfigurationLoad;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Google BigQuery load job configuration. A load job loads data from one of several formats into a
* table. Data is provided as URIs that point to objects in Google Cloud Storage. Load job
* configurations have {@link JobConfiguration.Type#LOAD} type.
*/
public final class LoadJobConfiguration extends JobConfiguration implements LoadConfiguration {
private static final long serialVersionUID = -2673554846792429829L;
private final List<String> sourceUris;
private final String fileSetSpecType;
private final TableId destinationTable;
private final List<String> decimalTargetTypes;
private final EncryptionConfiguration destinationEncryptionConfiguration;
private final JobInfo.CreateDisposition createDisposition;
private final JobInfo.WriteDisposition writeDisposition;
private final FormatOptions formatOptions;
private final String nullMarker;
private final Integer maxBadRecords;
private final Schema schema;
private final Boolean ignoreUnknownValues;
private final List<JobInfo.SchemaUpdateOption> schemaUpdateOptions;
private final Boolean autodetect;
private final TimePartitioning timePartitioning;
private final Clustering clustering;
private final Boolean useAvroLogicalTypes;
private final Map<String, String> labels;
private final Long jobTimeoutMs;
private final RangePartitioning rangePartitioning;
private final HivePartitioningOptions hivePartitioningOptions;
private final String referenceFileSchemaUri;
private final List<ConnectionProperty> connectionProperties;
private final Boolean createSession;
public static final class Builder extends JobConfiguration.Builder<LoadJobConfiguration, Builder>
implements LoadConfiguration.Builder {
private List<String> sourceUris;
private String fileSetSpecType;
private TableId destinationTable;
private List<String> decimalTargetTypes;
private EncryptionConfiguration destinationEncryptionConfiguration;
private JobInfo.CreateDisposition createDisposition;
private JobInfo.WriteDisposition writeDisposition;
private FormatOptions formatOptions;
private String nullMarker;
private Integer maxBadRecords;
private Schema schema;
private Boolean ignoreUnknownValues;
private List<String> projectionFields;
private List<JobInfo.SchemaUpdateOption> schemaUpdateOptions;
private Boolean autodetect;
private TimePartitioning timePartitioning;
private Clustering clustering;
private Boolean useAvroLogicalTypes;
private Map<String, String> labels;
private Long jobTimeoutMs;
private RangePartitioning rangePartitioning;
private HivePartitioningOptions hivePartitioningOptions;
private String referenceFileSchemaUri;
private List<ConnectionProperty> connectionProperties;
private Boolean createSession;
private Builder() {
super(Type.LOAD);
}
private Builder(LoadJobConfiguration loadConfiguration) {
this();
this.destinationTable = loadConfiguration.destinationTable;
this.decimalTargetTypes = loadConfiguration.decimalTargetTypes;
this.createDisposition = loadConfiguration.createDisposition;
this.writeDisposition = loadConfiguration.writeDisposition;
this.formatOptions = loadConfiguration.formatOptions;
this.nullMarker = loadConfiguration.nullMarker;
this.maxBadRecords = loadConfiguration.maxBadRecords;
this.schema = loadConfiguration.schema;
this.ignoreUnknownValues = loadConfiguration.ignoreUnknownValues;
this.sourceUris = loadConfiguration.sourceUris;
this.fileSetSpecType = loadConfiguration.fileSetSpecType;
this.schemaUpdateOptions = loadConfiguration.schemaUpdateOptions;
this.autodetect = loadConfiguration.autodetect;
this.destinationEncryptionConfiguration =
loadConfiguration.destinationEncryptionConfiguration;
this.timePartitioning = loadConfiguration.timePartitioning;
this.clustering = loadConfiguration.clustering;
this.useAvroLogicalTypes = loadConfiguration.useAvroLogicalTypes;
this.labels = loadConfiguration.labels;
this.jobTimeoutMs = loadConfiguration.jobTimeoutMs;
this.rangePartitioning = loadConfiguration.rangePartitioning;
this.hivePartitioningOptions = loadConfiguration.hivePartitioningOptions;
this.referenceFileSchemaUri = loadConfiguration.referenceFileSchemaUri;
this.connectionProperties = loadConfiguration.connectionProperties;
this.createSession = loadConfiguration.createSession;
}
private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
this();
JobConfigurationLoad loadConfigurationPb = configurationPb.getLoad();
this.destinationTable = TableId.fromPb(loadConfigurationPb.getDestinationTable());
if (loadConfigurationPb.getDecimalTargetTypes() != null) {
this.decimalTargetTypes = ImmutableList.copyOf(loadConfigurationPb.getDecimalTargetTypes());
}
if (loadConfigurationPb.getCreateDisposition() != null) {
this.createDisposition =
JobInfo.CreateDisposition.valueOf(loadConfigurationPb.getCreateDisposition());
}
if (loadConfigurationPb.getWriteDisposition() != null) {
this.writeDisposition =
JobInfo.WriteDisposition.valueOf(loadConfigurationPb.getWriteDisposition());
}
if (loadConfigurationPb.getSourceFormat() != null) {
this.formatOptions = FormatOptions.of(loadConfigurationPb.getSourceFormat());
}
if (loadConfigurationPb.getNullMarker() != null) {
this.nullMarker = loadConfigurationPb.getNullMarker();
}
if (loadConfigurationPb.getAllowJaggedRows() != null
|| loadConfigurationPb.getAllowQuotedNewlines() != null
|| loadConfigurationPb.getEncoding() != null
|| loadConfigurationPb.getFieldDelimiter() != null
|| loadConfigurationPb.getQuote() != null
|| loadConfigurationPb.getSkipLeadingRows() != null) {
CsvOptions.Builder builder =
CsvOptions.newBuilder()
.setEncoding(loadConfigurationPb.getEncoding())
.setFieldDelimiter(loadConfigurationPb.getFieldDelimiter())
.setQuote(loadConfigurationPb.getQuote());
if (loadConfigurationPb.getAllowJaggedRows() != null) {
builder.setAllowJaggedRows(loadConfigurationPb.getAllowJaggedRows());
}
if (loadConfigurationPb.getAllowQuotedNewlines() != null) {
builder.setAllowQuotedNewLines(loadConfigurationPb.getAllowQuotedNewlines());
}
if (loadConfigurationPb.getSkipLeadingRows() != null) {
builder.setSkipLeadingRows(loadConfigurationPb.getSkipLeadingRows());
}
this.formatOptions = builder.build();
}
this.maxBadRecords = loadConfigurationPb.getMaxBadRecords();
if (loadConfigurationPb.getSchema() != null) {
this.schema = Schema.fromPb(loadConfigurationPb.getSchema());
}
this.ignoreUnknownValues = loadConfigurationPb.getIgnoreUnknownValues();
this.projectionFields = loadConfigurationPb.getProjectionFields();
if (loadConfigurationPb.getSourceUris() != null) {
this.sourceUris = ImmutableList.copyOf(configurationPb.getLoad().getSourceUris());
}
if (loadConfigurationPb.getFileSetSpecType() != null) {
this.fileSetSpecType = loadConfigurationPb.getFileSetSpecType();
}
if (loadConfigurationPb.getSchemaUpdateOptions() != null) {
ImmutableList.Builder<JobInfo.SchemaUpdateOption> schemaUpdateOptionsBuilder =
new ImmutableList.Builder<>();
for (String rawSchemaUpdateOption : loadConfigurationPb.getSchemaUpdateOptions()) {
schemaUpdateOptionsBuilder.add(JobInfo.SchemaUpdateOption.valueOf(rawSchemaUpdateOption));
}
this.schemaUpdateOptions = schemaUpdateOptionsBuilder.build();
}
if (loadConfigurationPb.getTimePartitioning() != null) {
this.timePartitioning = TimePartitioning.fromPb(loadConfigurationPb.getTimePartitioning());
}
if (loadConfigurationPb.getClustering() != null) {
this.clustering = Clustering.fromPb(loadConfigurationPb.getClustering());
}
this.autodetect = loadConfigurationPb.getAutodetect();
this.useAvroLogicalTypes = loadConfigurationPb.getUseAvroLogicalTypes();
if (loadConfigurationPb.getDestinationEncryptionConfiguration() != null) {
this.destinationEncryptionConfiguration =
new EncryptionConfiguration.Builder(
loadConfigurationPb.getDestinationEncryptionConfiguration())
.build();
}
if (configurationPb.getLabels() != null) {
this.labels = configurationPb.getLabels();
}
if (configurationPb.getJobTimeoutMs() != null) {
this.jobTimeoutMs = configurationPb.getJobTimeoutMs();
}
if (loadConfigurationPb.getRangePartitioning() != null) {
this.rangePartitioning =
RangePartitioning.fromPb(loadConfigurationPb.getRangePartitioning());
}
if (loadConfigurationPb.getHivePartitioningOptions() != null) {
this.hivePartitioningOptions =
HivePartitioningOptions.fromPb(loadConfigurationPb.getHivePartitioningOptions());
}
if (loadConfigurationPb.getReferenceFileSchemaUri() != null) {
this.referenceFileSchemaUri = loadConfigurationPb.getReferenceFileSchemaUri();
}
if (loadConfigurationPb.getConnectionProperties() != null) {
this.connectionProperties =
Lists.transform(
loadConfigurationPb.getConnectionProperties(), ConnectionProperty.FROM_PB_FUNCTION);
}
createSession = loadConfigurationPb.getCreateSession();
}
@Override
public Builder setDestinationTable(TableId destinationTable) {
this.destinationTable = destinationTable;
return this;
}
@Override
public Builder setDestinationEncryptionConfiguration(
EncryptionConfiguration encryptionConfiguration) {
this.destinationEncryptionConfiguration = encryptionConfiguration;
return this;
}
@Override
public Builder setCreateDisposition(JobInfo.CreateDisposition createDisposition) {
this.createDisposition = createDisposition;
return this;
}
@Override
public Builder setWriteDisposition(JobInfo.WriteDisposition writeDisposition) {
this.writeDisposition = writeDisposition;
return this;
}
@Override
public Builder setFormatOptions(FormatOptions formatOptions) {
this.formatOptions = formatOptions;
return this;
}
@Override
public Builder setNullMarker(String nullMarker) {
this.nullMarker = nullMarker;
return this;
}
@Override
public Builder setMaxBadRecords(Integer maxBadRecords) {
this.maxBadRecords = maxBadRecords;
return this;
}
@Override
public Builder setSchema(Schema schema) {
this.schema = schema;
return this;
}
@Override
public Builder setIgnoreUnknownValues(Boolean ignoreUnknownValues) {
this.ignoreUnknownValues = ignoreUnknownValues;
return this;
}
@Override
public Builder setTimePartitioning(TimePartitioning timePartitioning) {
this.timePartitioning = timePartitioning;
return this;
}
@Override
public Builder setClustering(Clustering clustering) {
this.clustering = clustering;
return this;
}
@Override
public Builder setUseAvroLogicalTypes(Boolean useAvroLogicalTypes) {
this.useAvroLogicalTypes = useAvroLogicalTypes;
return this;
}
/**
* Sets the fully-qualified URIs that point to source data in Google Cloud Storage (e.g.
* gs://bucket/path). Each URI can contain one '*' wildcard character and it must come after the
* 'bucket' name.
*/
public Builder setSourceUris(List<String> sourceUris) {
this.sourceUris = ImmutableList.copyOf(checkNotNull(sourceUris));
return this;
}
/**
* Defines how to interpret files denoted by URIs. By default the files are assumed to be data
* files (this can be specified explicitly via FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH). A second
* option is "FILE_SET_SPEC_TYPE_NEW_LINE_DELIMITED_MANIFEST" which interprets each file as a
* manifest file, where each line is a reference to a file.
*/
public Builder setFileSetSpecType(String fileSetSpecType) {
this.fileSetSpecType = fileSetSpecType;
return this;
}
/**
* Defines the list of possible SQL data types to which the source decimal values are converted.
* This list and the precision and the scale parameters of the decimal field determine the
* target type. In the order of NUMERIC, BIGNUMERIC, and STRING, a type is picked if it is in
* the specified list and if it supports the precision and the scale. STRING supports all
* precision and scale values.
*
* @param decimalTargetTypes decimalTargetType or {@code null} for none
*/
public Builder setDecimalTargetTypes(List<String> decimalTargetTypes) {
this.decimalTargetTypes = decimalTargetTypes;
return this;
}
public Builder setAutodetect(Boolean autodetect) {
this.autodetect = autodetect;
return this;
}
@Override
public Builder setSchemaUpdateOptions(List<JobInfo.SchemaUpdateOption> schemaUpdateOptions) {
this.schemaUpdateOptions =
schemaUpdateOptions != null ? ImmutableList.copyOf(schemaUpdateOptions) : null;
return this;
}
/**
* The labels associated with this job. You can use these to organize and group your jobs. Label
* keys and values can be no longer than 63 characters, can only contain lowercase letters,
* numeric characters, underscores and dashes. International characters are allowed. Label
* values are optional. Label keys must start with a letter and each label in the list must have
* a different key.
*
* @param labels labels or {@code null} for none
*/
public Builder setLabels(Map<String, String> labels) {
this.labels = labels;
return this;
}
/**
* [Optional] Job timeout in milliseconds. If this time limit is exceeded, BigQuery may attempt
* to terminate the job.
*
* @param jobTimeoutMs jobTimeoutMs or {@code null} for none
*/
public Builder setJobTimeoutMs(Long jobTimeoutMs) {
this.jobTimeoutMs = jobTimeoutMs;
return this;
}
/**
* Range partitioning specification for this table. Only one of timePartitioning and
* rangePartitioning should be specified.
*
* @param rangePartitioning rangePartitioning or {@code null} for none
*/
public Builder setRangePartitioning(RangePartitioning rangePartitioning) {
this.rangePartitioning = rangePartitioning;
return this;
}
public Builder setHivePartitioningOptions(HivePartitioningOptions hivePartitioningOptions) {
this.hivePartitioningOptions = hivePartitioningOptions;
return this;
}
/**
* When creating an external table, the user can provide a reference file with the table schema.
* This is enabled for the following formats: AVRO, PARQUET, ORC.
*
* @param referenceFileSchemaUri or {@code null} for none
*/
public Builder setReferenceFileSchemaUri(String referenceFileSchemaUri) {
this.referenceFileSchemaUri = referenceFileSchemaUri;
return this;
}
public Builder setConnectionProperties(List<ConnectionProperty> connectionProperties) {
this.connectionProperties = ImmutableList.copyOf(connectionProperties);
return this;
}
public Builder setCreateSession(Boolean createSession) {
this.createSession = createSession;
return this;
}
@Override
public LoadJobConfiguration build() {
return new LoadJobConfiguration(this);
}
}
private LoadJobConfiguration(Builder builder) {
super(builder);
this.sourceUris = builder.sourceUris;
this.fileSetSpecType = builder.fileSetSpecType;
this.destinationTable = builder.destinationTable;
this.decimalTargetTypes = builder.decimalTargetTypes;
this.createDisposition = builder.createDisposition;
this.writeDisposition = builder.writeDisposition;
this.formatOptions = builder.formatOptions;
this.nullMarker = builder.nullMarker;
this.maxBadRecords = builder.maxBadRecords;
this.schema = builder.schema;
this.ignoreUnknownValues = builder.ignoreUnknownValues;
this.schemaUpdateOptions = builder.schemaUpdateOptions;
this.autodetect = builder.autodetect;
this.destinationEncryptionConfiguration = builder.destinationEncryptionConfiguration;
this.timePartitioning = builder.timePartitioning;
this.clustering = builder.clustering;
this.useAvroLogicalTypes = builder.useAvroLogicalTypes;
this.labels = builder.labels;
this.jobTimeoutMs = builder.jobTimeoutMs;
this.rangePartitioning = builder.rangePartitioning;
this.hivePartitioningOptions = builder.hivePartitioningOptions;
this.referenceFileSchemaUri = builder.referenceFileSchemaUri;
this.connectionProperties = builder.connectionProperties;
this.createSession = builder.createSession;
}
@Override
public TableId getDestinationTable() {
return destinationTable;
}
@Override
public EncryptionConfiguration getDestinationEncryptionConfiguration() {
return destinationEncryptionConfiguration;
}
@Override
public JobInfo.CreateDisposition getCreateDisposition() {
return this.createDisposition;
}
@Override
public JobInfo.WriteDisposition getWriteDisposition() {
return writeDisposition;
}
@Override
public String getNullMarker() {
return nullMarker;
}
@Override
public CsvOptions getCsvOptions() {
return formatOptions instanceof CsvOptions ? (CsvOptions) formatOptions : null;
}
public ParquetOptions getParquetOptions() {
return formatOptions instanceof ParquetOptions ? (ParquetOptions) formatOptions : null;
}
@Override
public DatastoreBackupOptions getDatastoreBackupOptions() {
return formatOptions instanceof DatastoreBackupOptions
? (DatastoreBackupOptions) formatOptions
: null;
}
@Override
public String getFormat() {
return formatOptions != null ? formatOptions.getType() : null;
}
@Override
public Integer getMaxBadRecords() {
return maxBadRecords;
}
@Override
public Schema getSchema() {
return schema;
}
@Override
public Boolean ignoreUnknownValues() {
return ignoreUnknownValues;
}
/**
* Returns the fully-qualified URIs that point to source data in Google Cloud Storage (e.g.
* gs://bucket/path). Each URI can contain one '*' wildcard character and it must come after the
* 'bucket' name.
*/
public List<String> getSourceUris() {
return sourceUris;
}
public String getFileSetSpecType() {
return fileSetSpecType;
}
public List<String> getDecimalTargetTypes() {
return decimalTargetTypes;
}
public Boolean getAutodetect() {
return autodetect;
}
@Override
public TimePartitioning getTimePartitioning() {
return timePartitioning;
}
@Override
public Clustering getClustering() {
return clustering;
}
@Override
public Boolean getUseAvroLogicalTypes() {
return useAvroLogicalTypes;
}
@Override
public List<JobInfo.SchemaUpdateOption> getSchemaUpdateOptions() {
return schemaUpdateOptions;
}
/** Returns the labels associated with this job */
public Map<String, String> getLabels() {
return labels;
}
/** Returns the timeout associated with this job */
public Long getJobTimeoutMs() {
return jobTimeoutMs;
}
/** Returns the range partitioning specification for the table */
public RangePartitioning getRangePartitioning() {
return rangePartitioning;
}
public HivePartitioningOptions getHivePartitioningOptions() {
return hivePartitioningOptions;
}
public String getReferenceFileSchemaUri() {
return referenceFileSchemaUri;
}
public List<ConnectionProperty> getConnectionProperties() {
return connectionProperties;
}
public Boolean getCreateSession() {
return createSession;
}
@Override
public Builder toBuilder() {
return new Builder(this);
}
@Override
ToStringHelper toStringHelper() {
return super.toStringHelper()
.add("destinationTable", destinationTable)
.add("decimalTargetTypes", decimalTargetTypes)
.add("destinationEncryptionConfiguration", destinationEncryptionConfiguration)
.add("createDisposition", createDisposition)
.add("writeDisposition", writeDisposition)
.add("formatOptions", formatOptions)
.add("nullMarker", nullMarker)
.add("maxBadRecords", maxBadRecords)
.add("schema", schema)
.add("ignoreUnknownValue", ignoreUnknownValues)
.add("sourceUris", sourceUris)
.add("fileSetSpecType", fileSetSpecType)
.add("schemaUpdateOptions", schemaUpdateOptions)
.add("autodetect", autodetect)
.add("timePartitioning", timePartitioning)
.add("clustering", clustering)
.add("useAvroLogicalTypes", useAvroLogicalTypes)
.add("labels", labels)
.add("jobTimeoutMs", jobTimeoutMs)
.add("rangePartitioning", rangePartitioning)
.add("hivePartitioningOptions", hivePartitioningOptions)
.add("referenceFileSchemaUri", referenceFileSchemaUri)
.add("connectionProperties", connectionProperties)
.add("createSession", createSession);
}
@Override
public boolean equals(Object obj) {
return obj == this
|| obj instanceof LoadJobConfiguration && baseEquals((LoadJobConfiguration) obj);
}
@Override
public int hashCode() {
return Objects.hash(baseHashCode(), sourceUris);
}
@Override
LoadJobConfiguration setProjectId(String projectId) {
if (Strings.isNullOrEmpty(getDestinationTable().getProject())) {
return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build();
}
return this;
}
@Override
com.google.api.services.bigquery.model.JobConfiguration toPb() {
JobConfigurationLoad loadConfigurationPb = new JobConfigurationLoad();
com.google.api.services.bigquery.model.JobConfiguration jobConfiguration =
new com.google.api.services.bigquery.model.JobConfiguration();
loadConfigurationPb.setDestinationTable(destinationTable.toPb());
if (createDisposition != null) {
loadConfigurationPb.setCreateDisposition(createDisposition.toString());
}
if (writeDisposition != null) {
loadConfigurationPb.setWriteDisposition(writeDisposition.toString());
}
if (nullMarker != null) {
loadConfigurationPb.setNullMarker(nullMarker);
}
if (getCsvOptions() != null) {
CsvOptions csvOptions = getCsvOptions();
loadConfigurationPb
.setFieldDelimiter(csvOptions.getFieldDelimiter())
.setAllowJaggedRows(csvOptions.allowJaggedRows())
.setAllowQuotedNewlines(csvOptions.allowQuotedNewLines())
.setEncoding(csvOptions.getEncoding())
.setQuote(csvOptions.getQuote());
if (csvOptions.getSkipLeadingRows() != null) {
// todo(mziccard) remove checked cast or comment when #1044 is closed
loadConfigurationPb.setSkipLeadingRows(Ints.checkedCast(csvOptions.getSkipLeadingRows()));
}
}
if (getParquetOptions() != null) {
ParquetOptions parquetOptions = getParquetOptions();
loadConfigurationPb.setParquetOptions(parquetOptions.toPb());
}
if (schema != null) {
loadConfigurationPb.setSchema(schema.toPb());
}
if (formatOptions != null) {
loadConfigurationPb.setSourceFormat(formatOptions.getType());
}
loadConfigurationPb.setMaxBadRecords(maxBadRecords);
loadConfigurationPb.setIgnoreUnknownValues(ignoreUnknownValues);
if (getDatastoreBackupOptions() != null) {
DatastoreBackupOptions backOptions = getDatastoreBackupOptions();
loadConfigurationPb.setProjectionFields(backOptions.getProjectionFields());
}
if (sourceUris != null) {
loadConfigurationPb.setSourceUris(ImmutableList.copyOf(sourceUris));
}
if (fileSetSpecType != null) {
loadConfigurationPb.setFileSetSpecType(fileSetSpecType);
}
if (decimalTargetTypes != null) {
loadConfigurationPb.setDecimalTargetTypes(ImmutableList.copyOf(decimalTargetTypes));
}
if (schemaUpdateOptions != null) {
ImmutableList.Builder<String> schemaUpdateOptionsBuilder = new ImmutableList.Builder<>();
for (JobInfo.SchemaUpdateOption schemaUpdateOption : schemaUpdateOptions) {
schemaUpdateOptionsBuilder.add(schemaUpdateOption.name());
}
loadConfigurationPb.setSchemaUpdateOptions(schemaUpdateOptionsBuilder.build());
}
loadConfigurationPb.setAutodetect(autodetect);
if (destinationEncryptionConfiguration != null) {
loadConfigurationPb.setDestinationEncryptionConfiguration(
destinationEncryptionConfiguration.toPb());
}
if (timePartitioning != null) {
loadConfigurationPb.setTimePartitioning(timePartitioning.toPb());
}
if (clustering != null) {
loadConfigurationPb.setClustering(clustering.toPb());
}
loadConfigurationPb.setUseAvroLogicalTypes(useAvroLogicalTypes);
if (labels != null) {
jobConfiguration.setLabels(labels);
}
if (jobTimeoutMs != null) {
jobConfiguration.setJobTimeoutMs(jobTimeoutMs);
}
if (rangePartitioning != null) {
loadConfigurationPb.setRangePartitioning(rangePartitioning.toPb());
}
if (hivePartitioningOptions != null) {
loadConfigurationPb.setHivePartitioningOptions(hivePartitioningOptions.toPb());
}
if (referenceFileSchemaUri != null) {
loadConfigurationPb.setReferenceFileSchemaUri(referenceFileSchemaUri);
}
if (connectionProperties != null) {
loadConfigurationPb.setConnectionProperties(
Lists.transform(connectionProperties, ConnectionProperty.TO_PB_FUNCTION));
}
if (createSession != null) {
loadConfigurationPb.setCreateSession(createSession);
}
jobConfiguration.setLoad(loadConfigurationPb);
return jobConfiguration;
}
/**
* Creates a builder for a BigQuery Load Job configuration given the destination table and source
* URIs.
*/
public static Builder newBuilder(TableId destinationTable, List<String> sourceUris) {
return new Builder().setDestinationTable(destinationTable).setSourceUris(sourceUris);
}
/**
* Creates a builder for a BigQuery Load Job configuration given the destination table and source
* URI.
*/
public static Builder builder(TableId destinationTable, String sourceUri) {
return newBuilder(destinationTable, ImmutableList.of(sourceUri));
}
/**
* Creates a builder for a BigQuery Load Job configuration given the destination table and source
* URI.
*/
public static Builder newBuilder(TableId destinationTable, String sourceUri) {
return newBuilder(destinationTable, ImmutableList.of(sourceUri));
}
/**
* Creates a builder for a BigQuery Load Job configuration given the destination table, format and
* source URIs.
*/
public static Builder newBuilder(
TableId destinationTable, List<String> sourceUris, FormatOptions format) {
return newBuilder(destinationTable, sourceUris).setFormatOptions(format);
}
/**
* Creates a builder for a BigQuery Load Job configuration given the destination table, format and
* source URI.
*/
public static Builder newBuilder(
TableId destinationTable, String sourceUri, FormatOptions format) {
return newBuilder(destinationTable, ImmutableList.of(sourceUri), format);
}
/** Returns a BigQuery Load Job Configuration for the given destination table and source URIs. */
public static LoadJobConfiguration of(TableId destinationTable, List<String> sourceUris) {
return newBuilder(destinationTable, sourceUris).build();
}
/** Returns a BigQuery Load Job Configuration for the given destination table and source URI. */
public static LoadJobConfiguration of(TableId destinationTable, String sourceUri) {
return of(destinationTable, ImmutableList.of(sourceUri));
}
/**
* Returns a BigQuery Load Job Configuration for the given destination table, format and source
* URI.
*/
public static LoadJobConfiguration of(
TableId destinationTable, List<String> sourceUris, FormatOptions format) {
return newBuilder(destinationTable, sourceUris, format).build();
}
/**
* Returns a BigQuery Load Job Configuration for the given destination table, format and source
* URI.
*/
public static LoadJobConfiguration of(
TableId destinationTable, String sourceUri, FormatOptions format) {
return of(destinationTable, ImmutableList.of(sourceUri), format);
}
@SuppressWarnings("unchecked")
static LoadJobConfiguration fromPb(
com.google.api.services.bigquery.model.JobConfiguration confPb) {
return new Builder(confPb).build();
}
}