spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject spark git commit: [SPARK-8026][SQL] Add Column.alias to Scala/Java DataFrame API
Date Tue, 02 Jun 2015 04:13:24 GMT
Repository: spark
Updated Branches:
  refs/heads/branch-1.4 efc0e0532 -> 8ac23762e


[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

(cherry picked from commit 89f642a0e8c3a6bc9149a0bb413f1a8939cb0283)
Signed-off-by: Reynold Xin <rxin@databricks.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/8ac23762
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/8ac23762
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/8ac23762

Branch: refs/heads/branch-1.4
Commit: 8ac23762ec1033ea0944d88246ada9f628ee9948
Parents: efc0e05
Author: Reynold Xin <rxin@databricks.com>
Authored: Mon Jun 1 21:13:15 2015 -0700
Committer: Reynold Xin <rxin@databricks.com>
Committed: Mon Jun 1 21:13:21 2015 -0700

----------------------------------------------------------------------
 .../src/main/scala/org/apache/spark/sql/Column.scala    | 12 ++++++++++++
 .../org/apache/spark/sql/ColumnExpressionSuite.scala    |  6 ++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/8ac23762/sql/core/src/main/scala/org/apache/spark/sql/Column.scala
----------------------------------------------------------------------
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 b49b1d3..d3efa83 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.

http://git-wip-us.apache.org/repos/asf/spark/blob/8ac23762/sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala
----------------------------------------------------------------------
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 d006b83..b8bb1bf 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(


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org


Mime
View raw message