Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.execution.command
import org.apache.spark.sql.{AnalysisException, Column, Row, SparkSession}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.{NoSuchPartitionException, UnresolvedAttribute}
import org.apache.spark.sql.catalyst.catalog.{CatalogTable, CatalogTableType}
import org.apache.spark.sql.catalyst.catalog.{CatalogTable, CatalogTableType, ExternalCatalogUtils}
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
import org.apache.spark.sql.catalyst.expressions.{And, EqualTo, Literal}
import org.apache.spark.sql.execution.datasources.PartitioningUtils
Expand Down Expand Up @@ -140,7 +140,13 @@ case class AnalyzePartitionCommand(
val df = tableDf.filter(Column(filter)).groupBy(partitionColumns: _*).count()

df.collect().map { r =>
val partitionColumnValues = partitionColumns.indices.map(r.get(_).toString)
val partitionColumnValues = partitionColumns.indices.map { i =>
if (r.isNullAt(i)) {
ExternalCatalogUtils.DEFAULT_PARTITION_NAME
Copy link
Contributor

@cloud-fan cloud-fan Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to change the read path? i.e. where we use these statistics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, as the same situation would happen if Hive's statistics are used instead of the ones computed by Spark

} else {
r.get(i).toString
}
}
val spec = tableMeta.partitionColumnNames.zip(partitionColumnValues).toMap
val count = BigInt(r.getLong(partitionColumns.size))
(spec, count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
}
}

test("SPARK-25028: column stats collection for null partitioning columns") {
val table = "analyze_partition_with_null"
withTempDir { dir =>
withTable(table) {
sql(s"""
|CREATE TABLE $table (value string, name string)
|USING PARQUET
|PARTITIONED BY (name)
|LOCATION '${dir.toURI}'""".stripMargin)
val df = Seq(("a", null), ("b", null)).toDF("value", "name")
df.write.mode("overwrite").insertInto(table)
sql(s"ANALYZE TABLE $table PARTITION (name) COMPUTE STATISTICS")
val partitions = spark.sessionState.catalog.listPartitions(TableIdentifier(table))
assert(partitions.head.stats.get.rowCount.get == 2)
}
}
}

test("number format in statistics") {
val numbers = Seq(
BigInt(0) -> (("0.0 B", "0")),
Expand Down