【问题标题】:Spark Cassandra Connector IN statement in where clause在 where 子句中的 Spark Cassandra 连接器 IN 语句
【发布时间】:2023-03-06 14:36:02
【问题描述】:

我正在使用 Spark 1.3.1 和 Spark 连接器。我写了一个类似的查询

rdd.select("foo", "bar").where("date > ?", date)

这很好用。我想将我的查询修改为

val catList = List(1, 2, 3) 
rdd.select("foo", "bar").where("date > ?", date).where("cat in (?)", catList)

但这给了我一个错误。我想知道“where”方法的正确语法是什么,以便它可以执行IN 查询。

编辑::

这对我有用

val catList = List(1, 2, 3)
val query = rdd.select("foo", "bar").where("date > ?", date).filter(r => catList.contains(r.getInt("cat")))

但我想知道我们是否可以在 where 方法中检查 in,因为我觉得 where 方法在性能方面比 filter 更有效。

【问题讨论】:

    标签: scala apache-spark cassandra


    【解决方案1】:

    它应该通过删除 ? 周围的括号来工作:

    rdd.select("foo", "bar").where("date > ?", date).where("cat in ?", catList)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-11
    • 2020-08-18
    • 2010-12-07
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多