You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "shujingyang-db (via GitHub)" <gi...@apache.org> on 2024/01/25 00:11:42 UTC

[PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

shujingyang-db opened a new pull request, #44875:
URL: https://github.com/apache/spark/pull/44875

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Enhance XML bad record handling with partial results support
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   Otherwise, we will get an empty result if the parser throws an exception
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Unit tests
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   No


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

Posted by "shujingyang-db (via GitHub)" <gi...@apache.org>.
shujingyang-db commented on code in PR #44875:
URL: https://github.com/apache/spark/pull/44875#discussion_r1465755400


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -280,20 +267,45 @@ class StaxXmlParser(
     while (!shouldStop) {
       parser.nextEvent match {
         case e: StartElement =>
-          kvPairs +=
-            (UTF8String.fromString(StaxXmlParserUtils.getName(e.asStartElement.getName, options)) ->
-            convertField(parser, valueType))
+          val key = UTF8String.fromString(
+            StaxXmlParserUtils.getName(e.asStartElement.getName, options))
+          try {
+            kvPairs += key -> convertField(parser, valueType)
+          } catch {
+            case partialValueException: PartialValueException =>
+              badRecordException = badRecordException.orElse(Some(partialValueException.cause))
+              StaxXmlParserUtils.skipChildren(parser)
+              kvPairs += key -> partialValueException.partialResult
+            case NonFatal(e) =>
+              badRecordException = badRecordException.orElse(Some(e))
+              StaxXmlParserUtils.skipChildren(parser)
+          }
         case c: Characters if !c.isWhiteSpace =>
           // Create a value tag field for it
-          kvPairs +=
+          val key = UTF8String.fromString(options.valueTag)
           // TODO: We don't support an array value tags in map yet.
-          (UTF8String.fromString(options.valueTag) -> convertTo(c.getData, valueType))
+          try {
+            kvPairs += (key -> convertTo(c.getData, valueType))
+          } catch {
+            case partialValueException: PartialValueException =>
+              badRecordException = badRecordException.orElse(Some(partialValueException.cause))
+              StaxXmlParserUtils.skipChildren(parser)
+              kvPairs += key -> partialValueException.partialResult
+            case NonFatal(e) =>
+              badRecordException = badRecordException.orElse(Some(e))
+              StaxXmlParserUtils.skipChildren(parser)

Review Comment:
   It will not. This is the exception branch.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

Posted by "shujingyang-db (via GitHub)" <gi...@apache.org>.
shujingyang-db commented on code in PR #44875:
URL: https://github.com/apache/spark/pull/44875#discussion_r1465755738


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -429,6 +451,7 @@ class StaxXmlParser(
           case e: SparkUpgradeException => throw e
           case NonFatal(e) =>
             badRecordException = badRecordException.orElse(Some(e))
+            StaxXmlParserUtils.skipChildren(parser)

Review Comment:
   It will not. It only skip the inner elements.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

Posted by "sandip-db (via GitHub)" <gi...@apache.org>.
sandip-db commented on code in PR #44875:
URL: https://github.com/apache/spark/pull/44875#discussion_r1465717275


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -280,20 +267,45 @@ class StaxXmlParser(
     while (!shouldStop) {
       parser.nextEvent match {
         case e: StartElement =>
-          kvPairs +=
-            (UTF8String.fromString(StaxXmlParserUtils.getName(e.asStartElement.getName, options)) ->
-            convertField(parser, valueType))
+          val key = UTF8String.fromString(
+            StaxXmlParserUtils.getName(e.asStartElement.getName, options))
+          try {
+            kvPairs += key -> convertField(parser, valueType)
+          } catch {
+            case partialValueException: PartialValueException =>
+              badRecordException = badRecordException.orElse(Some(partialValueException.cause))
+              StaxXmlParserUtils.skipChildren(parser)
+              kvPairs += key -> partialValueException.partialResult
+            case NonFatal(e) =>
+              badRecordException = badRecordException.orElse(Some(e))
+              StaxXmlParserUtils.skipChildren(parser)
+          }
         case c: Characters if !c.isWhiteSpace =>
           // Create a value tag field for it
-          kvPairs +=
+          val key = UTF8String.fromString(options.valueTag)
           // TODO: We don't support an array value tags in map yet.
-          (UTF8String.fromString(options.valueTag) -> convertTo(c.getData, valueType))
+          try {
+            kvPairs += (key -> convertTo(c.getData, valueType))
+          } catch {
+            case partialValueException: PartialValueException =>

Review Comment:
   `convertTo` is not going to throw `PartialValueException`



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -385,31 +397,41 @@ class StaxXmlParser(
           val attributes = e.getAttributes.asScala.toArray
           val field = StaxXmlParserUtils.getName(e.asStartElement.getName, options)
 
-          nameToIndex.get(field) match {
-            case Some(index) => schema(index).dataType match {
-              case st: StructType =>
-                row(index) = convertObjectWithAttributes(parser, st, attributes)
-
-              case ArrayType(dt: DataType, _) =>
-                val values = Option(row(index))
-                  .map(_.asInstanceOf[ArrayBuffer[Any]])
-                  .getOrElse(ArrayBuffer.empty[Any])
-                val newValue = dt match {
-                  case st: StructType =>
-                    convertObjectWithAttributes(parser, st, attributes)
-                  case dt: DataType =>
-                    convertField(parser, dt)
+            nameToIndex.get(field) match {
+              case Some(index) =>
+                try {
+                  schema(index).dataType match {
+                    case st: StructType =>
+                      row(index) = convertObjectWithAttributes(parser, st, attributes)
+
+                    case ArrayType(dt: DataType, _) =>
+                      val values = Option(row(index))
+                        .map(_.asInstanceOf[ArrayBuffer[Any]])
+                        .getOrElse(ArrayBuffer.empty[Any])
+                      val newValue = dt match {
+                        case st: StructType =>
+                          convertObjectWithAttributes(parser, st, attributes)
+                        case dt: DataType =>
+                          convertField(parser, dt)
+                      }
+                      row(index) = values :+ newValue
+
+                    case dt: DataType =>
+                      row(index) = convertField(parser, dt, attributes)
+                  }
+                } catch {
+                  case partialResultException: PartialValueException =>

Review Comment:
   nit:
   ```suggestion
                     case partialValueException: PartialValueException =>
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2685,4 +2684,40 @@ class XmlSuite extends QueryTest with SharedSparkSession {
         Row(1.0E38D, BigDecimal("92233720368547758070")) :: Nil
     )
   }
+
+  test("return partial results for bad records") {
+    withTempDir { dir =>
+      val xmlBadRecord1 =
+        s"""<ROW>
+         |    <double>0.1</double>

Review Comment:
   Add integer `valueTag`:
   
   ```suggestion
            |    3
            |    <double>0.1</double>
            |    4
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2685,4 +2684,40 @@ class XmlSuite extends QueryTest with SharedSparkSession {
         Row(1.0E38D, BigDecimal("92233720368547758070")) :: Nil
     )
   }
+
+  test("return partial results for bad records") {
+    withTempDir { dir =>
+      val xmlBadRecord1 =
+        s"""<ROW>
+         |    <double>0.1</double>
+         |    <array>0</array>
+         |    <array>mismatch</array>
+         |    <array>2</array>
+         |    <map>
+         |        <key1>1</key1>
+         |        <key2>2</key2>
+         |    </map>
+         |</ROW>""".stripMargin
+      val xmlBadRecord2 =
+        s"""<ROW>
+           |    <double>mismatch</double>

Review Comment:
   ```suggestion
              |     3
              |    <double>mismatch</double>
              |     mismatchValue
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2685,4 +2684,40 @@ class XmlSuite extends QueryTest with SharedSparkSession {
         Row(1.0E38D, BigDecimal("92233720368547758070")) :: Nil
     )
   }
+
+  test("return partial results for bad records") {
+    withTempDir { dir =>
+      val xmlBadRecord1 =
+        s"""<ROW>
+         |    <double>0.1</double>
+         |    <array>0</array>
+         |    <array>mismatch</array>
+         |    <array>2</array>
+         |    <map>
+         |        <key1>1</key1>
+         |        <key2>2</key2>
+         |    </map>
+         |</ROW>""".stripMargin
+      val xmlBadRecord2 =
+        s"""<ROW>
+           |    <double>mismatch</double>
+           |    <array>mismatch</array>
+           |    <array>1</array>
+           |    <array>2</array>
+           |    <map>
+           |        <key1>mismatch</key1>
+           |        <key2>2</key2>
+           |    </map>
+           |</ROW>""".stripMargin
+      Files.write(new File(dir, "f0").toPath, (xmlBadRecord1 ++ xmlBadRecord2).getBytes)
+      val schema = "double double, array array<int>, map map<string, int>, _corrupt_record string"

Review Comment:
   ```suggestion
         val schema = "_VALUE array<int>, double double, array array<int>, map map<string, int>, _corrupt_record string"
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2685,4 +2684,40 @@ class XmlSuite extends QueryTest with SharedSparkSession {
         Row(1.0E38D, BigDecimal("92233720368547758070")) :: Nil
     )
   }
+
+  test("return partial results for bad records") {
+    withTempDir { dir =>
+      val xmlBadRecord1 =
+        s"""<ROW>
+         |    <double>0.1</double>
+         |    <array>0</array>
+         |    <array>mismatch</array>
+         |    <array>2</array>
+         |    <map>
+         |        <key1>1</key1>
+         |        <key2>2</key2>

Review Comment:
   Add a valueTag in the map:
   
   ```suggestion
            |        <key1>1</key1>
            |        3
            |        <key2>2</key2>
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2685,4 +2684,40 @@ class XmlSuite extends QueryTest with SharedSparkSession {
         Row(1.0E38D, BigDecimal("92233720368547758070")) :: Nil
     )
   }
+
+  test("return partial results for bad records") {
+    withTempDir { dir =>
+      val xmlBadRecord1 =

Review Comment:
   Add a scenario with nested struct object with attributes and valueTag:
   Correct data:
   `<ROW><struct attr=3.0>4.0<b>5.0</b><struct></ROW>`
   
   XML data with mismatches:
   ```
   <ROW><struct attr=mismatch1>4.0<b>5.0</b><struct></ROW>
   <ROW><struct attr=3.0>mismatch2<b>5.0</b><struct></ROW>
   <ROW><struct attr=3.0>4.0<b>mismatch3</b><struct></ROW>
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2685,4 +2684,40 @@ class XmlSuite extends QueryTest with SharedSparkSession {
         Row(1.0E38D, BigDecimal("92233720368547758070")) :: Nil
     )
   }
+
+  test("return partial results for bad records") {
+    withTempDir { dir =>
+      val xmlBadRecord1 =
+        s"""<ROW>
+         |    <double>0.1</double>
+         |    <array>0</array>
+         |    <array>mismatch</array>
+         |    <array>2</array>
+         |    <map>
+         |        <key1>1</key1>
+         |        <key2>2</key2>
+         |    </map>
+         |</ROW>""".stripMargin
+      val xmlBadRecord2 =
+        s"""<ROW>
+           |    <double>mismatch</double>
+           |    <array>mismatch</array>
+           |    <array>1</array>
+           |    <array>2</array>
+           |    <map>
+           |        <key1>mismatch</key1>

Review Comment:
   ```suggestion
              |    <map>
              |        mismatch1
              |        <key1>mismatch</key1>
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -21,17 +21,14 @@ import java.nio.file.{Files, Path, Paths}
 import java.sql.{Date, Timestamp}
 import java.time.{Instant, LocalDateTime}
 import java.util.TimeZone
-

Review Comment:
   nit: revert



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -21,17 +21,14 @@ import java.nio.file.{Files, Path, Paths}
 import java.sql.{Date, Timestamp}
 import java.time.{Instant, LocalDateTime}
 import java.util.TimeZone
-
 import scala.collection.immutable.ArraySeq
 import scala.collection.mutable
 import scala.io.Source
 import scala.jdk.CollectionConverters._
-

Review Comment:
   nit: revert



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -429,6 +451,7 @@ class StaxXmlParser(
           case e: SparkUpgradeException => throw e
           case NonFatal(e) =>
             badRecordException = badRecordException.orElse(Some(e))
+            StaxXmlParserUtils.skipChildren(parser)

Review Comment:
   Will this skip valid entities?



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -21,17 +21,14 @@ import java.nio.file.{Files, Path, Paths}
 import java.sql.{Date, Timestamp}
 import java.time.{Instant, LocalDateTime}
 import java.util.TimeZone
-
 import scala.collection.immutable.ArraySeq
 import scala.collection.mutable
 import scala.io.Source
 import scala.jdk.CollectionConverters._
-
 import org.apache.commons.lang3.exception.ExceptionUtils
 import org.apache.hadoop.conf.Configuration
 import org.apache.hadoop.io.{LongWritable, Text}
 import org.apache.hadoop.io.compress.GzipCodec
-

Review Comment:
   nit: revert



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -280,20 +267,45 @@ class StaxXmlParser(
     while (!shouldStop) {
       parser.nextEvent match {
         case e: StartElement =>
-          kvPairs +=
-            (UTF8String.fromString(StaxXmlParserUtils.getName(e.asStartElement.getName, options)) ->
-            convertField(parser, valueType))
+          val key = UTF8String.fromString(
+            StaxXmlParserUtils.getName(e.asStartElement.getName, options))
+          try {
+            kvPairs += key -> convertField(parser, valueType)
+          } catch {
+            case partialValueException: PartialValueException =>
+              badRecordException = badRecordException.orElse(Some(partialValueException.cause))
+              StaxXmlParserUtils.skipChildren(parser)
+              kvPairs += key -> partialValueException.partialResult
+            case NonFatal(e) =>
+              badRecordException = badRecordException.orElse(Some(e))
+              StaxXmlParserUtils.skipChildren(parser)
+          }
         case c: Characters if !c.isWhiteSpace =>
           // Create a value tag field for it
-          kvPairs +=
+          val key = UTF8String.fromString(options.valueTag)
           // TODO: We don't support an array value tags in map yet.
-          (UTF8String.fromString(options.valueTag) -> convertTo(c.getData, valueType))
+          try {
+            kvPairs += (key -> convertTo(c.getData, valueType))
+          } catch {
+            case partialValueException: PartialValueException =>
+              badRecordException = badRecordException.orElse(Some(partialValueException.cause))
+              StaxXmlParserUtils.skipChildren(parser)
+              kvPairs += key -> partialValueException.partialResult
+            case NonFatal(e) =>
+              badRecordException = badRecordException.orElse(Some(e))
+              StaxXmlParserUtils.skipChildren(parser)

Review Comment:
   Will this skip other valid <key, value> pairs?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #44875: [SPARK-46848] XML: Enhance XML bad record handling with partial results support
URL: https://github.com/apache/spark/pull/44875


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

Posted by "sandip-db (via GitHub)" <gi...@apache.org>.
sandip-db commented on code in PR #44875:
URL: https://github.com/apache/spark/pull/44875#discussion_r1467238788


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -354,74 +394,109 @@ class StaxXmlParser(
       rootAttributes: Array[Attribute] = Array.empty): InternalRow = {
     val row = new Array[Any](schema.length)
     val nameToIndex = getFieldNameToIndex(schema)
+    var badRecordException: Option[Throwable] = None
     // If there are attributes, then we process them first.
-    convertAttributes(rootAttributes, schema).toSeq.foreach {
-      case (f, v) =>
-        nameToIndex.get(f).foreach { row(_) = v }
+    try {
+      convertAttributes(rootAttributes, schema).toSeq.foreach {
+        case (f, v) =>
+          nameToIndex.get(f).foreach { row(_) = v }
+      }
+    } catch {
+      case NonFatal(e) =>
+        badRecordException = badRecordException.orElse(Some(e))
     }
 
     val wildcardColName = options.wildcardColName
     val hasWildcard = schema.exists(_.name == wildcardColName)
 
-    var badRecordException: Option[Throwable] = None
-
     var shouldStop = false
     while (!shouldStop) {
       parser.nextEvent match {
-        case e: StartElement => try {
-          val attributes = e.getAttributes.asScala.toArray
+        case e: StartElement =>
           val field = StaxXmlParserUtils.getName(e.asStartElement.getName, options)
-
-          nameToIndex.get(field) match {
-            case Some(index) => schema(index).dataType match {
-              case st: StructType =>
-                row(index) = convertObjectWithAttributes(parser, st, field, attributes)
-
-              case ArrayType(dt: DataType, _) =>
-                val values = Option(row(index))
-                  .map(_.asInstanceOf[ArrayBuffer[Any]])
-                  .getOrElse(ArrayBuffer.empty[Any])
-                val newValue = dt match {
-                  case st: StructType =>
-                    convertObjectWithAttributes(parser, st, field, attributes)
-                  case dt: DataType =>
-                    convertField(parser, dt, field)
+          try {
+            val attributes = e.getAttributes.asScala.toArray
+            nameToIndex.get(field) match {
+              case Some(index) =>
+                  schema(index).dataType match {
+                    case st: StructType =>
+                      try {
+                        row(index) = convertObjectWithAttributes(parser, st, field, attributes)
+                      } catch {
+                        case partialValueException: PartialValueException =>
+                          badRecordException =
+                            badRecordException.orElse(Some(partialValueException.cause))
+                          row.update(index, partialValueException.partialResult)
+                      }
+
+

Review Comment:
   ```suggestion
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -354,74 +394,109 @@ class StaxXmlParser(
       rootAttributes: Array[Attribute] = Array.empty): InternalRow = {
     val row = new Array[Any](schema.length)
     val nameToIndex = getFieldNameToIndex(schema)
+    var badRecordException: Option[Throwable] = None
     // If there are attributes, then we process them first.
-    convertAttributes(rootAttributes, schema).toSeq.foreach {
-      case (f, v) =>
-        nameToIndex.get(f).foreach { row(_) = v }
+    try {
+      convertAttributes(rootAttributes, schema).toSeq.foreach {

Review Comment:
   If the first attribute has type mismatch, `convertAttributes ` will drop the subsequent ones.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46848] XML: Enhance XML bad record handling with partial results support [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #44875:
URL: https://github.com/apache/spark/pull/44875#issuecomment-2095014463

   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org