微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何过滤包含数组数据的 BigQuery 数据集?

如何解决如何过滤包含数组数据的 BigQuery 数据集?

我有一个包含数组数据的查询。我需要做的是执行可以过滤以下屏幕结果的查询,例如:

“给我带来玩家亚历克斯的数据”。这应该带来 2 行:

1. user1@example.com,2021-01-13 09:32:55.113 UTC,alex,4,[8,10]
2. user1@example.com,2021-01-13 09:30:07.572 UTC,10,[13,14]

BigQuery dataset with array data

如何构造这样的查询

解决方法

在 BigQuery 的标准 SQL 中尝试以下操作:

with data as (
  select    "email@email.com" as email,CURRENT_TIMESTAMP() as timestamp,['player1','alex','p3'] as player,[4,4,4] as must_respond_in,['2,9','8,10','7'] as responses
  UNION ALL
  select    "email@email.com" as email,[14,10,14] as must_respond_in,['1,16','13,14','0,0'] as responses
)
select  email,timestamp,player[offset(x)],must_respond_in[offset(x)],responses[offset(x)]
from data,unnest(data.player) as player_name with offset x where player_name = 'alex';

我使用 WITH OFFSET 子句来选择我需要的元素。 WITH 子句用于模拟您的数据。

,

另一种选择

select  email,player,must_respond_in,responses
from data t,t.player as player with offset
left join t.must_respond_in as must_respond_in with offset using(offset)
left join t.responses as responses with offset using(offset)
where player = 'alex'   

如果适用于您问题中的样本数据 - 输出为

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?