-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19261][SQL] Alter add columns for Hive serde and some datasource tables #16626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
52ca902
f498fa6
522443e
1af2654
ec57ee9
ec74849
8fca889
4a17529
9699128
9860e5c
dfff364
9f23254
180092f
5a8aa80
d3860e6
55577aa
6fa913a
7231efe
e4e9ecf
75e7441
9847030
1a383bb
f994ce9
5bf7360
599c45e
b3edfea
7d8a515
e895278
e171ac4
4391edd
a3fef12
1eb7cd3
04ce8f4
7d8437d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…s alter add columns
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,10 @@ import org.apache.spark.sql.catalyst.catalog.CatalogTableType._ | |
| import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference} | ||
| import org.apache.spark.sql.catalyst.util.quoteIdentifier | ||
| import org.apache.spark.sql.execution.datasources.PartitioningUtils | ||
| import org.apache.spark.sql.execution.datasources.{DataSource, FileFormat, PartitioningUtils} | ||
| import org.apache.spark.sql.execution.datasources.csv.CSVFileFormat | ||
| import org.apache.spark.sql.execution.datasources.json.JsonFileFormat | ||
| import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.util.Utils | ||
|
|
||
|
|
@@ -187,7 +190,7 @@ case class AlterTableAddColumnsCommand( | |
| columns: Seq[StructField]) extends RunnableCommand { | ||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val catalogTable = DDLUtils.verifyAlterTableAddColumn(catalog, table) | ||
| val catalogTable = verifyAlterTableAddColumn(catalog, table) | ||
|
|
||
| // If an exception is thrown here we can just assume the table is uncached; | ||
| // this can happen with Hive tables when the underlying catalog is in-memory. | ||
|
|
@@ -210,6 +213,41 @@ case class AlterTableAddColumnsCommand( | |
|
|
||
| Seq.empty[Row] | ||
| } | ||
|
|
||
| /** | ||
| * ALTER TABLE ADD COLUMNS command does not support temporary view/table, | ||
| * view, or datasource table with text, orc formats or external provider. | ||
| */ | ||
| private def verifyAlterTableAddColumn( | ||
| catalog: SessionCatalog, | ||
| table: TableIdentifier): CatalogTable = { | ||
| val catalogTable = catalog.getTempViewOrPermanentTableMetadata(table) | ||
|
|
||
| if (catalogTable.tableType == CatalogTableType.VIEW) { | ||
| throw new AnalysisException( | ||
| s"${table.toString} is a VIEW, which does not support ALTER ADD COLUMNS.") | ||
|
||
| } | ||
|
|
||
| if (DDLUtils.isDatasourceTable(catalogTable)) { | ||
| DataSource.lookupDataSource(catalogTable.provider.get).newInstance() match { | ||
| // For datasource table, this command can only support the following File format. | ||
| // TextFileFormat only default to one column "value" | ||
| // OrcFileFormat can not handle difference between user-specified schema and | ||
| // inferred schema yet. TODO, once this issue is resolved , we can add Orc back. | ||
| // Hive type is already considered as hive serde table, so the logic will not | ||
| // come in here. | ||
| case _: JsonFileFormat => | ||
| case _: CSVFileFormat => | ||
| case _: ParquetFileFormat => | ||
| case s => | ||
| throw new AnalysisException( | ||
| s"""${table.toString} is a datasource table with type $s, | ||
| |which does not support ALTER ADD COLUMNS.""".stripMargin) | ||
| } | ||
| } | ||
|
|
||
| catalogTable | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2001,17 +2001,17 @@ class HiveDDLSuite | |
| } | ||
| } | ||
|
|
||
| test("alter datasource table add columns - orc format not supported") { | ||
| Seq("orc", "ORC", "org.apache.spark.sql.hive.orc", | ||
| "org.apache.spark.sql.hive.orc.DefaultSource").foreach { source => | ||
| withTable("alter_add_ds_text") { | ||
| sql(s"CREATE TABLE alter_add_ds_text (c1 int) USING $source") | ||
| val e = intercept[AnalysisException] { | ||
| sql("ALTER TABLE alter_add_ds_text ADD COLUMNS (c2 int)") | ||
| }.getMessage | ||
| assert(e.contains("does not support ALTER ADD COLUMNS")) | ||
| } | ||
| Seq("orc", "ORC", "org.apache.spark.sql.hive.orc", | ||
|
||
| "org.apache.spark.sql.hive.orc.DefaultSource").foreach { source => | ||
| test(s"alter datasource table add columns - $source format not supported") { | ||
| withTable("alter_add_ds_text") { | ||
| sql(s"CREATE TABLE alter_add_ds_text (c1 int) USING $source") | ||
| val e = intercept[AnalysisException] { | ||
| sql("ALTER TABLE alter_add_ds_text ADD COLUMNS (c2 int)") | ||
| }.getMessage | ||
| assert(e.contains("does not support ALTER ADD COLUMNS")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("alter table add columns -- not support temp view") { | ||
|
|
@@ -2020,7 +2020,7 @@ class HiveDDLSuite | |
| val e = intercept[AnalysisException] { | ||
| sql("alter table tmp_v add columns (c3 int)") | ||
| } | ||
| assert(e.message.contains("is a temporary VIEW, which does not support ALTER ADD COLUMNS")) | ||
| assert(e.message.contains("is a VIEW, which does not support ALTER ADD COLUMNS")) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent