diff options
author | Kousuke Saruta <sarutak@oss.nttdata.co.jp> | 2015-06-28 08:29:07 -0700 |
---|---|---|
committer | Davies Liu <davies@databricks.com> | 2015-06-28 08:29:07 -0700 |
commit | ec784381967506f8db4d6a357c0b72df25a0aa1b (patch) | |
tree | 1fd0cb6e59ab11bc124627daf19d3dbec61aa421 /sql | |
parent | 77da5be6f11a7e9cb1d44f7fb97b93481505afe8 (diff) | |
download | spark-ec784381967506f8db4d6a357c0b72df25a0aa1b.tar.gz spark-ec784381967506f8db4d6a357c0b72df25a0aa1b.tar.bz2 spark-ec784381967506f8db4d6a357c0b72df25a0aa1b.zip |
[SPARK-8686] [SQL] DataFrame should support `where` with expression represented by String
DataFrame supports `filter` function with two types of argument, `Column` and `String`. But `where` doesn't.
Author: Kousuke Saruta <sarutak@oss.nttdata.co.jp>
Closes #7063 from sarutak/SPARK-8686 and squashes the following commits:
180f9a4 [Kousuke Saruta] Added test
d61aec4 [Kousuke Saruta] Add "where" method with String argument to DataFrame
Diffstat (limited to 'sql')
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala | 12 | ||||
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala b/sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala index 0db4df34f9..d75d883075 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala @@ -715,6 +715,18 @@ class DataFrame private[sql]( def where(condition: Column): DataFrame = filter(condition) /** + * Filters rows using the given SQL expression. + * {{{ + * peopleDf.where("age > 15") + * }}} + * @group dfops + * @since 1.5.0 + */ + def where(conditionExpr: String): DataFrame = { + filter(Column(new SqlParser().parseExpression(conditionExpr))) + } + + /** * Groups the [[DataFrame]] using the specified columns, so we can run aggregation on them. * See [[GroupedData]] for all the available aggregate functions. * diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala index 47443a917b..d06b9c5785 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala @@ -160,6 +160,12 @@ class DataFrameSuite extends QueryTest { testData.collect().filter(_.getInt(0) > 90).toSeq) } + test("filterExpr using where") { + checkAnswer( + testData.where("key > 50"), + testData.collect().filter(_.getInt(0) > 50).toSeq) + } + test("repartition") { checkAnswer( testData.select('key).repartition(10).select('key), |