sqlselect

Spark SQL passing a variable


I have following Spark sql and I want to pass variable to it. How to do that? I tried following way.

 sqlContext.sql("SELECT count from mytable WHERE id=$id")

Solution

  • You are almost there just missed s :)

    sqlContext.sql(s"SELECT count from mytable WHERE id=$id")