Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-44111 Prepare Apache Spark 4.0.0
  3. SPARK-48016

Fix a bug in try_divide function when with decimals

    XMLWordPrintableJSON

Details

    Description

      Binary Arithmetic operators should include the evalMode during makeCopy. Otherwise, the following query will throw DIVIDE_BY_ZERO error instead of returning null

       

      SELECT try_divide(1, decimal(0)); 

      This is caused from the rule DecimalPrecision:

      case b @ BinaryOperator(left, right) if left.dataType != right.dataType =>
        (left, right) match {
       ...
          case (l: Literal, r) if r.dataType.isInstanceOf[DecimalType] &&
              l.dataType.isInstanceOf[IntegralType] &&
              literalPickMinimumPrecision =>
            b.makeCopy(Array(Cast(l, DataTypeUtils.fromLiteral(l)), r)) 

       

      Attachments

        Activity

          People

            Gengliang.Wang Gengliang Wang
            Gengliang.Wang Gengliang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: