15

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?

4
  • May be possible version issue Commented May 30, 2016 at 3:59
  • I use spark-1.6.1. Commented May 30, 2016 at 4:07
  • Now it's possible, with Databricks Delta Lake Commented Jul 15, 2019 at 13:48
  • 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 Commented Jan 27, 2022 at 4:56

1 Answer 1

19

Spark SQL doesn't support UPDATE statements yet.

Hive has started supporting UPDATE since hive version 0.14. But even with Hive, it supports updates/deletes only on those tables that support transactions, it is mentioned in the hive documentation.

See the answers in databricks forums confirming that UPDATES/DELETES are not supported in Spark SQL as it doesn't support transactions. If we think, supporting random updates is very complex with most of the storage formats in big data. It requires scanning huge files, updating specific records and rewriting potentially TBs of data. It is not normal SQL.

Sign up to request clarification or add additional context in comments.

2 Comments

There is an open ticket in the Spark project to improve support for Hive transaction tables (i.e. Hive tables which support updates) issues.apache.org/jira/browse/SPARK-15348
Any new updates on this whether it is supported now ? or any alternative to do the same ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.