In Spark 2 this gives me an error in a conditional  IF ELSE statement

I recall seeing the same in standard SQL

I am doing a test for different sources (text file, ORC or Parquet) to be
read in dependent on value of var option

I wrote this

import org.apache.spark.sql.functions._
import java.util.Calendar
import org.joda.time._
var option = 1
val today = new DateTime()
val minutes = -15
val  minutesago =
val date =
val hour =
case class columns(INDEX: Int, TIMECREATED: String, SECURITY: String,
PRICE: String)

*if(option == 1 ) {   println("option = 1")   val df ="header",
false).csv("hdfs://rhes564:9000/data/prices/prices.*")   val df2 =
=> columns(p(0).toString.toInt,p(1).toString,
p(2).toString,p(3).toString))   df2.printSchema} else if (option == 2) {
val df2 =
spark.table("test.marketData").select('TIMECREATED,'SECURITY,'PRICE)} else
if (option == 3) {    val df2 =
else {    println("no valid option provided")    sys.exit(0)}*

With option 1 selected it goes through and shows this

option = 1
 |-- INDEX: integer (nullable = true)
 |-- TIMECREATED: string (nullable = true)
 |-- SECURITY: string (nullable = true)
 |-- PRICE: string (nullable = true)

But when I try to do df2.printSchema OUTSEDE of the LOOP, it comes back
with error

scala> df2.printSchema
<console>:31: error: not found: value df2

I can define a stud df2 before IF ELSE statement. Is that the best way of
dealing with it?


Dr Mich Talebzadeh

LinkedIn *

*Disclaimer:* Use it at your own risk. Any and all responsibility for any
loss, damage or destruction of data or any other property which may arise
from relying on this email's technical content is explicitly disclaimed.
The author will in no case be liable for any monetary damages arising from
such loss, damage or destruction.

Reply via email to