-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21617][SQL] Store correct table metadata when altering schema in Hive metastore. #18849
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aae3abd
[SPARK-21617][SQL] Store correct metadata in Hive for altered DS table.
2350b10
Fix 2.1 DDL suite to not use SparkSession.
7ccf474
Proper fix.
40ebc96
Check for compatibility using serde, not path.
2f57a3c
equals -> ==
0b27209
Break out and expand Hive_2_1_DDLSuite.
6824e35
Feedback.
7b777ed
Move `isHiveCompatible` to its own method.
abd6cf1
Move comment.
4a05b55
Remove special handling of case-sensitive tables.
3c8a6bb
Merge branch 'master' into SPARK-21617
b63539d
Merge branch 'master' into SPARK-21617
cef66ac
Only retry writing to metastore for data source tables.
c41683a
Redo style change.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix 2.1 DDL suite to not use SparkSession.
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,11 @@ import java.net.URI | |
|
|
||
| import scala.language.existentials | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.fs.Path | ||
| import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} | ||
|
|
||
| import org.apache.spark.{SparkException, SparkFunSuite} | ||
| import org.apache.spark.{SparkConf, SparkException, SparkFunSuite} | ||
| import org.apache.spark.launcher.SparkLauncher | ||
| import org.apache.spark.sql.{AnalysisException, QueryTest, Row, SaveMode, SparkSession} | ||
| import org.apache.spark.sql.catalyst.analysis.{NoSuchPartitionException, TableAlreadyExistsException} | ||
|
|
@@ -39,6 +40,7 @@ import org.apache.spark.sql.internal.{HiveSerDe, SQLConf} | |
| import org.apache.spark.sql.internal.StaticSQLConf._ | ||
| import org.apache.spark.sql.test.SQLTestUtils | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.tags.ExtendedHiveTest | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| // TODO(gatorsmile): combine HiveCatalogedDDLSuite and HiveDDLSuite | ||
|
|
@@ -2004,41 +2006,56 @@ class HiveDDLSuite | |
| * A separate set of DDL tests that uses Hive 2.1 libraries, which behave a little differently | ||
| * from the built-in ones. | ||
| */ | ||
| class HiveDDLSuite_2_1 extends SparkFunSuite with BeforeAndAfterEach with BeforeAndAfterAll { | ||
| @ExtendedHiveTest | ||
| class Hive_2_1_DDLSuite extends SparkFunSuite with TestHiveSingleton with BeforeAndAfterEach | ||
|
||
| with BeforeAndAfterAll { | ||
|
|
||
| private val spark = { | ||
| // Create a custom HiveExternalCatalog instance with the desired configuration. We cannot | ||
| // use SparkSession here since there's already an active on managed by the TestHive object. | ||
| private var catalog = { | ||
| val warehouse = Utils.createTempDir() | ||
| val metastore = Utils.createTempDir() | ||
| metastore.delete() | ||
| SparkSession.builder() | ||
| .config(SparkLauncher.SPARK_MASTER, "local") | ||
| .config(WAREHOUSE_PATH.key, warehouse.toURI().toString()) | ||
| .config(CATALOG_IMPLEMENTATION.key, "hive") | ||
| .config(HiveUtils.HIVE_METASTORE_VERSION.key, "2.1") | ||
| .config(HiveUtils.HIVE_METASTORE_JARS.key, "maven") | ||
| .config("spark.hadoop.javax.jdo.option.ConnectionURL", | ||
| s"jdbc:derby:;databaseName=${metastore.getAbsolutePath()};create=true") | ||
| // These options are needed since the defaults in Hive 2.1 cause exceptions with an | ||
| // empty metastore db. | ||
| .config("spark.hadoop.datanucleus.schema.autoCreateAll", "true") | ||
| .config("spark.hadoop.hive.metastore.schema.verification", "false") | ||
| .getOrCreate() | ||
| val sparkConf = new SparkConf() | ||
| .set(SparkLauncher.SPARK_MASTER, "local") | ||
| .set(WAREHOUSE_PATH.key, warehouse.toURI().toString()) | ||
| .set(CATALOG_IMPLEMENTATION.key, "hive") | ||
| .set(HiveUtils.HIVE_METASTORE_VERSION.key, "2.1") | ||
| .set(HiveUtils.HIVE_METASTORE_JARS.key, "maven") | ||
|
|
||
| val hadoopConf = new Configuration() | ||
| hadoopConf.set("hive.metastore.warehouse.dir", warehouse.toURI().toString()) | ||
| hadoopConf.set("javax.jdo.option.ConnectionURL", | ||
| s"jdbc:derby:;databaseName=${metastore.getAbsolutePath()};create=true") | ||
| // These options are needed since the defaults in Hive 2.1 cause exceptions with an | ||
| // empty metastore db. | ||
| hadoopConf.set("datanucleus.schema.autoCreateAll", "true") | ||
| hadoopConf.set("hive.metastore.schema.verification", "false") | ||
|
|
||
| new HiveExternalCatalog(sparkConf, hadoopConf) | ||
| } | ||
|
|
||
| override def afterEach: Unit = { | ||
| catalog.listTables("default").foreach { t => | ||
| catalog.dropTable("default", t, true, false) | ||
| } | ||
| spark.sessionState.catalog.reset() | ||
| } | ||
|
|
||
| override def afterAll(): Unit = { | ||
| spark.close() | ||
| catalog = null | ||
| } | ||
|
|
||
| test("SPARK-21617: ALTER TABLE..ADD COLUMNS for DataSource tables") { | ||
| spark.sql("CREATE TABLE t1 (c1 int) USING json") | ||
| spark.sql("ALTER TABLE t1 ADD COLUMNS (c2 int)") | ||
| val oldTable = spark.sessionState.catalog.externalCatalog.getTable("default", "t1") | ||
| catalog.createTable(oldTable, true) | ||
|
|
||
| val newSchema = StructType(oldTable.schema.fields ++ Array(StructField("c2", IntegerType))) | ||
| catalog.alterTableSchema("default", "t1", newSchema) | ||
|
|
||
| val df = spark.table("t1") | ||
| assert(df.schema.fieldNames === Array("c1", "c2")) | ||
| val updatedTable = catalog.getTable("default", "t1") | ||
| assert(updatedTable.schema.fieldNames === Array("c1", "c2")) | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Revert it back?