问题描述
显然,当使用BigQuery API时,BigQuery结果有一个cacheHit
属性.我尝试找到此属性,但不确定如何访问它.这是我使用BigQuery API的Java代码. cacheHit
不是我得到的TableResult tr
的属性:
Apparently, when using the BigQuery API, there is a cacheHit
property of a BigQuery result. I've tried finding this property and I'm not sure how I need to access it. Here's my Java code that uses the BigQuery API. cacheHit
isn't a property of the TableResult tr
that I get:
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();
}
我看了这个问题- BigQuery cacheHit属性
...但是那不是Java,而且我还没有找到我可以使用的任何results()
属性,如该问题所示.
... but that's not Java, and I haven't found any results()
property I can use, as suggested in that question.
这里有一些有关 JobStatistics2 的文档.对象,显然具有cacheHit
属性.
There's some documentation here about the JobStatistics2 object, that apparently has a cacheHit
property.
我可以得到一个JobStatistics
(不是一个JobStatistics2
对象),像这样:
I can get a JobStatistics
(not a JobStatistics2
object), like this:
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();
...但是我在js
上看不到任何cacheHit
属性.当我尝试创建JobStatistics2
时,通过更改实例化JobStatistics
的行,如下所示:
... but I don't see any cacheHit
property on js
. When I try creating a JobStatistics2
instead, by changing the line where I'm instantiating JobStatistics
, like this:
JobStatistics2 js = queryJob.getStatistics();
我收到错误Type parameter S has incompatible upper bounds: JobStatistics and JobStatistics2
.这并不意味着什么,当我搜索Google错误时,没有任何有用的结果.
I get an error Type parameter S has incompatible upper bounds: JobStatistics and JobStatistics2
. This doesn't mean much, and when I Google the error there are no useful results.
我觉得Google文档没有太大用处.如何访问cacheHit
属性,并仍然获得代码示例中所示的rowList
?
I'm not finding the Google documentation too useful. How can I access the cacheHit
property, and still obtain my rowList
as shown in the code example?
推荐答案
QueryStatistics
是JobStatistics
的嵌套类之一,可以看到此处,并且具有 getCacheHit()
方法:
QueryStatistics
is one of the nested classes of JobStatistics
as can be seen here and has a getCacheHit()
method:
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
...
QueryStatistics js = queryJob.getStatistics();
System.out.println(js.getCacheHit());
请参见完整代码此处用于我的测试.
See full code here for my test.
关于JobStatistics2
,这是针对com.google.api.services.bigquery
库而不是com.google.cloud.bigquery
.在这种情况下,您可以使用 getQuery()
从JobStatistics
获取一个JobStatistics2
对象,然后使用"> .
Regarding JobStatistics2
this is for com.google.api.services.bigquery
library and not com.google.cloud.bigquery
. In that case you could use getQuery()
from JobStatistics
to get a JobStatistics2
object and then use getCacheHit()
.
这篇关于如何访问BigQuery结果集的cacheHit属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!