Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ParquetOptions support and expose it in LoadJobConfiguratio…
…n and ExternalTableDefinition classes (#1318) * feat: add ParquetOptions support and expose it in LoadJobConfiguration and ExternalTableDefinition classes Fixes #1302 * update IT
- Loading branch information
1 parent
1586b02
commit 72b1715
Showing
6 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ParquetOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright 2021 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 com.google.common.base.MoreObjects; | ||
import java.util.Objects; | ||
|
||
public class ParquetOptions extends FormatOptions { | ||
|
||
private static final long serialVersionUID = 1992L; | ||
|
||
private final Boolean enableListInference; | ||
private final Boolean enumAsString; | ||
|
||
public Boolean getEnableListInference() { | ||
return enableListInference; | ||
} | ||
|
||
public Boolean getEnumAsString() { | ||
return enumAsString; | ||
} | ||
|
||
/** A builder for {@code ParquetOptions} objects. */ | ||
public static final class Builder { | ||
private Boolean enableListInference; | ||
private Boolean enumAsString; | ||
|
||
private Builder() {} | ||
|
||
private Builder(ParquetOptions parquetOptions) { | ||
this.enableListInference = parquetOptions.enableListInference; | ||
this.enumAsString = parquetOptions.enumAsString; | ||
} | ||
|
||
public Builder setEnableListInference(Boolean enableListInference) { | ||
this.enableListInference = enableListInference; | ||
return this; | ||
} | ||
|
||
public Builder setEnumAsString(Boolean enumAsString) { | ||
this.enumAsString = enumAsString; | ||
return this; | ||
} | ||
|
||
public ParquetOptions build() { | ||
return new ParquetOptions(this); | ||
} | ||
} | ||
/** Returns a builder for the {@link ParquetOptions} object. */ | ||
public Builder toBuilder() { | ||
return new Builder(this); | ||
} | ||
|
||
ParquetOptions(Builder builder) { | ||
super(FormatOptions.PARQUET); | ||
enableListInference = builder.enableListInference; | ||
enumAsString = builder.enumAsString; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("enableListInference", enableListInference) | ||
.add("enumAsString", enumAsString) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return Objects.hash(enableListInference, enumAsString); | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object obj) { | ||
if (obj == this) { | ||
return true; | ||
} | ||
if (obj == null || !obj.getClass().equals(ParquetOptions.class)) { | ||
return false; | ||
} | ||
ParquetOptions other = (ParquetOptions) obj; | ||
return enableListInference == other.enableListInference && enumAsString == other.enumAsString; | ||
} | ||
|
||
/** Returns a builder for a {@link ParquetOptions} object. */ | ||
public static ParquetOptions.Builder newBuilder() { | ||
return new ParquetOptions.Builder(); | ||
} | ||
|
||
static ParquetOptions fromPb( | ||
com.google.api.services.bigquery.model.ParquetOptions parquetOptions) { | ||
Builder builder = newBuilder(); | ||
if (parquetOptions.getEnableListInference() != null) { | ||
builder.setEnableListInference(parquetOptions.getEnableListInference()); | ||
} | ||
if (parquetOptions.getEnumAsString() != null) { | ||
builder.setEnumAsString(parquetOptions.getEnumAsString()); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
com.google.api.services.bigquery.model.ParquetOptions toPb() { | ||
com.google.api.services.bigquery.model.ParquetOptions parquetOptions = | ||
new com.google.api.services.bigquery.model.ParquetOptions(); | ||
if (enableListInference != null) { | ||
parquetOptions.setEnableListInference(enableListInference); | ||
} | ||
if (enumAsString != null) { | ||
parquetOptions.setEnumAsString(enumAsString); | ||
} | ||
return parquetOptions; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ParquetOptionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2021 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.truth.Truth.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class ParquetOptionsTest { | ||
|
||
private static final ParquetOptions OPTIONS = | ||
ParquetOptions.newBuilder().setEnableListInference(true).setEnumAsString(true).build(); | ||
|
||
@Test | ||
public void testToBuilder() { | ||
compareParquetOptions(OPTIONS, OPTIONS.toBuilder().build()); | ||
ParquetOptions parquetOptions = OPTIONS.toBuilder().setEnableListInference(true).build(); | ||
assertEquals(true, parquetOptions.getEnableListInference()); | ||
parquetOptions = parquetOptions.toBuilder().setEnumAsString(true).build(); | ||
compareParquetOptions(OPTIONS, parquetOptions); | ||
} | ||
|
||
@Test | ||
public void testToBuilderIncomplete() { | ||
ParquetOptions parquetOptions = | ||
ParquetOptions.newBuilder().setEnableListInference(true).build(); | ||
assertEquals(parquetOptions, parquetOptions.toBuilder().build()); | ||
} | ||
|
||
@Test | ||
public void testBuilder() { | ||
assertEquals(FormatOptions.PARQUET, OPTIONS.getType()); | ||
assertEquals(true, OPTIONS.getEnableListInference()); | ||
assertEquals(true, OPTIONS.getEnumAsString()); | ||
} | ||
|
||
@Test | ||
public void testToAndFromPb() { | ||
compareParquetOptions(OPTIONS, ParquetOptions.fromPb(OPTIONS.toPb())); | ||
ParquetOptions parquetOptions = | ||
ParquetOptions.newBuilder().setEnableListInference(true).build(); | ||
compareParquetOptions(parquetOptions, ParquetOptions.fromPb(parquetOptions.toPb())); | ||
} | ||
|
||
private void compareParquetOptions(ParquetOptions expected, ParquetOptions actual) { | ||
assertThat(expected).isEqualTo(actual); | ||
assertThat(expected.getEnableListInference()).isEqualTo(actual.getEnableListInference()); | ||
assertThat(expected.getEnumAsString()).isEqualTo(actual.getEnumAsString()); | ||
assertThat(expected.hashCode()).isEqualTo(actual.hashCode()); | ||
assertThat(expected.toString()).isEqualTo(actual.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters