diff options
author | Reynold Xin <rxin@databricks.com> | 2015-06-01 21:13:15 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2015-06-01 21:13:15 -0700 |
commit | 89f642a0e8c3a6bc9149a0bb413f1a8939cb0283 (patch) | |
tree | 767c930033aca07e7f414353b98b4f651f65c0c8 | |
parent | 6396cc0303ceabea53c4df436ffa50b82b7e233f (diff) | |
download | spark-89f642a0e8c3a6bc9149a0bb413f1a8939cb0283.tar.gz spark-89f642a0e8c3a6bc9149a0bb413f1a8939cb0283.tar.bz2 spark-89f642a0e8c3a6bc9149a0bb413f1a8939cb0283.zip |
[SPARK-8026][SQL] Add Column.alias to Scala/Java DataFrame API
Author: Reynold Xin <rxin@databricks.com>
Closes #6565 from rxin/alias and squashes the following commits:
286d880 [Reynold Xin] [SPARK-8026][SQL] Add Column.alias to Scala/Java DataFrame API
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/Column.scala | 12 | ||||
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/Column.scala b/sql/core/src/main/scala/org/apache/spark/sql/Column.scala index b49b1d3272..d3efa83380 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/Column.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/Column.scala @@ -717,6 +717,18 @@ class Column(protected[sql] val expr: Expression) extends Logging { def endsWith(literal: String): Column = this.endsWith(lit(literal)) /** + * Gives the column an alias. Same as `as`. + * {{{ + * // Renames colA to colB in select output. + * df.select($"colA".alias("colB")) + * }}} + * + * @group expr_ops + * @since 1.4.0 + */ + def alias(alias: String): Column = as(alias) + + /** * Gives the column an alias. * {{{ * // Renames colA to colB in select output. diff --git a/sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala index d006b83fc0..b8bb1bff9e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala @@ -27,6 +27,12 @@ import org.apache.spark.sql.types._ class ColumnExpressionSuite extends QueryTest { import org.apache.spark.sql.TestData._ + test("alias") { + val df = Seq((1, Seq(1, 2, 3))).toDF("a", "intList") + assert(df.select(df("a").as("b")).columns.head === "b") + assert(df.select(df("a").alias("b")).columns.head === "b") + } + test("single explode") { val df = Seq((1, Seq(1, 2, 3))).toDF("a", "intList") checkAnswer( |