From 2fa58ac491211608967fbab5d9b49465e034f654 Mon Sep 17 00:00:00 2001 From: Girish Sabhnani Date: Thu, 2 Aug 2018 16:21:50 -0700 Subject: [PATCH 1/5] update --- .../cloud/bigquery/ModelTableDefinition.java | 69 +++++++++++++++++++ .../cloud/bigquery/TableDefinition.java | 10 +++ 2 files changed, 79 insertions(+) create mode 100644 google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java new file mode 100644 index 000000000000..f456cc4ef7c2 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 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.api.services.bigquery.model.Table; +import com.google.auto.value.AutoValue; +import com.google.common.base.MoreObjects; +import java.io.Serializable; +import java.math.BigInteger; +import java.util.Objects; +import javax.annotation.Nullable; + +/** + * A Google BigQuery Model table definition. This definition is used to represent a BigQuery + * ML model. + * + * @see BigQuery ML Model + */ +@AutoValue +public abstract class ModelTableDefinition extends TableDefinition { + + //TODO(gsabhnani): Update this id. + private static final long serialVersionUID = 2113445776046717900L; + + @AutoValue.Builder + public abstract static class Builder + extends TableDefinition.Builder { + + public abstract Builder setType(Type type); + + + /** Creates a {@code ModelTableDefinition} object. */ + public abstract ModelTableDefinition build(); + } + + /** + * Returns a builder for a BigQuery ML model table definition. + */ + public static Builder newBuilder() { + return new AutoValue_ModelTableDefinition.Builder().setType(Type.MODEL); + } + + /** Returns a builder for the {@code + * BigQuery ML Model + */ + public static final Type MODEL = type.createAndRegister("MODEL"); + private Type(String constant) { super(constant); } @@ -157,6 +165,8 @@ static T fromPb(Table tablePb) { return (T) ViewDefinition.fromPb(tablePb); case "EXTERNAL": return (T) ExternalTableDefinition.fromPb(tablePb); + case "MODEL": + return (T) ModelTableDefinition.fromPb(tablePb); default: // never reached throw new IllegalArgumentException("Format " + tablePb.getType() + " is not supported"); From 1eed495e2edb203949fba70ee09f2a8149d85e48 Mon Sep 17 00:00:00 2001 From: Girish Sabhnani Date: Thu, 2 Aug 2018 17:05:17 -0700 Subject: [PATCH 2/5] update --- .../java/com/google/cloud/bigquery/BigQueryImplTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java index 7fd91024c8eb..4c695b22995a 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java @@ -108,10 +108,14 @@ public class BigQueryImplTest { private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2); private static final StandardTableDefinition TABLE_DEFINITION = StandardTableDefinition.of(TABLE_SCHEMA); + private static final ModelTableDefinition MODEL_TABLE_DEFINITION = + ModelTableDefinition.newBuilder().build(); private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_DEFINITION); private static final TableInfo OTHER_TABLE_INFO = TableInfo.of(OTHER_TABLE_ID, TABLE_DEFINITION); private static final TableInfo TABLE_INFO_WITH_PROJECT = TableInfo.of(TABLE_ID_WITH_PROJECT, TABLE_DEFINITION); + private static final TableInfo MODEL_TABLE_INFO_WITH_PROJECT = + TableInfo.of(TABLE_ID_WITH_PROJECT, MODEL_TABLE_DEFINITION); private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION = LoadJobConfiguration.of(TABLE_ID, "URI"); private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION_WITH_PROJECT = @@ -613,7 +617,8 @@ public void testListTables() { ImmutableList tableList = ImmutableList.of( new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PROJECT)), - new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO))); + new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_INFO)), + new Table(bigquery, new TableInfo.BuilderImpl(MODEL_TABLE_INFO_WITH_PROJECT))); Tuple> result = Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION)); EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) From e8a52e53f2c80a583636b0da7603c941c044185c Mon Sep 17 00:00:00 2001 From: Girish Sabhnani Date: Thu, 2 Aug 2018 17:20:24 -0700 Subject: [PATCH 3/5] update --- .../cloud/bigquery/ModelTableDefinition.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java index f456cc4ef7c2..894b78676390 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java @@ -33,20 +33,38 @@ @AutoValue public abstract class ModelTableDefinition extends TableDefinition { - //TODO(gsabhnani): Update this id. + //TODO(gsabhnani): Update this id?? private static final long serialVersionUID = 2113445776046717900L; @AutoValue.Builder public abstract static class Builder extends TableDefinition.Builder { - public abstract Builder setType(Type type); + public abstract Builder setNumBytes(Long numBytes); + + public abstract Builder setLocation(String location); + public abstract Builder setType(Type type); /** Creates a {@code ModelTableDefinition} object. */ public abstract ModelTableDefinition build(); } + /** Returns the size of this table in bytes, excluding any data in the streaming buffer. */ + @Nullable + public abstract Long getNumBytes(); + + /** + * Returns the geographic location where the table should reside. This value is inherited from the + * dataset. + * + * @see + * Dataset Location + */ + @Nullable + public abstract String getLocation(); + /** * Returns a builder for a BigQuery ML model table definition. */ @@ -59,11 +77,15 @@ public static Builder newBuilder() { @Override Table toPb() { - return super.toPb(); + Table tablePb = super.toPb(); + tablePb.setNumBytes(getNumBytes()); + tablePb.setLocation(getLocation()); + return tablePb; } @SuppressWarnings("unchecked") static ModelTableDefinition fromPb(Table tablePb) { - return newBuilder().table(tablePb).build(); + Builder builder = newBuilder().table(tablePb); + return builder.setNumBytes(tablePb.getNumBytes()).setLocation(tablePb.getLocation()).build(); } } From a39f0a801695beba944d9156cea631a85e7e710a Mon Sep 17 00:00:00 2001 From: Girish Sabhnani Date: Thu, 2 Aug 2018 17:33:00 -0700 Subject: [PATCH 4/5] update --- .../src/main/java/com/google/cloud/bigquery/TableInfo.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java index ac741967c117..55c950cd8122 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java @@ -32,7 +32,8 @@ /** * Google BigQuery table information. Use {@link StandardTableDefinition} to create simple BigQuery * table. Use {@link ViewDefinition} to create a BigQuery view. Use {@link ExternalTableDefinition} - * to create a BigQuery a table backed by external data. + * to create a BigQuery a table backed by external data. Use {@link ModelDefinition} to create a + * BigQuery ML model. * * @see Managing Tables */ From e2bd75d4ec4993e242238a2e982ba3ba86e3b8ab Mon Sep 17 00:00:00 2001 From: Girish Sabhnani Date: Fri, 3 Aug 2018 12:12:26 -0700 Subject: [PATCH 5/5] update --- .../com/google/cloud/bigquery/ModelTableDefinition.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java index 894b78676390..3f7bfccab356 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelTableDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google LLC + * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,9 @@ package com.google.cloud.bigquery; +import com.google.api.core.BetaApi; import com.google.api.services.bigquery.model.Table; import com.google.auto.value.AutoValue; -import com.google.common.base.MoreObjects; -import java.io.Serializable; -import java.math.BigInteger; -import java.util.Objects; import javax.annotation.Nullable; /** @@ -31,9 +28,9 @@ * @see BigQuery ML Model */ @AutoValue +@BetaApi public abstract class ModelTableDefinition extends TableDefinition { - //TODO(gsabhnani): Update this id?? private static final long serialVersionUID = 2113445776046717900L; @AutoValue.Builder