GitHub user izeigerman opened a pull request:
https://github.com/apache/spark/pull/14736
[SPARK-17024][SQL] Weird behaviour of the DataFrame when a column name
contains dots.
## What changes were proposed in this pull request?
The Spark SQL doesnât support field names that contains dots. Itâs not
about queries like `select` but about any manipulations with the dataset.
Here is a dataset example:
```
field1,field1.some,field2,field3.some
"field1","field1.some","field2","field3.some"
```
And a code snippet:
```
scala> spark.sqlContext.read.format("csv").option("header",
"true").option("inferSchema", "true").load(â/tmp/test.csv").collect
```
The result of this operation:
```
org.apache.spark.sql.AnalysisException: Can't extract value from field1#0;
at
org.apache.spark.sql.catalyst.expressions.ExtractValue$.apply(complexTypeExtractors.scala:73)
at
org.apache.spark.sql.catalyst.plans.logical.LogicalPlan$$anonfun$3.apply(LogicalPlan.scala:253)
at
org.apache.spark.sql.catalyst.plans.logical.LogicalPlan$$anonfun$3.apply(LogicalPlan.scala:252)
at
scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:124)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at
org.apache.spark.sql.catalyst.plans.logical.LogicalPlan.resolve(LogicalPlan.scala:252)
at
org.apache.spark.sql.catalyst.plans.logical.LogicalPlan.resolveQuoted(LogicalPlan.scala:168)
at
org.apache.spark.sql.catalyst.plans.logical.LogicalPlan$$anonfun$resolve$1.apply(LogicalPlan.scala:130)
at
org.apache.spark.sql.catalyst.plans.logical.LogicalPlan$$anonfun$resolve$1.apply(LogicalPlan.scala:129)
at
scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at
scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.Iterator$class.foreach(Iterator.scala:893)
â¦.
```
The following code fails with the same error:
```
scala> val df = spark.sqlContext.read.format("csv").option("header",
"true").option("inferSchema", "true").load("/tmp/test.csv")
df: org.apache.spark.sql.DataFrame = [field1: string, field1.some: string
... 2 more fields]
scala> df.select("field1", "`field1.some`", "field2",
"`field3.some`").collect
```
This patch makes `LogicalPlan` treat a dot-separated string as an
attribute's name in case when nested fields resolution fails.
## How was this patch tested?
Tested with a mentioned CSV file in the `CSVSuite` (not committed). I'm not
sure where exactly I should put a test for this. `LogicalPlanSuite` doesn't
look like appropriate place for this.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/izeigerman/spark iaroslav/spark-17024
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/14736.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #14736
----
commit 6059dfce21c071f4022ab6a17316a85748f0729e
Author: Iaroslav Zeigerman <[email protected]>
Date: 2016-08-20T19:18:24Z
fix attribute resolution for the Logical Plan in case when attributes
contain dots in their names.
----
---
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]