Github user DazhuangSu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19691#discussion_r193691275
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
    @@ -510,40 +511,86 @@ case class AlterTableRenamePartitionCommand(
      *
      * The syntax of this command is:
      * {{{
    - *   ALTER TABLE table DROP [IF EXISTS] PARTITION spec1[, PARTITION spec2, 
...] [PURGE];
    + *   ALTER TABLE table DROP [IF EXISTS] PARTITION (spec1, expr1)
    + *     [, PARTITION (spec2, expr2), ...] [PURGE];
      * }}}
      */
     case class AlterTableDropPartitionCommand(
         tableName: TableIdentifier,
    -    specs: Seq[TablePartitionSpec],
    +    partitions: Seq[(TablePartitionSpec, Seq[Expression])],
         ifExists: Boolean,
         purge: Boolean,
         retainData: Boolean)
    -  extends RunnableCommand {
    +  extends RunnableCommand with PredicateHelper {
     
       override def run(sparkSession: SparkSession): Seq[Row] = {
         val catalog = sparkSession.sessionState.catalog
         val table = catalog.getTableMetadata(tableName)
    +    val resolver = sparkSession.sessionState.conf.resolver
         DDLUtils.verifyAlterTableType(catalog, table, isView = false)
         DDLUtils.verifyPartitionProviderIsHive(sparkSession, table, "ALTER 
TABLE DROP PARTITION")
     
    -    val normalizedSpecs = specs.map { spec =>
    -      PartitioningUtils.normalizePartitionSpec(
    -        spec,
    -        table.partitionColumnNames,
    -        table.identifier.quotedString,
    -        sparkSession.sessionState.conf.resolver)
    +    val toDrop = partitions.flatMap { partition =>
    +      if (partition._1.isEmpty && !partition._2.isEmpty) {
    +        // There are only expressions in this drop condition.
    +        extractFromPartitionFilter(partition._2, catalog, table, resolver)
    +      } else if (!partition._1.isEmpty && partition._2.isEmpty) {
    +        // There are only partitionSpecs in this drop condition.
    +        extractFromPartitionSpec(partition._1, table, resolver)
    +      } else if (!partition._1.isEmpty && !partition._2.isEmpty) {
    +        // This drop condition has both partitionSpecs and expressions.
    +        extractFromPartitionFilter(partition._2, catalog, table, 
resolver).intersect(
    --- End diff --
    
    hi, @mgaido91 there is one problem after I changed the syntax,
    when i run sql `DROP PARTITION (p >=2)` it throws
    `org.apache.spark.sql.AnalysisException: cannot resolve 'p' given input 
columns: []`
    I'm trying to find a way to figure it out.
    
    By the way, is a syntax like `((partitionVal (',' partitionVal)*) | 
(expression (',' expression)*))` legal? Because I wrote a antlr4 syntax test, 
but it didn't work as I supposed.
    
    Besides, I was wrong that day. I think the if conditions won't be 
inefficient if there is a lot of partitions. it maybe inefficient if there are 
a lot of dropPartitionSpec which I don't think can happen easily.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to