Skip to content

Commit

Permalink
[SPARK-45562][SQL][FOLLOWUP] Restore test case not require rowTag o…
Browse files Browse the repository at this point in the history
…ption

### What changes were proposed in this pull request?
apache#43389 makes `rowTag` a required option. But the xml API (please see https://github.com/apache/spark/blob/7057952f6bc2c5cf97dd408effd1b18bee1cb8f4/sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala#L579C1-L579C1) is unrelated to `rowTag`.

This PR also improves some code and remove one line of unused code.

### Why are the changes needed?
Restore test case not require `rowTag` option.

### Does this PR introduce _any_ user-facing change?
'No'.

### How was this patch tested?
Exists test cases.

### Was this patch authored or co-authored using generative AI tooling?
'No'.

Closes apache#43455 from beliefer/SPARK-45562_followup.

Authored-by: Jiaan Geng <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
  • Loading branch information
beliefer authored and HyukjinKwon committed Oct 20, 2023
1 parent 820418a commit cd827d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ private[sql] class XmlOptions(
}

val compressionCodec = parameters.get(COMPRESSION).map(CompressionCodecs.getCodecClassName)
val rowTagOpt = parameters.get(XmlOptions.ROW_TAG)
val rowTagOpt = parameters.get(XmlOptions.ROW_TAG).map(_.trim)
require(!rowTagRequired || rowTagOpt.isDefined, s"'${XmlOptions.ROW_TAG}' option is required.")
val rowTag = rowTagOpt.getOrElse(XmlOptions.DEFAULT_ROW_TAG).trim
val rowTag = rowTagOpt.getOrElse(XmlOptions.DEFAULT_ROW_TAG)
require(rowTag.nonEmpty, s"'$ROW_TAG' option should not be an empty string.")
require(!rowTag.startsWith("<") && !rowTag.endsWith(">"),
s"'$ROW_TAG' should not include angle brackets")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,9 @@ class XmlSuite extends QueryTest with SharedSparkSession {
"<ROW><year>2015</year><make>Chevy</make><model>Volt</model><comment>No</comment></ROW>")
val xmlRDD = spark.sparkContext.parallelize(data)
val ds = spark.createDataset(xmlRDD)(Encoders.STRING)
assert(spark.read.option("rowTag", "ROW").xml(ds).collect().length === 3)
assert(spark.read.xml(ds).collect().length === 3)
}

import testImplicits._
test("from_xml basic test") {
val xmlData =
"""<parent foo="bar"><pid>14ft3</pid>
Expand Down

0 comments on commit cd827d1

Please sign in to comment.