【发布时间】:2021-03-23 21:58:19
【问题描述】:
我正在尝试从具有这种结构的数据框中过滤行:
|-- age: integer (nullable = true)
|-- qty: integer (nullable = true)
|-- dates: array (nullable = true)
| |-- element: timestamp (containsNull = true)
例如,在这个数据框中,我只想要第一行:
+---------+------------+------------------------------------------------------------------+
| age | qty |dates |
+---------+------------+------------------------------------------------------------------+
| 54 | 1| [2020-12-31 12:15:20, 2021-12-31 12:15:20] |
| 45 | 1| [2020-12-31 12:15:20, 2018-12-31 12:15:20, 2019-12-31 12:15:20] |
+---------+------------+------------------------------------------------------------------+
这是我的代码:
val result = sqlContext
.table("scores")
result.filter(array_contains(col("dates").cast("string"),
2021)).show(false)
但是我收到了这个错误:
org.apache.spark.sql.AnalysisException: 无法解析 'array_contains( 由于数据类型不匹配:参数必须是一个数组,后跟一个与 > 数组成员相同类型的值;
有人可以帮忙吗?
【问题讨论】:
标签: scala apache-spark apache-spark-sql