Skip to content

Commit

Permalink
Create ReadSession asynchronously (#928)
Browse files Browse the repository at this point in the history
* Create ReadSession asynchronously

* moving executor to private member
  • Loading branch information
vishalkarve15 committed Mar 20, 2023
1 parent 5f83d7c commit ae2a5eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public TableId getTableId() {

@Override
public Scan build() {
// start creating ReadSession asynchronously
// no further pushFilters / pruneColumns expected from this point
ctx.build();
return this; // new BigQueryScan(ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -109,6 +111,7 @@ public OptionalLong numRows() {
// "planBatchInputPartitionContexts" or
// "planInputPartitionContexts". We will use this to get table statistics in estimateStatistics.
private Supplier<ReadSessionResponse> readSessionResponse;
private final ExecutorService asyncReadSessionExecutor = Executors.newSingleThreadExecutor();

public BigQueryDataSourceReaderContext(
TableInfo table,
Expand Down Expand Up @@ -451,4 +454,10 @@ public BigQueryRDDFactory getBigQueryRddFactory() {
public TableInfo getTableInfo() {
return this.table;
}

public void build() {
// Supplier provided by Suppliers.memoize is thread-safe
asyncReadSessionExecutor.submit(() -> readSessionResponse.get());
asyncReadSessionExecutor.shutdown();
}
}

0 comments on commit ae2a5eb

Please sign in to comment.