public class BigQueryTemplate extends Object implements BigQueryOperations
Constructor and Description |
---|
BigQueryTemplate(com.google.cloud.bigquery.BigQuery bigQuery,
com.google.cloud.bigquery.storage.v1.BigQueryWriteClient bigQueryWriteClient,
Map<String,Object> bqInitSettings,
org.springframework.scheduling.TaskScheduler taskScheduler)
A Full constructor which creates the
BigQuery template. |
BigQueryTemplate(com.google.cloud.bigquery.BigQuery bigQuery,
String datasetName)
Deprecated.
As of release 3.3.1, use
BigQueryTemplate(BigQuery,BigQueryWriteClient,Map,TaskScheduler) instead
|
BigQueryTemplate(com.google.cloud.bigquery.BigQuery bigQuery,
String datasetName,
org.springframework.scheduling.TaskScheduler taskScheduler)
Deprecated.
As of release 3.3.1, use
BigQueryTemplate(BigQuery,BigQueryWriteClient,Map,TaskScheduler) instead
|
Modifier and Type | Method and Description |
---|---|
com.google.cloud.bigquery.Table |
createTable(String tableName,
com.google.cloud.bigquery.Schema schema) |
BigQueryJsonDataWriter |
getBigQueryJsonDataWriter(com.google.cloud.bigquery.storage.v1.TableName parentTable) |
com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse |
getCommitResponse(com.google.cloud.bigquery.storage.v1.TableName parentTable,
BigQueryJsonDataWriter writer) |
String |
getDatasetName() |
int |
getJsonWriterBatchSize() |
WriteApiResponse |
getWriteApiResponse(String tableName,
InputStream jsonInputStream) |
void |
setAutoDetectSchema(boolean autoDetectSchema)
Sets whether BigQuery should attempt to autodetect the schema of the data when loading data
into an empty table for the first time.
|
void |
setCreateDisposition(com.google.cloud.bigquery.JobInfo.CreateDisposition createDisposition)
Sets the
JobInfo.CreateDisposition which specifies whether a new table may be created in
BigQuery if needed. |
void |
setJobPollInterval(Duration jobPollInterval)
Sets the
Duration amount of time to wait between successive polls on the status of a
BigQuery job. |
void |
setWriteDisposition(com.google.cloud.bigquery.JobInfo.WriteDisposition writeDisposition)
Sets the
JobInfo.WriteDisposition which specifies how data should be inserted into BigQuery
tables. |
org.springframework.util.concurrent.ListenableFuture<com.google.cloud.bigquery.Job> |
writeDataToTable(String tableName,
InputStream inputStream,
com.google.cloud.bigquery.FormatOptions dataFormatOptions)
Writes data to a specified BigQuery table.
|
org.springframework.util.concurrent.ListenableFuture<com.google.cloud.bigquery.Job> |
writeDataToTable(String tableName,
InputStream inputStream,
com.google.cloud.bigquery.FormatOptions dataFormatOptions,
com.google.cloud.bigquery.Schema schema)
Writes data to a specified BigQuery table with a manually-specified table Schema.
|
org.springframework.util.concurrent.ListenableFuture<WriteApiResponse> |
writeJsonStream(String tableName,
InputStream jsonInputStream)
This method uses BigQuery Storage Write API to write new line delimited JSON file to the
specified table.
|
org.springframework.util.concurrent.ListenableFuture<WriteApiResponse> |
writeJsonStream(String tableName,
InputStream jsonInputStream,
com.google.cloud.bigquery.Schema schema)
This method uses BigQuery Storage Write API to write new line delimited JSON file to the
specified table.
|
@Deprecated public BigQueryTemplate(com.google.cloud.bigquery.BigQuery bigQuery, String datasetName)
BigQuery
template.bigQuery
- the underlying client object used to interface with BigQuerydatasetName
- the name of the dataset in which all operations will take place@Deprecated public BigQueryTemplate(com.google.cloud.bigquery.BigQuery bigQuery, String datasetName, org.springframework.scheduling.TaskScheduler taskScheduler)
BigQuery
template.bigQuery
- the underlying client object used to interface with BigQuerydatasetName
- the name of the dataset in which all operations will take placetaskScheduler
- the TaskScheduler
used to poll for the status of long-running
BigQuery operationspublic BigQueryTemplate(com.google.cloud.bigquery.BigQuery bigQuery, com.google.cloud.bigquery.storage.v1.BigQueryWriteClient bigQueryWriteClient, Map<String,Object> bqInitSettings, org.springframework.scheduling.TaskScheduler taskScheduler)
BigQuery
template.bigQuery
- the underlying client object used to interface with BigQuerybigQueryWriteClient
- the underlying BigQueryWriteClient reference use to connect with
BigQuery Storage Write ClientbqInitSettings
- Properties required for initialisation of this classtaskScheduler
- the TaskScheduler
used to poll for the status of long-running
BigQuery operationspublic void setAutoDetectSchema(boolean autoDetectSchema)
autoDetectSchema
- whether data schema should be autodetected from the structure of the
data. Default is true.public void setWriteDisposition(com.google.cloud.bigquery.JobInfo.WriteDisposition writeDisposition)
JobInfo.WriteDisposition
which specifies how data should be inserted into BigQuery
tables.writeDisposition
- whether to append to or truncate (overwrite) data in the BigQuery
table. Default is WriteDisposition.WRITE_APPEND
to append data to a table.public void setCreateDisposition(com.google.cloud.bigquery.JobInfo.CreateDisposition createDisposition)
JobInfo.CreateDisposition
which specifies whether a new table may be created in
BigQuery if needed.createDisposition
- whether to never create a new table in the BigQuery table or only if
needed.public void setJobPollInterval(Duration jobPollInterval)
Duration
amount of time to wait between successive polls on the status of a
BigQuery job.jobPollInterval
- the Duration
poll interval for BigQuery job status pollingpublic org.springframework.util.concurrent.ListenableFuture<com.google.cloud.bigquery.Job> writeDataToTable(String tableName, InputStream inputStream, com.google.cloud.bigquery.FormatOptions dataFormatOptions)
BigQueryOperations
writeDataToTable
in interface BigQueryOperations
tableName
- name of the table to write toinputStream
- input stream of the table data to writedataFormatOptions
- the format of the data to writeListenableFuture
containing the BigQuery Job indicating completion of operationpublic org.springframework.util.concurrent.ListenableFuture<com.google.cloud.bigquery.Job> writeDataToTable(String tableName, InputStream inputStream, com.google.cloud.bigquery.FormatOptions dataFormatOptions, com.google.cloud.bigquery.Schema schema)
BigQueryOperations
Example:
Schema schema = Schema.of(
Field.of("CountyId", StandardSQLTypeName.INT64),
Field.of("State", StandardSQLTypeName.STRING),
Field.of("County", StandardSQLTypeName.STRING)
);
ListenableFuture<Job> bigQueryJobFuture =
bigQueryTemplate.writeDataToTable(
TABLE_NAME, dataFile.getInputStream(), FormatOptions.csv(), schema);
writeDataToTable
in interface BigQueryOperations
tableName
- name of the table to write toinputStream
- input stream of the table data to writedataFormatOptions
- the format of the data to writeschema
- the schema of the table being loadedListenableFuture
containing the BigQuery Job indicating completion of operationpublic org.springframework.util.concurrent.ListenableFuture<WriteApiResponse> writeJsonStream(String tableName, InputStream jsonInputStream, com.google.cloud.bigquery.Schema schema)
writeJsonStream
in interface BigQueryOperations
tableName
- name of the table to write tojsonInputStream
- input stream of the json file to be writtenListenableFuture
containing the WriteApiResponse indicating completion of
operationpublic com.google.cloud.bigquery.Table createTable(String tableName, com.google.cloud.bigquery.Schema schema)
public org.springframework.util.concurrent.ListenableFuture<WriteApiResponse> writeJsonStream(String tableName, InputStream jsonInputStream)
writeJsonStream
in interface BigQueryOperations
tableName
- name of the table to write tojsonInputStream
- input stream of the json file to be writtenListenableFuture
containing the WriteApiResponse indicating completion of
operationpublic BigQueryJsonDataWriter getBigQueryJsonDataWriter(com.google.cloud.bigquery.storage.v1.TableName parentTable) throws com.google.protobuf.Descriptors.DescriptorValidationException, IOException, InterruptedException
com.google.protobuf.Descriptors.DescriptorValidationException
IOException
InterruptedException
public WriteApiResponse getWriteApiResponse(String tableName, InputStream jsonInputStream) throws com.google.protobuf.Descriptors.DescriptorValidationException, IOException, InterruptedException
com.google.protobuf.Descriptors.DescriptorValidationException
IOException
InterruptedException
public com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse getCommitResponse(com.google.cloud.bigquery.storage.v1.TableName parentTable, BigQueryJsonDataWriter writer)
public String getDatasetName()
public int getJsonWriterBatchSize()
Copyright © 2023. All rights reserved.