Skip to content

Commit

Permalink
Do not use .get() on ValueProvider during pipeline creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bvolpato committed Sep 21, 2022
1 parent d578e3d commit cf790b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

* Support for X source added (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).
* Decreased TextSource CPU utilization by 2.3x (Java) ([#23193](https://github.com/apache/beam/issues/23193)).
* Fixed bug when using SpannerIO with RuntimeValueProvider options (Java) ([#22146](https://github.com/apache/beam/issues/22146)).

## New Features / Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.beam.sdk.io.gcp.spanner;

import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull;

import com.google.auto.value.AutoValue;
import com.google.cloud.spanner.BatchReadOnlyTransaction;
import com.google.cloud.spanner.Options;
Expand All @@ -37,7 +39,6 @@
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.PCollectionView;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.cache.CacheBuilder;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.cache.CacheLoader;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.cache.LoadingCache;
Expand Down Expand Up @@ -118,8 +119,7 @@ public GeneratePartitionsFn(
SpannerConfig config, PCollectionView<? extends Transaction> txView) {
this.config = config;
this.txView = txView;
Preconditions.checkNotNull(config.getRpcPriority());
Preconditions.checkNotNull(config.getRpcPriority().get());
checkNotNull(config.getRpcPriority());
}

@Setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.beam.sdk.options.ValueProvider;
import org.apache.beam.sdk.transforms.display.DisplayData;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSet;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Duration;
Expand Down Expand Up @@ -161,8 +160,7 @@ public SpannerConfig withProjectId(String projectId) {

/** Specifies the Cloud Spanner instance ID. */
public SpannerConfig withInstanceId(ValueProvider<String> instanceId) {
Preconditions.checkNotNull(instanceId);
Preconditions.checkNotNull(instanceId.get());
checkNotNull(instanceId, "withInstanceId(instanceId) called with null input.");
return toBuilder().setInstanceId(instanceId).build();
}

Expand All @@ -173,8 +171,7 @@ public SpannerConfig withInstanceId(String instanceId) {

/** Specifies the Cloud Spanner database ID. */
public SpannerConfig withDatabaseId(ValueProvider<String> databaseId) {
Preconditions.checkNotNull(databaseId);
Preconditions.checkNotNull(databaseId.get());
checkNotNull(databaseId, "withDatabaseId(databaseId) called with null input.");
return toBuilder().setDatabaseId(databaseId).build();
}

Expand All @@ -185,8 +182,7 @@ public SpannerConfig withDatabaseId(String databaseId) {

/** Specifies the Cloud Spanner host. */
public SpannerConfig withHost(ValueProvider<String> host) {
Preconditions.checkNotNull(host);
Preconditions.checkNotNull(host.get());
checkNotNull(host, "withHost(host) called with null input.");
return toBuilder().setHost(host).build();
}

Expand Down Expand Up @@ -257,8 +253,7 @@ public SpannerConfig withRpcPriority(RpcPriority rpcPriority) {

/** Specifies the RPC priority. */
public SpannerConfig withRpcPriority(ValueProvider<RpcPriority> rpcPriority) {
Preconditions.checkNotNull(rpcPriority);
Preconditions.checkNotNull(rpcPriority.get());
checkNotNull(rpcPriority, "withRpcPriority(rpcPriority) called with null input.");
return toBuilder().setRpcPriority(rpcPriority).build();
}
}

0 comments on commit cf790b5

Please sign in to comment.