Skip to content

Commit

Permalink
try truncate fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiyan committed May 5, 2022
1 parent e979ef3 commit c7324b8
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,22 @@ case class HoodieSpark3ResolveReferences(sparkSession: SparkSession) extends Rul
case class HoodieSpark3PostAnalysisRule(sparkSession: SparkSession) extends Rule[LogicalPlan] {
override def apply(plan: LogicalPlan): LogicalPlan = {
plan match {
case ShowPartitions(child, specOpt, _)
if child.isInstanceOf[ResolvedTable] &&
child.asInstanceOf[ResolvedTable].table.isInstanceOf[HoodieInternalV2Table] =>
ShowHoodieTablePartitionsCommand(child.asInstanceOf[ResolvedTable].identifier.asTableIdentifier, specOpt.map(s => s.asInstanceOf[UnresolvedPartitionSpec].spec))
case ShowPartitions(ResolvedTable(_, idt, _: HoodieInternalV2Table, _), specOpt, _) =>
ShowHoodieTablePartitionsCommand(
idt.asTableIdentifier, specOpt.map(s => s.asInstanceOf[UnresolvedPartitionSpec].spec))

// Rewrite TruncateTableCommand to TruncateHoodieTableCommand
case TruncateTable(child)
if child.isInstanceOf[ResolvedTable] &&
child.asInstanceOf[ResolvedTable].table.isInstanceOf[HoodieInternalV2Table] =>
new TruncateHoodieTableCommand(child.asInstanceOf[ResolvedTable].identifier.asTableIdentifier, None)
case TruncateTable(ResolvedTable(_, idt, _: HoodieInternalV2Table, _)) =>
TruncateHoodieTableCommand(idt.asTableIdentifier, None)

case DropPartitions(child, specs, ifExists, purge)
if child.resolved && child.isInstanceOf[ResolvedTable] && child.asInstanceOf[ResolvedTable].table.isInstanceOf[HoodieInternalV2Table] =>
case TruncatePartition(
ResolvedTable(_, idt, _: HoodieInternalV2Table, _),
partitionSpec: UnresolvedPartitionSpec) =>
TruncateHoodieTableCommand(idt.asTableIdentifier, Some(partitionSpec.spec))

case DropPartitions(ResolvedTable(_, idt, _: HoodieInternalV2Table, _), specs, ifExists, purge) =>
AlterHoodieTableDropPartitionCommand(
child.asInstanceOf[ResolvedTable].identifier.asTableIdentifier,
idt.asTableIdentifier,
specs.seq.map(f => f.asInstanceOf[UnresolvedPartitionSpec]).map(s => s.spec),
ifExists,
purge,
Expand Down

0 comments on commit c7324b8

Please sign in to comment.