aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/scala/org
diff options
context:
space:
mode:
authorwangzhenhua <wangzhenhua@huawei.com>2017-04-14 19:16:47 +0800
committerWenchen Fan <wenchen@databricks.com>2017-04-14 19:16:47 +0800
commitfb036c4413c2cd4d90880d080f418ec468d6c0fc (patch)
tree8d155d76971538e5ffd6c1f5262653ae813646ce /sql/core/src/test/scala/org
parent7536e2849df6d63587fbf16b4ecb5db06fed7125 (diff)
downloadspark-fb036c4413c2cd4d90880d080f418ec468d6c0fc.tar.gz
spark-fb036c4413c2cd4d90880d080f418ec468d6c0fc.tar.bz2
spark-fb036c4413c2cd4d90880d080f418ec468d6c0fc.zip
[SPARK-20318][SQL] Use Catalyst type for min/max in ColumnStat for ease of estimation
## What changes were proposed in this pull request? Currently when estimating predicates like col > literal or col = literal, we will update min or max in column stats based on literal value. However, literal value is of Catalyst type (internal type), while min/max is of external type. Then for the next predicate, we again need to do type conversion to compare and update column stats. This is awkward and causes many unnecessary conversions in estimation. To solve this, we use Catalyst type for min/max in `ColumnStat`. Note that the persistent format in metastore is still of external type, so there's no inconsistency for statistics in metastore. This pr also fixes a bug for boolean type in `IN` condition. ## How was this patch tested? The changes for ColumnStat are covered by existing tests. For bug fix, a new test for boolean type in IN condition is added Author: wangzhenhua <wangzhenhua@huawei.com> Closes #17630 from wzhfy/refactorColumnStat.
Diffstat (limited to 'sql/core/src/test/scala/org')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala19
1 files changed, 11 insertions, 8 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala
index 1f547c5a2a..ddc393c8da 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala
@@ -26,6 +26,7 @@ import scala.util.Random
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogStatistics}
import org.apache.spark.sql.catalyst.plans.logical._
+import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.execution.datasources.LogicalRelation
import org.apache.spark.sql.internal.StaticSQLConf
import org.apache.spark.sql.test.{SharedSQLContext, SQLTestUtils}
@@ -117,7 +118,7 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
val df = data.toDF(stats.keys.toSeq :+ "carray" : _*)
stats.zip(df.schema).foreach { case ((k, v), field) =>
withClue(s"column $k with type ${field.dataType}") {
- val roundtrip = ColumnStat.fromMap("table_is_foo", field, v.toMap)
+ val roundtrip = ColumnStat.fromMap("table_is_foo", field, v.toMap(k, field.dataType))
assert(roundtrip == Some(v))
}
}
@@ -201,17 +202,19 @@ abstract class StatisticsCollectionTestBase extends QueryTest with SQLTestUtils
/** A mapping from column to the stats collected. */
protected val stats = mutable.LinkedHashMap(
"cbool" -> ColumnStat(2, Some(false), Some(true), 1, 1, 1),
- "cbyte" -> ColumnStat(2, Some(1L), Some(2L), 1, 1, 1),
- "cshort" -> ColumnStat(2, Some(1L), Some(3L), 1, 2, 2),
- "cint" -> ColumnStat(2, Some(1L), Some(4L), 1, 4, 4),
+ "cbyte" -> ColumnStat(2, Some(1.toByte), Some(2.toByte), 1, 1, 1),
+ "cshort" -> ColumnStat(2, Some(1.toShort), Some(3.toShort), 1, 2, 2),
+ "cint" -> ColumnStat(2, Some(1), Some(4), 1, 4, 4),
"clong" -> ColumnStat(2, Some(1L), Some(5L), 1, 8, 8),
"cdouble" -> ColumnStat(2, Some(1.0), Some(6.0), 1, 8, 8),
- "cfloat" -> ColumnStat(2, Some(1.0), Some(7.0), 1, 4, 4),
- "cdecimal" -> ColumnStat(2, Some(dec1), Some(dec2), 1, 16, 16),
+ "cfloat" -> ColumnStat(2, Some(1.0f), Some(7.0f), 1, 4, 4),
+ "cdecimal" -> ColumnStat(2, Some(Decimal(dec1)), Some(Decimal(dec2)), 1, 16, 16),
"cstring" -> ColumnStat(2, None, None, 1, 3, 3),
"cbinary" -> ColumnStat(2, None, None, 1, 3, 3),
- "cdate" -> ColumnStat(2, Some(d1), Some(d2), 1, 4, 4),
- "ctimestamp" -> ColumnStat(2, Some(t1), Some(t2), 1, 8, 8)
+ "cdate" -> ColumnStat(2, Some(DateTimeUtils.fromJavaDate(d1)),
+ Some(DateTimeUtils.fromJavaDate(d2)), 1, 4, 4),
+ "ctimestamp" -> ColumnStat(2, Some(DateTimeUtils.fromJavaTimestamp(t1)),
+ Some(DateTimeUtils.fromJavaTimestamp(t2)), 1, 8, 8)
)
private val randomName = new Random(31)