linhongliu-db commented on code in PR #60402:
URL: https://github.com/apache/spark/pull/60402#discussion_r4568630715
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -119,6 +159,9 @@ class V2ExpressionBuilder(e: Expression, isPredicate:
Boolean = false) extends L
} else {
generateExpression(constantExpr, isPredicate)
}
+ case _ if checkTimeZone && pushdownLosesTimeZone(expr) =>
Review Comment:
Addressed by the verified self-fix.
<!-- SPARK_DEV_REVIEW_REPLY
{"finding_ids":["adjudication:finding:ddl-guard-nulls-v2-metadata"],"thread_id":"inline:4556582787","verdict_sha256":"827ba55d7a1962942b5192bdcddb5a6dee04633fb069b60577fae8dc981fd7bf"}
-->
##########
docs/sql-migration-guide.md:
##########
@@ -25,6 +25,7 @@ license: |
## Upgrading from Spark SQL 4.4 to 5.0
- Since Spark 5.0, the Spark Thrift Server refuses to start when
`hive.server2.enable.doAs` is `true` and `hive.server2.authentication` verifies
user identities (any recognized type other than `NONE`/`NOSASL`). It
impersonates the connecting user for Hive metastore calls and driver-side file
system access, but executor-side data access still runs as the server's own
service identity, so storage-level permissions are checked against the service
principal rather than the connecting user (SPARK-5159). Spark 4.4 logs a
warning for the same configuration. To restore the previous behavior, set
`spark.sql.hive.thriftServer.allowIneffectiveDoAs` to `true`. Setting
`hive.server2.enable.doAs` to `false` also starts the server, but note that it
stops impersonating metastore calls as well, so it is not a no-op.
+- Since Spark 5.0, Data Source V2 push-down no longer pushes
time-zone-dependent casts and datetime field extractions (for example
`hour(ts)` or `dayofmonth(ts)` of a `TIMESTAMP` column) when the session time
zone differs from the JVM default time zone, so Spark evaluates them in the
session time zone instead of the source evaluating them in its own zone. To
restore the previous behavior, set
`spark.sql.legacy.dataSource.pushDownDatetimeIgnoringTimeZone` to `true`.
Review Comment:
Addressed by the verified self-fix.
<!-- SPARK_DEV_REVIEW_REPLY
{"finding_ids":["adjudication:finding:migration-note-omits-write-condition-failure"],"thread_id":"inline:4556582811","verdict_sha256":"827ba55d7a1962942b5192bdcddb5a6dee04633fb069b60577fae8dc981fd7bf"}
-->
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -30,15 +32,53 @@ import
org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc, Avg,
import org.apache.spark.sql.connector.expressions.filter.{AlwaysFalse,
AlwaysTrue, And => V2And, Not => V2Not, Or => V2Or, Predicate => V2Predicate}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{AnyTimestampNanoType, BooleanType,
DataType, IntegerType,
- StringType}
+ StringType, TimestampNTZNanosType, TimestampNTZType}
import org.apache.spark.unsafe.types.UTF8String
/**
* The builder to generate V2 expressions from catalyst expressions.
*/
class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) extends
Logging {
- def build(): Option[V2Expression] = generateExpression(e, isPredicate)
+ // Set when the time-zone guard in generateExpression rejected a
subexpression.
+ private var timeZoneGuardHit = false
+ private var checkTimeZone = true
+
+ def build(): Option[V2Expression] = {
+ timeZoneGuardHit = false
+ checkTimeZone = true
+ val translated = generateExpression(e, isPredicate)
+ if (!timeZoneGuardHit) {
+ translated
+ } else {
+ // The guard dropped a zone-dependent subexpression. Re-translate
ignoring the guard and keep
+ // that legacy translation only when the user opts back into
zone-ignoring push-down.
+ checkTimeZone = false
+ val legacyTranslated = generateExpression(e, isPredicate)
Review Comment:
Addressed by the verified self-fix.
<!-- SPARK_DEV_REVIEW_REPLY
{"finding_ids":["adjudication:finding:double-translation-pass"],"thread_id":"inline:4556582834","verdict_sha256":"827ba55d7a1962942b5192bdcddb5a6dee04633fb069b60577fae8dc981fd7bf"}
-->
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala:
##########
@@ -1667,6 +1667,38 @@ class JDBCV2Suite extends SharedSparkSession with
ExplainSuiteHelper {
checkAnswer(df9, Seq(Row("alex")))
}
+ // time1 is midnight in the JVM default zone (America/Los_Angeles in tests),
which is 21:00 of the
+ // previous day in Pacific/Honolulu. A zone-dependent field of a TIMESTAMP
must be evaluated in
+ // the session time zone, not pushed to the source (which evaluates it in
its own zone).
+ private def checkDatetimeFieldsInSessionTimeZone(fixed: Boolean): Unit = {
+ assert(TimeZone.getDefault.getID == "America/Los_Angeles")
+ withSQLConf(SQLConf.SESSION_LOCAL_TIMEZONE.key -> "Pacific/Honolulu") {
+ // hour(time1) is 21 for both rows in Honolulu (midnight LA -> 21:00 of
the previous day).
+ val hour = sql("SELECT name FROM h2.test.datetime WHERE hour(time1) =
21")
+ checkFiltersRemoved(hour, removed = !fixed)
+ checkAnswer(hour, if (fixed) Seq(Row("amy"), Row("alex")) else Seq.empty)
+ // dayofmonth(time1) reads CAST(time1 AS DATE); in Honolulu amy -> 18,
alex -> 17.
+ val day = sql("SELECT name FROM h2.test.datetime WHERE dayofmonth(time1)
= 18")
+ checkFiltersRemoved(day, removed = !fixed)
Review Comment:
Addressed by the verified self-fix.
<!-- SPARK_DEV_REVIEW_REPLY
{"finding_ids":["adjudication:finding:session-zone-test-depends-on-ansi"],"thread_id":"inline:4556582849","verdict_sha256":"827ba55d7a1962942b5192bdcddb5a6dee04633fb069b60577fae8dc981fd7bf"}
-->
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -30,15 +32,53 @@ import
org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc, Avg,
import org.apache.spark.sql.connector.expressions.filter.{AlwaysFalse,
AlwaysTrue, And => V2And, Not => V2Not, Or => V2Or, Predicate => V2Predicate}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{AnyTimestampNanoType, BooleanType,
DataType, IntegerType,
- StringType}
+ StringType, TimestampNTZNanosType, TimestampNTZType}
import org.apache.spark.unsafe.types.UTF8String
/**
* The builder to generate V2 expressions from catalyst expressions.
*/
class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) extends
Logging {
- def build(): Option[V2Expression] = generateExpression(e, isPredicate)
+ // Set when the time-zone guard in generateExpression rejected a
subexpression.
+ private var timeZoneGuardHit = false
+ private var checkTimeZone = true
+
+ def build(): Option[V2Expression] = {
+ timeZoneGuardHit = false
+ checkTimeZone = true
+ val translated = generateExpression(e, isPredicate)
+ if (!timeZoneGuardHit) {
+ translated
+ } else {
+ // The guard dropped a zone-dependent subexpression. Re-translate
ignoring the guard and keep
+ // that legacy translation only when the user opts back into
zone-ignoring push-down.
+ checkTimeZone = false
+ val legacyTranslated = generateExpression(e, isPredicate)
+ if
(SQLConf.get.getConf(SQLConf.LEGACY_PUSH_DOWN_DATETIME_IGNORING_TIME_ZONE)) {
+ legacyTranslated
+ } else {
+ translated
+ }
+ }
+ }
+
+ // A V2 Cast and Extract carry no time zone, and JDBC exchanges timestamps
in the JVM default
+ // zone, so a zone-dependent expression whose zone has other rules yields
other results remotely.
+ private def pushdownLosesTimeZone(expr: Expression): Boolean = {
Review Comment:
Addressed by the verified self-fix.
<!-- SPARK_DEV_REVIEW_REPLY
{"finding_ids":["finding:55b9a0419c4552975032"],"thread_id":"inline:4556582866","verdict_sha256":"827ba55d7a1962942b5192bdcddb5a6dee04633fb069b60577fae8dc981fd7bf"}
-->
--
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]