LuciferYang commented on code in PR #57526:
URL: https://github.com/apache/spark/pull/57526#discussion_r4566678517
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/statsEstimation/JoinEstimationSuite.scala:
##########
@@ -506,6 +506,18 @@ class JoinEstimationSuite extends StatsEstimationTestBase {
nullCount = Some(0), avgLen = Some(4), maxLen = Some(4)),
AttributeReference("ctimestamp", TimestampType)() ->
ColumnStat(distinctCount = Some(1),
min = Some(timestamp), max = Some(timestamp),
+ nullCount = Some(0), avgLen = Some(8), maxLen = Some(8)),
+ AttributeReference("ctimestamp_ntz", TimestampNTZType)() -> ColumnStat(
+ distinctCount = Some(1), min = Some(timestamp), max =
Some(timestamp),
+ nullCount = Some(0), avgLen = Some(8), maxLen = Some(8)),
+ AttributeReference("ctime", TimeType())() -> ColumnStat(distinctCount
= Some(1),
Review Comment:
In the join test, the `TIME` and day-time interval bounds are `1L`, which
fits in an `Int`, so `fromDouble` returning `double.toInt` for them would still
pass, and a join on `TIME` values after 00:00:02.147483647 would then get its
bounds clamped. Values like `TIME '12:00:00'` and one day would catch that.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/EstimationUtils.scala:
##########
@@ -135,16 +135,19 @@ object EstimationUtils {
*/
def toDouble(value: Any, dataType: DataType): Double = {
dataType match {
- case _: NumericType | DateType | TimestampType => value.toString.toDouble
+ case _: NumericType | DateType | TimestampType | TimestampNTZType |
Review Comment:
After this change, an equi-join on a `TIME` column that comes out of a
`Union` is estimated at 0 rows. `UnionEstimation.isTypeSupported` lists
`TimestampNTZType` and the ANSI interval types but not `TimeType`, so the Union
keeps the column's counts and drops its min/max, and `JoinEstimation` reads the
missing bounds as an all-null key. Before this PR the same query failed with
`MatchError`. The description defers Union to #53312, but that PR was closed
without being merged.
Could you add `_: TimeType` to `isTypeSupported`, with a test that a join
above a Union of two `TIME` children keeps a non-zero estimate?
`PhysicalDataType.ordering` already supports `TimeType`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/EstimationUtils.scala:
##########
@@ -135,16 +135,19 @@ object EstimationUtils {
*/
def toDouble(value: Any, dataType: DataType): Double = {
dataType match {
- case _: NumericType | DateType | TimestampType => value.toString.toDouble
+ case _: NumericType | DateType | TimestampType | TimestampNTZType |
Review Comment:
When you rebase, please add the four types to
`EstimationUtils.canEstimateWithHistogram` too. Master added it after this PR
was opened, as the list of types `toDouble` converts, and the equality and join
estimates check it before they use a histogram. This PR merges without a
conflict, so as is, `TIMESTAMP_NTZ` equality filters and joins would ignore the
histograms `ANALYZE` builds while range filters use them: on a value that
covers half the table, `ts = x` would be estimated at 1/ndv instead of about
half.
A filter and a join test on a `TIMESTAMP_NTZ` column with a histogram would
pin it. None of the new tests carries a histogram today.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]