From 80311628c27ea68704f46d9f5e6edea6466dfcb3 Mon Sep 17 00:00:00 2001 From: Damon Date: Fri, 29 Sep 2023 13:04:18 -0700 Subject: [PATCH] Remove warning from catch in table exists validation (#28288) * Remove warning from catch in table exists validation * Remove warning from catch in read table exists validation * Throw RuntimeException instead --- .../beam/sdk/io/gcp/bigtable/BigtableIO.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableIO.java b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableIO.java index 9f3c627a89ef9..92a0af2054827 100644 --- a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableIO.java +++ b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableIO.java @@ -19,8 +19,8 @@ import static org.apache.beam.sdk.io.gcp.bigtable.BigtableServiceFactory.BigtableServiceEntry; import static org.apache.beam.sdk.options.ValueProvider.StaticValueProvider; +import static org.apache.beam.sdk.util.Preconditions.checkArgumentNotNull; import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; -import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkNotNull; import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkState; import com.google.auto.value.AutoValue; @@ -689,14 +689,13 @@ public final String toString() { private void validateTableExists( BigtableConfig config, BigtableReadOptions readOptions, PipelineOptions options) { if (config.getValidate() && config.isDataAccessible() && readOptions.isDataAccessible()) { - String tableId = checkNotNull(readOptions.getTableId().get()); + ValueProvider tableIdProvider = checkArgumentNotNull(readOptions.getTableId()); + String tableId = checkArgumentNotNull(tableIdProvider.get()); try { - checkArgument( - getServiceFactory().checkTableExists(config, options, tableId), - "Table %s does not exist", - tableId); + boolean exists = getServiceFactory().checkTableExists(config, options, tableId); + checkArgument(exists, "Table %s does not exist", tableId); } catch (IOException e) { - LOG.warn("Error checking whether table {} exists; proceeding.", tableId, e); + throw new RuntimeException(e); } } } @@ -1122,14 +1121,13 @@ public String toString() { private void validateTableExists( BigtableConfig config, BigtableWriteOptions writeOptions, PipelineOptions options) { if (config.getValidate() && config.isDataAccessible() && writeOptions.isDataAccessible()) { - String tableId = checkNotNull(writeOptions.getTableId().get()); + ValueProvider tableIdProvider = checkArgumentNotNull(writeOptions.getTableId()); + String tableId = checkArgumentNotNull(tableIdProvider.get()); try { - checkArgument( - factory.checkTableExists(config, options, writeOptions.getTableId().get()), - "Table %s does not exist", - tableId); + boolean exists = factory.checkTableExists(config, options, tableId); + checkArgument(exists, "Table %s does not exist", tableId); } catch (IOException e) { - LOG.warn("Error checking whether table {} exists; proceeding.", tableId, e); + throw new RuntimeException(e); } } }