This is an automated email from the ASF dual-hosted git repository.

MaxGekk pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.x by this push:
     new 4fa6293719d0 [SPARK-57458][SQL][FOLLOWUP] Avoid non-local return in 
XmlInferSchema.tryParseTimestampNTZ
4fa6293719d0 is described below

commit 4fa6293719d0ce5a2c42f7b9686dc5dbae16eb20
Author: Wenchen Fan <[email protected]>
AuthorDate: Wed Jul 1 23:10:05 2026 +0200

    [SPARK-57458][SQL][FOLLOWUP] Avoid non-local return in 
XmlInferSchema.tryParseTimestampNTZ
    
    ### What changes were proposed in this pull request?
    
    This is a followup of 
[SPARK-57458](https://issues.apache.org/jira/browse/SPARK-57458). The 
nanosecond-precision timestamp inference in 
`XmlInferSchema.tryParseTimestampNTZ` used a `return` statement inside an 
`Option.foreach` closure, which is a non-local return implemented via a 
control-flow exception. This replaces it with a plain boolean check plus a 
local `return`, keeping the behavior identical while avoiding the non-local 
return.
    
    ### Why are the changes needed?
    
    Non-local returns rely on throwing/catching a `NonLocalReturnControl` 
exception, which is discouraged and flagged by lint tooling. The rewrite is 
equivalent and clearer.
    
    ### Does this PR introduce any user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Existing tests for nanosecond timestamp inference in the XML datasource 
cover this code path.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Yes, this patch was co-authored using generative AI tooling.
    
    Closes #56916 from cloud-fan/cloud-fan/xml-nano-nonlocal-return.
    
    Authored-by: Wenchen Fan <[email protected]>
    Signed-off-by: Max Gekk <[email protected]>
    (cherry picked from commit 8344fb3f018952ab33a0a0dbb8e1f60c84c7728f)
    Signed-off-by: Max Gekk <[email protected]>
---
 .../apache/spark/sql/catalyst/xml/XmlInferSchema.scala    | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala
index 7fbce121e624..2471cfc735bd 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala
@@ -542,14 +542,13 @@ class XmlInferSchema(private val options: XmlOptions, 
private val caseSensitive:
       if ((SQLConf.get.legacyTimeParserPolicy == LegacyBehaviorPolicy.LEGACY ||
         timestampType == TimestampNTZType) &&
         timestampNTZFormatter.parseWithoutTimeZoneOptional(field, 
false).isDefined) {
-        if (SQLConf.get.timestampNanosTypesEnabled) {
-          // Prefer nanosecond type when the fractional seconds part has more 
than 6 digits,
-          // indicating sub-microsecond precision that cannot be represented 
by TimestampNTZType.
-          val nanosOpt =
-            timestampNTZFormatter.parseWithoutTimeZoneNanosOptional(field, 9, 
false)
-          nanosOpt.filter(_.nanosWithinMicro != 0).foreach { _ =>
-            return Some(TimestampNTZNanosType(9))
-          }
+        // Prefer nanosecond type when there is a nonzero sub-microsecond 
component
+        // (nanosWithinMicro != 0) that TimestampNTZType cannot represent.
+        val hasSubMicro = SQLConf.get.timestampNanosTypesEnabled &&
+          timestampNTZFormatter.parseWithoutTimeZoneNanosOptional(field, 9, 
false)
+            .exists(_.nanosWithinMicro != 0)
+        if (hasSubMicro) {
+          return Some(TimestampNTZNanosType(9))
         }
         return Some(timestampType)
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to