metanil commented on code in PR #59760:
URL: https://github.com/apache/spark/pull/59760#discussion_r4542116221
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/TransformExpression.scala:
##########
@@ -202,4 +361,63 @@ object TransformExpression {
case t: TransformExpression => t.reducedWith.isDefined
case _ => false
}
+
+ /**
+ * `argument` at `declaredType`, or `None` when the function could not take
it. See
+ * [[TransformExpression.evaluableFunction]].
+ *
+ * An argument goes as it is when it is stored the way the declared type is
(`storedAlike`),
+ * which is how a function read it before this check. A numeric argument
narrower than declared
+ * (`UpCastRule.legalNumericPrecedence`), e.g. a `SMALLINT` against an `INT`
or an `INT` against a
+ * `DOUBLE`, is held as another JVM type, so it is cast. That gives the
value a magic `invoke` got
+ * from Java's widening before this check, which can lose digits for a
`BIGINT` against a
+ * `DOUBLE` as it did there, and needs no time zone. Anything else is
refused,
+ * a `DATE` against a `TIMESTAMP` in particular, whose cast takes the
session time zone.
+ */
+ private def atDeclaredType(argument: Expression, declaredType: DataType):
Option[Expression] =
+ (argument.dataType, declaredType) match {
+ case (argumentType, _) if storedAlike(argumentType, declaredType, nested
= false) =>
+ Some(argument)
+ case (argumentType, _) if
UpCastRule.legalNumericPrecedence(argumentType, declaredType) =>
+ Some(Cast(argument, declaredType))
+ case _ =>
+ None
+ }
+
+ /**
+ * Whether a value of type `from` is stored the way one of type `to` is, so
that a function
+ * declaring `to` reads it as it is:
+ * - two types with one physical type, e.g. a `VARCHAR` and a string of the
same collation, a
+ * `DATE` and an `INT`, or a `TIMESTAMP` and a `BIGINT`. A user-defined
type is stored as its
+ * `sqlType`;
+ * - two structs, arrays or maps whose fields, elements, keys and values
are stored alike, by
+ * position. Field names and nullability do not change how a value is
stored. A function
+ * declaring a non-nullable field gets the values a nullable one holds;
+ * - two decimals of one scale, so that the unscaled digits a function
reads are the same. At the
+ * top level the function gets the `Decimal` itself, whatever precision
it declares, e.g. a
+ * `DECIMAL(12,2)` key of a cogroup against a function declaring
`DECIMAL(10,2)`, which a
Review Comment:
Done: both copies say "a Pandas or Arrow cogroup" now. The explanation lives
once, in `createPartitioning`, and `canEvaluate` and `storedAlike` point there.
--
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]