根据数组列中的元素的存在过滤所有行
类似于
以下 | 的 | 火花 |
---|---|---|
我 | 有 | 一个 |
框 | 数据 “:5,...}] | ... |
规则
是一个数组列,每个元素都具有id
字段。
我想过滤所有包含id
&lt的规则的行; 3。如果没有UDFS ,是否可以这样做?我的数据帧非常大,UDF会损害我查询的perofrmace。
I have a spark dataframe similar to this:
... | Rules | ... |
---|---|---|
... | [{"id": 1,...}, {"id": 2}] | ... |
... | [{"id": 5,...}] | ... |
Rules
is an array column, where each element has the id
field.
And I want to filter all rows which contain a rule with id
< 3. Is it possible to do this without UDFs? My dataframe is very large and UDFs impair the perofrmace of my query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在高阶功能上使用可用的
You can use the
EXISTS
available on higher-order functions从数组中提取映射值,在数组中找到最大值或最小值(根据所需的值),并检查其小于3。返回布尔值。然后,您可以使用Where子句过滤。
如果您只想过滤这些行少于3的行,请使用;
如果要用少于3的ID过滤行,请使用;
Extract map values from the array, find the max or(min depending on what you want) value in the array and check it is less than 3. That returns a boolean. You then can filter using the where clause.
If you want to filter only those rows with id less than 3, use;
If you want to filter rows with any id less than 3, use;