如何在Databricks中重命名列?
以下内容不起作用:
ALTER TABLE mySchema.myTable change COLUMN old_name new_name int
它返回错误:
ALTER TABLE CHANGE COLUMN is not supported for changing column 'old_name' with type 'IntegerType >(nullable = true)' to 'new_name' with type 'IntegerType (nullable = true)';
如果有所不同,则此表使用的是Delta Lake,并且此“old_name”列未对其进行分区或z排序。
最佳答案
您不能在Databricks中重命名或更改列数据类型,只能添加新列,对其重新排序或添加列注释。为此,您必须使用overwriteSchema
选项重写该表。
请从this documentation中获取以下示例:
spark.read.table(...)
.withColumnRenamed("date", "date_created")
.write
.mode("overwrite")
.option("overwriteSchema", "true")
.table(...)
关于databricks - 如何在Databricks中重命名列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59491350/