Is it possible to delete a table available in bigQuery using Apache beam using Java?
p.apply("Delete Table name", BigQueryIO.readTableRows().fromQuery("DELETE FROM Table_name where condition"));
Is it possible to delete a table available in bigQuery using Apache beam using Java?
p.apply("Delete Table name", BigQueryIO.readTableRows().fromQuery("DELETE FROM Table_name where condition"));
I resolved this using BQ API.
BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credential).setProjectId(ProjectName).build().getService(); QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(Query).setUseLegacySql(false).build(); JobId jobId = JobId.of(UUID.randomUUID().toString()); Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
# Define the project ID and table ID
project_id = 'your-project-id'
dataset_id = 'your-dataset-id'
table_id = 'your-table-id'
# Create a PipelineOptions object
options = PipelineOptions()
options.view_as(beam.options.pipeline_options.GoogleCloudOptions).project = project_id
# Delete the BigQuery table
with beam.Pipeline(options=options) as p:
# Define a dummy element to create a PCollection
dummy_element = p | 'Create dummy element' >> beam.Create([None])
# Delete the BigQuery table
dummy_element | 'Delete BigQuery table' >> beam.io.WriteToBigQuery(
table=table_id,
dataset=dataset_id,
project=project_id,
create_disposition=beam.io.BigQueryDisposition.CREATE_NEVER,
write_disposition=beam.io.BigQueryDisposition.WRITE_EMPTY
)
import apache_beam as beam
project_id = 'your-project-id'
dataset_id = 'your-dataset-id'
table_id = 'your-table-id'
table_spec = f'{project_id}:{dataset_id}.{table_id}'
# Define a pipeline
pipeline = beam.Pipeline()
# Delete the BigQuery table
(
pipeline
| 'Create dummy data' >> beam.Create([{}])
| 'Delete BigQuery table' >> beam.io.WriteToBigQuery(
table_spec,
write_disposition=beam.io.BigQueryDisposition.DELETE,
create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED
)
)
# Run the pipeline
pipeline.run()