Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/14374#discussion_r72567433
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala
---
@@ -93,20 +93,45 @@ case class CreateMap(children: Seq[Expression]) extends
Expression {
if (children.size % 2 != 0) {
TypeCheckResult.TypeCheckFailure(s"$prettyName expects a positive
even number of arguments.")
} else if (keys.map(_.dataType).distinct.length > 1) {
- TypeCheckResult.TypeCheckFailure("The given keys of function map
should all be the same " +
- "type, but they are " +
keys.map(_.dataType.simpleString).mkString("[", ", ", "]"))
+ if (keys.map(_.dataType).forall(_.isInstanceOf[DecimalType])) {
+ TypeCheckResult.TypeCheckSuccess
+ } else {
+ TypeCheckResult.TypeCheckFailure("The given keys of function map
should all be the same " +
+ "type, but they are " +
keys.map(_.dataType.simpleString).mkString("[", ", ", "]"))
+ }
} else if (values.map(_.dataType).distinct.length > 1) {
- TypeCheckResult.TypeCheckFailure("The given values of function map
should all be the same " +
- "type, but they are " +
values.map(_.dataType.simpleString).mkString("[", ", ", "]"))
+ if (values.map(_.dataType).forall(_.isInstanceOf[DecimalType])) {
+ TypeCheckResult.TypeCheckSuccess
+ } else {
+ TypeCheckResult.TypeCheckFailure("The given values of function map
should all be the " +
+ "same type, but they are " +
values.map(_.dataType.simpleString).mkString("[", ", ", "]"))
+ }
} else {
TypeCheckResult.TypeCheckSuccess
}
}
+ private def checkDecimalType(colType: Seq[Expression]): DataType = {
+ val elementType =
colType.headOption.map(_.dataType).getOrElse(NullType)
+ elementType match {
+ case _ if elementType.isInstanceOf[DecimalType] =>
+ var tighter: DataType = elementType
+ colType.foreach { child =>
+ if
(elementType.asInstanceOf[DecimalType].isTighterThan(child.dataType)) {
--- End diff --
What I was referring to was that isTighterThan was not associative, and i
don't think you can just take the tightest one this way.
As an example:
a precision 10, scale 5
b precision 7, scale 1
in this case a is not tighter than b, but b would be chosen as the target
data type, leading to lose of precision.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]