<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: sbt scala compilation error in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168496#M41691</link>
    <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/10115/sahmad43.html"&gt;@Sami Ahmad&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Is the following missing from your import statements?&lt;/P&gt;&lt;PRE&gt;import org.apache.spark.sql.DataFrame&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Sep 2016 01:15:22 GMT</pubDate>
    <dc:creator>cstanca</dc:creator>
    <dc:date>2016-09-27T01:15:22Z</dc:date>
    <item>
      <title>sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168495#M41690</link>
      <description>&lt;P&gt;I am getting the following error during compilation, also below are the build.sbt file and the source code. :&lt;/P&gt;&lt;P&gt;error &lt;/P&gt;&lt;PRE&gt;[info] Done updating.
[info] Compiling 4 Scala sources to /root/weblogs/target/scala-2.11/classes...
[error] /root/weblogs/src/main/scala/LogSQL.scala:60: value createOrReplaceTempView is not a member of org.apache.spark.sql.DataFrame
[error]       requestsDataFrame.createOrReplaceTempView("requests")
[error]                         ^
[error] one error found
[error] (compile:compile) Compilation failed
&lt;/PRE&gt;&lt;P&gt;scala code &lt;/P&gt;&lt;PRE&gt;
[root@hadoop1 scala]# more LogSQL.scala
import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext, Time}
import org.apache.spark.storage.StorageLevel
import org.apache.spark.sql.SQLContext
import org.apache.spark.rdd.RDD
import org.apache.spark.SparkContext
import java.util.regex.Pattern
import java.util.regex.Matcher
import Utilities._
/** Illustrates using SparkSQL with Spark Streaming, to issue queries on
 *  Apache log data extracted from a stream on port 9999.
 */
object LogSQL {
  def main(args: Array[String]) {
    // Create the context with a 1 second batch size
    val ssc = new StreamingContext("local[*]", "LogSQL", Seconds(1))
    setupLogging()
    // Construct a regular expression (regex) to extract fields from raw Apache log lines
    val pattern = apacheLogPattern()
    // Create a socket stream to read log data published via netcat on port 9999 locally
    val lines = ssc.socketTextStream("127.0.0.1", 9998, StorageLevel.MEMORY_AND_DISK_SER)
    // Extract the (URL, status, user agent) we want from each log line
    val requests = lines.map(x =&amp;gt; {
      val matcher:Matcher = pattern.matcher(x)
      if (matcher.matches()) {
        val request = matcher.group(5)
        val requestFields = request.toString().split(" ")
        val url = util.Try(requestFields(1)) getOrElse "[error]"
        (url, matcher.group(6).toInt, matcher.group(9))
      } else {
        ("error", 0, "error")
      }
    })
    // Process each RDD from each batch as it comes in
    requests.foreachRDD((rdd, time) =&amp;gt; {
      // So we'll demonstrate using SparkSQL in order to query each RDD
      // using SQL queries.
      // Get the singleton instance of SQLContext
      val sqlContext = SQLContextSingleton.getInstance(rdd.sparkContext)
      import sqlContext.implicits._
      // SparkSQL can automatically create DataFrames from Scala "case classes".
      // We created the Record case class for this purpose.
      // So we'll convert each RDD of tuple data into an RDD of "Record"
      // objects, which in turn we can convert to a DataFrame using toDF()
      val requestsDataFrame = rdd.map(w =&amp;gt; Record(w._1, w._2, w._3)).toDF()
      // Create a SQL table from this DataFrame
      requestsDataFrame.createOrReplaceTempView("requests")
      // Count up occurrences of each user agent in this RDD and print the results.
      // The powerful thing is that you can do any SQL you want here!
      // But remember it's only querying the data in this RDD, from this batch.
      val wordCountsDataFrame =
        sqlContext.sql("select agent, count(*) as total from requests group by agent")
      println(s"========= $time =========")
      wordCountsDataFrame.show()
      // If you want to dump data into an external database instead, check out the
      // org.apache.spark.sql.DataFrameWriter class! It can write dataframes via
      // jdbc and many other formats! You can use the "append" save mode to keep
      // adding data from each batch.
    })
    // Kick it off
    ssc.checkpoint("C:/checkpoint/")
    ssc.start()
    ssc.awaitTermination()
  }
}
/** Case class for converting RDD to DataFrame */
case class Record(url: String, status: Int, agent: String)
/** Lazily instantiated singleton instance of SQLContext
 *  (Straight from included examples in Spark)  */
object SQLContextSingleton {
  @transient  private var instance: SQLContext = _
  def getInstance(sparkContext: SparkContext): SQLContext = {
    if (instance == null) {
      instance = new SQLContext(sparkContext)
    }
    instance
  }
}
&lt;/PRE&gt;&lt;P&gt;build.sbt  &lt;/P&gt;&lt;PRE&gt;[root@hadoop1 weblogs]# more build.sbt
name := "weblogs"
version := "1.0"
scalaVersion := "2.11.6"
resolvers ++= Seq(
"Apache HBase" at "http://repository.apache.org/content/repositories/releases",
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "1.6.2",
  "org.apache.spark" %% "spark-streaming" % "1.6.2",
  "org.apache.spark" %% "spark-sql" % "1.6.2",
  "org.apache.spark" %% "spark-mllib" % "1.6.2"
)

&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Sep 2016 05:02:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168495#M41690</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-09-24T05:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168496#M41691</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/10115/sahmad43.html"&gt;@Sami Ahmad&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Is the following missing from your import statements?&lt;/P&gt;&lt;PRE&gt;import org.apache.spark.sql.DataFrame&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2016 01:15:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168496#M41691</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-09-27T01:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168497#M41692</link>
      <description>&lt;P&gt;I added this line but still getting the same error ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;[info] Compiling 4 Scala sources to /root/weblogs/target/scala-2.11/classes...
[error] /root/weblogs/src/main/scala/LogSQL.scala:60: value createOrReplaceTempView is not a member of org.apache.spark.sql.DataFrame
[error]  requestsDataFrame.createOrReplaceTempView("requests")
[error]  ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 14 s, completed Sep 27, 2016 12:04:22 PM&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2016 23:05:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168497#M41692</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-09-27T23:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168498#M41693</link>
      <description>&lt;P&gt;can anyone compile the attached scala code please?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 23:28:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168498#M41693</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-09-27T23:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168499#M41694</link>
      <description>&lt;P&gt;I found two solutions to the similar problem I am facing on web , do they apply to my code ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1- Import implicits:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;      Note that this should be done only after an instance of org.apache.spark.sql.SQLContext is created. It should be written as:&lt;/P&gt;&lt;P&gt;     val sqlContext= new org.apache.spark.sql.SQLContext(sc)
      import sqlContext.implicits._&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2- Move case class outside of the method:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;      case class, by use of which you define the schema of the DataFrame, should be defined outside of the method needing it. You can read more about it here:&lt;/P&gt;&lt;P&gt;     &lt;A href="https://issues.scala-lang.org/browse/SI-6649"&gt;https://issues.scala-lang.org/browse/SI-6649&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 02:01:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168499#M41694</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-09-28T02:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168500#M41695</link>
      <description>&lt;P&gt;I fixed this issue by upgrading from SPARK 1.6.2  to SPARK2.0.   I actually upgraded my HDC2.4 cluster to HDC2.5.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 01:45:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168500#M41695</guid>
      <dc:creator>aliyesami</dc:creator>
      <dc:date>2016-09-30T01:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: sbt scala compilation error</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168501#M41696</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/10115/sahmad43.html"&gt;@Sami Ahmad&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The upgrade addressed it, but I guess that we still don't know the cause.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2016 00:55:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/sbt-scala-compilation-error/m-p/168501#M41696</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-10-01T00:55:28Z</dc:date>
    </item>
  </channel>
</rss>

