【问题标题】:Spark Execution for twitter Streaming用于 Twitter 流的 Spark 执行
【发布时间】:2016-09-30 07:16:06
【问题描述】:

您好,我是 spark 和 scala 的新手。我正在尝试使用以下代码通过火花流传输一些推文:

object TwitterStreaming {

  def main(args: Array[String]): Unit = {
    if (args.length < 1) {
      System.err.println("WrongUsage:   PropertiesFile, [<filters>]")
      System.exit(-1)
    }

    StreamingExamples.setStreaningLogLevels()
    val myConfigFile = args(0)
    val batchInterval_s = 1
    val fileConfig = ConfigFactory.parseFile(new File(myConfigFile))
    val appConf = ConfigFactory.load(fileConfig)  
    // Set the system properties so that Twitter4j library used by twitter stream
    // can use them to generate OAuth credentials

    System.setProperty("twitter4j.oauth.consumerKey", appConf.getString("consumerKey"))
    System.setProperty("twitter4j.oauth.consumerSecret", appConf.getString("consumerSecret"))
    System.setProperty("twitter4j.oauth.accessToken", appConf.getString("accessToken"))
    System.setProperty("twitter4j.oauth.accessTokenSecret", appConf.getString("accessTokenSecret"))

    val sparkConf = new SparkConf().setAppName("TwitterStreaming").setMaster(appConf.getString("SPARK_MASTER"))//local[2]

    val ssc = new StreamingContext(sparkConf, Seconds(batchInterval_s)) // creating spark streaming context
    val stream = TwitterUtils.createStream(ssc, None)
    val tweet_data = stream.map(status => TweetData(status.getId, "@" + status.getUser.getScreenName, status.getText.trim()))
    tweet_data.foreachRDD(rdd => {
      println(s"A sample of tweets I gathered over ${batchInterval_s}s: ${rdd.take(10).mkString(" ")} (total tweets fetched: ${rdd.count()})")
    })
  }

}

case class TweetData(id: BigInt, author: String, tweetText: String)

我的错误:

Exception in thread "main" com.typesafe.config.ConfigException$WrongType:/WorkSpace/InputFiles/application.conf: 5: Cannot concatenate object or list with a non-object-or-list, ConfigString("local") and SimpleConfigList([2]) are not compatible
at com.typesafe.config.impl.ConfigConcatenation.join(ConfigConcatenation.java:116)

谁能检查代码并告诉我哪里做错了?

【问题讨论】:

  • @gsamaras 我想映射到 TweetData 类...这样做有什么问题吗?
  • 在我看来,错误在于将“local[2]”作为 SPARK_MASTER 传递。如果是这种情况,如何设置 SPARK_MASTER
  • 请在您的配置文件中显示相关行(带有 SPARK_MASTER 的行) - 它似乎违反了typesafe.config 所期望的格式。您可以缩小问题的范围,只包含文件的内容和加载配置文件的两行代码 - 这就是例外的地方,其余的都不需要......
  • @TzachZohar 两行代码val fileConfig = ConfigFactory.parseFile(new File(myConfigFile)) val appConf = ConfigFactory.load(fileConfig) 和文件包含consumerKey=xxx consumerSecret=xxx accessToken=xxx accessTokenSecret=xxx SPARK_MASTER="local[2]"
  • 最好更新问题而不是评论

标签: scala apache-spark typesafe-config


【解决方案1】:

如果您的配置文件包含:

SPARK_MASTER=local[2]

改成:

SPARK_MASTER="local[2]"

【讨论】:

  • 有道理!
  • @Tzach Zohar 更改后,如果您需要绑定到另一个地址,我将设置 SPARK_LOCAL_IP
  • 这对我来说听起来像是另一个问题,所以我无法在这里回答。尝试搜索 SO / Google,这是标准的 Spark 内容...与此同时,如果您编辑问题以包含所有相关信息并且包含它,这将对未来的读者有所帮助 - 这意味着配置文件条目和加载它的代码。
  • 顺便说一句 - 如果“如果您需要绑定到另一个地址,请设置 SPARK_LOCAL_IP”显示为 警告 而不是 错误 - 您可以忽略它,它不应该干扰执行。
  • @TzachZohar 谢谢..它正在工作...谢谢大家的支持
猜你喜欢
  • 2019-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
相关资源
最近更新 更多