Skip to content

Commit

Permalink
SNOW-946574 Support Java 17 when Register UDF (#74)
Browse files Browse the repository at this point in the history
* support java 17 in UDF

* support rsa key

* add test for java 11 and 17

* fix test
  • Loading branch information
sfc-gh-bli authored Dec 13, 2023
1 parent a920b69 commit 9414376
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/precommit-udf-multiple-jdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: precommit test - udf with multiple JDK
on:
push:
branches: [ main ]
pull_request:
branches: '**'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 17 ]
fail-fast: false
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Decrypt profile.properties
run: .github/scripts/decrypt_profile.sh
env:
PROFILE_PASSWORD: ${{ secrets.PROFILE_PASSWORD }}
- name: Run test
run: mvn -Dgpg.skip test -Dsuites="com.snowflake.snowpark_test.AlwaysCleanUDFSuite"
2 changes: 2 additions & 0 deletions fips-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@
--add-opens=java.base/java.util=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-opens=java.base/sun.security.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand All @@ -588,6 +589,7 @@
--add-opens=java.base/java.util=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-opens=java.base/sun.security.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@
--add-opens=java.base/java.util=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-opens=java.base/sun.security.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand All @@ -620,6 +621,7 @@
--add-opens=java.base/java.util=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-opens=java.base/sun.security.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,8 @@ class UDXRegistrationHandler(session: Session) extends Logging {
} else ""
val createUdfQuery = s"CREATE $tempType " +
s"FUNCTION $udfName($sqlFunctionArgs) RETURNS " +
s"$returnSqlType LANGUAGE JAVA $importSql HANDLER='$className.$methodName' " +
s"$returnSqlType LANGUAGE JAVA $getRuntimeVersion " +
s"$importSql HANDLER='$className.$methodName' " +
s"target_path='$targetJarStageLocation' " + packageSql +
"AS $$ \n" + code + "\n$$"
logDebug(s"""
Expand Down Expand Up @@ -1156,4 +1157,15 @@ class UDXRegistrationHandler(session: Session) extends Logging {
}
}
}

private def getRuntimeVersion: String = {
val version = Utils.JavaVersion
if (version.startsWith("17")) {
"runtime_version = '17'"
} else {
// for any other version of JVM, let's use the default jvm, which is java 11.
// it is current behavior.
""
}
}
}
3 changes: 2 additions & 1 deletion src/test/scala/com/snowflake/snowpark_test/UDFSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,8 @@ trait UDFSuite extends TestData {

@UDFTest
class AlwaysCleanUDFSuite extends UDFSuite with AlwaysCleanSession {
test("Test with closure cleaner enabled") {
// todo: closure cleaner doesn't work with Java 17, fix in SNOW-991144
ignore("Test with closure cleaner enabled") {
val myDf = session.sql("select 'Raymond' NAME")
val readFileUdf = udf(TestClassWithoutFieldAccess.run)
myDf.withColumn("CONCAT", readFileUdf(col("NAME"))).show()
Expand Down

0 comments on commit 9414376

Please sign in to comment.