2

I am new to Spark-shell and I am getting this error when creating a dataframe from a csv file:

 scala> val bankDF = bankrdd.toDF() bankDF.registerTempTable("bankfull")                                                                                                               
<console>:1: error: ';' expected but '.' found.                                                                                                                                       
val bankDF = bankrdd.toDF() bankDF.registerTempTable("bankfull")


                              ^                        
n1tk
  • 2,406
  • 2
  • 21
  • 35
Tony Davis
  • 21
  • 1

2 Answers2

1

You are missing ; to separate the 2 statements.

Programming in Scala, First Edition

In a Scala program, a semicolon at the end of a statement is usually optional. You can type one if you want but you don't have to if the statement appears by itself on a single line.

On the other hand, a semicolon is required if you write multiple statements on a single line:

  val s = "hello"; println(s)

Sample working example Error(exactly as in your code):

scala> val rnd = Math.random() val n = Math.abs(rnd)
<console>:1: error: ';' expected but 'val' found.
val rnd = Math.random() val n = Math.abs(rnd)
                        ^

Sample working example Fixed:

scala> val rnd = Math.random(); val n = Math.abs(rnd)
rnd: Double = 0.5940919229549699
n: Double = 0.5940919229549699

So, in your case, you have 2 options to make it work:

Option1:

val bankDF = bankrdd.toDF(); bankDF.registerTempTable("bankfull")

Option2:

val bankDF = bankrdd.toDF()
bankDF.registerTempTable("bankfull")
with the following output:

scala> val bankDF = bankrdd.toDF(); bankDF.registerTempTable("bankfull")
warning: there was one deprecation warning; re-run with -deprecation for details
bankDF: org.apache.spark.sql.DataFrame = [value: string]
n1tk
  • 2,406
  • 2
  • 21
  • 35
0
val bankDF = bankrdd.toDF()
bankDF.registerTempTable("bankfull")

or

val bankDF = bankrdd.toDF().registerTempTable("bankfull")
Kris
  • 1,618
  • 1
  • 13
  • 13