scala jdbc SQLContext问题

时间:2017-02-15 16:49:26

标签: oracle scala jdbc

我收到错误 - 加载不是org.apache.spark.sql.SQLContext的成员。我在定义SQLContext后尝试了一些使用import explicits的东西,但是没有用。有谁遇到过这个问题?

这是.sbt文件

name := "sparkJDBC"
version := "0.1"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.5.1" 
libraryDependencies += "org.apache.tika" % "tika-core" % "1.11"
libraryDependencies += "org.apache.tika" % "tika-parsers" % "1.11"
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.0.0"

这是scala代码

import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf

import org.apache.spark.sql.SQLContext;



object sparkJDBC {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("Simple Application").setMaster("local[2]").set("spark.executor.memory","1g")
    val sc = new SparkContext(conf)
    var sqlContext = new org.apache.spark.sql.SQLContext(sc)
    import sqlContext.implicits._
    val chrttype = sqlContext.load("jdbc", 
    Map("url" -> "jdbc:oracle:thin:gductv1/gductv1@//localhost:1521/XE1",
    "dbtable" -> "chrt_typ"))
    val clntlvl1  = sqlContext.load("jdbc", 
   Map("url" -> "jdbc:oracle:thin:gductv1/gductv1@//localhost:1521/XE1", 
   "dbtable" -> "clnt_lvl1"))
    val join2 = chrttyp.join(clntlvl1,chrttyp.col("chrt_typ_key")===clntlvl1("lvl1_key"))
    join2.foreach(println)
    join2.printSchema()
    }
}

这是错误文件。

[info] Compiling 2 Scala sources to C:\apps\spark-2.1.0\ScalaFiles\target\scala-2.10\classes...
[error] C:\apps\spark-2.1.0\ScalaFiles\src\main\scala\SimpleApp2.scala:33: value load is not a member of org.apache.spar
k.sql.SQLContext
[error]     val chrttype = sqlContext.load("jdbc",
[error]                               ^
[error] C:\apps\spark-2.1.0\ScalaFiles\src\main\scala\SimpleApp2.scala:36: value load is not a member of org.apache.spar
k.sql.SQLContext
[error]     val clntlvl1  = sqlContext.load("jdbc",
[error]                                ^
[error] C:\apps\spark-2.1.0\ScalaFiles\src\main\scala\SimpleApp2.scala:39: not found: value chrttyp
[error]     val join2 = chrttyp.join(clntlvl1,chrttyp.col("chrt_typ_key")===clntlvl1("lvl1_key"))
[error]                 ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed

0 个答案:

没有答案