shujingyang-db commented on code in PR #44318:
URL: https://github.com/apache/spark/pull/44318#discussion_r1434433839
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/XmlInferSchema.scala:
##########
@@ -534,4 +541,55 @@ class XmlInferSchema(options: XmlOptions, caseSensitive:
Boolean)
}
}
}
+
+ /**
+ * This helper function merges the data type of value tags and inner
elements.
+ * It could only be structure data. Consider the following case,
+ * <a>
+ * value1
+ * <b>1</b>
+ * value2
+ * </a>
+ * Input: ''a struct<b int, _VALUE string>'' and ''_VALUE string''
+ * Return: ''a struct<b int, _VALUE array<string>>''
+ * @param objectType inner elements' type
+ * @param valueTagType value tag's type
+ */
+ private[xml] def addOrUpdateValueTagType(
+ objectType: DataType,
+ valueTagType: DataType): DataType = {
+ (objectType, valueTagType) match {
+ case (st: StructType, _) =>
+ // TODO(shujing): case sensitive?
+ val valueTagIndexOpt = st.getFieldIndex(options.valueTag)
+
+ valueTagIndexOpt match {
+ // If the field name exists in the inner elements,
+ // merge the type and infer the combined field as an array type if
necessary
+ case Some(index) if !st(index).dataType.isInstanceOf[ArrayType] =>
+ updateStructField(
+ st,
+ index,
+ ArrayType(compatibleType(st(index).dataType, valueTagType)))
+ case Some(index) =>
+ updateStructField(st, index, compatibleType(st(index).dataType,
valueTagType))
Review Comment:
Yes, this branch handles this case of array type. If it's an array, we will
merge the element types.
--
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]