sqlContext.sql("select * from T where columnB rlike '^[0-9]*$'").c-6ren">
gpt4 book ai didi

scala - 如何在 spark-sql 中使用 "not rlike"?

转载 作者:行者123 更新时间:2023-12-04 20:00:17 24 4
gpt4 key购买 nike

rlike工作正常,但 not rlike抛出错误:

scala> sqlContext.sql("select * from T where columnB rlike '^[0-9]*$'").collect()
res42: Array[org.apache.spark.sql.Row] = Array([412,0], [0,25], [412,25], [0,25])

scala> sqlContext.sql("select * from T where columnB not rlike '^[0-9]*$'").collect()
java.lang.RuntimeException: [1.35] failure: ``in'' expected but `rlike' found


val df = sc.parallelize(Seq(
(412, 0),
(0, 25),
(412, 25),
(0, 25)
)).toDF("columnA", "columnB")

或者是问题的延续 https://issues.apache.org/jira/browse/SPARK-4207 ?

最佳答案

在 PySpark 中执行此操作的简洁方法是:

df.filter(~df.column.rlike(pattern))

关于scala - 如何在 spark-sql 中使用 "not rlike"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34534088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com