This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 576b04d98 [test] Add test for hive-conf-dir in Spark catalog. (#4359)
576b04d98 is described below

commit 576b04d983bcde1cfb4502061d47462fc5bc30fc
Author: HunterXHunter <[email protected]>
AuthorDate: Wed Oct 23 21:56:30 2024 +0800

    [test] Add test for hive-conf-dir in Spark catalog. (#4359)
---
 .../paimon/spark/SparkCatalogWithHiveTest.java     | 28 +++++++++++++++++++++-
 .../spark/SparkGenericCatalogWithHiveTest.java     | 28 +++++++++++++++++++++-
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git 
a/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkCatalogWithHiveTest.java
 
b/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkCatalogWithHiveTest.java
index 22811af39..04159b94a 100644
--- 
a/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkCatalogWithHiveTest.java
+++ 
b/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkCatalogWithHiveTest.java
@@ -27,7 +27,10 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
+import java.io.FileNotFoundException;
+
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 /** Base tests for spark read. */
 public class SparkCatalogWithHiveTest {
@@ -48,7 +51,7 @@ public class SparkCatalogWithHiveTest {
 
     @Test
     public void testCreateFormatTable(@TempDir java.nio.file.Path tempDir) {
-        // firstly, we use hive metastore to creata table, and check the 
result.
+        // firstly, we use hive metastore to create table, and check the 
result.
         Path warehousePath = new Path("file:" + tempDir.toString());
         SparkSession spark =
                 SparkSession.builder()
@@ -107,4 +110,27 @@ public class SparkCatalogWithHiveTest {
                 .isGreaterThan(0);
         spark1.close();
     }
+
+    @Test
+    public void testSpecifyHiveConfDir(@TempDir java.nio.file.Path tempDir) {
+        Path warehousePath = new Path("file:" + tempDir.toString());
+        SparkSession spark =
+                SparkSession.builder()
+                        
.config("spark.sql.catalog.spark_catalog.hive-conf-dir", "nonExistentPath")
+                        .config("spark.sql.warehouse.dir", 
warehousePath.toString())
+                        // with hive metastore
+                        .config("spark.sql.catalogImplementation", "hive")
+                        .config(
+                                "spark.sql.catalog.spark_catalog",
+                                SparkGenericCatalog.class.getName())
+                        .master("local[2]")
+                        .getOrCreate();
+
+        assertThatThrownBy(() -> spark.sql("CREATE DATABASE my_db"))
+                .rootCause()
+                .isInstanceOf(FileNotFoundException.class)
+                .hasMessageContaining("nonExistentPath");
+
+        spark.close();
+    }
 }
diff --git 
a/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkGenericCatalogWithHiveTest.java
 
b/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkGenericCatalogWithHiveTest.java
index b0f1749df..84ea1ab5c 100644
--- 
a/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkGenericCatalogWithHiveTest.java
+++ 
b/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkGenericCatalogWithHiveTest.java
@@ -27,7 +27,10 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
+import java.io.FileNotFoundException;
+
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /** Base tests for spark read. */
@@ -100,7 +103,7 @@ public class SparkGenericCatalogWithHiveTest {
 
     @Test
     public void testBuildWithHive(@TempDir java.nio.file.Path tempDir) {
-        // firstly, we use hive metastore to creata table, and check the 
result.
+        // firstly, we use hive metastore to create table, and check the 
result.
         Path warehousePath = new Path("file:" + tempDir.toString());
         SparkSession spark =
                 SparkSession.builder()
@@ -148,4 +151,27 @@ public class SparkGenericCatalogWithHiveTest {
                                 .map(Object::toString))
                 .containsExactlyInAnyOrder("t1");
     }
+
+    @Test
+    public void testHiveCatalogOptions(@TempDir java.nio.file.Path tempDir) {
+        Path warehousePath = new Path("file:" + tempDir.toString());
+        SparkSession spark =
+                SparkSession.builder()
+                        
.config("spark.sql.catalog.spark_catalog.hive-conf-dir", "nonExistentPath")
+                        .config("spark.sql.warehouse.dir", 
warehousePath.toString())
+                        // with hive metastore
+                        .config("spark.sql.catalogImplementation", "hive")
+                        .config(
+                                "spark.sql.catalog.spark_catalog",
+                                SparkGenericCatalog.class.getName())
+                        .master("local[2]")
+                        .getOrCreate();
+
+        assertThatThrownBy(() -> spark.sql("CREATE DATABASE my_db"))
+                .rootCause()
+                .isInstanceOf(FileNotFoundException.class)
+                .hasMessageContaining("nonExistentPath");
+
+        spark.close();
+    }
 }

Reply via email to