java.lang.NoSuchMethodError: com.google.api.services.bigquery.model.JobConfigurationQuery.getConnect
Posted
技术标签:
【中文标题】java.lang.NoSuchMethodError: com.google.api.services.bigquery.model.JobConfigurationQuery.getConnectionProperties()Ljava/util/List;【英文标题】:java.lang.NoSuchMethodError: com.google.api.services.bigquery.model.JobConfigurationQuery.getConnectionProperties()Ljava/util/List; 【发布时间】:2020-12-30 15:39:01 【问题描述】:我在使用 com.google.api.services 时遇到了一些问题。我正在使用这个版本“BigQuery API v2(修订版 459)”:
https://www.javadoc.io/doc/com.google.apis/google-api-services-bigquery/v2-rev459-1.25.0/com/google/api/services/bigquery/model/JobConfigurationQuery.html
确实不存在方法“getConnectionProperties()”...这是完整的错误:
线程“主”java.lang.NoSuchMethodError 中的异常: com.google.api.services.bigquery.model.JobConfigurationQuery.getConnectionProperties()Ljava/util/List; 在 com.google.cloud.bigquery.QueryJobConfiguration$Builder.(QueryJobConfiguration.java:250) 在 com.google.cloud.bigquery.QueryJobConfiguration$Builder.(QueryJobConfiguration.java:95) 在 com.google.cloud.bigquery.QueryJobConfiguration.fromPb(QueryJobConfiguration.java:1060) 在 com.google.cloud.bigquery.JobConfiguration.fromPb(JobConfiguration.java:128) 在 com.google.cloud.bigquery.JobInfo$BuilderImpl.(JobInfo.java:158) 在 com.google.cloud.bigquery.Job.fromPb(Job.java:497) 在 com.google.cloud.bigquery.BigQueryImpl.create(BigQueryImpl.java:363) 在 com.google.cloud.bigquery.BigQueryImpl.create(BigQueryImpl.java:340) 在 bce_datahub.bigquery_template_0_1.bigquery_template.tJava_1Process(bigquery_template.java:383) 在 bce_datahub.bigquery_template_0_1.bigquery_template.runJobInTOS(bigquery_template.java:757) 在 bce_datahub.bigquery_template_0_1.bigquery_template.main(bigquery_template.java:583)
我看到了这个版本:
https://www.javadoc.io/doc/com.google.apis/google-api-services-bigquery/latest/com/google/api/services/bigquery/model/JobConfigurationQuery.html
包含这个方法,但如果我用这个版本替换它,我会得到另一个错误:
NoClassDefFoundError: com/google/api/services/bigquery/Bigquery$Builder
所以这个版本好像没有这个类。
我正在开发一个 Java 程序来:
-
在 Bigquery 上执行查询
在 Google 云存储上导出 BigQuery 表。
对于第 2 步,我没有问题。这些是我正在使用的 Jara:
我正在使用 Talend Studio,所以我必须安装 jar:一个一个。这是产生问题的脚本的一部分:
import java.io.File;
import java.io.FileInputStream;
import com.google.cloud.RetryOption;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.Table;
import com.google.cloud.bigquery.TableId;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.auth.oauth2.AccessToken;
import org.threeten.bp.Duration;
//INPUT
String credentialsPath = "...";
String projectId = "...";
String datasetName = "...";
String tableName = "...";
String bucketName = "...";
String objectName = "...";
String destinationUri = "...";
String dataFormat = "...";
String destFilePath = "...";
String ddl =
"DROP TABLE IF EXISTS `" + datasetName + "." + tableName + "`;"
+ "CREATE TABLE `" + datasetName + "." + tableName + "` AS "
+ "SELECT * FROM ...";
//Authentification
File credentialsFilePath = new File(credentialsPath);
FileInputStream serviceAccountStream = new FileInputStream(credentialsFilePath);
GoogleCredentials credentials;
credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests
BigQuery bigquery = BigQueryOptions.newBuilder()
.setProjectId(projectId)
.setCredentials(credentials).build()
.getService();
// Execute query on BigQuery
QueryJobConfiguration config = QueryJobConfiguration.newBuilder(ddl).build();
Job job = bigquery.create(JobInfo.of(config));
Job completedJob =
job.waitFor(
RetryOption.initialRetryDelay(Duration.ofSeconds(1)), //Checking period time [Optional]
RetryOption.totalTimeout(Duration.ofMinutes(3)) //Timeout [Optional]
);
if (completedJob == null)
System.out.println("Job not executed since it no longer exists.");
return;
else if (completedJob.getStatus().getError() != null)
System.out.println("BigQuery was unable to execute the query due to an error: \n" + job.getStatus().getError());
return;
System.out.println("Table create successful. Check in " + datasetName + " for the " + tableName + " table.");
...
【问题讨论】:
您遇到的问题与您的代码无关,它与依赖关系有关。我认为您有一个使用旧版本“google-api-services-bigquery”的库,因此出现“NoSuchmethodError” 是的,我知道问题出在依赖关系上。我正在使用最新版本的 com.google.cloud:google-cloud-bigquery(版本 1.126.3)。 【参考方案1】:已解决。
我安装了在 https://mvnrepository.com/artifact/com.google.apis/google-api-services-bigquery/v2-rev20201030-1.31.0 找到的 jar。
我不明白为什么我从这里下载的jar https://www.javadoc.io/doc/com.google.apis/google-api-services-bigquery/latest/com/google/api/services/bigquery/model/JobConfigurationQuery.html
没用。
似乎它们是不同的。不过我解决了我的问题。
【讨论】:
以上是关于java.lang.NoSuchMethodError: com.google.api.services.bigquery.model.JobConfigurationQuery.getConnect的主要内容,如果未能解决你的问题,请参考以下文章