-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-27592][SQL] Set the bucketed data source table SerDe correctly #24486
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 2 commits
6ce0a32
2fdc3a6
4e1dd5c
921bbb0
26c895a
87b302c
86e4394
842bd3e
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 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -358,12 +358,17 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat | |||||||||||||||||||||||||||||||
| "Spark SQL specific format, which is NOT compatible with Hive." | ||||||||||||||||||||||||||||||||
| (None, message) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // our bucketing is un-compatible with hive(different hash function) | ||||||||||||||||||||||||||||||||
| case _ if table.bucketSpec.nonEmpty => | ||||||||||||||||||||||||||||||||
| // our bucketing is un-compatible with hive(different hash function). | ||||||||||||||||||||||||||||||||
| // but downstream(Hive/Presto) still can read it as not bucketed table. | ||||||||||||||||||||||||||||||||
| // We set the SerDe correctly and bucketing_version to spark. | ||||||||||||||||||||||||||||||||
| // The downstream decides how to read it by themselves, a similar implementation: | ||||||||||||||||||||||||||||||||
| // https://github.com/prestosql/presto/pull/512 | ||||||||||||||||||||||||||||||||
| case Some(serde) if table.bucketSpec.nonEmpty => | ||||||||||||||||||||||||||||||||
| val message = | ||||||||||||||||||||||||||||||||
| s"Persisting bucketed data source table $qualifiedTableName into " + | ||||||||||||||||||||||||||||||||
| "Hive metastore in Spark SQL specific format, which is NOT compatible with Hive. " | ||||||||||||||||||||||||||||||||
| (None, message) | ||||||||||||||||||||||||||||||||
| tableProperties.put("bucketing_version", "spark") | ||||||||||||||||||||||||||||||||
| (Some(newHiveCompatibleMetastoreTable(serde)), message) | ||||||||||||||||||||||||||||||||
|
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. Should we set
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. Not necessary: spark/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala Lines 1009 to 1023 in fee695d
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| case Some(serde) => | ||||||||||||||||||||||||||||||||
| val message = | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import org.apache.spark.sql.catalyst.catalog.CatalogTableType | |
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser | ||
| import org.apache.spark.sql.catalyst.plans.logical.SubqueryAlias | ||
| import org.apache.spark.sql.hive.test.TestHiveSingleton | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.internal.{HiveSerDe, SQLConf} | ||
| import org.apache.spark.sql.test.{ExamplePointUDT, SQLTestUtils} | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
|
|
@@ -273,4 +273,26 @@ class DataSourceWithHiveMetastoreCatalogSuite | |
| } | ||
|
|
||
| } | ||
|
|
||
| test("Set the bucketed data source table SerDe correctly") { | ||
|
Contributor
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 include the jira id in test name. |
||
| val provider = "parquet" | ||
| withTable("t") { | ||
| spark.sql( | ||
| s""" | ||
| |CREATE TABLE t (c1 INT, c2 INT) | ||
| |USING $provider | ||
| |CLUSTERED BY (c1) | ||
| |SORTED BY (c1) | ||
| |INTO 2 BUCKETS | ||
| """.stripMargin) | ||
|
|
||
| val metadata = sessionState.catalog.getTableMetadata(TableIdentifier("t", Some("default"))) | ||
| assert(metadata.properties.get("bucketing_version") === Some("spark")) | ||
|
|
||
| val hiveSerDe = HiveSerDe.sourceToSerDe(provider).get | ||
| assert(metadata.storage.serde === hiveSerDe.serde) | ||
| assert(metadata.storage.inputFormat === hiveSerDe.inputFormat) | ||
| assert(metadata.storage.outputFormat === hiveSerDe.outputFormat) | ||
| } | ||
| } | ||
| } | ||
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.
What is the impact if the downstream makes a wrong decision?
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.
Sorry. It's not bucketed table at Hive side. Related code:
spark/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
Lines 444 to 459 in f9776e3
spark/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
Lines 976 to 990 in 33f3c48