Skip to content

Commit 3895bd9

Browse files
emkornfieldgcf-owl-bot[bot]
emkornfield
andauthored
feat: Add support for FileSetSpec (#2888)
* feat: Add support for FileSetSpec * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7e040e9 commit 3895bd9

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java

+30
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,20 @@ public Builder setSourceUris(List<String> sourceUris) {
7979
return setSourceUrisImmut(ImmutableList.copyOf(sourceUris));
8080
}
8181

82+
abstract Builder setFileSetSpecTypeInner(String spec);
83+
8284
abstract Builder setSourceUrisImmut(ImmutableList<String> sourceUris);
8385

86+
/**
87+
* Defines how to interpret files denoted by URIs. By default the files are assumed to be data
88+
* files (this can be specified explicitly via FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH). A second
89+
* option is "FILE_SET_SPEC_TYPE_NEW_LINE_DELIMITED_MANIFEST" which interprets each file as a
90+
* manifest file, where each line is a reference to a file.
91+
*/
92+
public Builder setFileSetSpecType(String fileSetSpecType) {
93+
return setFileSetSpecTypeInner(fileSetSpecType);
94+
}
95+
8496
/**
8597
* Sets the source format, and possibly some parsing options, of the external data. Supported
8698
* formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}.
@@ -232,6 +244,14 @@ public List<String> getSourceUris() {
232244
return getSourceUrisImmut();
233245
}
234246

247+
@Nullable
248+
public String getFileSetSpecType() {
249+
return getFileSetSpecTypeInner();
250+
}
251+
252+
@Nullable
253+
abstract String getFileSetSpecTypeInner();
254+
235255
@Nullable
236256
public abstract ImmutableList<String> getSourceUrisImmut();
237257

@@ -338,6 +358,10 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toExternalDataC
338358
if (getHivePartitioningOptions() != null) {
339359
externalConfigurationPb.setHivePartitioningOptions(getHivePartitioningOptions().toPb());
340360
}
361+
if (getFileSetSpecType() != null) {
362+
externalConfigurationPb.setFileSetSpecType(getFileSetSpecType());
363+
}
364+
341365
return externalConfigurationPb;
342366
}
343367

@@ -507,6 +531,9 @@ static ExternalTableDefinition fromPb(Table tablePb) {
507531
if (externalDataConfiguration.getReferenceFileSchemaUri() != null) {
508532
builder.setReferenceFileSchemaUri(externalDataConfiguration.getReferenceFileSchemaUri());
509533
}
534+
if (externalDataConfiguration.getFileSetSpecType() != null) {
535+
builder.setFileSetSpecType(externalDataConfiguration.getFileSetSpecType());
536+
}
510537
}
511538
return builder.build();
512539
}
@@ -566,6 +593,9 @@ static ExternalTableDefinition fromExternalDataConfiguration(
566593
builder.setHivePartitioningOptions(
567594
HivePartitioningOptions.fromPb(externalDataConfiguration.getHivePartitioningOptions()));
568595
}
596+
if (externalDataConfiguration.getFileSetSpecType() != null) {
597+
builder.setFileSetSpecType(externalDataConfiguration.getFileSetSpecType());
598+
}
569599

570600
return builder.build();
571601
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LoadJobConfiguration.java

+26
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public final class LoadJobConfiguration extends JobConfiguration implements Load
3838
private static final long serialVersionUID = -2673554846792429829L;
3939

4040
private final List<String> sourceUris;
41+
private final String fileSetSpecType;
4142
private final TableId destinationTable;
4243
private final List<String> decimalTargetTypes;
4344
private final EncryptionConfiguration destinationEncryptionConfiguration;
@@ -67,6 +68,7 @@ public static final class Builder extends JobConfiguration.Builder<LoadJobConfig
6768
implements LoadConfiguration.Builder {
6869

6970
private List<String> sourceUris;
71+
private String fileSetSpecType;
7072
private TableId destinationTable;
7173
private List<String> decimalTargetTypes;
7274
private EncryptionConfiguration destinationEncryptionConfiguration;
@@ -107,6 +109,7 @@ private Builder(LoadJobConfiguration loadConfiguration) {
107109
this.schema = loadConfiguration.schema;
108110
this.ignoreUnknownValues = loadConfiguration.ignoreUnknownValues;
109111
this.sourceUris = loadConfiguration.sourceUris;
112+
this.fileSetSpecType = loadConfiguration.fileSetSpecType;
110113
this.schemaUpdateOptions = loadConfiguration.schemaUpdateOptions;
111114
this.autodetect = loadConfiguration.autodetect;
112115
this.destinationEncryptionConfiguration =
@@ -175,6 +178,9 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
175178
if (loadConfigurationPb.getSourceUris() != null) {
176179
this.sourceUris = ImmutableList.copyOf(configurationPb.getLoad().getSourceUris());
177180
}
181+
if (loadConfigurationPb.getFileSetSpecType() != null) {
182+
this.fileSetSpecType = loadConfigurationPb.getFileSetSpecType();
183+
}
178184
if (loadConfigurationPb.getSchemaUpdateOptions() != null) {
179185
ImmutableList.Builder<JobInfo.SchemaUpdateOption> schemaUpdateOptionsBuilder =
180186
new ImmutableList.Builder<>();
@@ -306,6 +312,17 @@ public Builder setSourceUris(List<String> sourceUris) {
306312
return this;
307313
}
308314

315+
/**
316+
* Defines how to interpret files denoted by URIs. By default the files are assumed to be data
317+
* files (this can be specified explicitly via FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH). A second
318+
* option is "FILE_SET_SPEC_TYPE_NEW_LINE_DELIMITED_MANIFEST" which interprets each file as a
319+
* manifest file, where each line is a reference to a file.
320+
*/
321+
public Builder setFileSetSpecType(String fileSetSpecType) {
322+
this.fileSetSpecType = fileSetSpecType;
323+
return this;
324+
}
325+
309326
/**
310327
* Defines the list of possible SQL data types to which the source decimal values are converted.
311328
* This list and the precision and the scale parameters of the decimal field determine the
@@ -403,6 +420,7 @@ public LoadJobConfiguration build() {
403420
private LoadJobConfiguration(Builder builder) {
404421
super(builder);
405422
this.sourceUris = builder.sourceUris;
423+
this.fileSetSpecType = builder.fileSetSpecType;
406424
this.destinationTable = builder.destinationTable;
407425
this.decimalTargetTypes = builder.decimalTargetTypes;
408426
this.createDisposition = builder.createDisposition;
@@ -497,6 +515,10 @@ public List<String> getSourceUris() {
497515
return sourceUris;
498516
}
499517

518+
public String getFileSetSpecType() {
519+
return fileSetSpecType;
520+
}
521+
500522
public List<String> getDecimalTargetTypes() {
501523
return decimalTargetTypes;
502524
}
@@ -575,6 +597,7 @@ ToStringHelper toStringHelper() {
575597
.add("schema", schema)
576598
.add("ignoreUnknownValue", ignoreUnknownValues)
577599
.add("sourceUris", sourceUris)
600+
.add("fileSetSpecType", fileSetSpecType)
578601
.add("schemaUpdateOptions", schemaUpdateOptions)
579602
.add("autodetect", autodetect)
580603
.add("timePartitioning", timePartitioning)
@@ -655,6 +678,9 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
655678
if (sourceUris != null) {
656679
loadConfigurationPb.setSourceUris(ImmutableList.copyOf(sourceUris));
657680
}
681+
if (fileSetSpecType != null) {
682+
loadConfigurationPb.setFileSetSpecType(fileSetSpecType);
683+
}
658684
if (decimalTargetTypes != null) {
659685
loadConfigurationPb.setDecimalTargetTypes(ImmutableList.copyOf(decimalTargetTypes));
660686
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExternalTableDefinitionTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class ExternalTableDefinitionTest {
6060
.build();
6161
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION =
6262
ExternalTableDefinition.newBuilder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS)
63+
.setFileSetSpecType("FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH")
6364
.setDecimalTargetTypes(DECIMAL_TARGET_TYPES)
6465
.setCompression(COMPRESSION)
6566
.setConnectionId(CONNECTION_ID)
@@ -154,6 +155,7 @@ public void testToAndFromPbParquet() {
154155
private void compareExternalTableDefinition(
155156
ExternalTableDefinition expected, ExternalTableDefinition value) {
156157
assertEquals(expected, value);
158+
assertEquals(expected.getFileSetSpecType(), value.getFileSetSpecType());
157159
assertEquals(expected.getDecimalTargetTypes(), value.getDecimalTargetTypes());
158160
assertEquals(expected.getCompression(), value.getCompression());
159161
assertEquals(expected.getConnectionId(), value.getConnectionId());

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/LoadJobConfigurationTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class LoadJobConfigurationTest {
9191
.setCreateDisposition(CREATE_DISPOSITION)
9292
.setWriteDisposition(WRITE_DISPOSITION)
9393
.setFormatOptions(CSV_OPTIONS)
94+
.setFileSetSpecType("FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH")
9495
.setIgnoreUnknownValues(IGNORE_UNKNOWN_VALUES)
9596
.setMaxBadRecords(MAX_BAD_RECORDS)
9697
.setSchema(TABLE_SCHEMA)
@@ -240,6 +241,7 @@ private void compareLoadJobConfiguration(
240241
LoadJobConfiguration expected, LoadJobConfiguration value) {
241242
assertEquals(expected, value);
242243
assertEquals(expected.hashCode(), value.hashCode());
244+
assertEquals(expected.getFileSetSpecType(), value.getFileSetSpecType());
243245
assertEquals(expected.toString(), value.toString());
244246
assertEquals(expected.getDestinationTable(), value.getDestinationTable());
245247
assertEquals(expected.getDecimalTargetTypes(), value.getDecimalTargetTypes());

0 commit comments

Comments
 (0)