public class BigQueryTemplate extends Object implements BigQueryOperations
| Constructor and Description |
|---|
BigQueryTemplate(BigQuery bigQuery,
String datasetName)
Creates the
BigQuery template. |
BigQueryTemplate(BigQuery bigQuery,
String datasetName,
org.springframework.scheduling.TaskScheduler taskScheduler)
Creates the
BigQuery template. |
| Modifier and Type | Method and Description |
|---|---|
String |
getDatasetName() |
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 |
setJobPollInterval(Duration jobPollInterval)
Sets the
Duration amount of time to wait between successive polls on the status
of a BigQuery job. |
void |
setWriteDisposition(JobInfo.WriteDisposition writeDisposition)
Sets the
JobInfo.WriteDisposition which specifies how data should be inserted into
BigQuery tables. |
org.springframework.util.concurrent.ListenableFuture<Job> |
writeDataToTable(String tableName,
InputStream inputStream,
FormatOptions dataFormatOptions)
Writes data to a specified BigQuery table.
|
org.springframework.util.concurrent.ListenableFuture<Job> |
writeDataToTable(String tableName,
InputStream inputStream,
FormatOptions dataFormatOptions,
Schema schema)
Writes data to a specified BigQuery table with a manually-specified table Schema.
|
public BigQueryTemplate(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 placepublic BigQueryTemplate(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 void setAutoDetectSchema(boolean autoDetectSchema)
autoDetectSchema - whether data schema should be autodetected from the structure
of the data. Default is true.public void setWriteDisposition(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 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<Job> writeDataToTable(String tableName, InputStream inputStream, FormatOptions dataFormatOptions)
BigQueryOperationswriteDataToTable in interface BigQueryOperationstableName - 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<Job> writeDataToTable(String tableName, InputStream inputStream, FormatOptions dataFormatOptions, Schema schema)
BigQueryOperationsExample:
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 BigQueryOperationstableName - 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 String getDatasetName()
Copyright © 2021. All rights reserved.