Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ case class CatalogTablePartition(
* Note that Hive's metastore also tracks skewed columns. We should consider adding that in the
* future once we have a better understanding of how we want to handle skewed columns.
*
* @param hasUnsupportedFeatures is used to indicate whether all table metadata entries retrieved
* from the concrete underlying external catalog (e.g. Hive metastore) are supported by
* Spark SQL. For example, if the underlying Hive table has skewed columns, this information
* can't be mapped to [[CatalogTable]] since Spark SQL doesn't handle skewed columns for now.
* In this case `hasUnsupportedFeatures` is set to true. By default, it is false.
* @param unsupportedFeatures is a list of string descriptions of features that are used by the
* underlying table but not supported by Spark SQL yet.
*/
case class CatalogTable(
identifier: TableIdentifier,
Expand All @@ -102,7 +99,7 @@ case class CatalogTable(
viewOriginalText: Option[String] = None,
viewText: Option[String] = None,
comment: Option[String] = None,
hasUnsupportedFeatures: Boolean = false) {
unsupportedFeatures: Seq[String] = Seq.empty) {

// Verify that the provided columns are part of the schema
private val colNames = schema.map(_.name).toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,16 @@ case class ShowCreateTableCommand(table: TableIdentifier) extends RunnableComman
}

private def showCreateHiveTable(metadata: CatalogTable): String = {
def reportUnsupportedError(): Unit = {
throw new UnsupportedOperationException(
def reportUnsupportedError(features: Seq[String]): Unit = {
throw new AnalysisException(
s"Failed to execute SHOW CREATE TABLE against table ${metadata.identifier.quotedString}, " +
"because it contains table structure(s) (e.g. skewed columns) that Spark SQL doesn't " +
"support yet."
"which is created by Hive and uses the following unsupported feature(s)\n" +
features.map(" - " + _).mkString("\n")
)
}

if (metadata.hasUnsupportedFeatures) {
reportUnsupportedError()
if (metadata.unsupportedFeatures.nonEmpty) {
reportUnsupportedError(metadata.unsupportedFeatures)
}

val builder = StringBuilder.newBuilder
Expand All @@ -651,7 +651,7 @@ case class ShowCreateTableCommand(table: TableIdentifier) extends RunnableComman
case EXTERNAL => " EXTERNAL TABLE"
case VIEW => " VIEW"
case MANAGED => " TABLE"
case INDEX => reportUnsupportedError()
case INDEX => reportUnsupportedError(Seq("index table"))
}

builder ++= s"CREATE$tableTypeString ${table.quotedString}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,19 @@ private[hive] class HiveClientImpl(
val schema = h.getCols.asScala.map(fromHiveColumn) ++ partCols

// Skew spec, storage handler, and bucketing info can't be mapped to CatalogTable (yet)
val hasUnsupportedFeatures =
!h.getSkewedColNames.isEmpty ||
h.getStorageHandler != null ||
!h.getBucketCols.isEmpty
val unsupportedFeatures = ArrayBuffer.empty[String]

if (!h.getSkewedColNames.isEmpty) {
unsupportedFeatures += "skewed columns"
}

if (h.getStorageHandler != null) {
unsupportedFeatures += "storage handler"
}

if (!h.getBucketCols.isEmpty) {
unsupportedFeatures += "bucketing"
}

CatalogTable(
identifier = TableIdentifier(h.getTableName, Option(h.getDbName)),
Expand Down Expand Up @@ -369,7 +378,7 @@ private[hive] class HiveClientImpl(
properties = h.getParameters.asScala.toMap,
viewOriginalText = Option(h.getViewOriginalText),
viewText = Option(h.getViewExpandedText),
hasUnsupportedFeatures = hasUnsupportedFeatures)
unsupportedFeatures = unsupportedFeatures)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.sql.hive

import org.apache.spark.sql.QueryTest
import org.apache.spark.sql.{AnalysisException, QueryTest}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.catalog.CatalogTable
import org.apache.spark.sql.hive.test.TestHiveSingleton
Expand Down Expand Up @@ -247,7 +247,7 @@ class ShowCreateTableSuite extends QueryTest with SQLTestUtils with TestHiveSing
}
}

test("hive bucketing not supported") {
test("hive bucketing is not supported") {
withTable("t1") {
createRawHiveTable(
s"""CREATE TABLE t1 (a INT, b STRING)
Expand All @@ -257,9 +257,11 @@ class ShowCreateTableSuite extends QueryTest with SQLTestUtils with TestHiveSing
""".stripMargin
)

intercept[UnsupportedOperationException] {
val cause = intercept[AnalysisException] {
sql("SHOW CREATE TABLE t1")
}

assert(cause.getMessage.contains(" - bucketing"))
}
}

Expand Down