如何使用 array_remove Spark SQL 内置函数删除空值 [英] How to remove nulls with array_remove Spark SQL Built-in Function

查看:26
本文介绍了如何使用 array_remove Spark SQL 内置函数删除空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spark 2.4 引入了新的有用的涉及数组的 Spark SQL 函数,但当我发现以下结果时,我有点困惑:select array_remove(array(1, 2, 3, null, 3), null)null 而不是 [1, 2, 3, 3].

Spark 2.4 introduced new useful Spark SQL functions involving arrays but I was a little bit puzzled when I find out that the result of: select array_remove(array(1, 2, 3, null, 3), null) is null and not [1, 2, 3, 3].

这是预期的行为吗?是否可以使用 array_remove 删除空值?

Is this an expected behavior? Is it possible to remove nulls using array_remove?

作为旁注,目前我使用的替代方法是数据块中的高阶函数:

As a side note, for now the alternative I am using is a higher order function in databricks:

select filter(array(1, 2, 3, null, 3), x -> x is not null)

推荐答案

https://docs.databricks.com/_static/notebooks/apache-spark-2.4-functions.html

array_remove(array, T):数组从给定数组中移除所有等于给定元素的元素.

array_remove(array, T): array Remove all elements that equal to the given element from the given array.

注意:我只参考了文档,他们采用了相同的数据.**null 永远不能等于 null.

Note: I only referred the documentation and they have taken the same data. **null can never be equal to null.

这篇关于如何使用 array_remove Spark SQL 内置函数删除空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆