1

I am using the below code to run in Qubole Notebook and the code is running successfully.

case class cls_Sch(Id:String, Name:String)
class myClass { 
    implicit val sparkSession = org.apache.spark.sql.SparkSession.builder().enableHiveSupport().getOrCreate()
    sparkSession.sql("set spark.sql.crossJoin.enabled = true")
    sparkSession.sql("set spark.sql.caseSensitive=false")   
    import sparkSession.sqlContext.implicits._
    import org.apache.hadoop.fs.{FileSystem, Path, LocatedFileStatus, RemoteIterator, FileUtil}
    import org.apache.hadoop.conf.Configuration 
    import org.apache.spark.sql.DataFrame

    def my_Methd() {                

        var my_df = Seq(("1","Sarath"),("2","Amal")).toDF("Id","Name")      

        my_df.as[cls_Sch].take(my_df.count.toInt).foreach(t => {            

            println(s"${t.Name}")

        })              
    }
}
val obj_myClass = new myClass()
obj_myClass.my_Methd()

enter image description here

However when I run in the same code in Qubole's Analyze, I am getting the below error.

enter image description here

When I take out the below code, its running fine in Qubole's Anlayze.

my_df.as[cls_Sch].take(my_df.count.toInt).foreach(t => {            

            println(s"${t.Name}")

        })

I believe somewhere I have to change the usage of case class.

I am using Spark 2.3.

Can someone please let me know how to solve this issue.

Please let me know if you need any other details.

Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86

2 Answers2

1

For any reason the kernel finds problems when working with dataset. I made two tests that worked with Apache Toree:

enter image description here

Emiliano Martinez
  • 4,073
  • 2
  • 9
  • 19
1

All you have to do is have the import spark.implicits._ inside the my_Methd() function.

def my_Methd() {   

    import spark.implicits._     

    var my_df = Seq(("1","Sarath"),("2","Amal")).toDF("Id","Name")      

    my_df.as[cls_Sch].take(my_df.count.toInt).foreach(t => {            

        println(s"${t.Name}")

    })              
} 
Prasad Sogalad
  • 131
  • 1
  • 5