0
votes

I want to pass one path from spark submit command while loading data from one file to hive table. I am trying pass that path using below code but its showing mismatch input '$' expecting StringLiteral Inpath near 'inpath' in load statement.

    obj hive_scala{
    def main(args:Array[String]){
    // creating sparksession
    val dbsession=HiveWareHouseSession.session(sparksession).build()
    dbsession.setDatabase("dbname")
    if(args.length<1){
    System.exit(1)
    }
    var a="load data inpath $args(0) into table tablename";
    val b=dbsession.executeUpdate(a)
    }
    }

then using below spark submit command: spark-submit --class classname projectjar location(from here i need to load data into table) can anyone suggest how should i pass this path using spark-submit and what code needs to change in scala.

2

2 Answers

0
votes

Change the String to

var a=s"load data inpath ${args(0)} into table tablename";

The 's' prefix mark the String Interpolation. {} should be used for expressions

0
votes

Looks like you are missing some characters for using s interpolation:

 obj hive_scala {
    def main(args:Array[String]){
   // creating sparksession
   val dbsession = HiveWareHouseSession.session(sparksession).build()
   dbsession.setDatabase("dbname")
    if(args.length < 1){
      System.exit(1)
    }
   var a = s"load data inpath ${args(0)} into table tablename";
   val b = dbsession.executeUpdate(a)
 }

}