Skip to content

Commit 2c62e9d

Browse files
committed
fix for hive module
1 parent 5a7a819 commit 2c62e9d

File tree

8 files changed

+38
-15
lines changed

8 files changed

+38
-15
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/commands.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ case class SetCommand(
113113
@DeveloperApi
114114
case class ExplainCommand(
115115
logicalPlan: LogicalPlan,
116-
override val output: Seq[Attribute], extended: Boolean) extends RunnableCommand {
116+
override val output: Seq[Attribute], extended: Boolean = false) extends RunnableCommand {
117117

118118
// Run through the optimizer to generate the physical plan.
119119
override def run(sqlContext: SQLContext) = try {

sql/hive-thriftserver/v0.12.0/src/main/scala/org/apache/spark/sql/hive/thriftserver/Shim12.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import org.apache.hive.service.cli.operation.ExecuteStatementOperation
3333
import org.apache.hive.service.cli.session.HiveSession
3434

3535
import org.apache.spark.Logging
36-
import org.apache.spark.sql.catalyst.plans.logical.SetCommand
3736
import org.apache.spark.sql.catalyst.types._
37+
import org.apache.spark.sql.execution.SetCommand
3838
import org.apache.spark.sql.hive.thriftserver.ReflectionUtils._
3939
import org.apache.spark.sql.hive.{HiveContext, HiveMetastoreTypes}
4040
import org.apache.spark.sql.{SQLConf, SchemaRDD, Row => SparkRow}
@@ -190,7 +190,7 @@ private[hive] class SparkExecuteStatementOperation(
190190
result = hiveContext.sql(statement)
191191
logDebug(result.queryExecution.toString())
192192
result.queryExecution.logical match {
193-
case SetCommand(Some((SQLConf.THRIFTSERVER_POOL, Some(value)))) =>
193+
case SetCommand(Some((SQLConf.THRIFTSERVER_POOL, Some(value))), _) =>
194194
sessionToActivePool(parentSession.getSessionHandle) = value
195195
logInfo(s"Setting spark.scheduler.pool=$value for future statements in this session.")
196196
case _ =>

sql/hive-thriftserver/v0.13.1/src/main/scala/org/apache/spark/sql/hive/thriftserver/Shim13.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.apache.hive.service.cli.operation.ExecuteStatementOperation
3131
import org.apache.hive.service.cli.session.HiveSession
3232

3333
import org.apache.spark.Logging
34-
import org.apache.spark.sql.catalyst.plans.logical.SetCommand
34+
import org.apache.spark.sql.execution.SetCommand
3535
import org.apache.spark.sql.catalyst.types._
3636
import org.apache.spark.sql.hive.thriftserver.ReflectionUtils._
3737
import org.apache.spark.sql.hive.{HiveContext, HiveMetastoreTypes}
@@ -161,7 +161,7 @@ private[hive] class SparkExecuteStatementOperation(
161161
result = hiveContext.sql(statement)
162162
logDebug(result.queryExecution.toString())
163163
result.queryExecution.logical match {
164-
case SetCommand(Some((SQLConf.THRIFTSERVER_POOL, Some(value)))) =>
164+
case SetCommand(Some((SQLConf.THRIFTSERVER_POOL, Some(value))), _) =>
165165
sessionToActivePool(parentSession.getSessionHandle) = value
166166
logInfo(s"Setting spark.scheduler.pool=$value for future statements in this session.")
167167
case _ =>

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import org.apache.spark.sql.catalyst.ScalaReflection
3838
import org.apache.spark.sql.catalyst.analysis.{Analyzer, EliminateAnalysisOperators, OverrideCatalog, OverrideFunctionRegistry}
3939
import org.apache.spark.sql.catalyst.plans.logical._
4040
import org.apache.spark.sql.catalyst.types.DecimalType
41-
import org.apache.spark.sql.catalyst.types.decimal.Decimal
42-
import org.apache.spark.sql.execution.{SparkPlan, ExecutedCommand, ExtractPythonUdfs, QueryExecutionException}
41+
import org.apache.spark.sql.execution.{ExecutedCommand, ExtractPythonUdfs, SetCommand, QueryExecutionException}
4342
import org.apache.spark.sql.hive.execution.{HiveNativeCommand, DescribeHiveTableCommand}
4443
import org.apache.spark.sql.sources.DataSourceStrategy
4544

@@ -340,7 +339,6 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
340339

341340
override def strategies: Seq[Strategy] = extraStrategies ++ Seq(
342341
DataSourceStrategy,
343-
CommandStrategy,
344342
HiveCommandStrategy(self),
345343
TakeOrdered,
346344
ParquetOperations,

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ import org.apache.hadoop.hive.ql.lib.Node
2424
import org.apache.hadoop.hive.ql.metadata.Table
2525
import org.apache.hadoop.hive.ql.parse._
2626
import org.apache.hadoop.hive.ql.plan.PlanUtils
27+
import org.apache.spark.sql.SparkSQLParser
2728

28-
import org.apache.spark.sql.catalyst.SparkSQLParser
2929
import org.apache.spark.sql.catalyst.analysis._
3030
import org.apache.spark.sql.catalyst.expressions._
3131
import org.apache.spark.sql.catalyst.plans._
3232
import org.apache.spark.sql.catalyst.plans.logical
3333
import org.apache.spark.sql.catalyst.plans.logical._
3434
import org.apache.spark.sql.catalyst.types._
3535
import org.apache.spark.sql.catalyst.types.decimal.Decimal
36+
import org.apache.spark.sql.execution.ExplainCommand
3637
import org.apache.spark.sql.hive.execution.{HiveNativeCommand, DropTable, AnalyzeTable}
3738

3839
/* Implicit conversions */
@@ -45,6 +46,22 @@ import scala.collection.JavaConversions._
4546
*/
4647
private[hive] case object NativePlaceholder extends Command
4748

49+
/**
50+
* Returned for the "DESCRIBE [EXTENDED] [dbName.]tableName" command.
51+
* @param table The table to be described.
52+
* @param isExtended True if "DESCRIBE EXTENDED" is used. Otherwise, false.
53+
* It is effective only when the table is a Hive table.
54+
*/
55+
case class DescribeCommand(
56+
table: LogicalPlan,
57+
isExtended: Boolean) extends Command {
58+
override def output = Seq(
59+
// Column names are based on Hive.
60+
AttributeReference("col_name", StringType, nullable = false)(),
61+
AttributeReference("data_type", StringType, nullable = false)(),
62+
AttributeReference("comment", StringType, nullable = false)())
63+
}
64+
4865
/** Provides a mapping from HiveQL statements to catalyst logical plans and expression trees. */
4966
private[hive] object HiveQl {
5067
protected val nativeCommands = Seq(
@@ -448,17 +465,21 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
448465
// Just fake explain for any of the native commands.
449466
case Token("TOK_EXPLAIN", explainArgs)
450467
if noExplainCommands.contains(explainArgs.head.getText) =>
451-
ExplainCommand(NoRelation)
468+
ExplainCommand(NoRelation, Seq(AttributeReference("plan", StringType, nullable = false)()))
452469
case Token("TOK_EXPLAIN", explainArgs)
453470
if "TOK_CREATETABLE" == explainArgs.head.getText =>
454471
val Some(crtTbl) :: _ :: extended :: Nil =
455472
getClauses(Seq("TOK_CREATETABLE", "FORMATTED", "EXTENDED"), explainArgs)
456-
ExplainCommand(nodeToPlan(crtTbl), extended != None)
473+
ExplainCommand(nodeToPlan(crtTbl),
474+
Seq(AttributeReference("plan", StringType,
475+
nullable = false)()), extended != None)
457476
case Token("TOK_EXPLAIN", explainArgs) =>
458477
// Ignore FORMATTED if present.
459478
val Some(query) :: _ :: extended :: Nil =
460479
getClauses(Seq("TOK_QUERY", "FORMATTED", "EXTENDED"), explainArgs)
461-
ExplainCommand(nodeToPlan(query), extended != None)
480+
ExplainCommand(nodeToPlan(query),
481+
Seq(AttributeReference("plan", StringType, nullable = false)()),
482+
extended != None)
462483

463484
case Token("TOK_DESCTABLE", describeArgs) =>
464485
// Reference: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveStrategies.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.apache.spark.sql.catalyst.planning._
2525
import org.apache.spark.sql.catalyst.plans._
2626
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
2727
import org.apache.spark.sql.catalyst.types.StringType
28+
import org.apache.spark.sql.execution.{DescribeCommand => RunnableDescribeCommand}
2829
import org.apache.spark.sql.execution._
2930
import org.apache.spark.sql.hive
3031
import org.apache.spark.sql.hive.execution._
@@ -209,14 +210,14 @@ private[hive] trait HiveStrategies {
209210

210211
case class HiveCommandStrategy(context: HiveContext) extends Strategy {
211212
def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match {
212-
case describe: logical.DescribeCommand =>
213+
case describe: DescribeCommand =>
213214
val resolvedTable = context.executePlan(describe.table).analyzed
214215
resolvedTable match {
215216
case t: MetastoreRelation =>
216217
ExecutedCommand(
217218
DescribeHiveTableCommand(t, describe.output, describe.isExtended)) :: Nil
218219
case o: LogicalPlan =>
219-
ExecutedCommand(DescribeCommand(planLater(o), describe.output)) :: Nil
220+
ExecutedCommand(RunnableDescribeCommand(planLater(o), describe.output)) :: Nil
220221
}
221222

222223
case _ => Nil

sql/hive/src/main/scala/org/apache/spark/sql/hive/TestHive.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import org.apache.hadoop.hive.serde2.avro.AvroSerDe
3434
import org.apache.spark.{SparkConf, SparkContext}
3535
import org.apache.spark.util.Utils
3636
import org.apache.spark.sql.catalyst.analysis._
37-
import org.apache.spark.sql.catalyst.plans.logical.{CacheTableCommand, LogicalPlan}
37+
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
3838
import org.apache.spark.sql.catalyst.util._
39+
import org.apache.spark.sql.execution.CacheTableCommand
3940
import org.apache.spark.sql.hive._
4041
import org.apache.spark.sql.SQLConf
4142
import org.apache.spark.sql.hive.execution.HiveNativeCommand

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveComparisonTest.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import java.io._
2222
import org.scalatest.{BeforeAndAfterAll, FunSuite, GivenWhenThen}
2323

2424
import org.apache.spark.Logging
25+
import org.apache.spark.sql.execution.{SetCommand, ExplainCommand}
26+
import org.apache.spark.sql.hive.DescribeCommand
2527
import org.apache.spark.sql.catalyst.planning.PhysicalOperation
2628
import org.apache.spark.sql.catalyst.plans.logical._
2729
import org.apache.spark.sql.catalyst.util._

0 commit comments

Comments
 (0)