@@ -38,6 +38,7 @@ public final class ExtractJobConfiguration extends JobConfiguration {
38
38
private static final long serialVersionUID = 4147749733166593761L ;
39
39
40
40
private final TableId sourceTable ;
41
+ private final ModelId sourceModel ;
41
42
private final List <String > destinationUris ;
42
43
private final Boolean printHeader ;
43
44
private final String fieldDelimiter ;
@@ -51,6 +52,7 @@ public static final class Builder
51
52
extends JobConfiguration .Builder <ExtractJobConfiguration , Builder > {
52
53
53
54
private TableId sourceTable ;
55
+ private ModelId sourceModel ;
54
56
private List <String > destinationUris ;
55
57
private Boolean printHeader ;
56
58
private String fieldDelimiter ;
@@ -67,6 +69,7 @@ private Builder() {
67
69
private Builder (ExtractJobConfiguration jobInfo ) {
68
70
this ();
69
71
this .sourceTable = jobInfo .sourceTable ;
72
+ this .sourceModel = jobInfo .sourceModel ;
70
73
this .destinationUris = jobInfo .destinationUris ;
71
74
this .printHeader = jobInfo .printHeader ;
72
75
this .fieldDelimiter = jobInfo .fieldDelimiter ;
@@ -80,7 +83,12 @@ private Builder(ExtractJobConfiguration jobInfo) {
80
83
private Builder (com .google .api .services .bigquery .model .JobConfiguration configurationPb ) {
81
84
this ();
82
85
JobConfigurationExtract extractConfigurationPb = configurationPb .getExtract ();
83
- this .sourceTable = TableId .fromPb (extractConfigurationPb .getSourceTable ());
86
+ if (extractConfigurationPb .getSourceTable () != null ) {
87
+ this .sourceTable = TableId .fromPb (extractConfigurationPb .getSourceTable ());
88
+ }
89
+ if (extractConfigurationPb .getSourceModel () != null ) {
90
+ this .sourceModel = ModelId .fromPb (extractConfigurationPb .getSourceModel ());
91
+ }
84
92
this .destinationUris = extractConfigurationPb .getDestinationUris ();
85
93
this .printHeader = extractConfigurationPb .getPrintHeader ();
86
94
this .fieldDelimiter = extractConfigurationPb .getFieldDelimiter ();
@@ -101,6 +109,12 @@ public Builder setSourceTable(TableId sourceTable) {
101
109
return this ;
102
110
}
103
111
112
+ /** Sets the model to export. */
113
+ public Builder setSourceModel (ModelId sourceModel ) {
114
+ this .sourceModel = sourceModel ;
115
+ return this ;
116
+ }
117
+
104
118
/**
105
119
* Sets the list of fully-qualified Google Cloud Storage URIs (e.g. gs://bucket/path) where the
106
120
* extracted table should be written.
@@ -191,7 +205,8 @@ public ExtractJobConfiguration build() {
191
205
192
206
private ExtractJobConfiguration (Builder builder ) {
193
207
super (builder );
194
- this .sourceTable = checkNotNull (builder .sourceTable );
208
+ this .sourceTable = builder .sourceTable ;
209
+ this .sourceModel = builder .sourceModel ;
195
210
this .destinationUris = checkNotNull (builder .destinationUris );
196
211
this .printHeader = builder .printHeader ;
197
212
this .fieldDelimiter = builder .fieldDelimiter ;
@@ -207,6 +222,11 @@ public TableId getSourceTable() {
207
222
return sourceTable ;
208
223
}
209
224
225
+ /** Returns the model to export. */
226
+ public ModelId getSourceModel () {
227
+ return sourceModel ;
228
+ }
229
+
210
230
/**
211
231
* Returns the list of fully-qualified Google Cloud Storage URIs where the extracted table should
212
232
* be written.
@@ -263,6 +283,7 @@ public Builder toBuilder() {
263
283
ToStringHelper toStringHelper () {
264
284
return super .toStringHelper ()
265
285
.add ("sourceTable" , sourceTable )
286
+ .add ("sourceModel" , sourceModel )
266
287
.add ("destinationUris" , destinationUris )
267
288
.add ("format" , format )
268
289
.add ("printHeader" , printHeader )
@@ -284,6 +305,7 @@ public int hashCode() {
284
305
return Objects .hash (
285
306
baseHashCode (),
286
307
sourceTable ,
308
+ sourceModel ,
287
309
destinationUris ,
288
310
printHeader ,
289
311
fieldDelimiter ,
@@ -296,9 +318,12 @@ public int hashCode() {
296
318
297
319
@ Override
298
320
ExtractJobConfiguration setProjectId (String projectId ) {
299
- if (Strings .isNullOrEmpty (getSourceTable ().getProject ())) {
321
+ if (getSourceTable () != null && Strings .isNullOrEmpty (getSourceTable ().getProject ())) {
300
322
return toBuilder ().setSourceTable (getSourceTable ().setProjectId (projectId )).build ();
301
323
}
324
+ if (getSourceModel () != null && Strings .isNullOrEmpty (getSourceModel ().getProject ())) {
325
+ return toBuilder ().setSourceModel (getSourceModel ().setProjectId (projectId )).build ();
326
+ }
302
327
return this ;
303
328
}
304
329
@@ -308,7 +333,12 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
308
333
com .google .api .services .bigquery .model .JobConfiguration jobConfiguration =
309
334
new com .google .api .services .bigquery .model .JobConfiguration ();
310
335
extractConfigurationPb .setDestinationUris (destinationUris );
311
- extractConfigurationPb .setSourceTable (sourceTable .toPb ());
336
+ if (sourceTable != null ) {
337
+ extractConfigurationPb .setSourceTable (sourceTable .toPb ());
338
+ }
339
+ if (sourceModel != null ) {
340
+ extractConfigurationPb .setSourceModel (sourceModel .toPb ());
341
+ }
312
342
extractConfigurationPb .setPrintHeader (printHeader );
313
343
extractConfigurationPb .setFieldDelimiter (fieldDelimiter );
314
344
extractConfigurationPb .setDestinationFormat (format );
@@ -333,6 +363,15 @@ public static Builder newBuilder(TableId sourceTable, String destinationUri) {
333
363
return newBuilder (sourceTable , ImmutableList .of (destinationUri ));
334
364
}
335
365
366
+ /**
367
+ * Creates a builder for a BigQuery Extract Job configuration given source model and destination
368
+ * URI.
369
+ */
370
+ public static Builder newBuilder (ModelId sourceModel , String destinationUri ) {
371
+ checkArgument (!isNullOrEmpty (destinationUri ), "Provided destinationUri is null or empty" );
372
+ return newBuilder (sourceModel , ImmutableList .of (destinationUri ));
373
+ }
374
+
336
375
/**
337
376
* Creates a builder for a BigQuery Extract Job configuration given source table and destination
338
377
* URIs.
@@ -341,20 +380,42 @@ public static Builder newBuilder(TableId sourceTable, List<String> destinationUr
341
380
return new Builder ().setSourceTable (sourceTable ).setDestinationUris (destinationUris );
342
381
}
343
382
383
+ /**
384
+ * Creates a builder for a BigQuery Extract Job configuration given source model and destination
385
+ * URIs.
386
+ */
387
+ public static Builder newBuilder (ModelId sourceModel , List <String > destinationUris ) {
388
+ return new Builder ().setSourceModel (sourceModel ).setDestinationUris (destinationUris );
389
+ }
390
+
344
391
/**
345
392
* Returns a BigQuery Extract Job configuration for the given source table and destination URI.
346
393
*/
347
394
public static ExtractJobConfiguration of (TableId sourceTable , String destinationUri ) {
348
395
return newBuilder (sourceTable , destinationUri ).build ();
349
396
}
350
397
398
+ /**
399
+ * Returns a BigQuery Extract Job configuration for the given source model and destination URI.
400
+ */
401
+ public static ExtractJobConfiguration of (ModelId sourceModel , String destinationUri ) {
402
+ return newBuilder (sourceModel , destinationUri ).build ();
403
+ }
404
+
351
405
/**
352
406
* Returns a BigQuery Extract Job configuration for the given source table and destination URIs.
353
407
*/
354
408
public static ExtractJobConfiguration of (TableId sourceTable , List <String > destinationUris ) {
355
409
return newBuilder (sourceTable , destinationUris ).build ();
356
410
}
357
411
412
+ /**
413
+ * Returns a BigQuery Extract Job configuration for the given source model and destination URIs.
414
+ */
415
+ public static ExtractJobConfiguration of (ModelId sourceModel , List <String > destinationUris ) {
416
+ return newBuilder (sourceModel , destinationUris ).build ();
417
+ }
418
+
358
419
/**
359
420
* Returns a BigQuery Extract Job configuration for the given source table, format and destination
360
421
* URI.
@@ -365,6 +426,16 @@ public static ExtractJobConfiguration of(
365
426
return newBuilder (sourceTable , destinationUri ).setFormat (format ).build ();
366
427
}
367
428
429
+ /**
430
+ * Returns a BigQuery Extract Job configuration for the given source model, format and destination
431
+ * URI.
432
+ */
433
+ public static ExtractJobConfiguration of (
434
+ ModelId sourceTable , String destinationUri , String format ) {
435
+ checkArgument (!isNullOrEmpty (format ), "Provided format is null or empty" );
436
+ return newBuilder (sourceTable , destinationUri ).setFormat (format ).build ();
437
+ }
438
+
368
439
/**
369
440
* Returns a BigQuery Extract Job configuration for the given source table, format and destination
370
441
* URIs.
@@ -375,6 +446,16 @@ public static ExtractJobConfiguration of(
375
446
return newBuilder (sourceTable , destinationUris ).setFormat (format ).build ();
376
447
}
377
448
449
+ /**
450
+ * Returns a BigQuery Extract Job configuration for the given source table, format and destination
451
+ * URIs.
452
+ */
453
+ public static ExtractJobConfiguration of (
454
+ ModelId sourceModel , List <String > destinationUris , String format ) {
455
+ checkArgument (!isNullOrEmpty (format ), "Provided format is null or empty" );
456
+ return newBuilder (sourceModel , destinationUris ).setFormat (format ).build ();
457
+ }
458
+
378
459
@ SuppressWarnings ("unchecked" )
379
460
static ExtractJobConfiguration fromPb (
380
461
com .google .api .services .bigquery .model .JobConfiguration confPb ) {
0 commit comments