Sou*_*osh 6 scala alter-table apache-spark apache-spark-sql
我可以使用 ALTER TABLE 命令向现有 Spark 表添加新列吗?
var query = "ALTER TABLE " + "global_temp." + tableName(0) + " ADD COLUMN " + newColumnName + " " + newColumnDatatype
var drt = spark.sql(query)
Run Code Online (Sandbox Code Playgroud)
上面的代码引发以下错误。
no viable alternative at input 'ALTER TABLE global_temp.people_ty ADD COLUMN' new_age integer
Run Code Online (Sandbox Code Playgroud)
编辑
正确的语法如下
ALTER TABLE tablename ADD COLUMNS (newColumn newDataType)
Run Code Online (Sandbox Code Playgroud)
但是,它也会引发以下错误。
ALTER ADD COLUMNS does not support views.
You must drop and re-create the views for adding the new columns. Views: `global_temp`.`people_ty`
Run Code Online (Sandbox Code Playgroud)
在 Spark SQL 中,语法如 Soumyadip Ghosh 在评论中提到的
ALTER TABLE table_identifier ADD COLUMNS ( col_spec [ , ... ] )
Run Code Online (Sandbox Code Playgroud)
对我有用。
| 归档时间: |
|
| 查看次数: |
20427 次 |
| 最近记录: |