【发布时间】:2019-06-21 10:17:52
【问题描述】:
BigQuery 查询调用加载数据的时间过长。获得结果大约需要 7-8 秒,而在 BigQuery Google Cloud Platform 上需要 1 秒。
我已经尝试过与谷歌云 BigQuery 库的文档相同的方法。 https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries
InputStream is =
mContext.getAssets().open("service_account.json");
BigQuery bigquery = BigQueryOptions.newBuilder()
.setProjectId("uniorder-prod")
.setCredentials(ServiceAccountCredentials.fromStream(is))
.build().getService();
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder("standard sql query")
.setUseLegacySql(false)
.build();
JobId jobId = JobId.of(UUID.randomUUID().toString());
Job queryJob = bigquery
.create(JobInfo
.newBuilder(queryConfig)
.setJobId(jobId).build());
queryJob = queryJob.waitFor();
if (queryJob == null) {
throw new RuntimeException("Job no longer exists");
} else if (queryJob.getStatus().getError() != null) {
throw new
RuntimeException(queryJob.getStatus().getError().toString());
}
QueryResponse response = bigquery.getQueryResults(jobId);
TableResult result = queryJob.getQueryResults();
//Current query execution time is 7-8 second
//Expected query execution time is 1 or less than 1 second
//My SQL BigQuery
SELECT
EXTRACT(DATE
FROM
TIMESTAMP(param2.value.string_value)) AS date,
SUM(param3.value.double_value) AS total_price
FROM
`uniorder-prod.analytics_200255431.events_*`,
UNNEST(event_params) AS param1,
UNNEST(event_params) AS param2,
UNNEST(event_params) AS param3
WHERE
event_name = "total_consumption_res"
AND param1.key = "user_id"
AND param1.value.int_value = 118
AND param2.key = "timestamp"
AND param3.key = "total_price"
AND _TABLE_SUFFIX BETWEEN '20190601'
AND '20190630'
GROUP BY
date
ORDER BY
date ASC
【问题讨论】:
-
在 BigQuery (
queryJob = queryJob.waitFor();) 上运行查询与通过网络将查询结果拉回应用程序 (QueryResponse response = bigquery.getQueryResults(jobId);) 不同。您首先运行查询,然后获取结果。 -
那么有什么办法可以减少查询加载时间呢?
-
通过删除这两行,结果时间得到减少,但仍然需要 3-5 秒来加载数据,它应该是 1 秒或低于 1 秒。
-
为什么应该是 "1 秒或以下" 即你是基于什么?
-
您的网络/互联网速度不会影响您在 BigQuery 中的查询性能。 BigQuery 是一种多租户架构,您可以与其他用户共享计算资源。如果您想要低延迟响应,则说明您使用了错误的工具。我会考虑使用 CloudSQL 或 Datastore 之类的东西。
标签: android google-bigquery firebase-analytics