首页 > 解决方案 > 按数组列过滤 Scala 数据帧

问题描述

我的 scala 数据框有一列具有数据类型arrayelement: String)。我想显示该列中包含单词“hello”的数据框的那些行。

我有这个:

display(df.filter($"my_column".contains("hello")))

由于数据不匹配,我收到错误消息。它说argument 1 requires string type, however, 'my:column ' is of array<string> type

标签: scalaapache-spark-sql

解决方案


你可以使用array_contains函数

import org.apache.spark.sql.functions._

df.filter(array_contains(df.col("my_column"), "hello")).show

推荐阅读