@@ -92,6 +92,10 @@ type ExternalDataConfig struct {
92
92
93
93
// Additional options for CSV, GoogleSheets and Bigtable formats.
94
94
Options ExternalDataConfigOptions
95
+
96
+ // HivePartitioningOptions allows use of Hive partitioning based on the
97
+ // layout of objects in Google Cloud Storage.
98
+ HivePartitioningOptions * HivePartitioningOptions
95
99
}
96
100
97
101
func (e * ExternalDataConfig ) toBQ () bq.ExternalDataConfiguration {
@@ -106,6 +110,9 @@ func (e *ExternalDataConfig) toBQ() bq.ExternalDataConfiguration {
106
110
if e .Schema != nil {
107
111
q .Schema = e .Schema .toBQ ()
108
112
}
113
+ if e .HivePartitioningOptions != nil {
114
+ q .HivePartitioningOptions = e .HivePartitioningOptions .toBQ ()
115
+ }
109
116
if e .Options != nil {
110
117
e .Options .populateExternalDataConfig (& q )
111
118
}
@@ -134,6 +141,9 @@ func bqToExternalDataConfig(q *bq.ExternalDataConfiguration) (*ExternalDataConfi
134
141
return nil , err
135
142
}
136
143
}
144
+ if q .HivePartitioningOptions != nil {
145
+ e .HivePartitioningOptions = bqToHivePartitioningOptions (q .HivePartitioningOptions )
146
+ }
137
147
return e , nil
138
148
}
139
149
@@ -409,3 +419,65 @@ func bqToBigtableColumn(q *bq.BigtableColumn) (*BigtableColumn, error) {
409
419
}
410
420
return b , nil
411
421
}
422
+
423
+ // HivePartitioningMode is used in conjunction with HivePartitioningOptions.
424
+ type HivePartitioningMode string
425
+
426
+ const (
427
+ // AutoHivePartitioningMode automatically infers partitioning key and types.
428
+ AutoHivePartitioningMode HivePartitioningMode = "AUTO"
429
+ // StringHivePartitioningMode automatically infers partitioning keys and treats values as string.
430
+ StringHivePartitioningMode HivePartitioningMode = "STRINGS"
431
+ // CustomHivePartitioningMode allows custom definition of the external partitioning.
432
+ CustomHivePartitioningMode HivePartitioningMode = "CUSTOM"
433
+ )
434
+
435
+ // HivePartitioningOptions defines the behavior of Hive partitioning
436
+ // when working with external data.
437
+ type HivePartitioningOptions struct {
438
+
439
+ // Mode defines which hive partitioning mode to use when reading data.
440
+ Mode HivePartitioningMode
441
+
442
+ // When hive partition detection is requested, a common prefix for
443
+ // all source uris should be supplied. The prefix must end immediately
444
+ // before the partition key encoding begins.
445
+ //
446
+ // For example, consider files following this data layout.
447
+ // gs://bucket/path_to_table/dt=2019-01-01/country=BR/id=7/file.avro
448
+ // gs://bucket/path_to_table/dt=2018-12-31/country=CA/id=3/file.avro
449
+ //
450
+ // When hive partitioning is requested with either AUTO or STRINGS
451
+ // detection, the common prefix can be either of
452
+ // gs://bucket/path_to_table or gs://bucket/path_to_table/ (trailing
453
+ // slash does not matter).
454
+ SourceURIPrefix string
455
+
456
+ // If set to true, queries against this external table require
457
+ // a partition filter to be present that can perform partition
458
+ // elimination. Hive-partitioned load jobs with this field
459
+ // set to true will fail.
460
+ RequirePartitionFilter bool
461
+ }
462
+
463
+ func (o * HivePartitioningOptions ) toBQ () * bq.HivePartitioningOptions {
464
+ if o == nil {
465
+ return nil
466
+ }
467
+ return & bq.HivePartitioningOptions {
468
+ Mode : string (o .Mode ),
469
+ SourceUriPrefix : o .SourceURIPrefix ,
470
+ RequirePartitionFilter : o .RequirePartitionFilter ,
471
+ }
472
+ }
473
+
474
+ func bqToHivePartitioningOptions (q * bq.HivePartitioningOptions ) * HivePartitioningOptions {
475
+ if q == nil {
476
+ return nil
477
+ }
478
+ return & HivePartitioningOptions {
479
+ Mode : HivePartitioningMode (q .Mode ),
480
+ SourceURIPrefix : q .SourceUriPrefix ,
481
+ RequirePartitionFilter : q .RequirePartitionFilter ,
482
+ }
483
+ }
0 commit comments