From 6f962b633252e9f079aed27d14c84a304cbd4ff9 Mon Sep 17 00:00:00 2001 From: Shyamala Jayabalan Date: Tue, 6 Aug 2024 15:28:54 -0400 Subject: [PATCH 01/14] Added functions to scala and java --- .../snowflake/snowpark_java/Functions.java | 59 +++++++++++++++++ .../com/snowflake/snowpark/functions.scala | 66 +++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/src/main/java/com/snowflake/snowpark_java/Functions.java b/src/main/java/com/snowflake/snowpark_java/Functions.java index 56d8d08b..efc03e10 100644 --- a/src/main/java/com/snowflake/snowpark_java/Functions.java +++ b/src/main/java/com/snowflake/snowpark_java/Functions.java @@ -3879,6 +3879,65 @@ public static Column listagg(Column col, String delimiter) { public static Column listagg(Column col) { return new Column(com.snowflake.snowpark.functions.listagg(col.toScalaColumn())); } + /** + * Wrapper for Snowflake built-in reverse function. Gets the reversed string. Reverses the order + * of characters in a string, or of bytes in a binary value. The returned value is the same length + * as the input, but with the characters/bytes in reverse order. If subject is NULL, the result is + * also NULL. Example: SELECT REVERSE('Hello, world!'); +--------------------------+ | + * REVERSE('HELLO, WORLD!') | |--------------------------| | !dlrow ,olleH | + * +--------------------------+ + * + * @since 1.12.0 + * @param c Column to be reverse. + * @return Column object. + */ + public static Column reverse(Column name) { + return new Column(com.snowflake.snowpark.functions.reverse(name.toScalaColumn())); + } + + /** + * Wrapper for Snowflake built-in isnull function. Gets a boolean depending if value is NULL or + * not. Return true if the value in the column is null. Example:: >>> from + * snowflake.snowpark.functions import is_null >>> df = session.create_dataframe([1.2, + * float("nan"), None, 1.0], schema=["a"]) >>> df.select(is_null("a").as_("a")).collect() + * [Row(A=False), Row(A=False), Row(A=True), Row(A=False)] + * + * @since 1.12.0 + * @param c Column to qnalize if it is null value. + * @return Column object. + */ + public static Column isnull(Column c) { + return new Column(com.snowflake.snowpark.functions.isnull(c.toScalaColumn())); + } + + /** + * Wrapper for Snowflake built-in conv function. Convert number with from and to base. + * + * @since 1.10.0 + * @param c Column to be converted. + * @param fromBase Column from base format. + * @param toBase Column to base format. + * @return Column object. + */ + public static Column conv(Column c, Integer fromBase, Integer toBase) { + return new Column(com.snowflake.snowpark.functions.conv(c.toScalaColumn(), fromBase, toBase)); + } + /** + * Returns the current Unix timestamp (in seconds) as a long. Extracts a specified date or time + * portion from a date, time, or timestamp. how: EXTRACT , HOUR / MINUTE / SECOND , YEAR* / DAY* / + * WEEK* / MONTH / QUARTER Construction - DATE_PART( , ) + * SELECT TO_TIMESTAMP('2013-05-08T23:39:20.123-07:00') AS "TIME_STAMP1", DATE_PART(EPOCH_SECOND, + * "TIME_STAMP1") AS "EXTRACTED EPOCH SECOND"; + * +-------------------------+------------------------+ | TIME_STAMP1 | EXTRACTED EPOCH SECOND | + * |-------------------------+------------------------| | 2013-05-08 23:39:20.123 | 1368056360 | + * +-------------------------+------------------------+ + * + * @since 1.12.0 + * @note All calls of `unix_timestamp` within the same query return the same value + */ + public static Column unix_timestamp() { + return new Column(com.snowflake.snowpark.functions.unix_timestamp()); + } /** * Calls a user-defined function (UDF) by name. diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala index a7fd9ff0..b9bc93a4 100644 --- a/src/main/scala/com/snowflake/snowpark/functions.scala +++ b/src/main/scala/com/snowflake/snowpark/functions.scala @@ -3140,6 +3140,72 @@ object functions { */ def listagg(col: Column): Column = listagg(col, "", isDistinct = false) + /** + * Wrapper for Snowflake built-in reverse function. Gets the reversed string. + * Reverses the order of characters in a string, or of bytes in a binary value. + * The returned value is the same length as the input, but with the characters/bytes + * in reverse order. If subject is NULL, the result is also NULL. + * Example: SELECT REVERSE('Hello, world!'); + *+--------------------------+ + *| REVERSE('HELLO, WORLD!') | + *|--------------------------| + *| !dlrow ,olleH | + *+--------------------------+ + + * @since 1.12.0 + * @param c Column to be reverse. + * @return Column object. + */ + def reverse(c: Column): Column = + builtin("reverse")(c) + + /** + * Wrapper for Snowflake built-in isnull function. Gets a boolean + * depending if value is NULL or not. + * Return true if the value in the column is null. + *Example:: + * >>> from snowflake.snowpark.functions import is_null + * >>> df = session.create_dataframe([1.2, float("nan"), None, 1.0], + * schema=["a"]) + * >>> df.select(is_null("a").as_("a")).collect() + * [Row(A=False), Row(A=False), Row(A=True), Row(A=False)] + * @since 1.12.0 + * @param c Column to qnalize if it is null value. + * @return Column object. + */ + def isnull(c: Column): Column = is_null(c) + + /** + * Wrapper for Snowflake built-in conv function. Convert number with from and to base. + * @since 1.10.0 + * @param c Column to be converted. + * @param fromBase Column from base format. + * @param toBase Column to base format. + * @return Column object. + */ + def conv(c: Column, fromBase: Int, toBase: Int): Column = + callBuiltin("conv", c, fromBase, toBase) + + /** + * Returns the current Unix timestamp (in seconds) as a long. + * Extracts a specified date or time portion from a date, time, or timestamp. + * how: + * EXTRACT , HOUR / MINUTE / SECOND , YEAR* / DAY* / WEEK* / MONTH / QUARTER + * Construction - DATE_PART( , ) + * SELECT TO_TIMESTAMP('2013-05-08T23:39:20.123-07:00') AS "TIME_STAMP1", + * DATE_PART(EPOCH_SECOND, "TIME_STAMP1") AS "EXTRACTED EPOCH SECOND"; + * +-------------------------+------------------------+ + * | TIME_STAMP1 | EXTRACTED EPOCH SECOND | + * |-------------------------+------------------------| + * | 2013-05-08 23:39:20.123 | 1368056360 | + * +-------------------------+------------------------+ + * @since 1.12.0 + * @note All calls of `unix_timestamp` within the same query return the same value + */ + def unix_timestamp(): Column = { + builtin("date_part")("epoch_second", current_timestamp()) + } + /** * Invokes a built-in snowflake function with the specified name and arguments. * Arguments can be of two types From bcb076d5e4d8976a5ddd6bd21f1aeb86ea2c1347 Mon Sep 17 00:00:00 2001 From: Shyamala Jayabalan Date: Thu, 8 Aug 2024 09:19:50 -0400 Subject: [PATCH 02/14] Added test cases --- .../snowflake/snowpark_test/FunctionSuite.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index e473de12..17302628 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2178,6 +2178,22 @@ trait FunctionSuite extends TestData { sort = false) } + test("reverse") { + val data = Seq("cat").toDF("a") + checkAnswer( + data.select(reverse(col("a"))), + Seq(Row("tac")), + sort = false) + } + + test("isnull") { + val data = Seq("cat").toDF("a") + checkAnswer( + data.select(isnull(col("a"))), + Seq(Row("tac")), + sort = false) + } + } class EagerFunctionSuite extends FunctionSuite with EagerSession From eea9fc5bea552007f6c4748380b3afb00760c4e1 Mon Sep 17 00:00:00 2001 From: Shyamala Jayabalan Date: Thu, 15 Aug 2024 18:52:27 -0400 Subject: [PATCH 03/14] modified --- .../snowflake/snowpark_java/Functions.java | 5 ++-- .../com/snowflake/snowpark/functions.scala | 5 ++-- .../snowpark_test/JavaFunctionSuite.java | 6 +++++ .../snowpark_test/FunctionSuite.scala | 25 ++++++++++--------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/snowflake/snowpark_java/Functions.java b/src/main/java/com/snowflake/snowpark_java/Functions.java index efc03e10..82b94a92 100644 --- a/src/main/java/com/snowflake/snowpark_java/Functions.java +++ b/src/main/java/com/snowflake/snowpark_java/Functions.java @@ -7,6 +7,7 @@ import com.snowflake.snowpark_java.udf.*; import java.util.List; import java.util.function.Supplier; +import net.snowflake.client.jdbc.internal.org.checkerframework.checker.units.qual.C; /** * Provides utility functions that generate Column expression that you can pass to DataFrame @@ -3935,8 +3936,8 @@ public static Column conv(Column c, Integer fromBase, Integer toBase) { * @since 1.12.0 * @note All calls of `unix_timestamp` within the same query return the same value */ - public static Column unix_timestamp() { - return new Column(com.snowflake.snowpark.functions.unix_timestamp()); + public static Column unix_timestamp(Column C) { + return new Column(com.snowflake.snowpark.functions.unix_timestamp(C.toScalaColumn())); } /** diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala index b9bc93a4..4898005d 100644 --- a/src/main/scala/com/snowflake/snowpark/functions.scala +++ b/src/main/scala/com/snowflake/snowpark/functions.scala @@ -11,6 +11,7 @@ import com.snowflake.snowpark.internal.{ import scala.reflect.runtime.universe.TypeTag import scala.util.Random +import java.util.StringJoiner /** * Provides utility functions that generate [[Column]] expressions that you can pass to @@ -3202,8 +3203,8 @@ object functions { * @since 1.12.0 * @note All calls of `unix_timestamp` within the same query return the same value */ - def unix_timestamp(): Column = { - builtin("date_part")("epoch_second", current_timestamp()) + def unix_timestamp(c: Column): Column = { + builtin("date_part")("epoch_second", c) } /** diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index 6ee298d3..6a293cae 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2764,4 +2764,10 @@ public void any_value() { assert result.length == 1; assert result[0].getInt(0) == 1 || result[0].getInt(0) == 2 || result[0].getInt(0) == 3; } + + @Test + public void reverse() { + DataFrame df = getSession().sql("select * from values('cat') as t(a)"); + checkAnswer(df.select(Functions.reverse(df.col("a"))), new Row[] {Row.create("tac")}, false); + } } diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index 17302628..859fc189 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2178,22 +2178,23 @@ trait FunctionSuite extends TestData { sort = false) } - test("reverse") { + test("reverse") { val data = Seq("cat").toDF("a") - checkAnswer( - data.select(reverse(col("a"))), - Seq(Row("tac")), - sort = false) + checkAnswer(data.select(reverse(col("a"))), Seq(Row("tac")), sort = false) } - + test("isnull") { - val data = Seq("cat").toDF("a") - checkAnswer( - data.select(isnull(col("a"))), - Seq(Row("tac")), - sort = false) + val data = Seq("1", null).toDF("a") + checkAnswer(data.select(isnull(col("a"))), Seq(Row(true, false)), sort = false) + } + test("conv") { + val data = Seq("010101").toDF("a") + checkAnswer(data.select(conv(col("a"), 2, 16)), Seq(Row("15")), sort = false) + } + test("unix_timestamp") { + val data = Seq("2024-04-08T23:39:20.123-07:00").toDF("a") + checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1712619560123")), sort = false) } - } class EagerFunctionSuite extends FunctionSuite with EagerSession From bdf0ba90d5595e75add96166bab6c6a915435ca0 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 14:52:37 -0400 Subject: [PATCH 04/14] Modified version,comments --- .../snowflake/snowpark_java/Functions.java | 58 +++++++++++++------ .../com/snowflake/snowpark/functions.scala | 8 +-- .../snowpark_test/JavaFunctionSuite.java | 21 +++++++ 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/snowflake/snowpark_java/Functions.java b/src/main/java/com/snowflake/snowpark_java/Functions.java index 82b94a92..0bf44a2e 100644 --- a/src/main/java/com/snowflake/snowpark_java/Functions.java +++ b/src/main/java/com/snowflake/snowpark_java/Functions.java @@ -3884,12 +3884,21 @@ public static Column listagg(Column col) { * Wrapper for Snowflake built-in reverse function. Gets the reversed string. Reverses the order * of characters in a string, or of bytes in a binary value. The returned value is the same length * as the input, but with the characters/bytes in reverse order. If subject is NULL, the result is - * also NULL. Example: SELECT REVERSE('Hello, world!'); +--------------------------+ | - * REVERSE('HELLO, WORLD!') | |--------------------------| | !dlrow ,olleH | - * +--------------------------+ + * also NULL. * - * @since 1.12.0 - * @param c Column to be reverse. + *

Example: + * + *

{@code
+   * SELECT REVERSE('Hello, world!');
+   *   +--------------------------+
+   *   | REVERSE('HELLO, WORLD!') |
+   *   |--------------------------|
+   *   | !dlrow ,olleH            |
+   *   +--------------------------+
+   * }
+ * + * @since 1.14.0 + * @param name Column to be reverse. * @return Column object. */ public static Column reverse(Column name) { @@ -3898,13 +3907,18 @@ public static Column reverse(Column name) { /** * Wrapper for Snowflake built-in isnull function. Gets a boolean depending if value is NULL or - * not. Return true if the value in the column is null. Example:: >>> from - * snowflake.snowpark.functions import is_null >>> df = session.create_dataframe([1.2, + * not. Return true if the value in the column is null. + * + *

Example:: + * + *

{@code
+   * >>> from snowflake.snowpark.functions import is_null >>> df = session.create_dataframe([1.2,
    * float("nan"), None, 1.0], schema=["a"]) >>> df.select(is_null("a").as_("a")).collect()
    * [Row(A=False), Row(A=False), Row(A=True), Row(A=False)]
+   * }
* - * @since 1.12.0 - * @param c Column to qnalize if it is null value. + * @since 1.14.0 + * @param c Column to analyze if it is null value. * @return Column object. */ public static Column isnull(Column c) { @@ -3914,7 +3928,7 @@ public static Column isnull(Column c) { /** * Wrapper for Snowflake built-in conv function. Convert number with from and to base. * - * @since 1.10.0 + * @since 1.14.0 * @param c Column to be converted. * @param fromBase Column from base format. * @param toBase Column to base format. @@ -3925,16 +3939,24 @@ public static Column conv(Column c, Integer fromBase, Integer toBase) { } /** * Returns the current Unix timestamp (in seconds) as a long. Extracts a specified date or time - * portion from a date, time, or timestamp. how: EXTRACT , HOUR / MINUTE / SECOND , YEAR* / DAY* / - * WEEK* / MONTH / QUARTER Construction - DATE_PART( , ) - * SELECT TO_TIMESTAMP('2013-05-08T23:39:20.123-07:00') AS "TIME_STAMP1", DATE_PART(EPOCH_SECOND, - * "TIME_STAMP1") AS "EXTRACTED EPOCH SECOND"; - * +-------------------------+------------------------+ | TIME_STAMP1 | EXTRACTED EPOCH SECOND | - * |-------------------------+------------------------| | 2013-05-08 23:39:20.123 | 1368056360 | + * portion from a date, time, or timestamp. All calls of `unix_timestamp` within the same query + * return the same value + * + *

Example - DATE_PART( date_or_time_part ,date_or_time_expr ) + * + *

{@code
+   * SELECT TO_TIMESTAMP('2013-05-08T23:39:20.123-07:00') AS "TIME_STAMP1",
+   *  DATE_PART(EPOCH_SECOND, "TIME_STAMP1") AS "EXTRACTED EPOCH SECOND";
    * +-------------------------+------------------------+
+   * | TIME_STAMP1             | EXTRACTED EPOCH SECOND |
+   * |-------------------------+------------------------|
+   * | 2013-05-08 23:39:20.123 |             1368056360 |
+   * +-------------------------+------------------------+
+   * }
* - * @since 1.12.0 - * @note All calls of `unix_timestamp` within the same query return the same value + * @since 1.14.0 + * @param C Column to be converted. + * @return Column object. */ public static Column unix_timestamp(Column C) { return new Column(com.snowflake.snowpark.functions.unix_timestamp(C.toScalaColumn())); diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala index 4898005d..8fe1ff83 100644 --- a/src/main/scala/com/snowflake/snowpark/functions.scala +++ b/src/main/scala/com/snowflake/snowpark/functions.scala @@ -3153,7 +3153,7 @@ object functions { *| !dlrow ,olleH | *+--------------------------+ - * @since 1.12.0 + * @since 1.14.0 * @param c Column to be reverse. * @return Column object. */ @@ -3170,7 +3170,7 @@ object functions { * schema=["a"]) * >>> df.select(is_null("a").as_("a")).collect() * [Row(A=False), Row(A=False), Row(A=True), Row(A=False)] - * @since 1.12.0 + * @since 1.14.0 * @param c Column to qnalize if it is null value. * @return Column object. */ @@ -3178,7 +3178,7 @@ object functions { /** * Wrapper for Snowflake built-in conv function. Convert number with from and to base. - * @since 1.10.0 + * @since 1.14.0 * @param c Column to be converted. * @param fromBase Column from base format. * @param toBase Column to base format. @@ -3200,7 +3200,7 @@ object functions { * |-------------------------+------------------------| * | 2013-05-08 23:39:20.123 | 1368056360 | * +-------------------------+------------------------+ - * @since 1.12.0 + * @since 1.14.0 * @note All calls of `unix_timestamp` within the same query return the same value */ def unix_timestamp(c: Column): Column = { diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index 6a293cae..8c5310fc 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2770,4 +2770,25 @@ public void reverse() { DataFrame df = getSession().sql("select * from values('cat') as t(a)"); checkAnswer(df.select(Functions.reverse(df.col("a"))), new Row[] {Row.create("tac")}, false); } + + @Test + public void isnull() { + DataFrame df = getSession().sql("select * from values(1.2),(null),(2.3) as T(a)"); + Row[] expected = {Row.create(false), Row.create(true), Row.create(false)}; + checkAnswer(df.select(Functions.isnull(df.col("a"))), expected, false); + } + + public void conv() { + DataFrame df = getSession().sql("select * from values('010101') as t(a)"); + checkAnswer(df.select(Functions.conv(df.col("a"), 2, 16)), new Row[] {Row.create("15")}, false); + } + + public void unix_timestamp() { + DataFrame df = + getSession().sql("select * from values('2024-04-08T23:39:20.123-07:00') as t(a)"); + checkAnswer( + df.select(Functions.unix_timestamp(df.col("a"))), + new Row[] {Row.create("1712619560123")}, + false); + } } From 3179e0b6b0ec25694eaf491ac9c99c27332a101c Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 17:25:23 -0400 Subject: [PATCH 05/14] modified comments and test cases --- .../java/com/snowflake/snowpark_java/Functions.java | 12 ------------ .../scala/com/snowflake/snowpark/functions.scala | 11 ----------- .../snowflake/snowpark_test/JavaFunctionSuite.java | 5 ----- .../com/snowflake/snowpark_test/FunctionSuite.scala | 7 ++----- 4 files changed, 2 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/snowflake/snowpark_java/Functions.java b/src/main/java/com/snowflake/snowpark_java/Functions.java index 0bf44a2e..f0aa6288 100644 --- a/src/main/java/com/snowflake/snowpark_java/Functions.java +++ b/src/main/java/com/snowflake/snowpark_java/Functions.java @@ -3925,18 +3925,6 @@ public static Column isnull(Column c) { return new Column(com.snowflake.snowpark.functions.isnull(c.toScalaColumn())); } - /** - * Wrapper for Snowflake built-in conv function. Convert number with from and to base. - * - * @since 1.14.0 - * @param c Column to be converted. - * @param fromBase Column from base format. - * @param toBase Column to base format. - * @return Column object. - */ - public static Column conv(Column c, Integer fromBase, Integer toBase) { - return new Column(com.snowflake.snowpark.functions.conv(c.toScalaColumn(), fromBase, toBase)); - } /** * Returns the current Unix timestamp (in seconds) as a long. Extracts a specified date or time * portion from a date, time, or timestamp. All calls of `unix_timestamp` within the same query diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala index 8fe1ff83..da284055 100644 --- a/src/main/scala/com/snowflake/snowpark/functions.scala +++ b/src/main/scala/com/snowflake/snowpark/functions.scala @@ -3176,17 +3176,6 @@ object functions { */ def isnull(c: Column): Column = is_null(c) - /** - * Wrapper for Snowflake built-in conv function. Convert number with from and to base. - * @since 1.14.0 - * @param c Column to be converted. - * @param fromBase Column from base format. - * @param toBase Column to base format. - * @return Column object. - */ - def conv(c: Column, fromBase: Int, toBase: Int): Column = - callBuiltin("conv", c, fromBase, toBase) - /** * Returns the current Unix timestamp (in seconds) as a long. * Extracts a specified date or time portion from a date, time, or timestamp. diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index 8c5310fc..edd3dff8 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2778,11 +2778,6 @@ public void isnull() { checkAnswer(df.select(Functions.isnull(df.col("a"))), expected, false); } - public void conv() { - DataFrame df = getSession().sql("select * from values('010101') as t(a)"); - checkAnswer(df.select(Functions.conv(df.col("a"), 2, 16)), new Row[] {Row.create("15")}, false); - } - public void unix_timestamp() { DataFrame df = getSession().sql("select * from values('2024-04-08T23:39:20.123-07:00') as t(a)"); diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index 859fc189..5929f053 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2185,12 +2185,9 @@ trait FunctionSuite extends TestData { test("isnull") { val data = Seq("1", null).toDF("a") - checkAnswer(data.select(isnull(col("a"))), Seq(Row(true, false)), sort = false) - } - test("conv") { - val data = Seq("010101").toDF("a") - checkAnswer(data.select(conv(col("a"), 2, 16)), Seq(Row("15")), sort = false) + checkAnswer(data.select(isnull(col("a"))), Seq(Row(true), Row(false)), sort = false) } + test("unix_timestamp") { val data = Seq("2024-04-08T23:39:20.123-07:00").toDF("a") checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1712619560123")), sort = false) From 741b75c685b03f13fc27e45b0c655184adad0ce7 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 18:19:44 -0400 Subject: [PATCH 06/14] Modified format and test case --- .../com/snowflake/snowpark_test/JavaFunctionSuite.java | 2 -- .../com/snowflake/snowpark_test/FunctionSuite.scala | 10 ++++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index 2658c7ac..dc16494b 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2766,7 +2766,6 @@ public void any_value() { } @Test - public void reverse() { DataFrame df = getSession().sql("select * from values('cat') as t(a)"); checkAnswer(df.select(Functions.reverse(df.col("a"))), new Row[] {Row.create("tac")}, false); @@ -2949,5 +2948,4 @@ public void unbase64() { Row[] expected = {Row.create("test")}; checkAnswer(df.select(Functions.unbase64(Functions.col("a"))), expected, false); } - } diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index e0b632ba..34dbd27f 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2329,13 +2329,15 @@ trait FunctionSuite extends TestData { checkAnswer(data.select(reverse(col("a"))), Seq(Row("tac")), sort = false) } - test("isnull") { - val data = Seq("1", null).toDF("a") - checkAnswer(data.select(isnull(col("a"))), Seq(Row(true), Row(false)), sort = false) + test("NaN and Null") { + checkAnswer( + nanData1.select(equal_nan(col("A")), isnull(col("A"))), + Seq(Row(false, false), Row(true, false), Row(null, true), Row(false, false)), + sort = false) } test("unix_timestamp") { - val data = Seq("2024-04-08T23:39:20.123-07:00").toDF("a") + val data = Seq(Timestamp.valueOf("2024-04-08T23:39:20.123-07:00")).toDF("a") checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1712619560123")), sort = false) } } From 592064cd684a8a985c356ef62d9dced818759c5c Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 18:25:00 -0400 Subject: [PATCH 07/14] Modified format and test case --- src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index 34dbd27f..d6ca3a92 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2329,7 +2329,7 @@ trait FunctionSuite extends TestData { checkAnswer(data.select(reverse(col("a"))), Seq(Row("tac")), sort = false) } - test("NaN and Null") { + test("isnull") { checkAnswer( nanData1.select(equal_nan(col("A")), isnull(col("A"))), Seq(Row(false, false), Row(true, false), Row(null, true), Row(false, false)), From 3660a9a5af4a03b051e8463c34d921ae24728763 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 19:34:58 -0400 Subject: [PATCH 08/14] Modified format and test case --- src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index d6ca3a92..2f12d060 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2337,7 +2337,7 @@ trait FunctionSuite extends TestData { } test("unix_timestamp") { - val data = Seq(Timestamp.valueOf("2024-04-08T23:39:20.123-07:00")).toDF("a") + val data = Seq(Timestamp.valueOf("2024-04-08 23:39:20.123-07:00")).toDF("a") checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1712619560123")), sort = false) } } From 83282add172fb5d2e54fce4669826540a19552d3 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 20:04:45 -0400 Subject: [PATCH 09/14] Modified format and test case --- .../scala/com/snowflake/snowpark_test/FunctionSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index 2f12d060..c086eaf3 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2337,8 +2337,8 @@ trait FunctionSuite extends TestData { } test("unix_timestamp") { - val data = Seq(Timestamp.valueOf("2024-04-08 23:39:20.123-07:00")).toDF("a") - checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1712619560123")), sort = false) + val data = Seq(Timestamp.valueOf("2013-05-08 23:39:20.123")).toDF("a") + checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1368056360")), sort = false) } } From dccbc12b2015f5437b5f36332c0c0998b58f023b Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Tue, 20 Aug 2024 22:14:53 -0400 Subject: [PATCH 10/14] Modified format and test case --- src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index c086eaf3..a5327289 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2337,8 +2337,9 @@ trait FunctionSuite extends TestData { } test("unix_timestamp") { + val expected = Seq(1368056360).toDF("epoch") val data = Seq(Timestamp.valueOf("2013-05-08 23:39:20.123")).toDF("a") - checkAnswer(data.select(unix_timestamp(col("a"))), Seq(Row("1368056360")), sort = false) + checkAnswer(data.select(unix_timestamp(col("a"))), expected, sort = false) } } From a6034026497cf75b20fae34fba4ecb6c1644eef0 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Wed, 21 Aug 2024 20:44:23 -0400 Subject: [PATCH 11/14] Modified comments --- src/main/java/com/snowflake/snowpark_java/Functions.java | 7 +++---- .../com/snowflake/snowpark_test/JavaFunctionSuite.java | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/snowflake/snowpark_java/Functions.java b/src/main/java/com/snowflake/snowpark_java/Functions.java index 87740e6a..1ca240fc 100644 --- a/src/main/java/com/snowflake/snowpark_java/Functions.java +++ b/src/main/java/com/snowflake/snowpark_java/Functions.java @@ -8,7 +8,6 @@ import com.snowflake.snowpark_java.udf.*; import java.util.List; import java.util.function.Supplier; -import net.snowflake.client.jdbc.internal.org.checkerframework.checker.units.qual.C; /** * Provides utility functions that generate Column expression that you can pass to DataFrame @@ -3944,11 +3943,11 @@ public static Column isnull(Column c) { * } * * @since 1.14.0 - * @param C Column to be converted. + * @param c Column to be converted. * @return Column object. */ - public static Column unix_timestamp(Column C) { - return new Column(com.snowflake.snowpark.functions.unix_timestamp(C.toScalaColumn())); + public static Column unix_timestamp(Column c) { + return new Column(com.snowflake.snowpark.functions.unix_timestamp(c.toScalaColumn())); } /** diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index cfd2227c..cbfc9646 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2778,15 +2778,16 @@ public void isnull() { checkAnswer(df.select(Functions.isnull(df.col("a"))), expected, false); } + @Test public void unix_timestamp() { - DataFrame df = - getSession().sql("select * from values('2024-04-08T23:39:20.123-07:00') as t(a)"); + DataFrame df = getSession().sql("select * from values('2013-05-08 23:39:20.123') as t(a)"); checkAnswer( df.select(Functions.unix_timestamp(df.col("a"))), - new Row[] {Row.create("1712619560123")}, + new Row[] {Row.create(1368056360)}, false); } + @Test public void regexp_extract() { DataFrame df = getSession().sql("select * from values('A MAN A PLAN A CANAL') as T(a)"); Row[] expected = {Row.create("MAN")}; @@ -2840,6 +2841,7 @@ public void substring_index() { false); } + @Test public void test_asc() { DataFrame df = getSession().sql("select * from values(3),(1),(2) as t(a)"); Row[] expected = {Row.create(1), Row.create(2), Row.create(3)}; From 072b1db113f8cdfc1ee7af3c2724565bc9f87b91 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Wed, 21 Aug 2024 21:34:32 -0400 Subject: [PATCH 12/14] Modified testcase --- .../com/snowflake/snowpark_test/JavaFunctionSuite.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index cbfc9646..d03021ae 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2780,10 +2780,13 @@ public void isnull() { @Test public void unix_timestamp() { - DataFrame df = getSession().sql("select * from values('2013-05-08 23:39:20.123') as t(a)"); + DataFrame df = + getSession() + .sql( + "select to_timestamp('2013-05-08 23:39:20.123') as a from values('2013-05-08 23:39:20.123') as t(a)"); checkAnswer( df.select(Functions.unix_timestamp(df.col("a"))), - new Row[] {Row.create(1368056360)}, + new Row[] {Row.create(1368081560)}, false); } From fd901a813b7bc93a5b1b85c521b99bb75fe6d0d2 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Thu, 22 Aug 2024 09:32:19 -0400 Subject: [PATCH 13/14] Modified testcase result --- .../java/com/snowflake/snowpark_test/JavaFunctionSuite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java index d03021ae..8b3369f2 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java @@ -2786,7 +2786,7 @@ public void unix_timestamp() { "select to_timestamp('2013-05-08 23:39:20.123') as a from values('2013-05-08 23:39:20.123') as t(a)"); checkAnswer( df.select(Functions.unix_timestamp(df.col("a"))), - new Row[] {Row.create(1368081560)}, + new Row[] {Row.create(1368056360)}, false); } From cb4767ab74ee41a46f11208226430cce38d2a203 Mon Sep 17 00:00:00 2001 From: "shyamala.jayabalan" Date: Thu, 22 Aug 2024 11:15:20 -0400 Subject: [PATCH 14/14] Removed the import string joiner --- src/main/scala/com/snowflake/snowpark/functions.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala index b5018a2b..fd8b7ab1 100644 --- a/src/main/scala/com/snowflake/snowpark/functions.scala +++ b/src/main/scala/com/snowflake/snowpark/functions.scala @@ -12,7 +12,6 @@ import com.snowflake.snowpark.types.TimestampType import scala.reflect.runtime.universe.TypeTag import scala.util.Random -import java.util.StringJoiner /** * Provides utility functions that generate [[Column]] expressions that you can pass to