spark-test commented on code in PR #60130: URL: https://github.com/apache/spark/pull/60130#discussion_r4526727537
########## docs/sql-migration-guide.md: ########## @@ -82,6 +82,7 @@ license: | - Since Spark 4.4, a write to a Data Source V2 table that parses the SQL text of a CHECK constraint binds an unqualified built-in function name to `system.builtin`, regardless of the SQL path and `spark.sql.functionResolution.sessionOrder` (SPARK-60777). Previously, an existing constraint could call another function with the same name. - Since Spark 4.4, `CREATE TABLE`, `REPLACE TABLE`, and `ALTER TABLE ... ADD CONSTRAINT` on a Data Source V2 table fail with `SUBQUERY_IN_CHECK_CONSTRAINT` when the condition of a CHECK constraint contains a subquery. `ALTER TABLE ... ADD CONSTRAINT` keeps failing with `UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.HIGHER_ORDER_FUNCTION` on a subquery in a lambda function. Previously, most of these statements failed with `INTERNAL_ERROR`, but a subquery that needed no resolution, such as `id > (SELECT 0 AS a)`, was accepted and every write evaluated it again (SPARK-60781). Existing constraints that contain a subquery are not rejected. - Since Spark 4.4, a function created by `CREATE FUNCTION ... AS 'class'` whose class implements `org.apache.spark.sql.connector.catalog.functions.UnboundFunction` and extends either a Hive UDF class (such as `UDF` or `GenericUDF`) or `org.apache.spark.sql.expressions.UserDefinedAggregateFunction` runs as a DataSource V2 function instead of a Hive UDF or Spark UDAF, including functions created in earlier versions. Its result type, argument coercion, and null handling are defined by the V2 implementation selected by `UnboundFunction.bind`. Hive's `@UDFType` and Spark UDAF's `deterministic` property do not control the V2 path. For scalar functions, determinism uses `BoundFunction.isDeterministic()` (default `true`) and the arguments' determinism. A call with constant arguments can therefore become eligible for constant folding during query planning instead of being evaluated per row. +- Since Spark 4.4, `next_day` and `last_day` fail with `DATETIME_OVERFLOW` when the result is later than the maximum `DATE`, `+5881580-07-11`, and `trunc` fails with it when the result is earlier than the minimum `DATE`, `-5877641-06-23`, regardless of `spark.sql.ansi.enabled`. Previously, the result silently wrapped around to the other end of the `DATE` range; for example, `last_day(DATE'+5881580-07-11')` returned `-5877641-07-12` and `trunc(DATE'-5877641-06-23', 'MONTH')` returned `+5881580-06-20`, while `trunc` to `QUARTER` failed with `ARITHMETIC_OVERFLOW`. `next_day` and `trunc` to `WEEK` also returned a wrong date for the first days of the `DATE` range; for example, `next_day(DATE'-5877641-06-23', 'MO')` and `trunc(DATE'-5877641-07-01', 'WEEK')` returned `-5877641-06-25`, a Thursday, and now return `-5877641-06-29`. Review Comment: **Nit (P3):** This entry says that before this change every out-of-range result "silently wrapped around to the other end of the `DATE` range", with `trunc` to `QUARTER` as the only exception. By the base branch's `truncDate` arithmetic, that does not hold for `trunc(d, 'WEEK')` on `-5877641-06-25` through `-5877641-06-28`: `days - 7` wraps to the maximum end and the final `Int` sum wraps back, so all four return `-5877641-06-25`, a Thursday at the same end of the range. Only `-06-23` and `-06-24` land at the other end, on `+5881580-07-07`. These four dates now fail with `DATETIME_OVERFLOW`, which is the right new behavior; the new golden case `trunc(date'-5877641-06-28', 'WEEK')` is one of them. Neither this sentence nor the later "now return `-5877641-06-29`" one describes their old results, so a user who checks earlier outputs for other-end dates to find affected rows would miss them. The examples the entry cites are accurate. A rewording such as "Previously, these functions silently returned a wrong date, in most cases one at the other end of the `DATE` range" fixes it, as would naming the four `WEEK` dates as an exception. **Verification:** - **Inspection:** Check that every statement the migration-guide entry makes about the previous behavior holds for every input whose result now fails or changes. That includes trunc to WEEK of -5877641-06-25 through -5877641-06-28, which returned -5877641-06-25 on the base branch, and trunc to QUARTER, which failed with ARITHMETIC_OVERFLOW. -- 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]
