Reputation: 8957
I have a sql query with integer value as one argument.
Working:
sqlContext.sql("select concat(MinRange, '-', MaxRange) from range where 20 >= MinRange and 20 < MaxRange")
Not working:
sqlContext.sql("select concat(MinRange, '-', MaxRange) from range where "+intval+">= MinRange and "+intval+" < MaxRange")
Also this one with String interpolator, not working:
sqlContext.sql(s"select concat(MinRange, '-', MaxRange) from range where $intval >= MinRange and $intval < MaxRange")
I'm sure , i am missing something very basic.
Upvotes: 0
Views: 567
Reputation: 1175
First construct the query string then execute it will work.
val intval=10
val qry= "select concat(MinRange, '-', MaxRange) from range where "+intval+">= MinRange and "+intval+" < MaxRange"
sqlContext.sql(qry)
Upvotes: 1
Reputation: 1323
Did you check below:
1) Since u r building the <Column Name> run-time, can you check if the <Column Name> actually exists in "range" table.
2) Did you check what is the actual value of intVal variable during run-time? Make sure it is not getting null value, by giving a default value.
Upvotes: 0