Uh oh!
There was an error while loading. Please reload this page.
[SPARK-12988][SQL] Can't drop columns that contain dots - #10943
[SPARK-12988][SQL] Can't drop columns that contain dots#10943dilipbiswal wants to merge 4 commits into
Conversation
marmbrus
commented
Jan 27, 2016
ok to test |
SparkQA
commented
Jan 27, 2016
Test build #50215 has finished for PR 10943 at commit
|
cloud-fan
commented
Jan 27, 2016
Actually this kind of problem has come out many times, I think we should distinguish cc @rxin |
dilipbiswal
commented
Jan 27, 2016
@cloud-fan Thank you Wenchen for your comments. In my understanding , users need to use back-tick to quote the column names if they wanted them to be treated as a column name as opposed to column path. I tried the following example val df = Seq((1, 2, 3)).toDF("a_b", "a.c", "b.c") Is this not how it is supposed to work ? Can you please elaborate by taking a small |
cloud-fan
commented
Jan 27, 2016
FYI, the PR that fixed a similar problem for |
dilipbiswal
commented
Jan 28, 2016
@cloud-fan Thank you Wenchen. |
dilipbiswal
commented
Jan 31, 2016
@cloud-fan Hi Wenchen, let me know if i have interpreted your suggestion correctly ? Please let me know if something is amiss. df.resolve() has many callers .. so i have not changed its name but have added a comment. Let me know if you want me to refactor it. Thanks.. |
SparkQA
commented
Jan 31, 2016
Test build #50452 has finished for PR 10943 at commit
|
There was a problem hiding this comment.
how about
private[sql] def indexOf(colName: String): Option[Int] = {
val resolver = sqlContext.analyzer.resolver
val index = queryExecution.analyzed.output.indexWhere(f => resolver(f.name, colName))
if (index >= 0) Some(index) else None
}
then we can rewrite withColumn to:
indexOf(colName).map { index =>
select(output.updated(index, col.as(colName)).map(Column(_)) : _*)
}.getOrElse {
select(Column("*"), col.as(colName))
}
There may be better name for this, like resolveToIndex
dilipbiswal
commented
Feb 1, 2016
@cloud-fan Thank you Wenchen. I will try your suggestion and get back. |
dilipbiswal
commented
Feb 1, 2016
@cloud-fan Hi Wenchen, couldn't get the code snippet to compile and i made a change that looks like the following. defwithColumn(colName: String, col: Column):DataFrame= {
valoutput= queryExecution.analyzed.output
indexOf(colName).map {index =>valcolumns= output.zipWithIndex.map {
case (a, i) =>if (i == index) col.as(colName) elseColumn(a)
}
select(columns: _*)
}.getOrElse {
select(Column("*"), col.as(colName))
}
}Does this look okay to you ? Let me know please .. |
cloud-fan
commented
Feb 1, 2016
ah, change |
dilipbiswal
commented
Feb 2, 2016
@cloud-fan Thanks a lot. I have implemented as per your input. |
SparkQA
commented
Feb 2, 2016
Test build #50522 has finished for PR 10943 at commit
|
marmbrus
commented
Feb 2, 2016
test this please |
SparkQA
commented
Feb 2, 2016
Test build #50525 has finished for PR 10943 at commit
|
There was a problem hiding this comment.
do we need to do this? I think for these methods that require column name, user should just pass in an exact column name string, and we don't need to do any extra parsing here, i.e. no resolver, no strip for "`"
There was a problem hiding this comment.
for example, what if a column is named a`a? User should be able to just pass in a`a and we shouldn't strip the "`"
There was a problem hiding this comment.
@cloud-fan Hi Wenchen,
Can you please go through the following comment.
I was trying to address the 3rd bullet in the list. About your second question , per bullet one this should be disallowed ? Please let me know.
dilipbiswal
commented
Feb 2, 2016
@cloud-fan I have incorporated your suggestions except the comment about allowing sorrounding backticks in column name. Once we have a decision, i can remove it. Please let me know. |
dilipbiswal
commented
Feb 2, 2016
@cloud-fan Can we retest please ? |
cloud-fan
commented
Feb 2, 2016
retest this please |
SparkQA
commented
Feb 2, 2016
Test build #50582 has finished for PR 10943 at commit
|
dilipbiswal
commented
Feb 22, 2016
@cloud-fan Hi Wenchen, can you please advice on what is the next step for this PR ? I am thinking that it may require more discussion to decide if we need top keep or remove the df.drop(Column) interface. |
cloud-fan
commented
Feb 23, 2016
Sorry for the delay, we are discussing about this design choice, and will have an agreement this week or next week. Thanks for working on it and sorry for make you waiting :) |
dilipbiswal
commented
Feb 23, 2016
@cloud-fan No issues. Thanks for your reply :-) |
HyukjinKwon
commented
May 6, 2016
ping @cloud-fan |
cloud-fan
commented
May 7, 2016
cc @rxin , looks like we missed this one... |
## What changes were proposed in this pull request? Fixes "Can't drop top level columns that contain dots". This work is based on dilipbiswal's #10943. This PR fixes problems like: ``` scala> Seq((1, 2)).toDF("a.b", "a.c").drop("a.b") org.apache.spark.sql.AnalysisException: cannot resolve '`a.c`' given input columns: [a.b, a.c]; ``` `drop(columnName)` can only be used to drop top level column, so, we should parse the column name literally WITHOUT interpreting dot "." We should also NOT interpret back tick "`", otherwise it is hard to understand what ``` ```aaa```bbb`` ``` actually means. ## How was this patch tested? Unit tests. Author: Sean Zhong <seanzhong@databricks.com> Closes#13306 from clockfly/fix_drop_column.
## What changes were proposed in this pull request? Fixes "Can't drop top level columns that contain dots". This work is based on dilipbiswal's #10943. This PR fixes problems like: ``` scala> Seq((1, 2)).toDF("a.b", "a.c").drop("a.b") org.apache.spark.sql.AnalysisException: cannot resolve '`a.c`' given input columns: [a.b, a.c]; ``` `drop(columnName)` can only be used to drop top level column, so, we should parse the column name literally WITHOUT interpreting dot "." We should also NOT interpret back tick "`", otherwise it is hard to understand what ``` ```aaa```bbb`` ``` actually means. ## How was this patch tested? Unit tests. Author: Sean Zhong <seanzhong@databricks.com> Closes#13306 from clockfly/fix_drop_column. (cherry picked from commit 06514d6) Signed-off-by: Yin Huai <yhuai@databricks.com>
yhuai
commented
Jun 28, 2016
how about we close this pr since #13306 has been merged? |
Closing the following PRs due to requests or unresponsive users. Closesapache#13923Closesapache#14462Closesapache#13123Closesapache#14423 (requested by srowen) Closesapache#14424 (requested by srowen) Closesapache#14101 (requested by jkbradley) Closesapache#10676 (requested by srowen) Closesapache#10943 (requested by yhuai) Closesapache#9936Closesapache#10701
Neither of theses works:
val df = Seq((1, 1)).toDF("a_b", "a.c")
df.drop("a.c").collect()
df: org.apache.spark.sql.DataFrame = [a_b: int, a.c: int]
val df = Seq((1, 1)).toDF("a_b", "a.c")
df.drop("
a.c").collect()df: org.apache.spark.sql.DataFrame = [a_b: int, a.c: int]
Given that you can't use drop to drop subfields, it seems to me that we should treat the column name literally (i.e. as though it is wrapped in back ticks)