Class FakeDatasetService
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.testing.FakeDatasetService
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.AutoCloseable,BigQueryServices.DatasetService,BigQueryServices.WriteStreamService
@Internal public class FakeDatasetService extends java.lang.Object implements BigQueryServices.DatasetService, BigQueryServices.WriteStreamService, java.io.Serializable
A fake dataset service that can be serialized, for use in testReadFromTable.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.DatasetService
BigQueryServices.DatasetService.TableMetadataView
-
-
Constructor Summary
Constructors Constructor Description FakeDatasetService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse>commitWriteStreams(java.lang.String tableUrn, java.lang.Iterable<java.lang.String> writeStreamNames)Commit write streams of type PENDING.voidcreateDataset(java.lang.String projectId, java.lang.String datasetId, java.lang.String location, java.lang.String description, java.lang.Long defaultTableExpirationMs)Create aDatasetwith the givenlocation,descriptionand default expiration time for tables in the dataset (ifnull, tables don't expire).voidcreateTable(com.google.api.services.bigquery.model.Table table)Creates the specified table if it does not exist.com.google.cloud.bigquery.storage.v1.WriteStreamcreateWriteStream(java.lang.String tableUrn, com.google.cloud.bigquery.storage.v1.WriteStream.Type type)Create a Write Stream for use with the Storage Write API.voiddeleteDataset(java.lang.String projectId, java.lang.String datasetId)Deletes the dataset specified by the datasetId value.voiddeleteTable(com.google.api.services.bigquery.model.TableReference tableRef)Deletes the table specified by tableId from the dataset.voidfailOnInsert(java.util.Map<com.google.api.services.bigquery.model.TableRow,java.util.List<com.google.api.services.bigquery.model.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(java.lang.String streamName)Finalize a write stream.com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.FlushRowsResponse>flush(java.lang.String streamName, long offset)Flush a given stream up to the given offset.java.util.List<java.lang.String>getAllIds(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId)java.util.List<com.google.api.services.bigquery.model.TableRow>getAllRows(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId)com.google.api.services.bigquery.model.DatasetgetDataset(java.lang.String projectId, java.lang.String datasetId)Gets the specifiedDatasetresource by dataset ID.intgetInsertCount()BigQueryServices.StreamAppendClientgetStreamAppendClient(java.lang.String streamName, com.google.protobuf.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.com.google.api.services.bigquery.model.TablegetTable(com.google.api.services.bigquery.model.TableReference tableRef)Gets the specifiedTableresource by table ID.com.google.api.services.bigquery.model.TablegetTable(com.google.api.services.bigquery.model.TableReference tableRef, java.util.List<java.lang.String> selectedFields)com.google.api.services.bigquery.model.TablegetTable(com.google.api.services.bigquery.model.TableReference tableRef, java.util.List<java.lang.String> selectedFields, BigQueryServices.DatasetService.TableMetadataView view)com.google.api.services.bigquery.model.TablegetTableImpl(com.google.api.services.bigquery.model.TableReference tableRef, java.util.List<java.lang.String> selectedFields, BigQueryServices.DatasetService.TableMetadataView view)com.google.cloud.bigquery.storage.v1.TableSchemagetWriteStreamSchema(java.lang.String streamName)longinsertAll(com.google.api.services.bigquery.model.TableReference ref, java.util.List<com.google.api.services.bigquery.model.TableRow> rowList, java.util.List<java.lang.String> insertIdList)<T> longinsertAll(com.google.api.services.bigquery.model.TableReference ref, java.util.List<org.apache.beam.sdk.values.FailsafeValueInSingleWindow<com.google.api.services.bigquery.model.TableRow,com.google.api.services.bigquery.model.TableRow>> rowList, java.util.List<java.lang.String> insertIdList, InsertRetryPolicy retryPolicy, java.util.List<org.apache.beam.sdk.values.ValueInSingleWindow<T>> failedInserts, ErrorContainer<T> errorContainer, boolean skipInvalidRows, boolean ignoreUnknownValues, boolean ignoreInsertIds, java.util.List<org.apache.beam.sdk.values.ValueInSingleWindow<com.google.api.services.bigquery.model.TableRow>> successfulRows)InsertsTableRowswith the specified insertIds if not null.booleanisTableEmpty(com.google.api.services.bigquery.model.TableReference tableRef)Returns true if the table is empty.com.google.api.services.bigquery.model.TablepatchTableDescription(com.google.api.services.bigquery.model.TableReference tableReference, java.lang.String tableDescription)Patch BigQueryTabledescription.voidsetPrimaryKey(com.google.api.services.bigquery.model.TableReference tableReference, java.util.List<java.lang.String> columns)voidsetShouldFailRow(java.util.function.Function<com.google.api.services.bigquery.model.TableRow,java.lang.Boolean> shouldFailRow)static voidsetUp()voidupdateTableSchema(com.google.api.services.bigquery.model.TableReference tableReference, com.google.api.services.bigquery.model.TableSchema tableSchema)
-
-
-
Method Detail
-
close
public void close() throws java.lang.Exception- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
setUp
public static void setUp()
-
setShouldFailRow
public void setShouldFailRow(java.util.function.Function<com.google.api.services.bigquery.model.TableRow,java.lang.Boolean> shouldFailRow)
-
getTable
public com.google.api.services.bigquery.model.Table getTable(com.google.api.services.bigquery.model.TableReference tableRef) throws java.lang.InterruptedException, java.io.IOExceptionDescription copied from interface:BigQueryServices.DatasetServiceGets the specifiedTableresource by table ID.Returns null if the table is not found.
- Specified by:
getTablein interfaceBigQueryServices.DatasetService- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
getTable
public com.google.api.services.bigquery.model.Table getTable(com.google.api.services.bigquery.model.TableReference tableRef, @Nullable java.util.List<java.lang.String> selectedFields) throws java.lang.InterruptedException, java.io.IOException- Specified by:
getTablein interfaceBigQueryServices.DatasetService- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
getTable
public com.google.api.services.bigquery.model.Table getTable(com.google.api.services.bigquery.model.TableReference tableRef, @Nullable java.util.List<java.lang.String> selectedFields, @Nullable BigQueryServices.DatasetService.TableMetadataView view) throws java.lang.InterruptedException, java.io.IOException- Specified by:
getTablein interfaceBigQueryServices.DatasetService- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
getTableImpl
public com.google.api.services.bigquery.model.Table getTableImpl(com.google.api.services.bigquery.model.TableReference tableRef, @Nullable java.util.List<java.lang.String> selectedFields, @Nullable BigQueryServices.DatasetService.TableMetadataView view) throws java.lang.InterruptedException, java.io.IOException- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
getAllRows
public java.util.List<com.google.api.services.bigquery.model.TableRow> getAllRows(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId) throws java.lang.InterruptedException, java.io.IOException- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
getAllIds
public java.util.List<java.lang.String> getAllIds(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId) throws java.lang.InterruptedException, java.io.IOException- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
deleteTable
public void deleteTable(com.google.api.services.bigquery.model.TableReference tableRef) throws java.io.IOException, java.lang.InterruptedExceptionDescription 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:
java.io.IOExceptionjava.lang.InterruptedException
-
createTable
public void createTable(com.google.api.services.bigquery.model.Table table) throws java.io.IOExceptionDescription copied from interface:BigQueryServices.DatasetServiceCreates the specified table if it does not exist.- Specified by:
createTablein interfaceBigQueryServices.DatasetService- Throws:
java.io.IOException
-
updateTableSchema
public void updateTableSchema(com.google.api.services.bigquery.model.TableReference tableReference, com.google.api.services.bigquery.model.TableSchema tableSchema) throws java.io.IOException- Throws:
java.io.IOException
-
setPrimaryKey
public void setPrimaryKey(com.google.api.services.bigquery.model.TableReference tableReference, java.util.List<java.lang.String> columns) throws java.io.IOException- Throws:
java.io.IOException
-
isTableEmpty
public boolean isTableEmpty(com.google.api.services.bigquery.model.TableReference tableRef) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from interface:BigQueryServices.DatasetServiceReturns true if the table is empty.- Specified by:
isTableEmptyin interfaceBigQueryServices.DatasetService- Throws:
java.io.IOException- if the table is not found.java.lang.InterruptedException
-
getDataset
public com.google.api.services.bigquery.model.Dataset getDataset(java.lang.String projectId, java.lang.String datasetId) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from interface:BigQueryServices.DatasetServiceGets the specifiedDatasetresource by dataset ID.- Specified by:
getDatasetin interfaceBigQueryServices.DatasetService- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
createDataset
public void createDataset(java.lang.String projectId, java.lang.String datasetId, java.lang.String location, java.lang.String description, java.lang.Long defaultTableExpirationMs) throws java.io.IOException, java.lang.InterruptedExceptionDescription 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:
java.io.IOExceptionjava.lang.InterruptedException
-
deleteDataset
public void deleteDataset(java.lang.String projectId, java.lang.String datasetId) throws java.io.IOException, java.lang.InterruptedExceptionDescription 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:
java.io.IOExceptionjava.lang.InterruptedException
-
getInsertCount
public int getInsertCount()
-
insertAll
public long insertAll(com.google.api.services.bigquery.model.TableReference ref, java.util.List<com.google.api.services.bigquery.model.TableRow> rowList, @Nullable java.util.List<java.lang.String> insertIdList) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
insertAll
public <T> long insertAll(com.google.api.services.bigquery.model.TableReference ref, java.util.List<org.apache.beam.sdk.values.FailsafeValueInSingleWindow<com.google.api.services.bigquery.model.TableRow,com.google.api.services.bigquery.model.TableRow>> rowList, @Nullable java.util.List<java.lang.String> insertIdList, InsertRetryPolicy retryPolicy, java.util.List<org.apache.beam.sdk.values.ValueInSingleWindow<T>> failedInserts, ErrorContainer<T> errorContainer, boolean skipInvalidRows, boolean ignoreUnknownValues, boolean ignoreInsertIds, java.util.List<org.apache.beam.sdk.values.ValueInSingleWindow<com.google.api.services.bigquery.model.TableRow>> successfulRows) throws java.io.IOException, java.lang.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:
java.io.IOExceptionjava.lang.InterruptedException
-
patchTableDescription
public com.google.api.services.bigquery.model.Table patchTableDescription(com.google.api.services.bigquery.model.TableReference tableReference, @Nullable java.lang.String tableDescription) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from interface:BigQueryServices.DatasetServicePatch BigQueryTabledescription.- Specified by:
patchTableDescriptionin interfaceBigQueryServices.DatasetService- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
createWriteStream
public com.google.cloud.bigquery.storage.v1.WriteStream createWriteStream(java.lang.String tableUrn, com.google.cloud.bigquery.storage.v1.WriteStream.Type type) throws java.lang.InterruptedExceptionDescription copied from interface:BigQueryServices.WriteStreamServiceCreate a Write Stream for use with the Storage Write API.- Specified by:
createWriteStreamin interfaceBigQueryServices.WriteStreamService- Throws:
java.lang.InterruptedException
-
getWriteStreamSchema
@Nullable public com.google.cloud.bigquery.storage.v1.TableSchema getWriteStreamSchema(java.lang.String streamName)
- Specified by:
getWriteStreamSchemain interfaceBigQueryServices.WriteStreamService
-
getStreamAppendClient
public BigQueryServices.StreamAppendClient getStreamAppendClient(java.lang.String streamName, com.google.protobuf.DescriptorProtos.DescriptorProto descriptor, boolean useConnectionPool, com.google.cloud.bigquery.storage.v1.AppendRowsRequest.MissingValueInterpretation missingValueInterpretation) throws java.lang.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:
java.lang.Exception
-
flush
public com.google.api.core.ApiFuture<com.google.cloud.bigquery.storage.v1.FlushRowsResponse> flush(java.lang.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(java.lang.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(java.lang.String tableUrn, java.lang.Iterable<java.lang.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
public void failOnInsert(java.util.Map<com.google.api.services.bigquery.model.TableRow,java.util.List<com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors>> insertErrors)
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.
-
-