-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19229] [SQL] Disallow Creating Hive Source Tables when Hive Support is Not Enabled #16587
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 3 commits
3b718ed
1f20c65
0d2d9f2
5e0cd26
49e6e81
c6d6a24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,8 +156,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
|
|
||
| test("the table type of an external table should be EXTERNAL_TABLE") { | ||
| val catalog = newBasicCatalog() | ||
| val table = | ||
| newTable("external_table1", "db2").copy(tableType = CatalogTableType.EXTERNAL) | ||
| val table = newTable("external_table1", "db2").copy(tableType = CatalogTableType.EXTERNAL) | ||
| catalog.createTable(table, ignoreIfExists = false) | ||
| val actual = catalog.getTable("db2", "external_table1") | ||
| assert(actual.tableType === CatalogTableType.EXTERNAL) | ||
|
|
@@ -278,7 +277,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| schema = new StructType() | ||
| .add("HelLo", "int", nullable = false) | ||
| .add("WoRLd", "int", nullable = true), | ||
| provider = Some("hive"), | ||
| provider = Some("parquet"), | ||
|
||
| partitionColumnNames = Seq("WoRLd"), | ||
| bucketSpec = Some(BucketSpec(4, Seq("HelLo"), Nil))) | ||
| catalog.createTable(tbl, ignoreIfExists = false) | ||
|
|
@@ -330,7 +329,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| .add("col2", "string") | ||
| .add("partCol1", "int") | ||
| .add("partCol2", "string"), | ||
| provider = Some("hive"), | ||
| provider = Some("parquet"), | ||
| partitionColumnNames = Seq("partCol1", "partCol2")) | ||
| catalog.createTable(table, ignoreIfExists = false) | ||
|
|
||
|
|
@@ -357,7 +356,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| .add("col2", "string") | ||
| .add("partCol1", "int") | ||
| .add("partCol2", "string"), | ||
| provider = Some("hive"), | ||
| provider = Some("parquet"), | ||
| partitionColumnNames = Seq("partCol1", "partCol2")) | ||
| catalog.createTable(table, ignoreIfExists = false) | ||
|
|
||
|
|
@@ -505,7 +504,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| .add("col2", "string") | ||
| .add("partCol1", "int") | ||
| .add("partCol2", "string"), | ||
| provider = Some("hive"), | ||
| provider = Some("parquet"), | ||
| partitionColumnNames = Seq("partCol1", "partCol2")) | ||
| catalog.createTable(table, ignoreIfExists = false) | ||
|
|
||
|
|
@@ -726,7 +725,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| tableType = CatalogTableType.MANAGED, | ||
| storage = CatalogStorageFormat.empty, | ||
| schema = new StructType().add("a", "int").add("b", "string"), | ||
| provider = Some("hive") | ||
| provider = Some("parquet") | ||
| ) | ||
|
|
||
| catalog.createTable(table, ignoreIfExists = false) | ||
|
|
@@ -746,7 +745,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| Some(Utils.createTempDir().getAbsolutePath), | ||
| None, None, None, false, Map.empty), | ||
| schema = new StructType().add("a", "int").add("b", "string"), | ||
| provider = Some("hive") | ||
| provider = Some("parquet") | ||
| ) | ||
| catalog.createTable(externalTable, ignoreIfExists = false) | ||
| assert(!exists(db.locationUri, "external_table")) | ||
|
|
@@ -763,7 +762,7 @@ abstract class ExternalCatalogSuite extends SparkFunSuite with BeforeAndAfterEac | |
| .add("col2", "string") | ||
| .add("partCol1", "int") | ||
| .add("partCol2", "string"), | ||
| provider = Some("hive"), | ||
| provider = Some("parquet"), | ||
| partitionColumnNames = Seq("partCol1", "partCol2")) | ||
| catalog.createTable(table, ignoreIfExists = false) | ||
|
|
||
|
|
@@ -829,6 +828,7 @@ abstract class CatalogTestUtils { | |
| // Unimplemented methods | ||
| val tableInputFormat: String | ||
| val tableOutputFormat: String | ||
| val defaultProvider: String | ||
| def newEmptyCatalog(): ExternalCatalog | ||
|
|
||
| // These fields must be lazy because they rely on fields that are not implemented yet | ||
|
|
@@ -899,7 +899,7 @@ abstract class CatalogTestUtils { | |
| .add("col2", "string") | ||
| .add("a", "int") | ||
| .add("b", "string"), | ||
| provider = Some("hive"), | ||
| provider = Some(defaultProvider), | ||
| partitionColumnNames = Seq("a", "b"), | ||
| bucketSpec = Some(BucketSpec(4, Seq("col1"), Nil))) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,7 +96,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| .add("col2", "string") | ||
| .add("a", "int") | ||
| .add("b", "int"), | ||
| provider = Some("hive"), | ||
| provider = Some("parquet"), | ||
| partitionColumnNames = Seq("a", "b"), | ||
| createTime = 0L, | ||
| tracksPartitionsInCatalog = true) | ||
|
|
@@ -758,15 +758,17 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| testUnsetProperties(isDatasourceTable = true) | ||
| } | ||
|
|
||
| test("alter table: set serde") { | ||
| // TODO: move this test to HiveDDLSuite.scala | ||
| ignore("alter table: set serde") { | ||
| testSetSerde(isDatasourceTable = false) | ||
| } | ||
|
|
||
| test("alter table: set serde (datasource table)") { | ||
| testSetSerde(isDatasourceTable = true) | ||
| } | ||
|
|
||
| test("alter table: set serde partition") { | ||
| // TODO: move this test to HiveDDLSuite.scala | ||
| ignore("alter table: set serde partition") { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two test cases should be moved to HiveDDLSuite. However, it is ugly to copy the codes. Thus, my next plan is to improve the DDLSuite and HiveDDLSuite by creating an abstract class. |
||
| testSetSerdePartition(isDatasourceTable = false) | ||
| } | ||
|
|
||
|
|
@@ -1479,49 +1481,33 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
| ) | ||
| } | ||
|
|
||
| test("select/insert into the managed table") { | ||
| test("create a managed Hive source table") { | ||
| assume(spark.sparkContext.conf.get(CATALOG_IMPLEMENTATION) == "in-memory") | ||
| val tabName = "tbl" | ||
| withTable(tabName) { | ||
| sql(s"CREATE TABLE $tabName (i INT, j STRING)") | ||
| val catalogTable = | ||
| spark.sessionState.catalog.getTableMetadata(TableIdentifier(tabName, Some("default"))) | ||
| assert(catalogTable.tableType == CatalogTableType.MANAGED) | ||
|
|
||
| var message = intercept[AnalysisException] { | ||
| sql(s"INSERT OVERWRITE TABLE $tabName SELECT 1, 'a'") | ||
| }.getMessage | ||
| assert(message.contains("Hive support is required to insert into the following tables")) | ||
| message = intercept[AnalysisException] { | ||
| sql(s"SELECT * FROM $tabName") | ||
| val e = intercept[AnalysisException] { | ||
| sql(s"CREATE TABLE $tabName (i INT, j STRING)") | ||
| }.getMessage | ||
| assert(message.contains("Hive support is required to select over the following tables")) | ||
| assert(e.contains("Hive support is required for creating a Hive data source table " + | ||
| "`tbl`; or create a file-based data source table instead")) | ||
| } | ||
| } | ||
|
|
||
| test("select/insert into external table") { | ||
| test("create an external Hive source table") { | ||
| assume(spark.sparkContext.conf.get(CATALOG_IMPLEMENTATION) == "in-memory") | ||
| withTempDir { tempDir => | ||
| val tabName = "tbl" | ||
| withTable(tabName) { | ||
| sql( | ||
| s""" | ||
| |CREATE EXTERNAL TABLE $tabName (i INT, j STRING) | ||
| |ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' | ||
| |LOCATION '$tempDir' | ||
| val e = intercept[AnalysisException] { | ||
| sql( | ||
| s""" | ||
| |CREATE EXTERNAL TABLE $tabName (i INT, j STRING) | ||
| |ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' | ||
| |LOCATION '$tempDir' | ||
| """.stripMargin) | ||
| val catalogTable = | ||
| spark.sessionState.catalog.getTableMetadata(TableIdentifier(tabName, Some("default"))) | ||
| assert(catalogTable.tableType == CatalogTableType.EXTERNAL) | ||
|
|
||
| var message = intercept[AnalysisException] { | ||
| sql(s"INSERT OVERWRITE TABLE $tabName SELECT 1, 'a'") | ||
| }.getMessage | ||
| assert(message.contains("Hive support is required to insert into the following tables")) | ||
| message = intercept[AnalysisException] { | ||
| sql(s"SELECT * FROM $tabName") | ||
| }.getMessage | ||
| assert(message.contains("Hive support is required to select over the following tables")) | ||
| assert(e.contains("Hive support is required for creating a Hive data source table " + | ||
| "`tbl`; or create a file-based data source table instead")) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1692,20 +1678,27 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { | |
|
|
||
| test("truncate table - external table, temporary table, view (not allowed)") { | ||
| import testImplicits._ | ||
| val path = Utils.createTempDir().getAbsolutePath | ||
| (1 to 10).map { i => (i, i) }.toDF("a", "b").createTempView("my_temp_tab") | ||
| sql(s"CREATE EXTERNAL TABLE my_ext_tab LOCATION '$path'") | ||
| sql(s"CREATE VIEW my_view AS SELECT 1") | ||
| intercept[NoSuchTableException] { | ||
| sql("TRUNCATE TABLE my_temp_tab") | ||
| withTempPath { tempDir => | ||
| withTable("my_ext_tab") { | ||
| (("a", "b") :: Nil).toDF().write.parquet(tempDir.getCanonicalPath) | ||
| (1 to 10).map { i => (i, i) }.toDF("a", "b").createTempView("my_temp_tab") | ||
| sql(s"CREATE TABLE my_ext_tab using parquet LOCATION '$tempDir'") | ||
|
||
| sql(s"CREATE VIEW my_view AS SELECT 1") | ||
| intercept[NoSuchTableException] { | ||
| sql("TRUNCATE TABLE my_temp_tab") | ||
| } | ||
| assertUnsupported("TRUNCATE TABLE my_ext_tab") | ||
| assertUnsupported("TRUNCATE TABLE my_view") | ||
| } | ||
| } | ||
| assertUnsupported("TRUNCATE TABLE my_ext_tab") | ||
| assertUnsupported("TRUNCATE TABLE my_view") | ||
| } | ||
|
|
||
| test("truncate table - non-partitioned table (not allowed)") { | ||
| sql("CREATE TABLE my_tab (age INT, name STRING)") | ||
| assertUnsupported("TRUNCATE TABLE my_tab PARTITION (age=10)") | ||
| withTable("my_tab") { | ||
| sql("CREATE TABLE my_tab (age INT, name STRING) using parquet") | ||
| sql("INSERT INTO my_tab values (10, 'a')") | ||
| assertUnsupported("TRUNCATE TABLE my_tab PARTITION (age=10)") | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-16034 Partition columns should match when appending to existing data source tables") { | ||
|
|
||
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.
shall we put this in
HiveOnlyCheck?