cloud-fan commented on code in PR #60662:
URL: https://github.com/apache/spark/pull/60662#discussion_r4626871214
##########
docs/sql-migration-guide.md:
##########
@@ -104,6 +104,7 @@ license: |
- 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, these
functions silently returned a wrong date, in most cases one at 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`.
- Since Spark 4.4, a Variant `TIMESTAMP` value is rendered in the session time
zone (`spark.sql.session.timeZone`) when it is nested in an array, map, or
struct that is cast to `STRING`, in `Dataset.show()`, and in the output of the
spark-sql CLI and the Thrift server, as a top-level `CAST(v AS STRING)` already
does. Previously, these paths rendered it in UTC. For example, with
`spark.sql.session.timeZone` set to `America/Los_Angeles`,
`CAST(named_struct('a', CAST(TIMESTAMP'2020-01-01 00:00:00Z' AS VARIANT)) AS
STRING)` returns `{"2019-12-31 16:00:00-08:00"}` instead of `{"2020-01-01
00:00:00+00:00"}`. The rendered text carries an explicit offset, so it still
denotes the same instant. Sessions in UTC are not affected.
+- Since Spark 4.4, a CTE no longer replaces a `DELETE`, `UPDATE` or `MERGE`
target that has the same unqualified name, as it already did not replace an
`INSERT` target. Such a statement modifies the table or view that it names, or
fails with `TABLE_OR_VIEW_NOT_FOUND` when none exists, and other references to
the name in the statement, such as in a `WHERE` subquery or the `MERGE` source,
still read the CTE. Previously, a CTE whose body is a bare table reference made
the statement modify the table that the CTE reads: for example, `WITH o AS
(TABLE cat.db.orders) DELETE FROM o WHERE id = 1` deleted rows from
`cat.db.orders`. Any other CTE body made the statement fail with
`INTERNAL_ERROR` or `UNSUPPORTED_FEATURE.TABLE_OPERATION`. To modify the table
that the CTE reads, name that table as the target. To restore the previous
behavior, set `spark.sql.legacy.cteSubstituteDmlTarget` to `true`; such a
statement then again modifies the table that the CTE reads, which Spark loads
without the w
rite privileges of the statement.
Review Comment:
Right, thanks. I confirmed it with the legacy config on: `WITH t AS (SELECT
* FROM src) DELETE FROM t` succeeded and truncated `src`, while the UPDATE and
MERGE forms failed with `UNSUPPORTED_FEATURE.TABLE_OPERATION`. With a filtered
body, the in-memory test table does not take the filter in full, so there the
DELETE failed with `INTERNAL_ERROR`; the case where a source does take it and
the filter is lost follows from the planner code, so the text says it can
happen.
Fixed in 51a9de5fa69, in the migration note, the config doc and the PR
description, with a shorter version of your wording: UPDATE and MERGE failed
with any other CTE body, and so did DELETE unless Spark reduced the body to a
plain scan of a table that supports deletes by filter or truncation, in which
case it deleted from or truncated that table using only the DELETE condition.
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/DeleteFromTableSuiteBase.scala:
##########
@@ -1066,6 +1066,97 @@ abstract class DeleteFromTableSuiteBase extends
RowLevelOperationSuiteBase {
Row(3, 300, "hr"))) // unchanged (pk 3 not in source)
}
+ test("delete target is not replaced by a same-named CTE") {
Review Comment:
Added in 51a9de5fa69: `assertLastTransactionWriteLoadOptions()` after every
statement with a literal target shadowed by a CTE in the three tests, and not
after the `UPDATE IDENTIFIER(concat(...))` statement. I checked your regression
case: with a temporary change that makes the exemption in `CTESubstitution`
drop the write-privilege marker, all three tests fail at the new assertion.
--
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]