feat: update with latest from main (#4034) · googleapis/java-bigquery@ec447b5
@@ -17,6 +17,7 @@
1717package com.google.cloud.bigquery;
18181919import com.google.api.core.BetaApi;
20+import com.google.api.core.ObsoleteApi;
2021import com.google.api.gax.retrying.ResultRetryAlgorithm;
2122import com.google.cloud.ServiceDefaults;
2223import com.google.cloud.ServiceOptions;
@@ -26,6 +27,7 @@
2627import com.google.cloud.bigquery.spi.BigQueryRpcFactory;
2728import com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc;
2829import com.google.cloud.http.HttpTransportOptions;
30+import com.google.common.base.Preconditions;
2931import com.google.common.collect.ImmutableSet;
3032import io.opentelemetry.api.trace.Tracer;
3133import java.util.Set;
@@ -41,6 +43,7 @@ public class BigQueryOptions extends ServiceOptions<BigQuery, BigQueryOptions> {
4143// set the option ThrowNotFound when you want to throw the exception when the value not found
4244private boolean setThrowNotFound;
4345private boolean useInt64Timestamps;
46+private DataFormatOptions dataFormatOptions;
4447private JobCreationMode defaultJobCreationMode = JobCreationMode.JOB_CREATION_MODE_UNSPECIFIED;
4548private boolean enableOpenTelemetryTracing;
4649private Tracer openTelemetryTracer;
@@ -70,6 +73,7 @@ public static class Builder extends ServiceOptions.Builder<BigQuery, BigQueryOpt
70737174private String location;
7275private boolean useInt64Timestamps;
76+private DataFormatOptions dataFormatOptions;
7377private boolean enableOpenTelemetryTracing;
7478private Tracer openTelemetryTracer;
7579private ResultRetryAlgorithm<?> resultRetryAlgorithm;
@@ -94,11 +98,32 @@ public Builder setLocation(String location) {
9498return this;
9599 }
96100101+/**
102+ * This setter is marked as Obsolete. Prefer {@link #setDataFormatOptions(DataFormatOptions)} to
103+ * set the int64timestamp configuration instead.
104+ *
105+ * <p>If useInt64Timestamps value is set in here and via DataFormatOptions, the
106+ * DataFormatOptions configuration value is used.
107+ *
108+ * <p>{@code DataFormatOptions.newBuilder().setUseInt64Timestamp(...).build()}
109+ */
110+@ObsoleteApi("Use setDataFormatOptions(DataFormatOptions) instead")
97111public Builder setUseInt64Timestamps(boolean useInt64Timestamps) {
98112this.useInt64Timestamps = useInt64Timestamps;
99113return this;
100114 }
101115116+/**
117+ * Set the format options for the BigQuery data types
118+ *
119+ * @param dataFormatOptions Configuration of the formatting options
120+ */
121+public Builder setDataFormatOptions(DataFormatOptions dataFormatOptions) {
122+Preconditions.checkNotNull(dataFormatOptions, "DataFormatOptions cannot be null");
123+this.dataFormatOptions = dataFormatOptions;
124+return this;
125+ }
126+102127/**
103128 * Enables OpenTelemetry tracing functionality for this BigQuery instance
104129 *
@@ -143,6 +168,15 @@ private BigQueryOptions(Builder builder) {
143168 } else {
144169this.resultRetryAlgorithm = BigQueryBaseService.DEFAULT_BIGQUERY_EXCEPTION_HANDLER;
145170 }
171+172+// If dataFormatOptions is not set, then create a new instance and set it with the
173+// useInt64Timestamps configured in BigQueryOptions
174+if (builder.dataFormatOptions == null) {
175+this.dataFormatOptions =
176+DataFormatOptions.newBuilder().useInt64Timestamp(builder.useInt64Timestamps).build();
177+ } else {
178+this.dataFormatOptions = builder.dataFormatOptions;
179+ }
146180 }
147181148182private static class BigQueryDefaults implements ServiceDefaults<BigQuery, BigQueryOptions> {
@@ -191,8 +225,23 @@ public void setThrowNotFound(boolean setThrowNotFound) {
191225this.setThrowNotFound = setThrowNotFound;
192226 }
193227228+/**
229+ * This setter is marked as Obsolete. Prefer {@link
230+ * Builder#setDataFormatOptions(DataFormatOptions)} to set the int64timestamp configuration
231+ * instead.
232+ *
233+ * <p>If useInt64Timestamps is set via DataFormatOptions, then the value in DataFormatOptions will
234+ * be used. Otherwise, this value will be passed to DataFormatOptions.
235+ *
236+ * <p>Alternative: {@code DataFormatOptions.newBuilder().setUseInt64Timestamp(...).build()}
237+ */
238+@ObsoleteApi("Use Builder#setDataFormatOptions(DataFormatOptions) instead")
194239public void setUseInt64Timestamps(boolean useInt64Timestamps) {
195240this.useInt64Timestamps = useInt64Timestamps;
241+// Because this setter exists outside the Builder, DataFormatOptions needs be rebuilt to
242+// account for this setting.
243+this.dataFormatOptions =
244+dataFormatOptions.toBuilder().useInt64Timestamp(useInt64Timestamps).build();
196245 }
197246198247@Deprecated
@@ -206,8 +255,22 @@ public boolean getThrowNotFound() {
206255return setThrowNotFound;
207256 }
208257258+/**
259+ * This getter is marked as Obsolete. Prefer {@link
260+ * DataFormatOptions.Builder#useInt64Timestamp(boolean)} to set the int64timestamp configuration
261+ * instead.
262+ *
263+ * <p>Warning: DataFormatOptions values have precedence. Use {@link
264+ * DataFormatOptions#useInt64Timestamp()} to get `useInt64Timestamp` value used by the BigQuery
265+ * client.
266+ */
267+@ObsoleteApi("Use getDataFormatOptions().isUseInt64Timestamp() instead")
209268public boolean getUseInt64Timestamps() {
210-return useInt64Timestamps;
269+return dataFormatOptions.useInt64Timestamp();
270+ }
271+272+public DataFormatOptions getDataFormatOptions() {
273+return dataFormatOptions;
211274 }
212275213276public JobCreationMode getDefaultJobCreationMode() {