spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [spark] ueshin commented on a change in pull request #24232: [SPARK-27297] [SQL] Add higher order functions to scala API
Date Wed, 21 Aug 2019 03:18:03 GMT
ueshin commented on a change in pull request #24232: [SPARK-27297] [SQL] Add higher order functions
to scala API
URL: https://github.com/apache/spark/pull/24232#discussion_r315983284
 
 

 ##########
 File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala
 ##########
 @@ -1917,19 +1921,33 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession
{
       null
     ).toDF("i")
 
+    // transform(i, x -> x + 1)
+    val resA = Seq(
+      Row(Seq(2, 10, 9, 8)),
+      Row(Seq(6, 9, 10, 8, 3)),
+      Row(Seq.empty),
+      Row(null))
+
+    // transform(i, (x, i) -> x + i)
+    val resB = Seq(
+      Row(Seq(1, 10, 10, 10)),
+      Row(Seq(5, 9, 11, 10, 6)),
+      Row(Seq.empty),
+      Row(null))
+
     def testArrayOfPrimitiveTypeNotContainsNull(): Unit = {
-      checkAnswer(df.selectExpr("transform(i, x -> x + 1)"),
-        Seq(
-          Row(Seq(2, 10, 9, 8)),
-          Row(Seq(6, 9, 10, 8, 3)),
-          Row(Seq.empty),
-          Row(null)))
-      checkAnswer(df.selectExpr("transform(i, (x, i) -> x + i)"),
-        Seq(
-          Row(Seq(1, 10, 10, 10)),
-          Row(Seq(5, 9, 11, 10, 6)),
-          Row(Seq.empty),
-          Row(null)))
+      checkAnswer(df.selectExpr("transform(i, x -> x + 1)"), resA)
+      checkAnswer(df.selectExpr("transform(i, (x, i) -> x + i)"), resB)
+
+      checkAnswer(df.select(transform(col("i"), x => x + 1)), resA)
+      checkAnswer(df.select(transform(col("i"), (x, i) => x + i)), resB)
+
+      checkAnswer(df.select(transform(col("i"), new JFunc {
+        def call(x: Column) = x + 1
+      })), resA)
+      checkAnswer(df.select(transform(col("i"), new JFunc2 {
+        def call(x: Column, i: Column) = x + i
+      })), resB)
 
 Review comment:
   Please try this:
   
   ```java
   
   import org.junit.*;
   
   import static org.apache.spark.sql.functions.*;
   
   public class JavaDataFrameFunctionsSuite {
     @Test
     public void testTransform() {
       transform(expr("array(1, 2, 3)"), x -> x);
     }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


Mime
View raw message