LuciferYang commented on code in PR #60616:
URL: https://github.com/apache/spark/pull/60616#discussion_r4625198458


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/EstimationUtils.scala:
##########
@@ -96,21 +96,17 @@ object EstimationUtils {
       // then stores the type's default size as the lengths). The distinct 
count is left as is.
       // It is too high only when stored values differ just in trailing 
spaces, which the
       // padding makes equal.
-      // TODO(SPARK-60830): under 
spark.sql.charVarchar.standardSemantics.enabled the scan wraps
-      // CHAR and VARCHAR columns in charTypeReadSideCheck and 
varcharTypeReadSideCheck instead,
-      // so they still lose their statistics here and in 
FilterEstimation.calculateSingleCondition.
-      // They need an extractor of their own, because V2ExpressionBuilder 
relies on
-      // ReadSidePadding never matching the checks. Under first-class CHAR 
types the filter unwrap
-      // also has to see through the cast to STRING.
       case alias @ Alias(CharVarcharUtils.ReadSidePadding(attr: Attribute, n), 
_)
           if attributeStats.contains(attr) =>
+        alias.toAttribute -> padToCharLength(attributeStats(attr), n)
+      // Under standard CHAR/VARCHAR semantics the scan wraps CHAR and VARCHAR 
columns in
+      // read-side checks instead, and ANALYZE TABLE reads through those as 
well. The CHAR check
+      // pads like the padding above. The VARCHAR check never makes a value 
longer, so its
+      // lengths are kept.
+      case alias @ Alias(CharVarcharUtils.ReadSideCheck(attr: Attribute, n, 
isChar), _)

Review Comment:
   Fixed. `getAliasStats` now strips the same cast before matching, both on a 
bare attribute and over the read-side padding or check, so the union output and 
`SELECT CAST(c AS STRING) AS k` keep the column's statistics. 
`ProjectEstimationSuite` covers both conf shapes and the casts that stay 
(another collation, a length-checked type, an INT column), and the end-to-end 
test now checks a `GROUP BY` over `c UNION ALL s`, estimated and counted at 10 
rows under both confs.
   



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

Reply via email to