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

    https://github.com/apache/spark/pull/18421#discussion_r126273805
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala ---
    @@ -93,30 +93,50 @@ class SparkSqlAstBuilder extends AstBuilder {
       }
     
       /**
    -   * Create an [[AnalyzeTableCommand]] command or an 
[[AnalyzeColumnCommand]] command.
    -   * Example SQL for analyzing table :
    +   * Create an [[AnalyzeTableCommand]] command, or an 
[[AnalyzePartitionCommand]]
    +   * or an [[AnalyzeColumnCommand]] command.
    +   * Example SQL for analyzing table or a set of partitions :
        * {{{
    -   *   ANALYZE TABLE table COMPUTE STATISTICS [NOSCAN];
    +   *   ANALYZE TABLE [db_name.]tablename [PARTITION (partcol1[=val1], 
partcol2[=val2], ...)]
    +   *   COMPUTE STATISTICS [NOSCAN];
        * }}}
    +   *
        * Example SQL for analyzing columns :
        * {{{
    -   *   ANALYZE TABLE table COMPUTE STATISTICS FOR COLUMNS column1, column2;
    +   *   ANALYZE TABLE [db_name.]tablename COMPUTE STATISTICS FOR COLUMNS 
column1, column2;
        * }}}
        */
       override def visitAnalyze(ctx: AnalyzeContext): LogicalPlan = 
withOrigin(ctx) {
    -    if (ctx.partitionSpec != null) {
    -      logWarning(s"Partition specification is ignored: 
${ctx.partitionSpec.getText}")
    +    if (ctx.identifier != null &&
    +        ctx.identifier.getText.toLowerCase(Locale.ROOT) != "noscan") {
    +      throw new ParseException(s"Expected `NOSCAN` instead of 
`${ctx.identifier.getText}`", ctx)
         }
    -    if (ctx.identifier != null) {
    -      if (ctx.identifier.getText.toLowerCase(Locale.ROOT) != "noscan") {
    -        throw new ParseException(s"Expected `NOSCAN` instead of 
`${ctx.identifier.getText}`", ctx)
    +
    +    val partitionSpec =
    +      if (ctx.partitionSpec != null) {
    +        val filteredSpec = 
visitPartitionSpec(ctx.partitionSpec).filter(_._2.isDefined)
    +        if (filteredSpec.isEmpty) {
    +          None
    +        } else {
    +          Some(filteredSpec.mapValues(_.get))
    +        }
    +      } else {
    +        None
    +      }
    +
    +    val table = visitTableIdentifier(ctx.tableIdentifier)
    +    if (ctx.identifierSeq() == null) {
    +      if (partitionSpec.isDefined) {
    +        AnalyzePartitionCommand(table, partitionSpec.get, noscan = 
ctx.identifier != null)
    +      } else {
    +        AnalyzeTableCommand(table, noscan = ctx.identifier != null)
    --- End diff --
    
    @mbasmanova IIUC, the logic is wrong here. For example, when analyzing 
partition (ds, hr), we should not remove them in parser. Currently we parse it 
to AnalyzeTableCommand, which collects table-level stats. But what we need to 
do is to collect partition-level stats for all partitions.
    Check hive's behavior here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to