Skip to content

Commit 4389607

Browse files
committed
Add specific node CreateHiveTableAsSelect and remove type parameter of CreateTableAsSelect.
1 parent 5b611cb commit 4389607

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ case class InsertIntoTable(
137137
}
138138
}
139139

140-
case class CreateTableAsSelect[T](
141-
databaseName: Option[String],
142-
tableName: String,
143-
child: LogicalPlan,
144-
allowExisting: Boolean,
145-
desc: T) extends UnaryNode {
140+
trait CreateTableAsSelect extends UnaryNode {
141+
self: Product =>
142+
def databaseName: Option[String]
143+
def tableName: String
144+
def child: LogicalPlan
145+
def allowExisting: Boolean
146+
146147
override def output = Seq.empty[Attribute]
147148
override lazy val resolved = databaseName != None && childrenResolved
148149
}

sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class DataFrame private[sql](
141141
// happen right away to let these side effects take place eagerly.
142142
case _: Command |
143143
_: InsertIntoTable |
144-
_: CreateTableAsSelect[_] |
144+
_: CreateTableAsSelect |
145145
_: CreateTableUsingAsSelect |
146146
_: WriteToFile =>
147147
LogicalRDD(queryExecution.analyzed.output, queryExecution.toRdd)(sqlContext)

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
2424
import org.apache.hadoop.hive.metastore.api.{FieldSchema, Partition => TPartition, Table => TTable}
2525
import org.apache.hadoop.hive.metastore.{TableType, Warehouse}
2626
import org.apache.hadoop.hive.ql.metadata._
27+
import org.apache.hadoop.hive.ql.lib.Node
2728
import org.apache.hadoop.hive.ql.plan.CreateTableDesc
2829
import org.apache.hadoop.hive.serde.serdeConstants
2930
import org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe
@@ -527,7 +528,7 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with
527528

528529
// TODO extra is in type of ASTNode which means the logical plan is not resolved
529530
// Need to think about how to implement the CreateTableAsSelect.resolved
530-
case CreateTableAsSelect(db, tableName, child, allowExisting, extra: ASTNode) =>
531+
case CreateHiveTableAsSelect(db, tableName, child, allowExisting, extra) =>
531532
val (dbName, tblName) = processDatabaseAndTableName(db, tableName)
532533
val databaseName = dbName.getOrElse(hive.sessionState.getCurrentDatabase)
533534

@@ -546,7 +547,7 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with
546547
}
547548
}
548549

549-
sa.analyze(extra, new Context(hive.hiveconf))
550+
sa.analyze(extra.asInstanceOf[ASTNode], new Context(hive.hiveconf))
550551
Some(sa.getQB().getTableDesc)
551552
}
552553

@@ -663,6 +664,14 @@ private[hive] case class InsertIntoHiveTable(
663664
}
664665
}
665666

667+
private[hive] case class CreateHiveTableAsSelect(
668+
databaseName: Option[String],
669+
tableName: String,
670+
child: LogicalPlan,
671+
allowExisting: Boolean,
672+
desc: Node) extends CreateTableAsSelect {
673+
}
674+
666675
private[hive] case class MetastoreRelation
667676
(databaseName: String, tableName: String, alias: Option[String])
668677
(val table: TTable, val partitions: Seq[TPartition])

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
557557
"TOK_TABLEPROPERTIES"),
558558
children)
559559
val (db, tableName) = extractDbNameTableName(tableNameParts)
560-
CreateTableAsSelect(db, tableName, nodeToPlan(query), allowExisting != None, node)
560+
CreateHiveTableAsSelect(db, tableName, nodeToPlan(query), allowExisting != None, node)
561561

562562
// If its not a "CREATE TABLE AS" like above then just pass it back to hive as a native command.
563563
case Token("TOK_CREATETABLE", _) => NativePlaceholder

0 commit comments

Comments
 (0)