cloud-fan commented on a change in pull request #31034:
URL: https://github.com/apache/spark/pull/31034#discussion_r553827099
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -298,6 +300,30 @@ class Analyzer(override val catalogManager: CatalogManager)
CleanupAliases)
)
+ /**
+ * Initialize the tag of Cast so we can distinguish if Cast is
auto-generated by Analyzer and
+ * strip auto-generated cast when use Cast.sql.
+ */
+ object InitializeCastTag extends Rule[LogicalPlan] {
+ private def setCastTag(plan: LogicalPlan): Unit = {
+ plan.resolveOperators { case p =>
+ p.transformExpressions {
+ case cast: CastBase =>
+ cast.setTagValue(Cast.AUTO_GENERATED_TAG, false)
Review comment:
I think a more explicit and easy way to find user-specified casts is:
1. the cast created in the SQL parser
2. the cast created in `Column.cast`
This rule catches all casts that before the plan is analyzed, but it's
possible that spark may re-analyze a query plan (with dataframe API).
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]