|
| 1 | +/* |
| 2 | + * Copyright 2018 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.api.core.BetaApi; |
| 20 | +import com.google.api.services.bigquery.model.Table; |
| 21 | +import com.google.auto.value.AutoValue; |
| 22 | +import javax.annotation.Nullable; |
| 23 | + |
| 24 | +/** |
| 25 | + * A Google BigQuery Model table definition. This definition is used to represent a BigQuery |
| 26 | + * ML model. |
| 27 | + * |
| 28 | + * @see <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create#models_in_bqml_name">BigQuery ML Model</a> |
| 29 | + */ |
| 30 | +@AutoValue |
| 31 | +@BetaApi |
| 32 | +public abstract class ModelTableDefinition extends TableDefinition { |
| 33 | + |
| 34 | + private static final long serialVersionUID = 2113445776046717900L; |
| 35 | + |
| 36 | + @AutoValue.Builder |
| 37 | + public abstract static class Builder |
| 38 | + extends TableDefinition.Builder<ModelTableDefinition, Builder> { |
| 39 | + |
| 40 | + public abstract Builder setNumBytes(Long numBytes); |
| 41 | + |
| 42 | + public abstract Builder setLocation(String location); |
| 43 | + |
| 44 | + public abstract Builder setType(Type type); |
| 45 | + |
| 46 | + /** Creates a {@code ModelTableDefinition} object. */ |
| 47 | + public abstract ModelTableDefinition build(); |
| 48 | + } |
| 49 | + |
| 50 | + /** Returns the size of this table in bytes, excluding any data in the streaming buffer. */ |
| 51 | + @Nullable |
| 52 | + public abstract Long getNumBytes(); |
| 53 | + |
| 54 | + /** |
| 55 | + * Returns the geographic location where the table should reside. This value is inherited from the |
| 56 | + * dataset. |
| 57 | + * |
| 58 | + * @see <a |
| 59 | + * href="https://cloud.google.com/bigquery/docs/managing_jobs_datasets_projects#dataset-location"> |
| 60 | + * Dataset Location</a> |
| 61 | + */ |
| 62 | + @Nullable |
| 63 | + public abstract String getLocation(); |
| 64 | + |
| 65 | + /** |
| 66 | + * Returns a builder for a BigQuery ML model table definition. |
| 67 | + */ |
| 68 | + public static Builder newBuilder() { |
| 69 | + return new AutoValue_ModelTableDefinition.Builder().setType(Type.MODEL); |
| 70 | + } |
| 71 | + |
| 72 | + /** Returns a builder for the {@code <ModelTableDefinition} object. */ |
| 73 | + public abstract Builder toBuilder(); |
| 74 | + |
| 75 | + @Override |
| 76 | + Table toPb() { |
| 77 | + Table tablePb = super.toPb(); |
| 78 | + tablePb.setNumBytes(getNumBytes()); |
| 79 | + tablePb.setLocation(getLocation()); |
| 80 | + return tablePb; |
| 81 | + } |
| 82 | + |
| 83 | + @SuppressWarnings("unchecked") |
| 84 | + static ModelTableDefinition fromPb(Table tablePb) { |
| 85 | + Builder builder = newBuilder().table(tablePb); |
| 86 | + return builder.setNumBytes(tablePb.getNumBytes()).setLocation(tablePb.getLocation()).build(); |
| 87 | + } |
| 88 | +} |
0 commit comments