-
Notifications
You must be signed in to change notification settings - Fork 135
feat: Introduce DataFormatOptions to configure the output of BigQuery data types #4010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
7c8c47f
9caca67
6e16c81
cfc0b26
dd4e58f
65e0927
7952544
ad4128c
0affa6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Copyright 2025 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.auto.value.AutoValue; | ||
| import java.io.Serializable; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Google BigQuery DataFormatOptions. Configures the output format for data types returned from | ||
| * BigQuery. | ||
| */ | ||
| @AutoValue | ||
| public abstract class DataFormatOptions implements Serializable { | ||
| public enum TimestampFormatOptions { | ||
| TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED("TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED"), | ||
| FLOAT64("FLOAT64"), | ||
| INT64("INT64"), | ||
| ISO8601_STRING("ISO8601_STRING"); | ||
|
|
||
| private final String format; | ||
|
|
||
| TimestampFormatOptions(String format) { | ||
| this.format = format; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return format; | ||
| } | ||
| } | ||
|
|
||
| public abstract boolean useInt64Timestamp(); | ||
|
|
||
| @Nullable | ||
| public abstract TimestampFormatOptions timestampFormatOptions(); | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new AutoValue_DataFormatOptions.Builder().useInt64Timestamp(false); | ||
| } | ||
|
|
||
| public abstract Builder toBuilder(); | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract Builder useInt64Timestamp(boolean useInt64Timestamp); | ||
|
|
||
| public abstract Builder timestampFormatOptions(TimestampFormatOptions timestampFormatOptions); | ||
|
|
||
| abstract TimestampFormatOptions timestampFormatOptions(); | ||
|
|
||
| abstract DataFormatOptions autoBuild(); | ||
|
|
||
| public DataFormatOptions build() { | ||
| if (timestampFormatOptions() == null) { | ||
| timestampFormatOptions(TimestampFormatOptions.TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED); | ||
| } | ||
| return autoBuild(); | ||
| } | ||
lqiu96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| com.google.api.services.bigquery.model.DataFormatOptions toPb() { | ||
| com.google.api.services.bigquery.model.DataFormatOptions request = | ||
| new com.google.api.services.bigquery.model.DataFormatOptions(); | ||
| request.setUseInt64Timestamp(useInt64Timestamp()); | ||
| if (timestampFormatOptions() != null) { | ||
| request.setTimestampOutputFormat(timestampFormatOptions().toString()); | ||
| } | ||
| return request; | ||
| } | ||
|
|
||
| DataFormatOptions fromPb(com.google.api.services.bigquery.model.DataFormatOptions request) { | ||
lqiu96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AutoValue_DataFormatOptions.Builder builder = new AutoValue_DataFormatOptions.Builder(); | ||
lqiu96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (request.getUseInt64Timestamp() != null) { | ||
| builder.useInt64Timestamp(request.getUseInt64Timestamp()); | ||
| } | ||
| if (request.getTimestampOutputFormat() != null) { | ||
| builder.timestampFormatOptions( | ||
| TimestampFormatOptions.valueOf(request.getTimestampOutputFormat())); | ||
|
||
| } | ||
| return builder.build(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you would prefer
@ObsoleteApiover@Deprecated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Deprecatedcould result downstream customer's CI jobs failing based on their compiler settings. We prefer@ObsoleteApias a first warning and then moving to@Deprecatedin a future major version.