Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update query in Spark SQL

I wonder can I use the update query in sparksql just like:

sqlContext.sql("update users set name = '*' where name is null")

I got the error:

org.apache.spark.sql.AnalysisException: 
Unsupported language features in query:update users set name = '*' where name is null

If the sparksql does not support the update query or am i writing the code incorrectly?

like image 295
ZMath_lin Avatar asked May 30 '16 03:05

ZMath_lin


People also ask

Can we do update in Spark SQL?

In Spark, updating the DataFrame can be done by using withColumn() transformation function, In this article, I will explain how to update or change the DataFrame column. I will also explain how to update the column based on condition.

How do you write an update query in PySpark?

You can do update a PySpark DataFrame Column using withColum(), select() and sql(), since DataFrame's are distributed immutable collection you can't really change the column values however when you change the value using withColumn() or any approach, PySpark returns a new Dataframe with updated values.

How do you update a Spark record?

One possible approach to insert or update records in the database from Spark Dataframe is to first write the dataframe to a csv file. Next, the csv can be streamed (to prevent out-of-memory error if the csv file is too large).

Can we update a Delta table?

Update a table. You can update data that matches a predicate in a Delta table. For example, to fix a spelling mistake in the eventType , you can run the following: Scala.


1 Answers

Spark SQL now supports update, delete and such data modification operations if the underlying table is in delta format.

Check this out: https://docs.delta.io/0.4.0/delta-update.html#update-a-table

like image 192
Anjana K V Avatar answered Oct 21 '22 12:10

Anjana K V