【问题标题】:Utils.Scala Databricks ~ Twitter Stream in ScalaUtils.Scala Databricks ~ Scala 中的 Twitter 流
【发布时间】:2015-11-17 21:02:31
【问题描述】:

我在 IntelliJ 中工作并收到此错误:

Error:(118, 13) not found: value Utils
        Utils.parseCommandLineWithTwitterCredentials(args)
        ^

This 是试图引用的代码。

如果我将此代码直接放入我的 main 中,错误就会解决。


这是我的 build.sbt 文件:

name := "TwtrStream"

version := "1.0"

scalaVersion := "2.10.4"

libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.5.2"
libraryDependencies += "org.apache.spark" % "spark-streaming_2.10" % "1.5.2"
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.5.2"
libraryDependencies += "org.apache.spark" % "spark-mllib_2.10" % "1.5.2"
libraryDependencies += "org.apache.spark" % "spark-streaming-twitter_2.10" % "1.5.2"
libraryDependencies += "com.google.code.gson" % "gson" % "2.3.1"

这是我得到错误的代码:Utils.IntParam DOES NOT RESOLVE

object Collect {
    private var numTweetsCollected = 0L
    private var partNum = 0
    private var gson = new Gson()

    def main(args: Array[String]) {
      // Process program arguments and set properties
      if (args.length < 3) {
        System.err.println("Usage: " + this.getClass.getSimpleName +
          "<outputDirectory> <numTweetsToCollect> <intervalInSeconds> <partitionsEachInterval>")
        System.exit(1)
      }
      val Array(outputDirectory, Utils.IntParam(numTweetsToCollect),  Utils.IntParam(intervalSecs), Utils.IntParam(partitionsEachInterval)) =
        Utils.parseCommandLineWithTwitterCredentials(args)
      /*
      https://github.com/databricks/reference-apps/blob/master/twitter_classifier/scala/src/main/scala/com/databricks/apps/twitter_classifier/Utils.scala
       */
      val outputDir = new File(outputDirectory.toString)
      if (outputDir.exists()) {
        System.err.println("ERROR - %s already exists: delete or specify another directory".format(
          outputDirectory))
        System.exit(1)
      }
      outputDir.mkdirs()

      println("Initializing Streaming Spark Context...")
      val conf = new SparkConf().setAppName(this.getClass.getSimpleName)
      val sc = new SparkContext(conf)
      val ssc = new StreamingContext(sc, Seconds(intervalSecs))

      val tweetStream = TwitterUtils.createStream(ssc, Utils.getAuth)
        .map(gson.toJson(_))

      tweetStream.foreachRDD((rdd, time) => {
        val count = rdd.count()
        if (count > 0) {
          val outputRDD = rdd.repartition(partitionsEachInterval)
          outputRDD.saveAsTextFile(outputDirectory + "/tweets_" + time.milliseconds.toString)
          numTweetsCollected += count
          if (numTweetsCollected > numTweetsToCollect) {
            System.exit(0)
          }
        }
      })
    }
  }

【问题讨论】:

    标签: scala twitter apache-spark streaming


    【解决方案1】:

    实际上,问题在于您尝试访问的类不在您的项目中,也不在您的依赖项列表中的任何库中。

    因此,您需要将该类添加到您的项目中或创建一个类似的。

    your.package
    |_ Collect.scala
    |_ Utils.scala
    

    现在您可以在您的收集对象代码中使用它。

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      • 2019-03-05
      • 2022-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      相关资源
      最近更新 更多