Search code examples
apache-sparkgoogle-cloud-platformgoogle-bigquerygoogle-cloud-dataproc

Google Cloud Dataproc drop BigQuery table not working


Hi I tried to delete a table from BigQuery using java client library in Dataproc, started spark-shell as below:

spark-shell --packages com.google.cloud:google-cloud-bigquery:1.59.0

and import following dependency

import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.JobId;
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.QueryResponse;
import com.google.cloud.bigquery.TableResult;
import java.util.UUID;

val bigquery = BigQueryOptions.getDefaultInstance().getService() 
bigquery.delete("test","temp")

here test and temp are my dataset and table name respectively but after running above statement it show following error:

java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
  at com.google.api.gax.retrying.BasicRetryingFuture.<init>(BasicRetryingFuture.java:82)
  at com.google.api.gax.retrying.DirectRetryingExecutor.createFuture(DirectRetryingExecutor.java:88)
  at com.google.api.gax.retrying.DirectRetryingExecutor.createFuture(DirectRetryingExecutor.java:74)
  at com.google.cloud.RetryHelper.run(RetryHelper.java:75)
  at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
  at com.google.cloud.bigquery.BigQueryImpl.delete(BigQueryImpl.java:386)
  at com.google.cloud.bigquery.BigQueryImpl.delete(BigQueryImpl.java:375)
  ... 48 elided   

Solution

  • This is because you have on classpath an older Guava library version (brought as Hadoop/Spark dependency) that does not have MoreExecutors.directExecutor method.

    To fix this issue you need to include and shade/relocate (to avoid conflicts with other libraries on classpath) google-cloud-bigquery library and its dependencies (including Guava) into your application's UberJar.

    Here is an example of how to do this using Maven Shade plugin.