Skip to content

Commit

Permalink
Use undeclared dependency in examples (findbugs)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikkyrk committed Dec 13, 2016
1 parent de8ae66 commit 12aa5a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions examples/java/pom.xml
Expand Up @@ -423,6 +423,11 @@
<artifactId>avro</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>

<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-pubsub</artifactId>
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.io.gcp.datastore.DatastoreIO;
import org.apache.beam.sdk.io.gcp.datastore.DatastoreV1;
import org.apache.beam.sdk.options.Default;
import org.apache.beam.sdk.options.Description;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
Expand Down Expand Up @@ -54,6 +55,8 @@ public interface Options extends PipelineOptions {
void setGqlQuery(ValueProvider<String> value);

@Description("Cloud Datastore Namespace")
// Emtpy String denotes default namespace.
@Default.String("")
ValueProvider<String> getNamespace();
void setNamespace(@Nullable ValueProvider<String> value);
}
Expand Down
Expand Up @@ -282,7 +282,7 @@ static int getEstimatedNumSplits(Datastore datastore, Query query, @Nullable Str
private static long queryLatestStatisticsTimestamp(Datastore datastore,
@Nullable String namespace) throws DatastoreException {
Query.Builder query = Query.newBuilder();
if (namespace == null) {
if (namespace == null || namespace.isEmpty()) {
query.addKindBuilder().setName("__Stat_Total__");
} else {
query.addKindBuilder().setName("__Stat_Ns_Total__");
Expand Down Expand Up @@ -317,7 +317,7 @@ static long getEstimatedSizeBytes(Datastore datastore, Query query, @Nullable St
LOG.info("Latest stats timestamp for kind {} is {}", ourKind, latestTimestamp);

Query.Builder queryBuilder = Query.newBuilder();
if (namespace == null) {
if (namespace == null || namespace.isEmpty()) {
queryBuilder.addKindBuilder().setName("__Stat_Kind__");
} else {
queryBuilder.addKindBuilder().setName("__Stat_Ns_Kind__");
Expand Down Expand Up @@ -345,7 +345,16 @@ static long getEstimatedSizeBytes(Datastore datastore, Query query, @Nullable St
/** Builds a {@link RunQueryRequest} from the {@code query} and {@code namespace}. */
static RunQueryRequest makeRequest(Query query, @Nullable String namespace) {
RunQueryRequest.Builder requestBuilder = RunQueryRequest.newBuilder().setQuery(query);
if (namespace != null) {
if (namespace != null && !namespace.isEmpty()) {
requestBuilder.getPartitionIdBuilder().setNamespaceId(namespace);
}
return requestBuilder.build();
}

/** Builds a {@link RunQueryRequest} from the {@code GqlQuery} and {@code namespace}. */
static RunQueryRequest makeRequest(GqlQuery gqlQuery, @Nullable String namespace) {
RunQueryRequest.Builder requestBuilder = RunQueryRequest.newBuilder().setGqlQuery(gqlQuery);
if (namespace != null && !namespace.isEmpty()) {
requestBuilder.getPartitionIdBuilder().setNamespaceId(namespace);
}
return requestBuilder.build();
Expand All @@ -359,7 +368,7 @@ private static List<Query> splitQuery(Query query, @Nullable String namespace,
Datastore datastore, QuerySplitter querySplitter, int numSplits) throws DatastoreException {
// If namespace is set, include it in the split request so splits are calculated accordingly.
PartitionId.Builder partitionBuilder = PartitionId.newBuilder();
if (namespace != null) {
if (namespace != null && !namespace.isEmpty()) {
partitionBuilder.setNamespaceId(namespace);
}

Expand Down Expand Up @@ -620,7 +629,8 @@ public void processElement(ProcessContext c) throws Exception {
String gqlQueryWithZeroLimit = gqlQuery.get() + " limit 0";
GqlQuery gql = GqlQuery.newBuilder().setQueryString(gqlQueryWithZeroLimit)
.setAllowLiterals(true).build();
RunQueryRequest req = RunQueryRequest.newBuilder().setGqlQuery(gql).build();

RunQueryRequest req = makeRequest(gql, options.getNamespace());
RunQueryResponse resp = datastore.runQuery(req);
Query translatedQuery = resp.getQuery();

Expand Down Expand Up @@ -704,17 +714,6 @@ public void processElement(ProcessContext c) throws Exception {
c.output(KV.of(key++, subquery));
}
}

@Override
public void populateDisplayData(DisplayData.Builder builder) {
super.populateDisplayData(builder);

builder
.addIfNotNull(DisplayData.item("projectId", options.getProjectId())
.withLabel("ProjectId"))
.addIfNotNull(DisplayData.item("namespace", options.getNamespace())
.withLabel("Namespace"));
}
}

/**
Expand Down
Expand Up @@ -126,7 +126,7 @@ public void testE2EV1ReadWithGQLQuery() throws Exception {

// Creates entities and write them to datastore
private static void writeEntitiesToDatastore(V1TestOptions options, String project,
String ancestor, long numEntities) throws Exception {
String ancestor, long numEntities) throws Exception {
Datastore datastore = getDatastore(options, project);
// Write test entities to datastore
V1TestWriter writer = new V1TestWriter(datastore, new UpsertMutationBuilder());
Expand Down

0 comments on commit 12aa5a9

Please sign in to comment.