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 TypeMethodDescriptionvoidclose()com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse> commitWriteStreams(String tableUrn, Iterable<String> writeStreamNames) Commit write streams of type PENDING.voidcreateDataset(String projectId, String datasetId, String location, String description, Long defaultTableExpirationMs) Create aDatasetwith the givenlocation,descriptionand default expiration time for tables in the dataset (ifnull, tables don't expire).voidcreateTable(Table table) Creates the specified table if it does not exist.com.google.cloud.bigquery.storage.v1.WriteStreamcreateWriteStream(String tableUrn, com.google.cloud.bigquery.storage.v1.WriteStream.Type type) Create a Write Stream for use with the Storage Write API.voiddeleteDataset(String projectId, String datasetId) Deletes the dataset specified by the datasetId value.voiddeleteTable(TableReference tableRef) Deletes the table specified by tableId from the dataset.voidfailOnInsert(Map<TableRow, List<TableDataInsertAllResponse.InsertErrors>> insertErrors) Cause a givenTableRowobject 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 specifiedDatasetresource by dataset ID.intgetStreamAppendClient(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 specifiedTableresource 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.TableSchemagetWriteStreamSchema(String streamName) long<T> longinsertAll(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) InsertsTableRowswith the specified insertIds if not null.booleanisTableEmpty(TableReference tableRef) Returns true if the table is empty.patchTableDescription(TableReference tableReference, String tableDescription) Patch BigQueryTabledescription.voidsetPrimaryKey(TableReference tableReference, List<String> columns) voidsetShouldFailRow(Function<TableRow, Boolean> shouldFailRow) static voidsetUp()voidupdateTableSchema(TableReference tableReference, TableSchema tableSchema)
-
Constructor Details
-
FakeDatasetService
public FakeDatasetService()
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
setUp
public static void setUp() -
setShouldFailRow
-
getTable
Description copied from interface:BigQueryServices.DatasetServiceGets the specifiedTableresource by table ID.Returns null if the table is not found.
- Specified by:
getTablein interfaceBigQueryServices.DatasetService- Throws:
InterruptedExceptionIOException
-
getTable
public Table getTable(TableReference tableRef, @Nullable List<String> selectedFields) throws InterruptedException, IOException - Specified by:
getTablein interfaceBigQueryServices.DatasetService- Throws:
InterruptedExceptionIOException
-
getTable
public Table getTable(TableReference tableRef, @Nullable List<String> selectedFields, @Nullable BigQueryServices.DatasetService.TableMetadataView view) throws InterruptedException, IOException - Specified by:
getTablein interfaceBigQueryServices.DatasetService- Throws:
InterruptedExceptionIOException
-
getTableImpl
public Table getTableImpl(TableReference tableRef, @Nullable List<String> selectedFields, @Nullable BigQueryServices.DatasetService.TableMetadataView view) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
getAllRows
public List<TableRow> getAllRows(String projectId, String datasetId, String tableId) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
getAllIds
public List<String> getAllIds(String projectId, String datasetId, String tableId) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
deleteTable
Description copied from interface:BigQueryServices.DatasetServiceDeletes the table specified by tableId from the dataset. If the table contains data, all the data will be deleted.- Specified by:
deleteTablein interfaceBigQueryServices.DatasetService- Throws:
IOExceptionInterruptedException
-
createTable
Description copied from interface:BigQueryServices.DatasetServiceCreates the specified table if it does not exist.- Specified by:
createTablein 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.DatasetServiceReturns true if the table is empty.- Specified by:
isTableEmptyin 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.DatasetServiceGets the specifiedDatasetresource by dataset ID.- Specified by:
getDatasetin interfaceBigQueryServices.DatasetService- Throws:
IOExceptionInterruptedException
-
createDataset
public void createDataset(String projectId, String datasetId, String location, String description, Long defaultTableExpirationMs) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetServiceCreate aDatasetwith the givenlocation,descriptionand default expiration time for tables in the dataset (ifnull, tables don't expire).- Specified by:
createDatasetin interfaceBigQueryServices.DatasetService- Throws:
IOExceptionInterruptedException
-
deleteDataset
public void deleteDataset(String projectId, String datasetId) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetServiceDeletes the dataset specified by the datasetId value.Before you can delete a dataset, you must delete all its tables.
- Specified by:
deleteDatasetin interfaceBigQueryServices.DatasetService- Throws:
IOExceptionInterruptedException
-
getInsertCount
public int getInsertCount() -
insertAll
public long insertAll(TableReference ref, List<TableRow> rowList, @Nullable List<String> insertIdList) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
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.DatasetServiceInsertsTableRowswith 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:
insertAllin interfaceBigQueryServices.DatasetService- Throws:
IOExceptionInterruptedException
-
patchTableDescription
public Table patchTableDescription(TableReference tableReference, @Nullable String tableDescription) throws IOException, InterruptedException Description copied from interface:BigQueryServices.DatasetServicePatch BigQueryTabledescription.- Specified by:
patchTableDescriptionin interfaceBigQueryServices.DatasetService- Throws:
IOExceptionInterruptedException
-
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.WriteStreamServiceCreate a Write Stream for use with the Storage Write API.- Specified by:
createWriteStreamin interfaceBigQueryServices.WriteStreamService- Throws:
InterruptedException
-
getWriteStreamSchema
@Nullable public com.google.cloud.bigquery.storage.v1.TableSchema getWriteStreamSchema(String streamName) - Specified by:
getWriteStreamSchemain 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.WriteStreamServiceCreate an append client for a given Storage API write stream. The stream must be created first.- Specified by:
getStreamAppendClientin 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.WriteStreamServiceFlush a given stream up to the given offset. The stream must have type BUFFERED.- Specified by:
flushin interfaceBigQueryServices.WriteStreamService
-
finalizeWriteStream
public com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.FinalizeWriteStreamResponse> finalizeWriteStream(String streamName) Description copied from interface:BigQueryServices.WriteStreamServiceFinalize a write stream. After finalization, no more records can be appended to the stream.- Specified by:
finalizeWriteStreamin 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.WriteStreamServiceCommit write streams of type PENDING. The streams must be finalized before committing.- Specified by:
commitWriteStreamsin interfaceBigQueryServices.WriteStreamService
-
failOnInsert
Cause a givenTableRowobject 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.
-