|
| 1 | +/* |
| 2 | + * Copyright 2021 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.bigquery; |
| 18 | + |
| 19 | +import com.google.common.base.MoreObjects; |
| 20 | +import java.util.Objects; |
| 21 | + |
| 22 | +public class ParquetOptions extends FormatOptions { |
| 23 | + |
| 24 | + private static final long serialVersionUID = 1992L; |
| 25 | + |
| 26 | + private final Boolean enableListInference; |
| 27 | + private final Boolean enumAsString; |
| 28 | + |
| 29 | + public Boolean getEnableListInference() { |
| 30 | + return enableListInference; |
| 31 | + } |
| 32 | + |
| 33 | + public Boolean getEnumAsString() { |
| 34 | + return enumAsString; |
| 35 | + } |
| 36 | + |
| 37 | + /** A builder for {@code ParquetOptions} objects. */ |
| 38 | + public static final class Builder { |
| 39 | + private Boolean enableListInference; |
| 40 | + private Boolean enumAsString; |
| 41 | + |
| 42 | + private Builder() {} |
| 43 | + |
| 44 | + private Builder(ParquetOptions parquetOptions) { |
| 45 | + this.enableListInference = parquetOptions.enableListInference; |
| 46 | + this.enumAsString = parquetOptions.enumAsString; |
| 47 | + } |
| 48 | + |
| 49 | + public Builder setEnableListInference(Boolean enableListInference) { |
| 50 | + this.enableListInference = enableListInference; |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | + public Builder setEnumAsString(Boolean enumAsString) { |
| 55 | + this.enumAsString = enumAsString; |
| 56 | + return this; |
| 57 | + } |
| 58 | + |
| 59 | + public ParquetOptions build() { |
| 60 | + return new ParquetOptions(this); |
| 61 | + } |
| 62 | + } |
| 63 | + /** Returns a builder for the {@link ParquetOptions} object. */ |
| 64 | + public Builder toBuilder() { |
| 65 | + return new Builder(this); |
| 66 | + } |
| 67 | + |
| 68 | + ParquetOptions(Builder builder) { |
| 69 | + super(FormatOptions.PARQUET); |
| 70 | + enableListInference = builder.enableListInference; |
| 71 | + enumAsString = builder.enumAsString; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public String toString() { |
| 76 | + return MoreObjects.toStringHelper(this) |
| 77 | + .add("enableListInference", enableListInference) |
| 78 | + .add("enumAsString", enumAsString) |
| 79 | + .toString(); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public final int hashCode() { |
| 84 | + return Objects.hash(enableListInference, enumAsString); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public final boolean equals(Object obj) { |
| 89 | + if (obj == this) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + if (obj == null || !obj.getClass().equals(ParquetOptions.class)) { |
| 93 | + return false; |
| 94 | + } |
| 95 | + ParquetOptions other = (ParquetOptions) obj; |
| 96 | + return enableListInference == other.enableListInference && enumAsString == other.enumAsString; |
| 97 | + } |
| 98 | + |
| 99 | + /** Returns a builder for a {@link ParquetOptions} object. */ |
| 100 | + public static ParquetOptions.Builder newBuilder() { |
| 101 | + return new ParquetOptions.Builder(); |
| 102 | + } |
| 103 | + |
| 104 | + static ParquetOptions fromPb( |
| 105 | + com.google.api.services.bigquery.model.ParquetOptions parquetOptions) { |
| 106 | + Builder builder = newBuilder(); |
| 107 | + if (parquetOptions.getEnableListInference() != null) { |
| 108 | + builder.setEnableListInference(parquetOptions.getEnableListInference()); |
| 109 | + } |
| 110 | + if (parquetOptions.getEnumAsString() != null) { |
| 111 | + builder.setEnumAsString(parquetOptions.getEnumAsString()); |
| 112 | + } |
| 113 | + return builder.build(); |
| 114 | + } |
| 115 | + |
| 116 | + com.google.api.services.bigquery.model.ParquetOptions toPb() { |
| 117 | + com.google.api.services.bigquery.model.ParquetOptions parquetOptions = |
| 118 | + new com.google.api.services.bigquery.model.ParquetOptions(); |
| 119 | + if (enableListInference != null) { |
| 120 | + parquetOptions.setEnableListInference(enableListInference); |
| 121 | + } |
| 122 | + if (enumAsString != null) { |
| 123 | + parquetOptions.setEnumAsString(enumAsString); |
| 124 | + } |
| 125 | + return parquetOptions; |
| 126 | + } |
| 127 | +} |
0 commit comments