@Generated(value="by gapic-generator") @BetaApi public class BaseBigQueryStorageClient extends Object implements com.google.api.gax.core.BackgroundResource
The BigQuery storage API can be used to read data stored in BigQuery.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
TableReference tableReference = TableReference.newBuilder().build();
String parent = "";
int requestedStreams = 0;
ReadSession response = baseBigQueryStorageClient.createReadSession(tableReference, parent, requestedStreams);
}
Note: close() needs to be called on the baseBigQueryStorageClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of BaseBigQueryStorageSettings to create(). For example:
To customize credentials:
BaseBigQueryStorageSettings baseBigQueryStorageSettings =
BaseBigQueryStorageSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
BaseBigQueryStorageClient baseBigQueryStorageClient =
BaseBigQueryStorageClient.create(baseBigQueryStorageSettings);
To customize the endpoint:
BaseBigQueryStorageSettings baseBigQueryStorageSettings =
BaseBigQueryStorageSettings.newBuilder().setEndpoint(myEndpoint).build();
BaseBigQueryStorageClient baseBigQueryStorageClient =
BaseBigQueryStorageClient.create(baseBigQueryStorageSettings);
Modifier | Constructor and Description |
---|---|
protected |
BaseBigQueryStorageClient(BaseBigQueryStorageSettings settings)
Constructs an instance of BaseBigQueryStorageClient, using the given settings.
|
protected |
BaseBigQueryStorageClient(BigQueryStorageStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
Storage.BatchCreateReadSessionStreamsResponse |
batchCreateReadSessionStreams(Storage.BatchCreateReadSessionStreamsRequest request)
Creates additional streams for a ReadSession.
|
Storage.BatchCreateReadSessionStreamsResponse |
batchCreateReadSessionStreams(Storage.ReadSession session,
int requestedStreams)
Creates additional streams for a ReadSession.
|
com.google.api.gax.rpc.UnaryCallable<Storage.BatchCreateReadSessionStreamsRequest,Storage.BatchCreateReadSessionStreamsResponse> |
batchCreateReadSessionStreamsCallable()
Creates additional streams for a ReadSession.
|
void |
close() |
static BaseBigQueryStorageClient |
create()
Constructs an instance of BaseBigQueryStorageClient with default settings.
|
static BaseBigQueryStorageClient |
create(BaseBigQueryStorageSettings settings)
Constructs an instance of BaseBigQueryStorageClient, using the given settings.
|
static BaseBigQueryStorageClient |
create(BigQueryStorageStub stub)
Constructs an instance of BaseBigQueryStorageClient, using the given stub for making calls.
|
Storage.ReadSession |
createReadSession(Storage.CreateReadSessionRequest request)
Creates a new read session.
|
Storage.ReadSession |
createReadSession(TableReferenceProto.TableReference tableReference,
String parent,
int requestedStreams)
Creates a new read session.
|
com.google.api.gax.rpc.UnaryCallable<Storage.CreateReadSessionRequest,Storage.ReadSession> |
createReadSessionCallable()
Creates a new read session.
|
void |
finalizeStream(Storage.FinalizeStreamRequest request)
Triggers the graceful termination of a single stream in a ReadSession.
|
void |
finalizeStream(Storage.Stream stream)
Triggers the graceful termination of a single stream in a ReadSession.
|
com.google.api.gax.rpc.UnaryCallable<Storage.FinalizeStreamRequest,Empty> |
finalizeStreamCallable()
Triggers the graceful termination of a single stream in a ReadSession.
|
BaseBigQueryStorageSettings |
getSettings() |
BigQueryStorageStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
com.google.api.gax.rpc.ServerStreamingCallable<Storage.ReadRowsRequest,Storage.ReadRowsResponse> |
readRowsCallable()
Reads rows from the table in the format prescribed by the read session.
|
void |
shutdown() |
void |
shutdownNow() |
Storage.SplitReadStreamResponse |
splitReadStream(Storage.SplitReadStreamRequest request)
Splits a given read stream into two Streams.
|
Storage.SplitReadStreamResponse |
splitReadStream(Storage.Stream originalStream)
Splits a given read stream into two Streams.
|
com.google.api.gax.rpc.UnaryCallable<Storage.SplitReadStreamRequest,Storage.SplitReadStreamResponse> |
splitReadStreamCallable()
Splits a given read stream into two Streams.
|
protected BaseBigQueryStorageClient(BaseBigQueryStorageSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected BaseBigQueryStorageClient(BigQueryStorageStub stub)
public static final BaseBigQueryStorageClient create() throws IOException
IOException
public static final BaseBigQueryStorageClient create(BaseBigQueryStorageSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final BaseBigQueryStorageClient create(BigQueryStorageStub stub)
public final BaseBigQueryStorageSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public BigQueryStorageStub getStub()
public final Storage.ReadSession createReadSession(TableReferenceProto.TableReference tableReference, String parent, int requestedStreams)
A particular row can be read by at most one stream. When the caller has reached the end of each stream in the session, then all the data in the table has been read.
Read sessions automatically expire 24 hours after they are created and do not require manual clean-up by the caller.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
TableReference tableReference = TableReference.newBuilder().build();
String parent = "";
int requestedStreams = 0;
ReadSession response = baseBigQueryStorageClient.createReadSession(tableReference, parent, requestedStreams);
}
tableReference
- Required. Reference to the table to read.parent
- Required. String of the form `projects/{project_id}` indicating the project this
ReadSession is associated with. This is the project that will be billed for usage.requestedStreams
- Initial number of streams. If unset or 0, we will provide a value of
streams so as to produce reasonable throughput. Must be non-negative. The number of streams
may be lower than the requested number, depending on the amount parallelism that is
reasonable for the table and the maximum amount of parallelism allowed by the system.
Streams must be read starting from offset 0.
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Storage.ReadSession createReadSession(Storage.CreateReadSessionRequest request)
A particular row can be read by at most one stream. When the caller has reached the end of each stream in the session, then all the data in the table has been read.
Read sessions automatically expire 24 hours after they are created and do not require manual clean-up by the caller.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
TableReference tableReference = TableReference.newBuilder().build();
String parent = "";
CreateReadSessionRequest request = CreateReadSessionRequest.newBuilder()
.setTableReference(tableReference)
.setParent(parent)
.build();
ReadSession response = baseBigQueryStorageClient.createReadSession(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<Storage.CreateReadSessionRequest,Storage.ReadSession> createReadSessionCallable()
A particular row can be read by at most one stream. When the caller has reached the end of each stream in the session, then all the data in the table has been read.
Read sessions automatically expire 24 hours after they are created and do not require manual clean-up by the caller.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
TableReference tableReference = TableReference.newBuilder().build();
String parent = "";
CreateReadSessionRequest request = CreateReadSessionRequest.newBuilder()
.setTableReference(tableReference)
.setParent(parent)
.build();
ApiFuture<ReadSession> future = baseBigQueryStorageClient.createReadSessionCallable().futureCall(request);
// Do something
ReadSession response = future.get();
}
public final com.google.api.gax.rpc.ServerStreamingCallable<Storage.ReadRowsRequest,Storage.ReadRowsResponse> readRowsCallable()
Each request also returns a set of stream statistics reflecting the estimated total number of rows in the read stream. This number is computed based on the total table size and the number of active streams in the read session, and may change as other streams continue to read data.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
StreamPosition readPosition = StreamPosition.newBuilder().build();
ReadRowsRequest request = ReadRowsRequest.newBuilder()
.setReadPosition(readPosition)
.build();
ServerStream<ReadRowsResponse> stream = baseBigQueryStorageClient.readRowsCallable().call(request);
for (ReadRowsResponse response : stream) {
// Do something when receive a response
}
}
public final Storage.BatchCreateReadSessionStreamsResponse batchCreateReadSessionStreams(Storage.ReadSession session, int requestedStreams)
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
ReadSession session = ReadSession.newBuilder().build();
int requestedStreams = 0;
BatchCreateReadSessionStreamsResponse response = baseBigQueryStorageClient.batchCreateReadSessionStreams(session, requestedStreams);
}
session
- Required. Must be a non-expired session obtained from a call to
CreateReadSession. Only the name field needs to be set.requestedStreams
- Required. Number of new streams requested. Must be positive. Number of
added streams may be less than this, see CreateReadSessionRequest for more information.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Storage.BatchCreateReadSessionStreamsResponse batchCreateReadSessionStreams(Storage.BatchCreateReadSessionStreamsRequest request)
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
ReadSession session = ReadSession.newBuilder().build();
int requestedStreams = 0;
BatchCreateReadSessionStreamsRequest request = BatchCreateReadSessionStreamsRequest.newBuilder()
.setSession(session)
.setRequestedStreams(requestedStreams)
.build();
BatchCreateReadSessionStreamsResponse response = baseBigQueryStorageClient.batchCreateReadSessionStreams(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<Storage.BatchCreateReadSessionStreamsRequest,Storage.BatchCreateReadSessionStreamsResponse> batchCreateReadSessionStreamsCallable()
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
ReadSession session = ReadSession.newBuilder().build();
int requestedStreams = 0;
BatchCreateReadSessionStreamsRequest request = BatchCreateReadSessionStreamsRequest.newBuilder()
.setSession(session)
.setRequestedStreams(requestedStreams)
.build();
ApiFuture<BatchCreateReadSessionStreamsResponse> future = baseBigQueryStorageClient.batchCreateReadSessionStreamsCallable().futureCall(request);
// Do something
BatchCreateReadSessionStreamsResponse response = future.get();
}
public final void finalizeStream(Storage.Stream stream)
This API does not delete the stream -- it remains visible in the ReadSession, and any data processed by the stream is not released to other streams. However, no additional data will be assigned to the stream once this call completes. Callers must continue reading data on the stream until the end of the stream is reached so that data which has already been assigned to the stream will be processed.
This method will return an error if there are no other live streams in the Session, or if SplitReadStream() has been called on the given Stream.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
Stream stream = Stream.newBuilder().build();
baseBigQueryStorageClient.finalizeStream(stream);
}
stream
- Stream to finalize.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void finalizeStream(Storage.FinalizeStreamRequest request)
This API does not delete the stream -- it remains visible in the ReadSession, and any data processed by the stream is not released to other streams. However, no additional data will be assigned to the stream once this call completes. Callers must continue reading data on the stream until the end of the stream is reached so that data which has already been assigned to the stream will be processed.
This method will return an error if there are no other live streams in the Session, or if SplitReadStream() has been called on the given Stream.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
Stream stream = Stream.newBuilder().build();
FinalizeStreamRequest request = FinalizeStreamRequest.newBuilder()
.setStream(stream)
.build();
baseBigQueryStorageClient.finalizeStream(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<Storage.FinalizeStreamRequest,Empty> finalizeStreamCallable()
This API does not delete the stream -- it remains visible in the ReadSession, and any data processed by the stream is not released to other streams. However, no additional data will be assigned to the stream once this call completes. Callers must continue reading data on the stream until the end of the stream is reached so that data which has already been assigned to the stream will be processed.
This method will return an error if there are no other live streams in the Session, or if SplitReadStream() has been called on the given Stream.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
Stream stream = Stream.newBuilder().build();
FinalizeStreamRequest request = FinalizeStreamRequest.newBuilder()
.setStream(stream)
.build();
ApiFuture<Void> future = baseBigQueryStorageClient.finalizeStreamCallable().futureCall(request);
// Do something
future.get();
}
public final Storage.SplitReadStreamResponse splitReadStream(Storage.Stream originalStream)
Moreover, the two child streams will be allocated back to back in the original Stream. Concretely, it is guaranteed that for streams Original, Primary, and Residual, that Original[0-j] = Primary[0-j] and Original[j-n] = Residual[0-m] once the streams have been read to completion.
This method is guaranteed to be idempotent.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
Stream originalStream = Stream.newBuilder().build();
SplitReadStreamResponse response = baseBigQueryStorageClient.splitReadStream(originalStream);
}
originalStream
- Stream to split.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Storage.SplitReadStreamResponse splitReadStream(Storage.SplitReadStreamRequest request)
Moreover, the two child streams will be allocated back to back in the original Stream. Concretely, it is guaranteed that for streams Original, Primary, and Residual, that Original[0-j] = Primary[0-j] and Original[j-n] = Residual[0-m] once the streams have been read to completion.
This method is guaranteed to be idempotent.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
Stream originalStream = Stream.newBuilder().build();
SplitReadStreamRequest request = SplitReadStreamRequest.newBuilder()
.setOriginalStream(originalStream)
.build();
SplitReadStreamResponse response = baseBigQueryStorageClient.splitReadStream(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<Storage.SplitReadStreamRequest,Storage.SplitReadStreamResponse> splitReadStreamCallable()
Moreover, the two child streams will be allocated back to back in the original Stream. Concretely, it is guaranteed that for streams Original, Primary, and Residual, that Original[0-j] = Primary[0-j] and Original[j-n] = Residual[0-m] once the streams have been read to completion.
This method is guaranteed to be idempotent.
Sample code:
try (BaseBigQueryStorageClient baseBigQueryStorageClient = BaseBigQueryStorageClient.create()) {
Stream originalStream = Stream.newBuilder().build();
SplitReadStreamRequest request = SplitReadStreamRequest.newBuilder()
.setOriginalStream(originalStream)
.build();
ApiFuture<SplitReadStreamResponse> future = baseBigQueryStorageClient.splitReadStreamCallable().futureCall(request);
// Do something
SplitReadStreamResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.