Skip to content

Commit

Permalink
[SEDONA-541] Allow concurrent snowflake testers: PR 2/2 (#1358)
Browse files Browse the repository at this point in the history
* Use random db name

* Fix the silly bug

* Make sure the same database is shared among all test cases

* Fix

* Fix again
  • Loading branch information
jiayuasu authored Apr 25, 2024
1 parent 378f2f0 commit 0b083d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public static SnowClient newFromEnv() throws SQLException {
prop.put("user", System.getenv("SNOWFLAKE_USER"));
prop.put("password", System.getenv("SNOWFLAKE_PASSWORD"));
}
prop.put("db", System.getenv("SNOWFLAKE_DB"));
prop.put("schema", System.getenv("SNOWFLAKE_SCHEMA"));
prop.put("warehouse", System.getenv("SNOWFLAKE_WAREHOUSE"));
prop.put("role", System.getenv("SNOWFLAKE_ROLE"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public class TestBase extends TestCase {

private static boolean jarUploaded = false;

String snowflake_db_name = generateRandomString(8);
private static String snowflake_db_name = null;

public void registerUDF(String functionName, Class<?> ... paramTypes) {
try {
String ddl = UDFDDLGenerator.buildUDFDDL(UDFs.class.getMethod(
functionName,
paramTypes
), buildDDLConfigs, "@ApacheSedona", false, "");
System.out.println(ddl);
ResultSet res = snowClient.executeQuery(ddl);
res.next();
assert res.getString(1).contains("successfully created");
Expand All @@ -77,7 +76,6 @@ public void registerUDFV2(String functionName, Class<?> ... paramTypes) {
functionName,
paramTypes
), buildDDLConfigs, "@ApacheSedona", false, "");
System.out.println(ddl);
ResultSet res = snowClient.executeQuery(ddl);
res.next();
assert res.getString(1).contains("successfully created");
Expand All @@ -89,7 +87,6 @@ public void registerUDFV2(String functionName, Class<?> ... paramTypes) {
public void registerUDTF(Class<?> clz) {
try {
String ddl = UDTFDDLGenerator.buildUDTFDDL(clz, buildDDLConfigs, "@ApacheSedona", false, "");
System.out.println(ddl);
ResultSet res = snowClient.executeQuery(ddl);
res.next();
assert res.getString(1).contains("successfully created");
Expand All @@ -109,6 +106,8 @@ public void init() throws SQLException {
System.out.println("Using Snowflake DB: " + snowflake_db_name);
// upload libraries
if (!jarUploaded) {
snowflake_db_name = "TMP_TESTDB_" + generateRandomString(8);
System.out.println("Creating Snowflake DB: " + snowflake_db_name);
// drop then create db to make sure test env fresh
snowClient.executeQuery("drop database if exists " + snowflake_db_name);
snowClient.executeQuery("create database " + snowflake_db_name);
Expand All @@ -120,6 +119,11 @@ public void init() throws SQLException {
snowClient.uploadFile(String.format("tmp/geotools-wrapper-%s.jar", geotoolsVersion), "ApacheSedona");
jarUploaded = true;
}
else {
System.out.println("Using Snowflake DB: " + snowflake_db_name);
snowClient.executeQuery("use database " + snowflake_db_name);
snowClient.executeQuery("use schema " + System.getenv("SNOWFLAKE_SCHEMA"));
}
registerDependantUDFs();
}

Expand All @@ -128,6 +132,7 @@ public void tearDown()
try {
System.out.println("Dropping Snowflake DB: " + snowflake_db_name);
snowClient.executeQuery("drop database if exists " + snowflake_db_name);
jarUploaded = false;
}
catch (SQLException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 0b083d0

Please sign in to comment.