Spark支持子查询吗?

时间:2015-08-06 11:06:28

标签: hadoop apache-spark hive presto

当我运行此查询时,我遇到了此类错误

  select * from raw_2 where ip NOT IN (select * from raw_1);
  

org.apache.spark.sql.AnalysisException:

查询中不支持的语言功能:

 select * from raw_2 where ip NOT IN (select * from raw_1)
  TOK_QUERY 1, 0,24, 14
    TOK_FROM 1, 4,6, 14
      TOK_TABREF 1, 6,6, 14
        TOK_TABNAME 1, 6,6, 14
          raw_2 1, 6,6, 14
    TOK_INSERT 0, -1,24, 0
      TOK_DESTINATION 0, -1,-1, 0
       TOK_DIR 0, -1,-1, 0
          TOK_TMP_FILE 0, -1,-1, 0
      TOK_SELECT 0, 0,2, 0
        TOK_SELEXPR 0, 2,2, 0
          TOK_ALLCOLREF 0, 2,2, 0
      TOK_WHERE 1, 8,24, 29
       NOT 1, 10,24, 29
          TOK_SUBQUERY_EXPR 1, 14,10, 33
            TOK_SUBQUERY_OP 1, 14,14, 33
              IN 1, 14,14, 33
            TOK_QUERY 1, 16,24, 51
              TOK_FROM 1, 21,23, 51
                TOK_TABREF 1, 23,23, 51
                  TOK_TABNAME 1, 23,23, 51
                    raw_1 1, 23,23, 51
              TOK_INSERT 0, -1,19, 0
          TOK_DESTINATION 0, -1,-1, 0
            TOK_DIR 0, -1,-1, 0
              TOK_TMP_FILE 0, -1,-1, 0
          TOK_SELECT 0, 17,19, 0
            TOK_SELEXPR 0, 19,19, 0
              TOK_ALLCOLREF 0, 19,19, 0
      TOK_TABLE_OR_COL 1, 10,10, 26
        ip 1, 10,10, 26
  

scala.NotImplementedError:没有ASTNode类型的解析规则:817,text:

  TOK_SUBQUERY_EXPR :
  TOK_SUBQUERY_EXPR 1, 14,10, 33
    TOK_SUBQUERY_OP 1, 14,14, 33
      IN 1, 14,14, 33
    TOK_QUERY 1, 16,24, 51
      TOK_FROM 1, 21,23, 51
        TOK_

1 个答案:

答案 0 :(得分:5)

Spark 2.0.0 +

因为2.0.0 Spark支持全范围的子查询。有关详细信息,请参阅Does SparkSQL support subquery?

Spark< 2.0.0

  

Spark是否支持子查询?

一般来说确实如此。构造如SELECT * FROM (SELECT * FROM foo WHERE bar = 1) as tmp在Spark SQL中完全有效的查询。

the Catalyst parser source我所知,它不支持NOT IN子句中的内部查询:

| termExpression ~ (NOT ~ IN ~ "(" ~> rep1sep(termExpression, ",")) <~ ")" ^^ {
    case e1 ~ e2 => Not(In(e1, e2))
  }

仍然可以使用外连接,然后使用过滤器来获得相同的效果。