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
11 changes: 7 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,14 @@ private[sql] case class ResolvedDataSource(provider: Class[_], relation: BaseRel
private[sql] case class DescribeCommand(
table: LogicalPlan,
isExtended: Boolean) extends Command {
override def output = Seq(
override val output = Seq(
// Column names are based on Hive.
AttributeReference("col_name", StringType, nullable = false)(),
AttributeReference("data_type", StringType, nullable = false)(),
AttributeReference("comment", StringType, nullable = false)())
AttributeReference("col_name", StringType, nullable = false,
new MetadataBuilder().putString("comment", "name of the column").build())(),
AttributeReference("data_type", StringType, nullable = false,
new MetadataBuilder().putString("comment", "data type of the column").build())(),
AttributeReference("comment", StringType, nullable = false,
new MetadataBuilder().putString("comment", "comment of the column").build())())
}

private[sql] case class CreateTableUsing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,14 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
// TODO: Actually, a user may mean tableName.columnName. Need to resolve this issue.
val tableIdent = extractTableIdent(nameParts.head)
DescribeCommand(
UnresolvedRelation(tableIdent, None), extended.isDefined)
UnresolvedRelation(tableIdent, None), isExtended = extended.isDefined)
case Token(".", dbName :: tableName :: colName :: Nil) =>
// It is describing a column with the format like "describe db.table column".
NativePlaceholder
case tableName =>
// It is describing a table with the format like "describe table".
DescribeCommand(
UnresolvedRelation(Seq(tableName.getText), None),
extended.isDefined)
UnresolvedRelation(Seq(tableName.getText), None), isExtended = extended.isDefined)
}
}
// All other cases.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql.hive.execution

import org.apache.spark.sql.{Row, QueryTest}
import org.apache.spark.sql.hive.test.TestHive._

/**
* A set of tests that validates commands can also be queried by like a table
*/
class HiveOperatorQueryableSuite extends QueryTest {
test("SPARK-5324 query result of describe command") {
loadTestTable("src")

// register a describe command to be a temp table
sql("desc src").registerTempTable("mydesc")
checkAnswer(
sql("desc mydesc"),
Seq(
Row("col_name", "string", "name of the column"),
Row("data_type", "string", "data type of the column"),
Row("comment", "string", "comment of the column")))

checkAnswer(
sql("select * from mydesc"),
Seq(
Row("key", "int", null),
Row("value", "string", null)))

checkAnswer(
sql("select col_name, data_type, comment from mydesc"),
Seq(
Row("key", "int", null),
Row("value", "string", null)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter {
Locale.setDefault(originalLocale)
}

test("SPARK-4908: concurent hive native commands") {
test("SPARK-4908: concurrent hive native commands") {
(1 to 100).par.map { _ =>
sql("USE default")
sql("SHOW TABLES")
Expand Down