apache-spark - 以字符串开头的 Spark Dataframe 搜索列

标签 apache-spark apache-spark-sql spark-dataframe

我需要根据列值应以预定义字符串开头的条件过滤数据框。

我正在尝试以下操作:

 val domainConfigJSON = sqlContext.read
    .jdbc(url, "CONFIG", prop)
    .select("DID", "CONF", "KEY").filter("key like 'config.*'")

并获得异常:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'KEY = 'config.*'' at line 1


Using spark: 1.6.1

最佳答案

您可以使用 startsWith Column 类中存在的函数。

myDataFrame.filter(col("columnName").startswith("PREFIX"))

关于apache-spark - 以字符串开头的 Spark Dataframe 搜索列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45552293/

相关文章:

scala - 写入 HDFS - hive 时如何控制 Spark 流中的行数和/或输出文件大小?

python - 如何提高 Spark 中的小数精度?

apache-spark - 基于其他数据帧中的列 Spark 重复数据帧中的列

python - 分组数据的模式(pySpark

sql - 如何在spark中使用多个键构建查找功能

apache-spark - 卡夫卡+ Spark 流: ClosedChannelException

apache-spark - 计算 pyspark Dataframe 中的列数?

scala - Spark 2.0缺少Spark隐式

python-3.x - 如何将整个 pyspark 数据框的大小写更改为较低或较高

scala - 有没有更好的方法来显示整个 Spark SQL DataFrame?