-
Notifications
You must be signed in to change notification settings - Fork 596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upgrade bq libraries #7264
Merged
Merged
upgrade bq libraries #7264
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package org.broadinstitute.hellbender.utils.bigquery; | ||
|
||
import com.google.api.gax.rpc.ServerStream; | ||
import com.google.cloud.bigquery.BigQueryOptions; | ||
import com.google.cloud.bigquery.storage.v1beta1.*; | ||
import com.google.cloud.bigquery.storage.v1beta1.ReadOptions.TableReadOptions.Builder; | ||
import com.google.common.base.Preconditions; | ||
import com.google.cloud.bigquery.storage.v1.AvroRows; | ||
import com.google.cloud.bigquery.storage.v1.BigQueryReadClient; | ||
import com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest; | ||
import com.google.cloud.bigquery.storage.v1.DataFormat; | ||
import com.google.cloud.bigquery.storage.v1.ReadRowsRequest; | ||
import com.google.cloud.bigquery.storage.v1.ReadSession; | ||
import com.google.cloud.bigquery.storage.v1.ReadSession.TableReadOptions; | ||
import com.google.cloud.bigquery.storage.v1.ReadSession.TableReadOptions.Builder; | ||
|
||
import com.google.cloud.bigquery.storage.v1.ReadRowsResponse; | ||
import org.apache.avro.generic.GenericDatumReader; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.avro.io.BinaryDecoder; | ||
|
@@ -22,11 +27,9 @@ public class StorageAPIAvroReader implements GATKAvroReader { | |
|
||
private static final Logger logger = LogManager.getLogger(StorageAPIAvroReader.class); | ||
|
||
private static int rowCount = 0; | ||
private BigQueryReadClient client; | ||
|
||
private BigQueryStorageClient client; | ||
|
||
private Iterator<Storage.ReadRowsResponse> serverStream; | ||
private Iterator<ReadRowsResponse> serverStream; | ||
|
||
private org.apache.avro.Schema schema; | ||
|
||
|
@@ -36,7 +39,7 @@ public class StorageAPIAvroReader implements GATKAvroReader { | |
// collection. | ||
private BinaryDecoder decoder = null; | ||
|
||
private AvroProto.AvroRows currentAvroRows; | ||
private AvroRows currentAvroRows; | ||
|
||
// GenericRecord object will be reused. | ||
private GenericRecord nextRow = null; | ||
|
@@ -54,32 +57,39 @@ public StorageAPIAvroReader(final TableReference tableRef, final String rowRestr | |
try { | ||
logger.info("Using Storage API from " + tableRef.getFQTableName() + " with '" + rowRestriction + "'"); | ||
|
||
this.client = BigQueryStorageClient.create(); | ||
this.client = BigQueryReadClient.create(); | ||
|
||
final String parent = String.format("projects/%s", parentProjectId == null || parentProjectId.isEmpty() ? tableRef.tableProject : parentProjectId); | ||
|
||
final TableReferenceProto.TableReference tableReference = TableReferenceProto.TableReference.newBuilder() | ||
.setProjectId(tableRef.tableProject) | ||
.setDatasetId(tableRef.tableDataset) | ||
.setTableId(tableRef.tableName) | ||
.build(); | ||
final String srcTable = | ||
String.format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there no longer tableReference objects, just table objects? Doing this with a builder pattern feels cleaner |
||
"projects/%s/datasets/%s/tables/%s", | ||
tableRef.tableProject, tableRef.tableDataset, tableRef.tableName); | ||
|
||
Builder readOptions = ReadOptions.TableReadOptions.newBuilder() | ||
.addAllSelectedFields(tableRef.fields); | ||
Builder readOptions = | ||
ReadSession.TableReadOptions.newBuilder() | ||
.addAllSelectedFields(tableRef.fields); | ||
|
||
if (rowRestriction != null) { | ||
readOptions.setRowRestriction(rowRestriction); | ||
} | ||
final ReadOptions.TableReadOptions tableReadOptions = readOptions.build(); | ||
|
||
final Storage.CreateReadSessionRequest.Builder builder = Storage.CreateReadSessionRequest.newBuilder() | ||
.setParent(parent) | ||
.setTableReference(tableReference) | ||
.setReadOptions(tableReadOptions) | ||
.setRequestedStreams(1) | ||
.setFormat(Storage.DataFormat.AVRO); | ||
|
||
final Storage.ReadSession session = client.createReadSession(builder.build()); | ||
final TableReadOptions tableReadOptions = readOptions.build(); | ||
|
||
// Start specifying the read session we want created. | ||
ReadSession.Builder sessionBuilder = | ||
ReadSession.newBuilder() | ||
.setTable(srcTable) | ||
.setDataFormat(DataFormat.AVRO) | ||
.setReadOptions(tableReadOptions); | ||
|
||
// Begin building the session creation request. | ||
CreateReadSessionRequest.Builder builder = | ||
CreateReadSessionRequest.newBuilder() | ||
.setParent(parent) | ||
.setReadSession(sessionBuilder) | ||
.setMaxStreamCount(1); | ||
|
||
final ReadSession session = client.createReadSession(builder.build()); | ||
if (session.getStreamsCount() > 0) { | ||
|
||
this.schema = new org.apache.avro.Schema.Parser().parse(session.getAvroSchema().getSchema()); | ||
|
@@ -90,12 +100,10 @@ public StorageAPIAvroReader(final TableReference tableRef, final String rowRestr | |
logger.info("Storage API Session ID: " + session.getName()); | ||
|
||
// Use the first stream to perform reading. | ||
Storage.StreamPosition readPosition = Storage.StreamPosition.newBuilder() | ||
.setStream(session.getStreams(0)) | ||
.build(); | ||
String streamName = session.getStreams(0).getName(); | ||
|
||
Storage.ReadRowsRequest readRowsRequest = Storage.ReadRowsRequest.newBuilder() | ||
.setReadPosition(readPosition) | ||
ReadRowsRequest readRowsRequest = ReadRowsRequest.newBuilder() | ||
.setReadStream(streamName) | ||
.build(); | ||
|
||
this.serverStream = client.readRowsCallable().call(readRowsRequest).iterator(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that google renamed storageAPI to ReadAPI, should we rename this class? not super important.