|
| 1 | +package com.google.cloud.bigquery; |
| 2 | + |
| 3 | +/** |
| 4 | + * Google BigQuery DataFormatOptions. Configures the output format for data types returned from |
| 5 | + * BigQuery. |
| 6 | + */ |
| 7 | +public class DataFormatOptions { |
| 8 | + public enum TimestampFormatOptions { |
| 9 | + TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED("TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED"), |
| 10 | + FLOAT64("FLOAT64"), |
| 11 | + INT64("INT64"), |
| 12 | + ISO8601_STRING("ISO8601_STRING"); |
| 13 | + |
| 14 | + private final String format; |
| 15 | + |
| 16 | + TimestampFormatOptions(String format) { |
| 17 | + this.format = format; |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + public String toString() { |
| 22 | + return format; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + private boolean useInt64Timestamp; |
| 27 | + private TimestampFormatOptions timestampFormatOptions; |
| 28 | + |
| 29 | + public DataFormatOptions( |
| 30 | + boolean useInt64Timestamp, TimestampFormatOptions timestampFormatOptions) { |
| 31 | + this.useInt64Timestamp = useInt64Timestamp; |
| 32 | + this.timestampFormatOptions = timestampFormatOptions; |
| 33 | + } |
| 34 | + |
| 35 | + public boolean isUseInt64Timestamp() { |
| 36 | + return useInt64Timestamp; |
| 37 | + } |
| 38 | + |
| 39 | + public void setUseInt64Timestamp(boolean useInt64Timestamp) { |
| 40 | + this.useInt64Timestamp = useInt64Timestamp; |
| 41 | + } |
| 42 | + |
| 43 | + public TimestampFormatOptions getTimestampFormatOptions() { |
| 44 | + return timestampFormatOptions; |
| 45 | + } |
| 46 | + |
| 47 | + public void setTimestampFormatOptions(TimestampFormatOptions timestampFormatOptions) { |
| 48 | + this.timestampFormatOptions = timestampFormatOptions; |
| 49 | + } |
| 50 | + |
| 51 | + com.google.api.services.bigquery.model.DataFormatOptions toPb() { |
| 52 | + com.google.api.services.bigquery.model.DataFormatOptions request = |
| 53 | + new com.google.api.services.bigquery.model.DataFormatOptions(); |
| 54 | + request.setUseInt64Timestamp(useInt64Timestamp); |
| 55 | + if (timestampFormatOptions != null) { |
| 56 | + request.setTimestampOutputFormat(timestampFormatOptions.toString()); |
| 57 | + } |
| 58 | + return request; |
| 59 | + } |
| 60 | + |
| 61 | + DataFormatOptions fromPb(com.google.api.services.bigquery.model.DataFormatOptions request) { |
| 62 | + return new DataFormatOptions( |
| 63 | + request.getUseInt64Timestamp(), |
| 64 | + TimestampFormatOptions.valueOf(request.getTimestampOutputFormat())); |
| 65 | + } |
| 66 | +} |
0 commit comments