sarutak commented on PR #60119:
URL: https://github.com/apache/spark/pull/60119#issuecomment-6713425247

   Thank you for the approval and the comments, @dongjoon-hyun. As you asked, I 
rebased onto the latest master, which conflicted with SPARK-60983 in 
`ExprUtils`, and force-pushed f7509b27339. The rebase resolves the conflict in 
each commit, the changes for this review are in the last commit, "Address 
review comments", and replies are inline.
   
   In the rebase, the expressions this PR adds moved into 
`ExprUtils.isTotalOperator`, on which `canEvaluateUnconditionally` builds since 
SPARK-60983, as whether each of them can fail depends only on the types of its 
children. Two rules on master also see the wider check: `ConstantPropagation`, 
which now substitutes constants under the added expressions because they are in 
`isTotalOperator`, e.g. `y = 5 AND x > z + y` with ANSI mode off becomes `y = 5 
AND x > z + 5`, and `InferFiltersFromConstraints`, which infers filters such as 
`year(d) = 2024`, `LIKE 'a%'` and arithmetic with ANSI mode off again, as 
SPARK-60985 anticipated. The last commit adds tests for both, and updates the 
examples in the migration guide entry and the doc of 
`spark.sql.legacy.inferFailableFiltersFromConstraints`.
   
   Both rules replace a value with one that is only equal to it, so the check 
now also leaves out a cast of a `FLOAT` or `DOUBLE` to a string or a variant, 
also in LEGACY and TRY mode: `-0.0 = 0.0` holds, but their strings differ, and 
`x = y AND CAST(y AS STRING) = '-0.0'` would otherwise infer `CAST(x AS STRING) 
= '-0.0'` and drop a row with `x` = 0.0 and `y` = -0.0. `ConstantPropagation` 
already folds `x = 0.0 AND CAST(x AS STRING) = '-0.0'` to false on master, and 
the legacy configuration infers such filters too; I filed SPARK-61139 to fix 
those at the rules, after which this exclusion can go. Strings of a non-binary 
collation, which can also be equal but differ, are already guarded by both 
rules, which replace them only as a direct operand of a comparison; the last 
commit adds a test for each. With 
`spark.sql.legacy.allowNegativeScaleOfDecimal`, the check also leaves out the 
casts from or to a decimal of a negative scale outside TRY mode, and from a 
string in TRY mode, which runs
  the LEGACY cast, as `Decimal.toLong` raises `ArrayIndexOutOfBoundsException` 
for one, e.g. in a LEGACY cast of a `DECIMAL(3, -2)` to a `BIGINT`, and in 
every mode the binary arithmetic over one, as `Decimal.%` raises an 
`ArithmeticException` for a very negative one.
   
   The latest master also has SPARK-61050, after which `div`, `%` and `pmod` 
over decimals no longer raise `Division impossible`, so the check now also 
accepts them outside ANSI mode, which this PR left out for that error, and 
`try_mod` (`Remainder` in TRY mode) too. `IntegralDivide` and `Pmod`, which 
have no `try_` form, stay out in TRY mode, as they raise on a zero divisor 
there. As items 1 and 2 and the rebase accept more expressions, also in ANSI 
mode, I also updated the description. Since this widens what is accepted after 
your approval, could you take another look when you get a chance?


-- 
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]

Reply via email to