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

    https://github.com/apache/spark/pull/15090#discussion_r79543613
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsColumnSuite.scala 
---
    @@ -0,0 +1,343 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.sql.{Date, Timestamp}
    +
    +import org.apache.spark.sql.AnalysisException
    +import org.apache.spark.sql.catalyst.plans.logical.ColumnStats
    +import org.apache.spark.sql.catalyst.util.DateTimeUtils
    +import org.apache.spark.sql.execution.command.AnalyzeColumnCommand
    +import org.apache.spark.sql.types._
    +
    +class StatisticsColumnSuite extends StatisticsTest {
    +  import testImplicits._
    +
    +  test("parse analyze column commands") {
    +    val table = "table"
    +    assertAnalyzeCommand(
    +      s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS key, value",
    +      classOf[AnalyzeColumnCommand])
    +
    +    intercept[AnalysisException] {
    +      sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS")
    +    }
    +  }
    +
    +  test("check correctness of columns") {
    +    val table = "tbl"
    +    val quotedColumn = "x.yz"
    +    val quotedName = s"`$quotedColumn`"
    +    withTable(table) {
    +      sql(s"CREATE TABLE $table (abc int, $quotedName string)")
    +
    +      val invalidColError = intercept[AnalysisException] {
    +        sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS key")
    +      }
    +      assert(invalidColError.message == s"Invalid column name: key.")
    +
    +      withSQLConf("spark.sql.caseSensitive" -> "true") {
    +        val invalidErr = intercept[AnalysisException] {
    +          sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS ABC")
    +        }
    +        assert(invalidErr.message == s"Invalid column name: ABC.")
    +      }
    +
    +      withSQLConf("spark.sql.caseSensitive" -> "false") {
    +        sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS 
${quotedName.toUpperCase}, " +
    +          s"ABC, $quotedName")
    +        val df = sql(s"SELECT * FROM $table")
    +        val stats = df.queryExecution.analyzed.collect {
    +          case rel: MetastoreRelation =>
    +            val colStats = rel.catalogTable.stats.get.colStats
    +            // check deduplication
    +            assert(colStats.size == 2)
    +            assert(colStats.contains(quotedColumn))
    +            assert(colStats.contains("abc"))
    +        }
    +        assert(stats.size == 1)
    +      }
    +    }
    +  }
    +
    +  private def getNonNullValues[T](values: Seq[Option[T]]): Seq[T] = {
    +    values.filter(_.isDefined).map(_.get)
    +  }
    +
    +  test("column-level statistics for integral type columns") {
    +    val values = (0 to 5).map { i =>
    +      if (i % 2 == 0) None else Some(i)
    +    }
    +    val data = values.map { i =>
    +      (i.map(_.toByte), i.map(_.toShort), i.map(_.toInt), i.map(_.toLong))
    +    }
    +
    +    val df = data.toDF("c1", "c2", "c3", "c4")
    +    val nonNullValues = getNonNullValues[Int](values)
    +    val statsSeq = df.schema.map { f =>
    --- End diff --
    
    Please rename all the `statsSeq` to `expectedColStats`


---
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