database - Bigquery : array of values in a field

标签 database google-bigquery

我被要求用 JavaScript 开发一个客户端应用程序,用于查询 BigQuery 上存储的一些表,因此目前我正在掌握查询语法。

我的架构具有以下字段:

download_speed: FLOAT
real_address: STRING
timestamp: INTEGER
upload_speed: FLOAT
[...]

我想找到不同日期汇总的平均上传和下载速度,并跟踪不同的 IP,所以我编写了以下查询:

SELECT LEFT( FORMAT_UTC_USEC(UTC_USEC_TO_DAY(timestamp*1000000)),10) as date_day,
AVG (download_speed)avg_download,
AVG (upload_speed)avg_upload,
real_address
FROM [xxxxxxxxxxxx:xxxxxxx.xxxx]
GROUP BY date_day, real_address
ORDER BY date_day ASC

这没关系,但结果是平坦的,我需要每天汇总平均速度,以便我可以将它们绘制在时间轴上。一种可能是处理查询客户端返回的 json,但对于大量数据集和许多具有不同地址的不同用户(正如我们应该拥有的那样),这种方法对我来说听起来是自杀行为。

所以我问自己是否有一种方法可以在字段中保存包含给定日期的所有地址的数组。我想要返回这个元组结构:

+---------------+-------------------+--------------------+--------------------+
|    date_day   |   avg_download    |   avg_upload       |   real_addr_list   |
+---------------+-------------------+--------------------+--------------------+
|               |                   |                    |   79.20.xx.xx,     |
|   2013-01-13  |   510574.63       |    29599.92        |   151.46.xxx.xx,   |
|               |                   |                    |   151.70.xx.xx     |
+---------------+-------------------+--------------------+--------------------+

这可能吗,还是我被迫在 BigQuery 之外处理结果?

预先感谢您的帮助。

最佳答案

好的,我发现 BigQuery 支持函数 GROUP_CONCAT('str'),其用法如下:

Concatenates multiple strings into a single comma-delimited string, rather like SUM() for strings. Use this with a grouping statement and a field name for str to concatenate a list of all string values in a group into a single string

如果有人感兴趣,查询是:

SELECT LEFT( FORMAT_UTC_USEC(UTC_USEC_TO_DAY(timestamp*1000000)),10) as date_day,
AVG (download_speed)avg_download,
AVG (upload_speed)avg_upload,
GROUP_CONCAT(real_address)as real_address_list
FROM [xxxxxxx:xxxxx.xxxxx]
GROUP BY date_day
ORDER BY date_day ASC

希望这对其他人也有用。

关于database - Bigquery : array of values in a field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14857207/

相关文章:

google-analytics - hits.page.searchKeyword 与搜索页面 url 不匹配

google-bigquery - BigQuery Standard 分组时获取第一个非空值

php不显示数据库结果

database - 希腊语 - X 购物车

mysql - 如何连接具有相同属性的两个表?

database - 什么是更好的数据库设计 : more tables or more columns?

google-bigquery - 在 BigQuery 中,如何计算列上的更改数量

python - Django/Python 应用程序的数据库引擎选择

google-analytics - 将数据从BigQuery取回Google Analytics(分析)

google-bigquery - 加载操作中的 BigQuery 错误 : Could not connect with BigQuery server