Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.apache.beam.sdk.util.BigQueryServicesImpl;
import org.apache.beam.sdk.util.BigQueryTableInserter;
import org.apache.beam.sdk.util.BigQueryTableRowIterator;
import org.apache.beam.sdk.util.IOChannelFactory;
import org.apache.beam.sdk.util.IOChannelUtils;
import org.apache.beam.sdk.util.MimeTypes;
import org.apache.beam.sdk.util.PropertyNames;
import org.apache.beam.sdk.util.Reshuffle;
Expand Down Expand Up @@ -1015,7 +1017,19 @@ public PDone apply(PCollection<TableRow> input) {
table.setProjectId(options.getProject());
}
String jobIdToken = UUID.randomUUID().toString();
String tempFilePrefix = options.getTempLocation() + "/BigQuerySinkTemp/" + jobIdToken;
String tempLocation = options.getTempLocation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should rely on IOChannelUtils / IOChannelFactory and not call out to paths directly.
For example:
IOChannelFactory factory = IOChannelUtils.getFactory(path);
String tempFilePrefix = factory.resolve(factory.resolve(tempLocation, "BigQuerySinkTemp"), jobIdToken);
checkArgument(testBigQueryService == null || factory instanceof GCSIOChannelFactory, ....);

Other than this comment I think the code is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

Removed the check of gcs path, since it is done in validate().
In there (line 993), I am using GcsPath directly and expect it fails for non gcs path.
I am not checking the GCSIOChannelFactory, because I think there might be other implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Dan, any additional comments?

String tempFilePrefix;
try {
IOChannelFactory factory = IOChannelUtils.getFactory(tempLocation);
tempFilePrefix = factory.resolve(
factory.resolve(tempLocation, "BigQuerySinkTemp"),
jobIdToken);
} catch (IOException e) {
throw new RuntimeException(
String.format("Failed to resolve BigQuery temp location in %s", tempLocation),
e);
}

BigQueryServices bqServices = getBigQueryServices();
return input.apply("Write", org.apache.beam.sdk.io.Write.to(
new BigQuerySink(
Expand Down