Description
The code below throws org.apache.spark.sql.AnalysisException: Found duplicate column(s) in the data schema: `camelcase`; for multiple file formats due to a duplicate column in the requested schema.
import org.apache.spark.sql.types._ spark.conf.set("spark.sql.caseSensitive", "false") val formats = Seq("parquet", "orc", "avro", "json") val caseInsensitiveSchema = new StructType().add("LowerCase", LongType).add("camelcase", LongType).add("CamelCase", LongType) formats.map{ format => val path = s"/tmp/$format" spark .range(1L) .selectExpr("id AS lowercase", "id + 1 AS camelCase") .write.mode("overwrite").format(format).save(path) spark.read.schema(caseInsensitiveSchema).format(format).load(path).show }
Similar code with nested schema behaves inconsistently across file formats and sometimes returns incorrect results:
import org.apache.spark.sql.types._ spark.conf.set("spark.sql.caseSensitive", "false") val formats = Seq("parquet", "orc", "avro", "json") val caseInsensitiveSchema = new StructType().add("StructColumn", new StructType().add("LowerCase", LongType).add("camelcase", LongType).add("CamelCase", LongType)) formats.map{ format => val path = s"/tmp/$format" spark .range(1L) .selectExpr("NAMED_STRUCT('lowercase', id, 'camelCase', id + 1) AS StructColumn") .write.mode("overwrite").format(format).save(path) spark.read.schema(caseInsensitiveSchema).format(format).load(path).show }
The desired behavior likely should be returning an exception just like in the flat schema scenario.
Attachments
Issue Links
- relates to
-
SPARK-32510 JDBC doesn't check duplicate column names in nested structures
- Resolved
-
SPARK-20460 Make it more consistent to handle column name duplication
- Resolved
- links to