I am executing multiple hive queries in a loop from my spark job using the following piece of code
implicit val sparkSession = SparkSession
.builder()
.config(sparkConf)
.enableHiveSupport()
.getOrCreate()
val bizEventFolders = fs.listStatus(outputPath)
bizEventFolders.foreach(folder => {
val filePath = folder.getPath().toString
if(filePath.contains(outputDir+"biz_evnt_key=")){
val bizEventKey = filePath.replaceAll(outputDir+"biz_evnt_key=","")
val addPartitionHiveQuery = s"alter table $tableName add if not exists partition (year=$year, month=$month, day=$day, hr=$hour,biz_evnt_key=$bizEventKey) location '${outputDir}biz_evnt_key=$bizEventKey'"
sparkSession.sql(addPartitionHiveQuery)
logger.info(s"successfully ran add partition hive query $addPartitionHiveQuery")
}
})
problem is, I have to run multiple such queries one after the other for adding all the partitions to the HIVE table, how can I submit all the queries at once to spark instead of firing them one by one?