Reply
New Contributor
Posts: 2
Registered: ‎03-01-2019
Accepted Solution

pass parameters to file with sql statement using Scala to be used sqlContext.sql(string)

I am using Scala on data science workbench and I have file with sql stataement would like to make it dynamic sql by passing argument to parameters. I then would like to pass it  sqlContext.sql(string) .

 

This is what I have tried but does not work.

val FromDate = "2019-02-25"

val sqlfile = fromFile("sql3.py").getLines.mkString

val result = sqlContext.sql(sqlfile)

On the file I have:

Select col1, col2 from table1 where transdate = '${FromDate}'

 

Any help would be appreciated

 

Thanks

Cloudera Employee
Posts: 4
Registered: ‎08-22-2018

Re: pass parameters to file with sql statement using Scala to be used sqlContext.sql(string)

Highlighted
New Contributor
Posts: 2
Registered: ‎03-01-2019

Re: pass parameters to file with sql statement using Scala to be used sqlContext.sql(string)

This worked at the end..

 

val FromDate = "2019-02-25"

val sqlfile = fromFile("sql3.py").getLines.mkString

val sqlfil2= sqlfile.replace("${From_timeStamp}",From_timeStamp)

val result = sqlContext.sql(sqlfile2)

On the file I have:

Select col1, col2 from table1 where transdate = '${FromDate}'

Announcements