Skip to content

Commit

Permalink
[test] Add test for hive-conf-dir in Spark catalog. (#4359)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinMingQiang authored Oct 23, 2024
1 parent 8235c61 commit 576b04d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
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 {
Expand All @@ -48,7 +51,7 @@ public static void closeMetastore() throws Exception {

@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()
Expand Down Expand Up @@ -107,4 +110,27 @@ public void testCreateFormatTable(@TempDir java.nio.file.Path tempDir) {
.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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
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. */
Expand Down Expand Up @@ -100,7 +103,7 @@ public void testCreateTableCaseSensitive(@TempDir java.nio.file.Path tempDir) {

@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()
Expand Down Expand Up @@ -148,4 +151,27 @@ public void testBuildWithHive(@TempDir java.nio.file.Path tempDir) {
.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();
}
}

0 comments on commit 576b04d

Please sign in to comment.