Siva kumar
Siva kumar

Reputation: 11

Running the hive queries from a file through code via sparkcontext or hivecontext (not through command line)

Consider there are few hive queries in a file, my moto is to run the file using hivecontext or sparkcontext

Using command line I can do that by hive -f 'filepath/filename' But I have to run it via code (hivecontext or sparkcontext) Can anybody help on this?

For a single query I can use:

sparkContext.SQL('query')

But I have to run a file which is having queries.

Upvotes: 0

Views: 1711

Answers (2)

Sampat Kumar
Sampat Kumar

Reputation: 502

You can run your hql file some where like the below :

val Test = sqlContext.sql(open("file.hql").read())

Upvotes: 0

A. BENCHAMA
A. BENCHAMA

Reputation: 1

You can do it using Spark/Scala:

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

Upvotes: 0

Related Questions