如何从列出大查询作业中获取查询?

时间:2018-01-12 07:23:16

标签: java google-bigquery

我试图从job.list中检索每个作业的查询但是JobConfiguration没有该字段。

BigQuery bigQuery = bigqueryClientServiceFactory.getClientService(dataStoreId);

        Page<Job> listJobs = bigQuery.listJobs(JobListOption.pageSize(100),JobListOption.fields(JobField.values()));
        for(Job job:listJobs.iterateAll()){
            com.google.cloud.bigquery.JobConfiguration configuration = job.getConfiguration();
        }

1 个答案:

答案 0 :(得分:2)

您需要将JobConfiguration转换为QueryJobConfiguration并调用getQuery()方法:

public static void main(String[] args) {
        BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
        Page<Job> listJobs = bigquery.listJobs(BigQuery.JobListOption.pageSize(100));
        for(Job job:listJobs.iterateAll()){
            if (job.getConfiguration() instanceof QueryJobConfiguration){
                QueryJobConfiguration queryConfig = job.getConfiguration();
                System.out.println(queryConfig.getQuery());
            }
        }
    }