sandip-db commented on code in PR #44571:
URL: https://github.com/apache/spark/pull/44571#discussion_r1443135604


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2561,10 +2575,10 @@ class XmlSuite extends QueryTest with 
SharedSparkSession {
          |            </array1>
          |            value10
          |            <array1>
-         |                <struct3>
+         |                <struct3><!--A comment within tags-->
          |                    <array2>3</array2>
          |                    value11
-         |                    <array2>4</array2>
+         |                    <array2>4</array2><!--A comment within tags-->

Review Comment:
   Adding multiple comments with spaces between them:
   ```suggestion
            |                    <array2>4</array2> <!--First comment--> 
<!--Second comment--> 
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2561,10 +2575,10 @@ class XmlSuite extends QueryTest with 
SharedSparkSession {
          |            </array1>
          |            value10
          |            <array1>
-         |                <struct3>
+         |                <struct3><!--A comment within tags-->
          |                    <array2>3</array2>
          |                    value11
-         |                    <array2>4</array2>
+         |                    <array2>4</array2><!--A comment within tags-->
          |                </struct3>
          |                <string>string</string>
          |                value12

Review Comment:
   GitHub doesn't allow to add review comment to any arbirary line. So 
commenting here.
   
   Add a comment between `value16` and `</ROW>` with a space before and after 
the comment.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParserUtils.scala:
##########
@@ -178,4 +179,11 @@ object StaxXmlParserUtils {
       }
     }
   }
+
+  def consumeNextEndElement(parser: XMLEventReader): Unit = {

Review Comment:
   For defensive purpose, consider passing the name of the `StartElement` and 
assert that it matches with the `EndElement`:
   
   ```suggestion
     def skipNextEndElement(parser: XMLEventReader): Unit = {
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/xml/XmlSuite.scala:
##########
@@ -2550,7 +2564,7 @@ class XmlSuite extends QueryTest with SharedSparkSession {
          |                value4
          |                <struct3>
          |                    value5
-         |                    <array2>1</array2>
+         |                    <array2>1<!--A comment within tags--></array2>

Review Comment:
   Adding multiple comments with spaces between them:
   ```suggestion
            |                    <array2>1 <!--First comment--> <!--Second 
comment--> </array2>
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala:
##########
@@ -288,16 +253,15 @@ class XmlInferSchema(options: XmlOptions, caseSensitive: 
Boolean)
             case dt: DataType => dt
           }
           // Add the field and datatypes so that we can check if this is 
ArrayType.
-          val field = StaxXmlParserUtils.getName(e.asStartElement.getName, 
options)
           addOrUpdateType(nameToDataType, field, inferredType)
 
         case c: Characters if !c.isWhiteSpace =>
-          // This can be an attribute-only object
+          // This can be a value tag
           val valueTagType = inferFrom(c.getData)
           addOrUpdateType(nameToDataType, options.valueTag, valueTagType)
 
         case _: EndElement =>

Review Comment:
   Is `EndDocument` needed here as well?



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParserUtils.scala:
##########
@@ -178,4 +179,11 @@ object StaxXmlParserUtils {
       }
     }
   }
+
+  def consumeNextEndElement(parser: XMLEventReader): Unit = {
+    parser.nextEvent() match {
+      case _: EndElement => // do nothing
+      case _ => throw new IllegalStateException("Invalid state")
+    }

Review Comment:
   Extra events (comments, etc.) before EndElement need to be skipped.



-- 
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]

Reply via email to