<?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 toDF is not a member of org.apache.spark.rdd.RDD in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/toDF-is-not-a-member-of-org-apache-spark-rdd-RDD/m-p/56551#M49267</link>
    <description>&lt;P&gt;Im working on a spark program which can load the data into a Hive table.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.SaveMode
import org.apache.spark.sql._
import org.apache.spark.sql.DataFrame

object SparkToHive {
  case class partc(id:Int, name:String, salary:Int, dept:String, location:String)
  def main(args: Array[String]) {
    val warehouseLocation = "file:${system:user.dir}/spark-warehouse"
    val sparkSession = SparkSession.builder.master("local[2]").appName("Saving data into HiveTable using Spark")
                        .enableHiveSupport()
                        .config("hive.exec.dynamic.partition", "true")
                        .config("hive.exec.dynamic.partition.mode", "nonstrict")
                        .config("hive.metastore.warehouse.dir", "/user/hive/warehouse")
                        .getOrCreate()
    import sparkSession.implicits._
    val partfile = sparkSession.sparkContext.textFile("partfile")
    val partdata = partfile.map(part =&amp;gt; part.split(","))
    val partRDD  = partdata.map(line =&amp;gt; partc(line(0).toInt, line(1), line(2).toInt, line(3), line(4)))
    val partDF   = partRDD.toDF()
    partDF.write.mode(SaveMode.Append).insertInto("parttab")
  }
}&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;But I am getting error at this line:&lt;/P&gt;&lt;PRE&gt;val partDF   = partRDD.toDF()&lt;/PRE&gt;&lt;P&gt;saying:&lt;/P&gt;&lt;PRE&gt;value toDF is not a member of org.apache.spark.rdd.RDD[com.sparktohive.load.SparkToHive.partc]&lt;/PRE&gt;&lt;P&gt;Could anyone tell me how can I fix it ?&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 11:50:11 GMT</pubDate>
    <dc:creator>Sidhartha</dc:creator>
    <dc:date>2022-09-16T11:50:11Z</dc:date>
    <item>
      <title>toDF is not a member of org.apache.spark.rdd.RDD</title>
      <link>https://community.cloudera.com/t5/Support-Questions/toDF-is-not-a-member-of-org-apache-spark-rdd-RDD/m-p/56551#M49267</link>
      <description>&lt;P&gt;Im working on a spark program which can load the data into a Hive table.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.SaveMode
import org.apache.spark.sql._
import org.apache.spark.sql.DataFrame

object SparkToHive {
  case class partc(id:Int, name:String, salary:Int, dept:String, location:String)
  def main(args: Array[String]) {
    val warehouseLocation = "file:${system:user.dir}/spark-warehouse"
    val sparkSession = SparkSession.builder.master("local[2]").appName("Saving data into HiveTable using Spark")
                        .enableHiveSupport()
                        .config("hive.exec.dynamic.partition", "true")
                        .config("hive.exec.dynamic.partition.mode", "nonstrict")
                        .config("hive.metastore.warehouse.dir", "/user/hive/warehouse")
                        .getOrCreate()
    import sparkSession.implicits._
    val partfile = sparkSession.sparkContext.textFile("partfile")
    val partdata = partfile.map(part =&amp;gt; part.split(","))
    val partRDD  = partdata.map(line =&amp;gt; partc(line(0).toInt, line(1), line(2).toInt, line(3), line(4)))
    val partDF   = partRDD.toDF()
    partDF.write.mode(SaveMode.Append).insertInto("parttab")
  }
}&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;But I am getting error at this line:&lt;/P&gt;&lt;PRE&gt;val partDF   = partRDD.toDF()&lt;/PRE&gt;&lt;P&gt;saying:&lt;/P&gt;&lt;PRE&gt;value toDF is not a member of org.apache.spark.rdd.RDD[com.sparktohive.load.SparkToHive.partc]&lt;/PRE&gt;&lt;P&gt;Could anyone tell me how can I fix it ?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:50:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/toDF-is-not-a-member-of-org-apache-spark-rdd-RDD/m-p/56551#M49267</guid>
      <dc:creator>Sidhartha</dc:creator>
      <dc:date>2022-09-16T11:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: toDF is not a member of org.apache.spark.rdd.RDD</title>
      <link>https://community.cloudera.com/t5/Support-Questions/toDF-is-not-a-member-of-org-apache-spark-rdd-RDD/m-p/56569#M49268</link>
      <description>&lt;DIV class="post-text"&gt;&lt;P&gt;The mistake I made was&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Case class should be outside the main and inside the object&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;In this line:&lt;/P&gt;&lt;PRE&gt;val partfile = sparkSession.read.text("partfile").as[String]&lt;/PRE&gt;&lt;P&gt;, I used&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;read.text("..")&lt;/PRE&gt;&lt;P&gt;to get a file into Spark where we can use&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;read.textFile("...")&lt;/PRE&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 27 Jun 2017 13:32:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/toDF-is-not-a-member-of-org-apache-spark-rdd-RDD/m-p/56569#M49268</guid>
      <dc:creator>Sidhartha</dc:creator>
      <dc:date>2017-06-27T13:32:16Z</dc:date>
    </item>
  </channel>
</rss>

