Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 52bb4df

Browse files
committed
Changes to make queryPath optional
1 parent f93cc83 commit 52bb4df

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/main/java/com/google/swarm/tokenization/DLPTextToBigQueryStreamingV2PipelineOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public interface DLPTextToBigQueryStreamingV2PipelineOptions
9292
void setTableRef(String tableRef);
9393

9494
@Description("read method default, direct, export")
95-
@Default.Enum("EXPORT")
95+
@Default.Enum("DEFAULT")
9696
Method getReadMethod();
9797

9898
void setReadMethod(Method method);

src/main/java/com/google/swarm/tokenization/common/BigQueryReadTransform.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.swarm.tokenization.common;
1717

18+
import autovalue.shaded.org.checkerframework.checker.nullness.qual.Nullable;
1819
import com.google.api.services.bigquery.model.TableRow;
1920
import com.google.auto.value.AutoValue;
2021
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO;
@@ -50,6 +51,7 @@ public abstract static class Builder {
5051

5152
public abstract Builder setKeyRange(Integer keyRange);
5253

54+
@Nullable
5355
public abstract Builder setQuery(String query);
5456

5557
public abstract BigQueryReadTransform build();
@@ -64,23 +66,28 @@ public PCollection<KV<String, TableRow>> expand(PBegin input) {
6466

6567
switch (readMethod()) {
6668
case DEFAULT:
67-
return input
68-
.apply(
69-
"ReadFromBigQuery",
70-
BigQueryIO.readTableRows()
71-
.fromQuery(query())
72-
.usingStandardSql()
73-
.withMethod(Method.DEFAULT))
74-
.apply("AddTableNameAsKey", WithKeys.of(tableRef()));
69+
if(query()!=null) {
70+
return input
71+
.apply(
72+
"ReadFromBigQuery",
73+
BigQueryIO.readTableRows()
74+
.fromQuery(query())
75+
.usingStandardSql()
76+
.withMethod(Method.DEFAULT))
77+
.apply("AddTableNameAsKey", WithKeys.of(tableRef()));
78+
}
79+
else {
80+
return input
81+
.apply(
82+
"ReadFromBigQuery",
83+
BigQueryIO.readTableRows()
84+
.from(tableRef())
85+
.withMethod(Method.DEFAULT))
86+
.apply("AddTableNameAsKey", WithKeys.of(tableRef()));
87+
}
88+
7589
case EXPORT:
76-
return input
77-
.apply(
78-
"ReadFromBigQuery",
79-
BigQueryIO.readTableRows()
80-
.fromQuery(query())
81-
.usingStandardSql()
82-
.withMethod(Method.DEFAULT))
83-
.apply("AddTableNameAsKey", WithKeys.of(tableRef()));
90+
throw new IllegalArgumentException("Export method not supported");
8491

8592
case DIRECT_READ:
8693
throw new IllegalArgumentException("Direct read not supported");

src/main/java/com/google/swarm/tokenization/common/Util.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ private static void validateStorageWriteApiAtLeastOnce(BigQueryOptions options)
439439
}
440440

441441
public static String getQueryFromGcs(String gcsPath) {
442+
if(gcsPath == null){
443+
LOG.debug("Query path not provided, entire table will be read");
444+
return null;
445+
}
442446
GcsPath path = GcsPath.fromUri(URI.create(gcsPath));
443447
Storage storage = StorageOptions.getDefaultInstance().getService();
444448
BlobId blobId = BlobId.of(path.getBucket(), path.getObject());

0 commit comments

Comments
 (0)