title: How to use UPDATE command in spark-sql & DataFrames
body: <p>I am trying to implement <code>UPDATE</code> command on <code>DataFrames</code> in spark. But getting this error. Please put suggestions on what should be done.</p>
  
  <pre><code>17/01/19 11:49:39 INFO Replace$: query --&gt; UPDATE temp SET c2 = REPLACE(c2,"i","a");
  17/01/19 11:49:39 ERROR Main$: [1.1] failure: ``with'' expected but identifier UPDATE found
  
  UPDATE temp SET c2 = REPLACE(c2,"i","a");
  ^
  java.lang.RuntimeException: [1.1] failure: ``with'' expected but identifier UPDATE found
  
  UPDATE temp SET c2 = REPLACE(c2,"i","a");
  </code></pre>
  
  <p>This is the program</p>
  
  <pre><code>object Replace extends SparkPipelineJob{
    val logger = LoggerFactory.getLogger(getClass)
    protected implicit val jsonFormats: Formats = DefaultFormats
  
    def createSetCondition(colTypeMap:List[(String,DataType)], pattern:String, replacement:String):String = {
      val res = colTypeMap map {
        case (c,t) =&gt;
          if(t == StringType)
            c+" = REPLACE(" + c + ",\"" + pattern + "\",\"" + replacement + "\")"
          else
            c+" = REPLACE(" + c + "," + pattern + "," + replacement + ")"
      }
      return res.mkString(" , ")
    }
  
    override def execute(dataFrames: List[DataFrame], sc: SparkContext, sqlContext: SQLContext, params: String, productId: Int) : List[DataFrame] = {
      import sqlContext.implicits._
  
      val replaceData = ((parse(params)).extractOpt[ReplaceDataSchema]).get
      logger.info(s"Replace-replaceData --&gt; ${replaceData}")
  
      val (inputDf, (columnsMap, colTypeMap)) = (dataFrames(0), LoadInput.colMaps(dataFrames(0)))
  
      val tableName = Constants.TEMP_TABLE
      inputDf.registerTempTable(tableName)
  
      val colMap = replaceData.colName map {
        x =&gt; (x,colTypeMap.get(x).get)
      }
      logger.info(s"colMap --&gt; ${colMap}")
  
      val setCondition = createSetCondition(colMap,replaceData.input,replaceData.output)
      val query = "UPDATE "+tableName+" SET "+setCondition+";"
      logger.info(s"query --&gt; ${query}")
  
      val outputDf = sqlContext.sql(query)
      List(outputDf)
    }
  }
  </code></pre>
  
  <p>Here is some extra information.</p>
  
  <pre><code>17/01/19 11:49:39 INFO Replace$: Replace-replaceData --&gt; ReplaceDataSchema(List(SchemaDetectData(s3n://fakepath/data37.csv,None,None)),List(c2),i,a)
  17/01/19 11:49:39 INFO Replace$: colMap --&gt; List((c2,StringType))
  </code></pre>
  
  <p>data37.csv</p>
  
  <pre><code>c1 c2
  90 nine
  </code></pre>
  
  <p>Please ask for extra information if needed.</p>