Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

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

avatar
Visitor

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

1 ACCEPTED SOLUTION

avatar
Visitor

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}'

View solution in original post

3 REPLIES 3

avatar
Expert Contributor

avatar
Visitor

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}'

avatar
New Contributor

Only one question I have the line which you made bold in that you are trying to replace "from_timestamp" but you are using "fromdate" in your sql file.

 

Any reason behind it ?