我对com.google.api.services有一些问题。我正在使用这个版本“BigQueryAPI 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()”并不存在。。。这是完全错误:
线程“main”java.lang.nosuchmethoderror中出现异常:com.google.api.services.bigquery.model.jobconfigurationquery.getconnectionproperties()ljava/util/list;在com.google.cloud.bigquery.queryjobconfiguration$builder。java:250)在com.google.cloud.bigquery.queryjobconfiguration$builder。java:95)在com.google.cloud.bigquery.queryjobconfiguration.frompb(queryjobconfiguration。java:1060)在com.google.cloud.bigquery.jobconfiguration.frompb(作业配置。java:128)在com.google.cloud.bigquery.jobinfo$builderimpl。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\u datahub.bigquery\u template\u 0\u 1.bigquery\u template.tjava\u 1process(bigquery\u template)。java:383)在bce\u datahub.bigquery\u template\u 0\u 1.bigquery\u template.runjobintos(bigquery\u template)。java:757)在bce\u datahub.bigquery\u template\u 0\u 1.bigquery\u template.main(bigquery\u 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表。
对于第二步,我没有问题。这些是我正在使用的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.");
...
1条答案
按热度按时间wfypjpf41#
断然的。
我安装了我在https://mvnrepository.com/artifact/com.google.apis/google-api-services-bigquery/v2-rev20201030-1.31.0.
我不明白为什么我从这里下载的jarhttps://www.javadoc.io/doc/com.google.apis/google-api-services-bigquery/latest/com/google/api/services/bigquery/model/jobconfigurationquery.html
不起作用。
似乎他们是不同的。但是我解决了我的问题。