Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Aug 8, 2024
1 parent e014c23 commit 6744918
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/snowflake/snowpark_java/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3986,7 +3986,7 @@ public static Column expr(String s) {
* <pre>{@code
* DataFrame df = getSession().sql("select * from values(1,2,3) as T(a,b,c)");
* df.select(Functions.array(df.col("a"), df.col("b"), df.col("c")).as("array")).show();
*-----------
* -----------
* |"ARRAY" |
* -----------
* |[ |
Expand All @@ -4001,10 +4001,11 @@ public static Column expr(String s) {
* @param cols The input column names
* @return Column object as array.
*/
public static Column array(Column... cols) { return array_construct(cols); }
public static Column array(Column... cols) {
return array_construct(cols);
}

/**
*
* Converts an input expression into the corresponding date in the specified date format.
*
* <pre>{@code
Expand Down
11 changes: 8 additions & 3 deletions src/main/scala/com/snowflake/snowpark/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package com.snowflake.snowpark

import com.snowflake.snowpark.internal.analyzer._
import com.snowflake.snowpark.internal.ScalaFunctions._
import com.snowflake.snowpark.internal.{ErrorMessage, OpenTelemetry, UDXRegistrationHandler, Utils}
import com.snowflake.snowpark.internal.{
ErrorMessage,
OpenTelemetry,
UDXRegistrationHandler,
Utils
}
import com.snowflake.snowpark.types.TimestampType

import scala.reflect.runtime.universe.TypeTag
Expand Down Expand Up @@ -3151,7 +3156,7 @@ object functions {
* |1 |
* --------
* }}}
*
*
* @since 1.14.0
* @param colName Column name.
* @return Column object ordered in a descending manner.
Expand Down Expand Up @@ -3299,7 +3304,7 @@ object functions {
* |d |
* ---------------------
* }}}
*
*
* @since 1.14.0
* @param c Column to obtain last value.
* @return Column object.
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -2783,9 +2783,8 @@ public void test_desc() {

@Test
public void test_size() {
DataFrame df = getSession()
.sql(
"select array_construct(a,b,c) as arr from values(1,2,3) as T(a,b,c)");
DataFrame df =
getSession().sql("select array_construct(a,b,c) as arr from values(1,2,3) as T(a,b,c)");
Row[] expected = {Row.create(3)};

checkAnswer(df.select(Functions.size(Functions.col("arr"))), expected, false);
Expand Down Expand Up @@ -2815,10 +2814,18 @@ public void date_format() {

@Test
public void last() {
DataFrame df = getSession().sql("select * from values (5, 'a', 10), (5, 'b', 20),\n" +
" (3, 'd', 15), (3, 'e', 40) as T(grade,name,score)");
DataFrame df =
getSession()
.sql(
"select * from values (5, 'a', 10), (5, 'b', 20),\n"
+ " (3, 'd', 15), (3, 'e', 40) as T(grade,name,score)");

Row[] expected = {Row.create("a"), Row.create("a"), Row.create("d"), Row.create("d")};
checkAnswer(df.select(Functions.last(df.col("name")).over(Window.partitionBy(df.col("grade")).orderBy(df.col("score").desc()))), expected, false);
checkAnswer(
df.select(
Functions.last(df.col("name"))
.over(Window.partitionBy(df.col("grade")).orderBy(df.col("score").desc()))),
expected,
false);
}
}
18 changes: 11 additions & 7 deletions src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ trait FunctionSuite extends TestData {
val expected = Seq((3)).toDF("size")
checkAnswer(input.select(size(col("size"))), expected, sort = false)
}

test("expr function") {

val input = Seq(1, 2, 3).toDF("id")
Expand All @@ -2226,19 +2226,23 @@ trait FunctionSuite extends TestData {
val input = Seq("2023-10-10", "2022-05-15").toDF("date")
val expected = Seq("2023/10/10", "2022/05/15").toDF("formatted_date")

checkAnswer(input.select(date_format(col("date"), "YYYY/MM/DD").as("formatted_date")),
expected, sort = false)
checkAnswer(
input.select(date_format(col("date"), "YYYY/MM/DD").as("formatted_date")),
expected,
sort = false)
}

test("last function") {

val input = Seq((5, "a", 10), (5, "b", 20),
(3, "d", 15), (3, "e", 40)).toDF("grade", "name", "score")
val input =
Seq((5, "a", 10), (5, "b", 20), (3, "d", 15), (3, "e", 40)).toDF("grade", "name", "score")
val window = Window.partitionBy(col("grade")).orderBy(col("score").desc)
val expected = Seq("a", "a", "d", "d").toDF("last_score_name")

checkAnswer(input.select(last(col("name")).over(window).as("last_score_name")),
expected, sort = false)
checkAnswer(
input.select(last(col("name")).over(window).as("last_score_name")),
expected,
sort = false)
}

}
Expand Down

0 comments on commit 6744918

Please sign in to comment.