Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何访问BigQuery结果集的cacheHit属性?_Java_Google Cloud Platform_Google Bigquery - Fatal编程技术网

Java 如何访问BigQuery结果集的cacheHit属性?

Java 如何访问BigQuery结果集的cacheHit属性?,java,google-cloud-platform,google-bigquery,Java,Google Cloud Platform,Google Bigquery,显然,在使用BigQuery API时,BigQuery结果有一个cacheHit属性。我已尝试查找此属性,但不确定需要如何访问它。下面是我使用BigQueryAPI的Java代码cacheHit不是我得到的TableResulttr的属性: try { QueryJobConfiguration queryJobConfiguration = QueryJobConfiguration.newBuilder( "mySQLqueryTe

显然,在使用BigQuery API时,BigQuery结果有一个
cacheHit
属性。我已尝试查找此属性,但不确定需要如何访问它。下面是我使用BigQueryAPI的Java代码
cacheHit
不是我得到的TableResult
tr
的属性:

try
{
    QueryJobConfiguration queryJobConfiguration =

        QueryJobConfiguration.newBuilder(
                "mySQLqueryText"
        )
        .setUseLegacySql(false)
        .setAllowLargeResults(false)
        .setUseQueryCache(true)
        .build();

    try {
        TableResult tr = bigQuery.query(queryJobConfiguration);

        Iterable<FieldValueList> rowList = tr.getValues();

        ....
    }
    catch (BigQueryException e) {
        // do stuff
    }
} catch (InterruptedException e) {
    e.printStackTrace();
}
。。。但是我在
js
上没有看到任何
cacheHit
属性。当我尝试创建
JobStatistics 2
时,通过更改实例化
JobStatistics
的行,如下所示:

QueryJobConfiguration queryJobConfiguration =

    QueryJobConfiguration.newBuilder(
            "myQueryString"
    )
    .setUseLegacySql(false)
    .setAllowLargeResults(false)
    .setUseQueryCache(true)
    .build();

    JobId jobId = JobId.of(UUID.randomUUID().toString());
    Job queryJob = bigQuery.create(JobInfo.newBuilder(queryJobConfiguration).setJobId(jobId).build());

try {

    queryJob = queryJob.waitFor();

    if (queryJob != null) {

        JobStatistics js = queryJob.getStatistics();

    Iterable<FieldValueList> rowList = bigQuery.query(queryJobConfiguration).getValues();
JobStatistics2 js = queryJob.getStatistics();
我得到一个错误
类型参数S的上限不兼容:JobStatistics和JobStatistics2
。这并不意味着什么,当我用谷歌搜索错误时,没有有用的结果


我不觉得谷歌文档太有用。如何访问
cacheHit
属性,并仍然获得代码示例中所示的
行列表?

QueryStatistics
是可以看到的
JobStatistics
的嵌套类之一,它有一个方法:

import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
...
QueryStatistics js=queryJob.getStatistics();
System.out.println(js.getCacheHit());
请参阅我的测试的完整代码


关于
jobstatistics 2
这是针对
com.google.api.services.bigquery
库而不是
com.google.cloud.bigquery
。在这种情况下,您可以使用from
JobStatistics
获得一个
JobStatistics2
对象,然后使用。

奇妙的答案-这是我在StackOverflow上看到的最好的努力之一。非常感谢:)