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

Michael Armbrust commented on SPARK-6635:
-----------------------------------------

+1 to {{withName}} overwriting existing columns.

> DataFrame.withColumn can create columns with identical names
> ------------------------------------------------------------
>
>                 Key: SPARK-6635
>                 URL: https://issues.apache.org/jira/browse/SPARK-6635
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 1.3.0
>            Reporter: Joseph K. Bradley
>
> DataFrame lets you create multiple columns with the same name, which causes 
> problems when you try to refer to columns by name.
> Proposal: If a column is added to a DataFrame with a column of the same name, 
> then the new column should replace the old column.
> {code}
> scala> val df = sc.parallelize(Array(1,2,3)).toDF("x")
> df: org.apache.spark.sql.DataFrame = [x: int]
> scala> val df3 = df.withColumn("x", df("x") + 1)
> df3: org.apache.spark.sql.DataFrame = [x: int, x: int]
> scala> df3.collect()
> res1: Array[org.apache.spark.sql.Row] = Array([1,2], [2,3], [3,4])
> scala> df3("x")
> org.apache.spark.sql.AnalysisException: Reference 'x' is ambiguous, could be: 
> x, x.;
>       at 
> org.apache.spark.sql.catalyst.plans.logical.LogicalPlan.resolve(LogicalPlan.scala:216)
>       at 
> org.apache.spark.sql.catalyst.plans.logical.LogicalPlan.resolve(LogicalPlan.scala:121)
>       at org.apache.spark.sql.DataFrame.resolve(DataFrame.scala:161)
>       at org.apache.spark.sql.DataFrame.col(DataFrame.scala:436)
>       at org.apache.spark.sql.DataFrame.apply(DataFrame.scala:426)
>       at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:26)
>       at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:31)
>       at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:33)
>       at $iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:35)
>       at $iwC$$iwC$$iwC$$iwC.<init>(<console>:37)
>       at $iwC$$iwC$$iwC.<init>(<console>:39)
>       at $iwC$$iwC.<init>(<console>:41)
>       at $iwC.<init>(<console>:43)
>       at <init>(<console>:45)
>       at .<init>(<console>:49)
>       at .<clinit>(<console>)
>       at .<init>(<console>:7)
>       at .<clinit>(<console>)
>       at $print(<console>)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:606)
>       at 
> org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:1065)
>       at 
> org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1338)
>       at 
> org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:840)
>       at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:871)
>       at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:819)
>       at 
> org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:856)
>       at 
> org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
>       at org.apache.spark.repl.SparkILoop.command(SparkILoop.scala:813)
>       at org.apache.spark.repl.SparkILoop.processLine$1(SparkILoop.scala:656)
>       at org.apache.spark.repl.SparkILoop.innerLoop$1(SparkILoop.scala:664)
>       at 
> org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$loop(SparkILoop.scala:669)
>       at 
> org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply$mcZ$sp(SparkILoop.scala:996)
>       at 
> org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:944)
>       at 
> org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:944)
>       at 
> scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
>       at 
> org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$process(SparkILoop.scala:944)
>       at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:1058)
>       at org.apache.spark.repl.Main$.main(Main.scala:31)
>       at org.apache.spark.repl.Main.main(Main.scala)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:606)
>       at 
> org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:569)
>       at 
> org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:166)
>       at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:189)
>       at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:110)
>       at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
> {code}



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

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

Reply via email to