Github user wzhfy commented on a diff in the pull request:
https://github.com/apache/spark/pull/17758#discussion_r121288362
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/test/DataFrameReaderWriterSuite.scala
---
@@ -687,4 +687,46 @@ class DataFrameReaderWriterSuite extends QueryTest
with SharedSQLContext with Be
testRead(spark.read.schema(userSchemaString).text(dir, dir), data ++
data, userSchema)
testRead(spark.read.schema(userSchemaString).text(Seq(dir, dir): _*),
data ++ data, userSchema)
}
+
+ test("SPARK-20460 Check name duplication in schema") {
+ withTempDir { src =>
+ val columnDuplicateSchema = StructType(
+ StructField("a", IntegerType) ::
+ StructField("a", IntegerType) ::
+ Nil)
+
+ // Check CSV format
+ Seq("a,a",
"1,1").toDF().coalesce(1).write.mode("overwrite").text(src.toString)
+ val e1 = intercept[AnalysisException] {
+
spark.read.format("csv").schema(columnDuplicateSchema).option("header", false)
+ .load(src.toString)
+ }
+ assert(e1.getMessage.contains("""Found duplicate column(s) in
datasource: "a";"""))
+
+ // If `inferSchema` is true, a CSV format is duplicate-safe (See
SPARK-16896)
+ val df = spark.read.format("csv").option("inferSchema",
true).option("header", true)
+ .load(src.toString)
+ checkAnswer(df, Row(1, 1))
+
+ // Check JSON format
+ Seq("""{"a":1,
"a":1}"""""").toDF().coalesce(1).write.mode("overwrite").text(src.toString)
--- End diff --
nit: duplicate `"""`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]