-1

I would like to execute a set of hiveQL statements in my spark driver code, something like below

var res = hiveContext.sql("""use testdb;drop table temp;select ...")

When i executed this code, it gave me an error saying

Error: missing EOF near testdb

Can someone point to me where I am going wrong? Is it really possible to execute more than one statement using the approach above?

Further, i tried putting all my statements in a file "test.hql", and used the below code snippet.

sqlContext.sql(scala.io.Source.fromFile("mytest.hql").mkString)    

Still got the same error as above.

Any thoughts?

Bala
  • 675
  • 2
  • 7
  • 23

1 Answers1

-1

You can put all your queries on file and use this code to execute queries

queryFile = "path_of_your_file_queries"
Source.fromFile(queryFile, "utf-8").getLines().foreach(query => sparksql.sql(query))