Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1619170 Create New Github Action to Check the Code Format #140

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/code-format-check.yml
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions scripts/format_checker.sh
Original file line number Diff line number Diff line change
@@ -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
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
Loading