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

    https://github.com/apache/spark/pull/15090#discussion_r79168577
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsColumnSuite.scala 
---
    @@ -0,0 +1,228 @@
    +/*
    + * 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, Row}
    +import org.apache.spark.sql.catalyst.plans.logical.BasicColStats
    +import org.apache.spark.sql.execution.command.AnalyzeColumnCommand
    +import org.apache.spark.sql.types._
    +
    +class StatisticsColumnSuite extends StatisticsTest {
    +
    +  test("parse analyze column commands") {
    +    val table = "table"
    +    assertAnalyzeCommand(
    +      s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS key, value",
    +      classOf[AnalyzeColumnCommand])
    +
    +    val noColumnError = intercept[AnalysisException] {
    +      sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS")
    +    }
    +    assert(noColumnError.message == "Need to specify the columns to 
analyze. Usage: " +
    +      "ANALYZE TABLE tbl COMPUTE STATISTICS FOR COLUMNS key, value")
    +
    +    withTable(table) {
    +      sql(s"CREATE TABLE $table (key INT, value STRING)")
    +      val invalidColError = intercept[AnalysisException] {
    +        sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS k")
    +      }
    +      assert(invalidColError.message == s"Invalid column name: k")
    +
    +      val duplicateColError = intercept[AnalysisException] {
    +        sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS key, 
value, key")
    +      }
    +      assert(duplicateColError.message == s"Duplicate column name: key")
    +
    +      withSQLConf("spark.sql.caseSensitive" -> "true") {
    +        val invalidErr = intercept[AnalysisException] {
    +          sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS keY")
    +        }
    +        assert(invalidErr.message == s"Invalid column name: keY")
    +      }
    +
    +      withSQLConf("spark.sql.caseSensitive" -> "false") {
    +        val duplicateErr = intercept[AnalysisException] {
    +          sql(s"ANALYZE TABLE $table COMPUTE STATISTICS FOR COLUMNS key, 
value, vaLue")
    +        }
    +        assert(duplicateErr.message == s"Duplicate column name: vaLue")
    +      }
    +    }
    +  }
    +
    +  test("basic statistics for integral type columns") {
    +    val rdd = sparkContext.parallelize(Seq("1", null, "2", "3", null)).map 
{ i =>
    +      if (i != null) Row(i.toByte, i.toShort, i.toInt, i.toLong) else 
Row(i, i, i, i)
    +    }
    +    val schema = StructType(
    +      StructField(name = "c1", dataType = ByteType, nullable = true) ::
    +        StructField(name = "c2", dataType = ShortType, nullable = true) ::
    +        StructField(name = "c3", dataType = IntegerType, nullable = true) 
::
    +        StructField(name = "c4", dataType = LongType, nullable = true) :: 
Nil)
    +    val expectedBasicStats = BasicColStats(
    +      dataType = ByteType, numNulls = 2, max = Some(3), min = Some(1), ndv 
= Some(3))
    --- End diff --
    
    It is weird that this works. The Min and the Max value should not be equal 
for Short and Long types.


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