Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-48016][SQL][3.4] Fix a bug in try_divide function when with decimals #46289

Commits on Apr 29, 2024

  1. [SPARK-48016][SQL] Fix a bug in try_divide function when with decimals

     Currently, the following query will throw DIVIDE_BY_ZERO error instead of returning null
     ```
    SELECT try_divide(1, decimal(0));
    ```
    
    This is caused by 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))
    ```
    The result of the above makeCopy will contain `ANSI` as the `evalMode`, instead of `TRY`.
    This PR is to fix this bug by replacing the makeCopy method calls with withNewChildren
    
    Bug fix in try_* functions.
    
    Yes, it fixes a long-standing bug in the try_divide function.
    
    New UT
    
    No
    
    Closes apache#46286 from gengliangwang/avoidMakeCopy.
    
    Authored-by: Gengliang Wang <gengliang@apache.org>
    Signed-off-by: Gengliang Wang <gengliang@apache.org>
    (cherry picked from commit 3fbcb26)
    Signed-off-by: Gengliang Wang <gengliang@apache.org>
    gengliangwang committed Apr 29, 2024
    Configuration menu
    Copy the full SHA
    f527c0b View commit details
    Browse the repository at this point in the history