spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dongjoon Hyun (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-17041) Columns in schema are no longer case sensitive when reading csv file
Date Sat, 13 Aug 2016 22:16:20 GMT

    [ https://issues.apache.org/jira/browse/SPARK-17041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15420105#comment-15420105
] 

Dongjoon Hyun commented on SPARK-17041:
---------------------------------------

Hi, [~barrybecker4]
I reproduced your problems and I think I can give you the solution.
{code}
scala> spark.read.format("csv").option("header", "false").option("inferSchema", "false").schema(StructType(Seq(StructField("c",
StringType, false), StructField("C", StringType, false)))).csv("/tmp/csv_caseSensitive").show
org.apache.spark.sql.AnalysisException: Reference 'c' is ambiguous, could be: c#45, c#46.;
...

scala> sql("set spark.sql.caseSensitive=true")
res9: org.apache.spark.sql.DataFrame = [key: string, value: string]

scala> spark.read.format("csv").option("header", "false").option("inferSchema", "false").schema(StructType(Seq(StructField("c",
StringType, false), StructField("C", StringType, false)))).csv("/tmp/csv_caseSensitive").show
+---+---+
|  c|  C|
+---+---+
| c1| C1|
|  1|  2|
+---+---+
{code}

> Columns in schema are no longer case sensitive when reading csv file
> --------------------------------------------------------------------
>
>                 Key: SPARK-17041
>                 URL: https://issues.apache.org/jira/browse/SPARK-17041
>             Project: Spark
>          Issue Type: Bug
>          Components: Input/Output
>    Affects Versions: 2.0.0
>            Reporter: Barry Becker
>
> It used to be (in spark 1.6.2) that I could read a csv file that had columns with  names
that differed only by case. For example, one column may be "output" and another called "Output".
Now (with spark 2.0.0) if I try to read such a file, I get an error like this:
> {code}
> org.apache.spark.sql.AnalysisException: Reference 'Output' is ambiguous, could be: Output#1263,
Output#1295.;
> {code}
> The schema (dfSchema below) that I pass to the csv read looks like this:
> {code}
> StructType( StructField(Output,StringType,true), ... StructField(output,StringType,true),
...)
> {code}
> The code that does the read is this
> {code}
> sqlContext.read
>           .format("csv")
>           .option("header", "false") // Use first line of all files as header
>           .option("inferSchema", "false") // Automatically infer data types
>           .schema(dfSchema)
>           .csv(dataFile)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message