spark-xml icon indicating copy to clipboard operation
spark-xml copied to clipboard

<xs:choice maxOccurs="unbounded"> does not produce array type

Open marpetr opened this issue 1 year ago • 3 comments

Example input:

	<xs:complexType name="Fruits">
		<xs:choice maxOccurs="unbounded">
			<xs:element name="apple" type="js:Apple"/>
			<xs:element name="orange" type="js:Orange"/>
		</xs:choice>
	</xs:complexType>

Expected output: fruits: struct<apple: array<struct<...>>, orange: array<struct<...>>>

Actual output: fruits: struct<apple: struct<...>, orange: struct<...>>

Proposed fix: https://github.com/databricks/spark-xml/blob/ddd1ef573a5318748763fafc974e4f7d8876fd6f/src/main/scala/com/databricks/spark/xml/util/XSDToSchema.scala#L227

-               if (element.getMaxOccurs == 1) {
+               if (element.getMaxOccurs == 1 && choice.getMaxOccurs == 1) {

marpetr avatar Jun 17 '24 08:06 marpetr