-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17620][SQL] Determine Serde by hive.default.fileformat when Creating Hive Serde Tables #15190
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
[SPARK-17620][SQL] Determine Serde by hive.default.fileformat when Creating Hive Serde Tables #15190
Changes from all commits
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 |
|---|---|---|
|
|
@@ -988,9 +988,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { | |
| .orElse(Some("org.apache.hadoop.mapred.TextInputFormat")), | ||
| outputFormat = defaultHiveSerde.flatMap(_.outputFormat) | ||
| .orElse(Some("org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat")), | ||
| // Note: Keep this unspecified because we use the presence of the serde to decide | ||
| // whether to convert a table created by CTAS to a datasource table. | ||
| serde = None, | ||
| serde = defaultHiveSerde.flatMap(_.serde), | ||
|
Member
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. In
Contributor
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. @viirya Please see my comment below |
||
| compressed = false, | ||
| properties = Map()) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,10 +30,12 @@ import org.apache.spark.sql.catalyst.plans.PlanTest | |
| import org.apache.spark.sql.catalyst.plans.logical.{Generate, ScriptTransformation} | ||
| import org.apache.spark.sql.execution.command._ | ||
| import org.apache.spark.sql.execution.datasources.CreateTable | ||
| import org.apache.spark.sql.hive.test.TestHive | ||
| import org.apache.spark.sql.hive.test.{TestHive, TestHiveSingleton} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.test.SQLTestUtils | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
||
| class HiveDDLCommandSuite extends PlanTest { | ||
| class HiveDDLCommandSuite extends PlanTest with SQLTestUtils with TestHiveSingleton { | ||
| val parser = TestHive.sessionState.sqlParser | ||
|
|
||
| private def extractTableDesc(sql: String): (CatalogTable, Boolean) = { | ||
|
|
@@ -556,4 +558,24 @@ class HiveDDLCommandSuite extends PlanTest { | |
| assert(partition2.get.apply("c") == "1" && partition2.get.apply("d") == "2") | ||
| } | ||
|
|
||
| test("Test the default fileformat for Hive-serde tables") { | ||
|
Member
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. Let's add a test for |
||
| withSQLConf("hive.default.fileformat" -> "orc") { | ||
| val (desc, exists) = extractTableDesc("CREATE TABLE IF NOT EXISTS fileformat_test (id int)") | ||
| assert(exists) | ||
| assert(desc.storage.inputFormat == Some("org.apache.hadoop.hive.ql.io.orc.OrcInputFormat")) | ||
| assert(desc.storage.outputFormat == Some("org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat")) | ||
| assert(desc.storage.serde == Some("org.apache.hadoop.hive.ql.io.orc.OrcSerde")) | ||
| } | ||
|
|
||
| withSQLConf("hive.default.fileformat" -> "parquet") { | ||
| val (desc, exists) = extractTableDesc("CREATE TABLE IF NOT EXISTS fileformat_test (id int)") | ||
| assert(exists) | ||
| val input = desc.storage.inputFormat | ||
| val output = desc.storage.outputFormat | ||
| val serde = desc.storage.serde | ||
| assert(input == Some("org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat")) | ||
| assert(output == Some("org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat")) | ||
| assert(serde == Some("org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe")) | ||
| } | ||
| } | ||
| } | ||
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.
I think this is kept as unspecified because it is intended to write the table with Hive write path. If we specify serde here, it will be converted to datasource table. Is it ok? cc @cloud-fan
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.
cc @yhuai to confirm
Uh oh!
There was an error while loading. Please reload this page.
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.
The comment is not valid now. This was removed by the PR: #13386 (See the code changes made in HiveMetastoreCatalog.scala)
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.
The current checking conditions are based on ctx.createFileFormat and ctx.rowFormat. Thus, I think this PR looks ok. : )
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.
@viirya @cloud-fan Actually i am not sure, if the above comment is in sync with the code. When we had this comment, we used to have CreateTableAsSelectLogicalPlan to represent the CTAS case and we used to check for serde's presence to determine whether or not to convert it to a data source table like following.
I think this code has changed and moved to SparkSqlParser ?
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.
yeah. looks ok now.