Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/16626#discussion_r99680331 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala --- @@ -814,4 +816,50 @@ object DDLUtils { } } } + + /** + * ALTER TABLE ADD COLUMNS command does not support temporary view/table, + * view, or datasource table with text, orc formats or external provider. + */ + def verifyAlterTableAddColumn( + catalog: SessionCatalog, + table: TableIdentifier): CatalogTable = { + if (catalog.isTemporaryTable(table)) { + throw new AnalysisException( + s"${table.toString} is a temporary VIEW, which does not support ALTER ADD COLUMNS.") + } + + val catalogTable = catalog.getTableMetadata(table) + if (catalogTable.tableType == CatalogTableType.VIEW) { + throw new AnalysisException( + s"${table.toString} is a VIEW, which does not support ALTER ADD COLUMNS.") + } + + if (isDatasourceTable(catalogTable)) { + catalogTable.provider.get match { + case provider if provider.toLowerCase == "text" => + // TextFileFormat can not support adding column either because text datasource table + // is resolved as a single-column table only. + throw new AnalysisException( + s"""${table.toString} is a text format datasource table, + |which does not support ALTER ADD COLUMNS.""".stripMargin) + case provider if provider.toLowerCase == "orc" + || provider.startsWith("org.apache.spark.sql.hive.orc") => + // TODO Current native orc reader can not handle the difference between + // user-specified schema and inferred schema from ORC data file yet. + throw new AnalysisException( + s"""${table.toString} is an ORC datasource table, + |which does not support ALTER ADD COLUMNS.""".stripMargin) + case provider + if (!DataSource.lookupDataSource(provider).newInstance().isInstanceOf[FileFormat]) => --- End diff -- `FileFormat` only covers a few cases. It does not cover the other external data sources. How about using a white list here in this function?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org