SPARK : failure: ``union'' expected but `(' found

前端 未结 2 1831
野趣味
野趣味 2020-12-10 14:10

I have a dataframe called df with column named employee_id. I am doing:

 df.registerTempTable(\"d_f\")
val query = \"\"\"SELECT *, ROW_NUMBER() OVER (ORDER B         


        
2条回答
  •  孤城傲影
    2020-12-10 15:11

    Yes It is true,

    I am using spark version 1.6.0 and there you need a HiveContext to implement 'dense_rank' method.

    From Spark 2.0.0 on words there will be no more 'dense_rank' method.

    So for Spark 1.4,1.6 <2.0 you should apply like this.

    table hive_employees having three fields :: place : String, name : String, salary : Int

    val conf = new SparkConf().setAppName("denseRank test")//.setMaster("local")

    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    val hqlContext = new org.apache.spark.sql.hive.HiveContext(sc) 
    

    val result = hqlContext.sql("select empid,empname, dense_rank() over(partition by empsalary order by empname) as rank from hive_employees")

    result.show()

提交回复
热议问题