You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by rxin <gi...@git.apache.org> on 2016/07/27 15:44:12 UTC

[GitHub] spark pull request #14374: [SPARK-16735][SQL] `map` should create a decimal ...

Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14374#discussion_r72465258
  
    --- 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 --
    
    isTighterThan is not associative - i think this would be a problem?



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org