使用来自spark

时间:2015-05-19 19:35:00

标签: hadoop hiveql apache-spark-sql

我有下面的SQL



SELECT LIMIT, 
       COL1, 
       COL2, 
       COL3
 FROM   
(SELECT ROW_NUMBER () OVER (ORDER BY COL5 DESC) AS LIMIT, 
        FROM_UNIXTIME(COL_DATETIME,'dd-MM-yyyy HH24:mi:ss') COL1,
        CASE WHEN COL6 IN ('A', 'B') THEN A_NUMBER ELSE B_NUMBER END AS COL2, 
        COL3
 FROM   DBNAME.TABLENAME 
WHERE   COL7 LIKE ('123456%')  
  AND   COL_DATETIME BETWEEN 20150201000000 AND 20150202235959) X




我可以从hive成功执行它。但我想从火花中执行它。我已经创建了一个spark-sql-hive上下文,如下面的



scala> val sqlHContext = new org.apache.spark.sql.hive.HiveContext(sc)
sqlHContext: org.apache.spark.sql.hive.HiveContext = org.apache.spark.sql.hive.HiveContext@71138de5




然后我尝试执行上面的SQL查询,如下所示



sqlHContext.sql("SELECT LIMIT, COL1, COL2, COL3 FROM (SELECT ROW_NUMBER () OVER (ORDER BY COL5 DESC) AS LIMIT, FROM_UNIXTIME(COL_DATETIME,'dd-MM-yyyy HH24:mi:ss') COL1, CASE WHEN COL6 IN ('A', 'B') THEN A_NUMBER ELSE B_NUMBER END AS COL2, COL3 FROM DBNAME.TABLENAME WHERE  COL7 LIKE ('123456%')  AND COL_DATETIME BETWEEN 20150201000000 AND 20150202235959) X").collect().foreach(println)




但是得到了错误



org.apache.spark.sql.AnalysisException: 
Unsupported language features in query:


scala.NotImplementedError: No parse rules for ASTNode type: 882, text: TOK_WINDOWSPEC :
TOK_WINDOWSPEC 1, 90,98, 339
  TOK_PARTITIONINGSPEC 1, 91,97, 339
    TOK_ORDERBY 1, 91,97, 339
      TOK_TABSORTCOLNAMEDESC 1, 95,97, 339
        TOK_TABLE_OR_COL 1, 95,95, 339
          CALL_DATETIME 1, 95,95, 339
" +
         
org.apache.spark.sql.hive.HiveQl$.nodeToExpr(HiveQl.scala:1261)




看起来不支持分析功能。我正在使用spark版本1.3.0; hive版本1.1.0和hadoop版本2.7.0

还有其他方法可以通过spark实现吗?

1 个答案:

答案 0 :(得分:1)

自Spark 1.4.0起支持窗口函数。仍有一些限制,例如ROWS BETWEEN尚不支持。有关示例,请查看Spark window functions上的此博客文章。