From a703ef0915894cdc27d7c1a58c51dee6bb3fe6f9 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Thu, 8 Aug 2024 15:53:40 -0700 Subject: [PATCH 1/4] add format checker --- scripts/format_checker.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 scripts/format_checker.sh diff --git a/scripts/format_checker.sh b/scripts/format_checker.sh new file mode 100644 index 00000000..ffc48bb5 --- /dev/null +++ b/scripts/format_checker.sh @@ -0,0 +1,11 @@ +#!/bin/bash -ex + +mvn clean compile + +if [ -z "$(git status --porcelain)" ]; then + echo "Code Format Check: Passed!" +else + echo "Code Format Check: Failed!" + echo "Run 'mvn clean compile' to reformat" + exit 1 +fi \ No newline at end of file From 83e3dc622ea704f003bcb382ca1fae4f28996066 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Thu, 8 Aug 2024 15:54:57 -0700 Subject: [PATCH 2/4] chmod --- scripts/format_checker.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/format_checker.sh diff --git a/scripts/format_checker.sh b/scripts/format_checker.sh old mode 100644 new mode 100755 From e014c2323b38cbc645d1d405bfe140914f585549 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Thu, 8 Aug 2024 16:04:26 -0700 Subject: [PATCH 3/4] create new github action --- .github/workflows/code-format-check.yml | 20 ++++++++++++++++++++ scripts/format_checker.sh | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/code-format-check.yml diff --git a/.github/workflows/code-format-check.yml b/.github/workflows/code-format-check.yml new file mode 100644 index 00000000..ac84376d --- /dev/null +++ b/.github/workflows/code-format-check.yml @@ -0,0 +1,20 @@ +name: Code Format Check +on: + push: + branches: [ main ] + pull_request: + branches: '**' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + - name: Install Java + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Check Format + run: scripts/format_checker.sh + \ No newline at end of file diff --git a/scripts/format_checker.sh b/scripts/format_checker.sh index ffc48bb5..3b4f9af4 100755 --- a/scripts/format_checker.sh +++ b/scripts/format_checker.sh @@ -8,4 +8,4 @@ else echo "Code Format Check: Failed!" echo "Run 'mvn clean compile' to reformat" exit 1 -fi \ No newline at end of file +fi From 6744918560576bd436af3a5fe4a3808c01beb18c Mon Sep 17 00:00:00 2001 From: Bing Li Date: Thu, 8 Aug 2024 16:09:25 -0700 Subject: [PATCH 4/4] reformat --- .../snowflake/snowpark_java/Functions.java | 7 ++++--- .../com/snowflake/snowpark/functions.scala | 11 ++++++++--- .../snowpark_test/JavaFunctionSuite.java | 19 +++++++++++++------ .../snowpark_test/FunctionSuite.scala | 18 +++++++++++------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/snowflake/snowpark_java/Functions.java b/src/main/java/com/snowflake/snowpark_java/Functions.java index 8daaf9fc..65f50020 100644 --- a/src/main/java/com/snowflake/snowpark_java/Functions.java +++ b/src/main/java/com/snowflake/snowpark_java/Functions.java @@ -3986,7 +3986,7 @@ public static Column expr(String s) { *
{@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"  |
    * -----------
    * |[        |
@@ -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.
    *
    * 
{@code
diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala
index 662a00c4..5c6f599f 100644
--- a/src/main/scala/com/snowflake/snowpark/functions.scala
+++ b/src/main/scala/com/snowflake/snowpark/functions.scala
@@ -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
@@ -3151,7 +3156,7 @@ object functions {
    * |1     |
    * --------
    * }}}
- *
+   *
    * @since 1.14.0
    * @param colName Column name.
    * @return Column object ordered in a descending manner.
@@ -3299,7 +3304,7 @@ object functions {
    * |d                  |
    * ---------------------
    * }}}
- *
+   *
    * @since 1.14.0
    * @param c Column to obtain last value.
    * @return Column object.
diff --git a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java
index edddec2e..624ea481 100644
--- a/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java
+++ b/src/test/java/com/snowflake/snowpark_test/JavaFunctionSuite.java
@@ -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);
@@ -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);
   }
 }
diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala
index 806a6ff8..8a89d87b 100644
--- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala
+++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala
@@ -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")
@@ -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)
   }
 
 }