Spark - Operation not allowed: alter table replace columns

4k Views Asked by At

Looks like hive replace columns is not working with spark 2.2.1 and also with 2.3.1

alterSchemaSql : alter table myschema.mytable replace columns (a int,b int,d int)
Exception in thread "main" org.apache.spark.sql.catalyst.parser.ParseException: 
Operation not allowed: alter table replace columns(line 2, pos 6)

Looks like it's been fixed for ADD COLUMNS 2.2 version onwards. It also works for me but replace columns still fails.

Operation not allowed: alter table add columns(line 1, pos 0)

Following docs says it should be supported. Not sure why it's failing for me. https://spark.apache.org/docs/2.2.0/sql-programming-guide.html#supported-hive-features

https://docs.databricks.com/spark/latest/spark-sql/language-manual/alter-table-or-view.html#replace-columns

1

There are 1 best solutions below

0
On

Sadly, it seems ALTER TABLE table REPLACE is not implemented by Spark.

Take a look at SparkSqlParser.scala: SparkSqlParser.scala

There, you can see, what SQL statements work with Spark.