shujingyang-db commented on code in PR #43319:
URL: https://github.com/apache/spark/pull/43319#discussion_r1355401700
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala:
##########
@@ -219,11 +219,27 @@ private[sql] object XmlInferSchema {
dataTypes += inferredType
nameToDataType += (field -> dataTypes)
+ case c: Characters if !c.isWhiteSpace =>
+ // This can be an attribute-only object
+ val valueTagType = inferFrom(c.getData, options)
+ nameToDataType += options.valueTag -> ArrayBuffer(valueTagType)
+
case _: EndElement =>
shouldStop = StaxXmlParserUtils.checkEndElement(parser)
case _ => // do nothing
}
+ }
+ // A structure object is an attribute-only element
+ // if it only consists of attributes and valueTags.
+ // If not, we will remove the valueTag field from the schema
+ val attributesOnly = nameToDataType.forall {
+ case (fieldName, dataTypes) =>
+ dataTypes.length == 1 &&
+ (fieldName == options.valueTag ||
fieldName.startsWith(options.attributePrefix))
Review Comment:
I agree on it. However this is our current
[behavior](https://github.com/shujingyang-db/spark/blob/8fd10a40641c831155ffd644e331f0b818f72700/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala#L198),
we might need to keep aligned with it.
--
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]