Class FakeDatasetService
java.lang.Object
org.apache.beam.sdk.io.gcp.testing.FakeDatasetService
- All Implemented Interfaces:
Serializable
,AutoCloseable
,BigQueryServices.DatasetService
,BigQueryServices.WriteStreamService
@Internal
public class FakeDatasetService
extends Object
implements BigQueryServices.DatasetService, BigQueryServices.WriteStreamService, Serializable
A fake dataset service that can be serialized, for use in testReadFromTable.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.DatasetService
BigQueryServices.DatasetService.TableMetadataView
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
com.google.api.core.ApiFuture
<com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse> commitWriteStreams
(String tableUrn, Iterable<String> writeStreamNames) Commit write streams of type PENDING.void
createDataset
(String projectId, String datasetId, String location, String description, Long defaultTableExpirationMs) Create aDataset
with the givenlocation
,description
and default expiration time for tables in the dataset (ifnull
, tables don't expire).void
createTable
(Table table) Creates the specified table if it does not exist.com.google.cloud.bigquery.storage.v1.WriteStream
createWriteStream
(String tableUrn, com.google.cloud.bigquery.storage.v1.WriteStream.Type type) Create a Write Stream for use with the Storage Write API.void
deleteDataset
(String projectId, String datasetId) Deletes the dataset specified by the datasetId value.void
deleteTable
(TableReference tableRef) Deletes the table specified by tableId from the dataset.void
failOnInsert
(Map<TableRow, List<TableDataInsertAllResponse.InsertErrors>> insertErrors) Cause a givenTableRow
object to fail when it's inserted.com.google.api.core.ApiFuture
<com.google.cloud.bigquery.storage.v1.FinalizeWriteStreamResponse> finalizeWriteStream
(String streamName) Finalize a write stream.com.google.api.core.ApiFuture
<com.google.cloud.bigquery.storage.v1.FlushRowsResponse> Flush a given stream up to the given offset.getAllRows
(String projectId, String datasetId, String tableId) getDataset
(String projectId, String datasetId) Gets the specifiedDataset
resource by dataset ID.int
getStreamAppendClient
(String streamName, DescriptorProtos.DescriptorProto descriptor, boolean useConnectionPool, com.google.cloud.bigquery.storage.v1.AppendRowsRequest.MissingValueInterpretation missingValueInterpretation) Create an append client for a given Storage API write stream.getTable
(TableReference tableRef) Gets the specifiedTable
resource by table ID.getTable
(TableReference tableRef, List<String> selectedFields) getTable
(TableReference tableRef, List<String> selectedFields, BigQueryServices.DatasetService.TableMetadataView view) getTableImpl
(TableReference tableRef, List<String> selectedFields, BigQueryServices.DatasetService.TableMetadataView view) com.google.cloud.bigquery.storage.v1.TableSchema
getWriteStreamSchema
(String streamName) long
<T> long
insertAll
(TableReference ref, List<FailsafeValueInSingleWindow<TableRow, TableRow>> rowList, List<String> insertIdList, InsertRetryPolicy retryPolicy, List<ValueInSingleWindow<T>> failedInserts, ErrorContainer<T> errorContainer, boolean skipInvalidRows, boolean ignoreUnknownValues, boolean ignoreInsertIds, List<ValueInSingleWindow<TableRow>> successfulRows) InsertsTableRows
with the specified insertIds if not null.boolean
isTableEmpty
(TableReference tableRef) Returns true if the table is empty.patchTableDescription
(TableReference tableReference, String tableDescription) Patch BigQueryTable
description.void
setPrimaryKey
(TableReference tableReference, List<String> columns) void
setShouldFailRow
(Function<TableRow, Boolean> shouldFailRow) static void
setUp()
void
updateTableSchema
(TableReference tableReference, TableSchema tableSchema)
-
Constructor Details
-
FakeDatasetService
public FakeDatasetService()
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
setUp
public static void setUp() -
setShouldFailRow
-
getTable
Description copied from interface:BigQueryServices.DatasetService
Gets the specifiedTable
resource by table ID.Returns null if the table is not found.
- Specified by:
getTable
in interfaceBigQueryServices.DatasetService
- Throws:
InterruptedException
IOException
-
getTable
public Table getTable(TableReference tableRef, @Nullable List<String> selectedFields) throws InterruptedException, IOException - Specified by:
getTable
in interfaceBigQueryServices.DatasetService
- Throws:
InterruptedException
IOException
-
getTable
public Table getTable(TableReference tableRef, @Nullable List<String> selectedFields, @Nullable BigQueryServices.DatasetService.TableMetadataView view) throws InterruptedException, IOException - Specified by:
getTable
in interfaceBigQueryServices.DatasetService
- Throws:
InterruptedException
IOException
-
getTableImpl
public Table getTableImpl(TableReference tableRef, @Nullable List<String> selectedFields, @Nullable BigQueryServices.DatasetService.TableMetadataView view) throws InterruptedException, IOException - Throws:
InterruptedException
IOException
-
getAllRows
public List<TableRow> getAllRows(String projectId, String datasetId, String tableId) throws InterruptedException, IOException - Throws:
InterruptedException
IOException
-
getAllIds
public List<String> getAllIds(String projectId, String datasetId, String tableId) throws InterruptedException, IOException - Throws:
InterruptedException
IOException
-
deleteTable
Description copied from interface:BigQueryServices.DatasetService
Deletes the table specified by tableId from the dataset. If the table contains data, all the data will be deleted.- Specified by:
deleteTable
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
InterruptedException
-
createTable
Description copied from interface:BigQueryServices.DatasetService
Creates the specified table if it does not exist.- Specified by:
createTable
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
-
updateTableSchema
public void updateTableSchema(TableReference tableReference, TableSchema tableSchema) throws IOException - Throws:
IOException
-
setPrimaryKey
- Throws:
IOException
-
isTableEmpty
Description copied from interface:BigQueryServices.DatasetService
Returns true if the table is empty.- Specified by:
isTableEmpty
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
- if the table is not found.InterruptedException
-
getDataset
public Dataset getDataset(String projectId, String datasetId) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetService
Gets the specifiedDataset
resource by dataset ID.- Specified by:
getDataset
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
InterruptedException
-
createDataset
public void createDataset(String projectId, String datasetId, String location, String description, Long defaultTableExpirationMs) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetService
Create aDataset
with the givenlocation
,description
and default expiration time for tables in the dataset (ifnull
, tables don't expire).- Specified by:
createDataset
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
InterruptedException
-
deleteDataset
public void deleteDataset(String projectId, String datasetId) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetService
Deletes the dataset specified by the datasetId value.Before you can delete a dataset, you must delete all its tables.
- Specified by:
deleteDataset
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
InterruptedException
-
getInsertCount
public int getInsertCount() -
insertAll
public long insertAll(TableReference ref, List<TableRow> rowList, @Nullable List<String> insertIdList) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
insertAll
public <T> long insertAll(TableReference ref, List<FailsafeValueInSingleWindow<TableRow, TableRow>> rowList, @Nullable List<String> insertIdList, InsertRetryPolicy retryPolicy, List<ValueInSingleWindow<T>> failedInserts, ErrorContainer<T> errorContainer, boolean skipInvalidRows, boolean ignoreUnknownValues, boolean ignoreInsertIds, List<ValueInSingleWindow<TableRow>> successfulRows) throws IOException, InterruptedExceptionDescription copied from interface:BigQueryServices.DatasetService
InsertsTableRows
with the specified insertIds if not null.If any insert fail permanently according to the retry policy, those rows are added to failedInserts.
Returns the total bytes count of
TableRows
.- Specified by:
insertAll
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
InterruptedException
-
patchTableDescription
public Table patchTableDescription(TableReference tableReference, @Nullable String tableDescription) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetService
Patch BigQueryTable
description.- Specified by:
patchTableDescription
in interfaceBigQueryServices.DatasetService
- Throws:
IOException
InterruptedException
-
createWriteStream
public com.google.cloud.bigquery.storage.v1.WriteStream createWriteStream(String tableUrn, com.google.cloud.bigquery.storage.v1.WriteStream.Type type) throws InterruptedException Description copied from interface:BigQueryServices.WriteStreamService
Create a Write Stream for use with the Storage Write API.- Specified by:
createWriteStream
in interfaceBigQueryServices.WriteStreamService
- Throws:
InterruptedException
-
getWriteStreamSchema
@Nullable public com.google.cloud.bigquery.storage.v1.TableSchema getWriteStreamSchema(String streamName) - Specified by:
getWriteStreamSchema
in interfaceBigQueryServices.WriteStreamService
-
getStreamAppendClient
public BigQueryServices.StreamAppendClient getStreamAppendClient(String streamName, DescriptorProtos.DescriptorProto descriptor, boolean useConnectionPool, com.google.cloud.bigquery.storage.v1.AppendRowsRequest.MissingValueInterpretation missingValueInterpretation) throws Exception Description copied from interface:BigQueryServices.WriteStreamService
Create an append client for a given Storage API write stream. The stream must be created first.- Specified by:
getStreamAppendClient
in interfaceBigQueryServices.WriteStreamService
- Throws:
Exception
-
flush
public com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.FlushRowsResponse> flush(String streamName, long offset) Description copied from interface:BigQueryServices.WriteStreamService
Flush a given stream up to the given offset. The stream must have type BUFFERED.- Specified by:
flush
in interfaceBigQueryServices.WriteStreamService
-
finalizeWriteStream
public com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.FinalizeWriteStreamResponse> finalizeWriteStream(String streamName) Description copied from interface:BigQueryServices.WriteStreamService
Finalize a write stream. After finalization, no more records can be appended to the stream.- Specified by:
finalizeWriteStream
in interfaceBigQueryServices.WriteStreamService
-
commitWriteStreams
public com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse> commitWriteStreams(String tableUrn, Iterable<String> writeStreamNames) Description copied from interface:BigQueryServices.WriteStreamService
Commit write streams of type PENDING. The streams must be finalized before committing.- Specified by:
commitWriteStreams
in interfaceBigQueryServices.WriteStreamService
-
failOnInsert
Cause a givenTableRow
object to fail when it's inserted. The errors link the list will be returned on subsequent retries, and the insert will succeed when the errors run out.
-