From 248b0591b031ef5d017bc4f710b9b0496e751c39 Mon Sep 17 00:00:00 2001 From: Jin Xing Date: Fri, 6 May 2022 15:29:47 +0800 Subject: [PATCH] [HUDI-4042] Support truncate-partition for Spark-3.2 (#5506) --- .../hudi/analysis/HoodieSpark3Analysis.scala | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieSpark3Analysis.scala b/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieSpark3Analysis.scala index e20f93459..4c77733b1 100644 --- a/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieSpark3Analysis.scala +++ b/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieSpark3Analysis.scala @@ -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,