-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-5579][SQL][DataFrame] Support for project/filter using SQL expressions #4348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import org.apache.spark.api.java.JavaRDD | |
import org.apache.spark.api.python.SerDeUtil | ||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.storage.StorageLevel | ||
import org.apache.spark.sql.catalyst.ScalaReflection | ||
import org.apache.spark.sql.catalyst.{SqlParser, ScalaReflection} | ||
import org.apache.spark.sql.catalyst.analysis.{ResolvedStar, UnresolvedRelation} | ||
import org.apache.spark.sql.catalyst.expressions._ | ||
import org.apache.spark.sql.catalyst.plans.{JoinType, Inner} | ||
|
@@ -124,11 +124,11 @@ private[sql] class DataFrameImpl protected[sql]( | |
} | ||
|
||
override def sort(sortCol: String, sortCols: String*): DataFrame = { | ||
orderBy(apply(sortCol), sortCols.map(apply) :_*) | ||
sort((sortCol +: sortCols).map(apply) :_*) | ||
} | ||
|
||
override def sort(sortExpr: Column, sortExprs: Column*): DataFrame = { | ||
val sortOrder: Seq[SortOrder] = (sortExpr +: sortExprs).map { col => | ||
override def sort(sortExprs: Column*): DataFrame = { | ||
val sortOrder: Seq[SortOrder] = sortExprs.map { col => | ||
col.expr match { | ||
case expr: SortOrder => | ||
expr | ||
|
@@ -143,8 +143,8 @@ private[sql] class DataFrameImpl protected[sql]( | |
sort(sortCol, sortCols :_*) | ||
} | ||
|
||
override def orderBy(sortExpr: Column, sortExprs: Column*): DataFrame = { | ||
sort(sortExpr, sortExprs :_*) | ||
override def orderBy(sortExprs: Column*): DataFrame = { | ||
sort(sortExprs :_*) | ||
} | ||
|
||
override def col(colName: String): Column = colName match { | ||
|
@@ -179,10 +179,20 @@ private[sql] class DataFrameImpl protected[sql]( | |
select((col +: cols).map(Column(_)) :_*) | ||
} | ||
|
||
override def selectExpr(exprs: String*): DataFrame = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one could be merged into select(), column is also a valid expression There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not if it has space ... it will just fail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should work in these cases with this implementation.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea - but asking users to wrap a column name in backticks in strings is fairly annoying. |
||
select(exprs.map { expr => | ||
Column(new SqlParser().parseExpression(expr)) | ||
} :_*) | ||
} | ||
|
||
override def filter(condition: Column): DataFrame = { | ||
Filter(condition.expr, logicalPlan) | ||
} | ||
|
||
override def filter(conditionExpr: String): DataFrame = { | ||
filter(Column(new SqlParser().parseExpression(conditionExpr))) | ||
} | ||
|
||
override def where(condition: Column): DataFrame = { | ||
filter(condition) | ||
} | ||
|
@@ -329,7 +339,7 @@ private[sql] class DataFrameImpl protected[sql]( | |
|
||
override def save(path: String): Unit = { | ||
val dataSourceName = sqlContext.conf.defaultDataSourceName | ||
save(dataSourceName, ("path" -> path)) | ||
save(dataSourceName, "path" -> path) | ||
} | ||
|
||
override def save( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davies take a look at the Python changes.