sqlcontext故障:预期为``联合'',但找到了标识符finalresult

时间:2019-06-07 20:40:16

标签: scala

写作时
val tagScore = sqlContext.sql(“ SELECT movieid, 标记名,(eachTagCount / totalCount)AS tagScore 来自finalresult”)) eachTagCount,totalCount是其他表中的两列

 `val finalresult = sqlContext.sql("SELECT MovieId,Tag AS eachTagCount, count AS totalCount FROM result ORDER BY MovieId")

    finalresult.rdd
      .map(_.toSeq.map(_+"").reduce(_+","+_))
      .saveAsTextFile("/usr/local/spark/dataset/algorithm3/output5")
     case class fine(  MovieId:Int,Tag:String,count:Int,totalcount:Int)
     val Data5 = sc.textFile("file:///usr/local/spark/dataset/algorithm3/output5").map(_.split(",")).map(p => fine(p(0).trim.toInt,p(1),p(2).trim.toInt,p(3).trim.toInt)).toDF()
    Data5.registerTempTable("finalresult")

val tagScore = sqlContext.sql("SELECT MovieId,Tag,(eachTagCount/totalCount) AS tagScoreFROM finalresult")

    tagScore.rdd
      .map(_.toSeq.map(_+"").reduce(_+","+_))
      .saveAsTextFile("/usr/local/spark/dataset/algorithm3/output6")`

运行此异常后出现

  

线程“主”中的异常java.lang.ExceptionInInitializerError       在model3.main(model3.scala)   原因:java.lang.RuntimeException:[1.62]错误:预期为“联合”,但找到了标识符finalresult

选择MovieId,Tag,(eachTagCount / totalCount)AS tagScoreFROM finalresult                                                              ^     在scala.sys.package $ .error(package.scala:27)     在org.apache.spark.sql.catalyst.AbstractSparkSQLParser.parse(AbstractSparkSQLParser.scala:36)     在org.apache.spark.sql.catalyst.DefaultParserDialect.parse(ParserDialect.scala:67)     在org.apache.spark.sql.SQLContext $$ anonfun $ 2.apply(SQLContext.scala:211)

how to solve it?

1 个答案:

答案 0 :(得分:0)

查看定义为与已注册临时表相同的数据帧(都有一些名称) finalresult解决了问题,那就是将其作为变量而不是表。

请重命名变量或临时表。