diff --git a/spark-sql-application/src/main/java/org/opensearch/sql/FlintDelegatingSessionCatalog.java b/spark-sql-application/src/main/java/org/opensearch/sql/FlintDelegatingSessionCatalog.java index 86c4caba8..6ed9fa980 100644 --- a/spark-sql-application/src/main/java/org/opensearch/sql/FlintDelegatingSessionCatalog.java +++ b/spark-sql-application/src/main/java/org/opensearch/sql/FlintDelegatingSessionCatalog.java @@ -39,6 +39,9 @@ public final void setDelegateCatalog(CatalogPlugin delegate) { // do nothing } + /** + * Using V2SessionCatalog name: spark_catalog. + */ @Override public String name() { return delegate.name(); @@ -46,10 +49,8 @@ public String name() { @Override public final void initialize(String name, CaseInsensitiveStringMap options) { - delegate = SparkSession.getActiveSession() - .get() - .sessionState() - .catalogManager().v2SessionCatalog(); + this.delegate = + SparkSession.getActiveSession().get().sessionState().catalogManager().v2SessionCatalog(); } @Override diff --git a/spark-sql-application/src/test/scala/org/opensearch/sql/FlintDelegatingSessionCatalogTest.scala b/spark-sql-application/src/test/scala/org/opensearch/sql/FlintDelegatingSessionCatalogTest.scala index 7bd8d0397..f6be0b1c3 100644 --- a/spark-sql-application/src/test/scala/org/opensearch/sql/FlintDelegatingSessionCatalogTest.scala +++ b/spark-sql-application/src/test/scala/org/opensearch/sql/FlintDelegatingSessionCatalogTest.scala @@ -10,6 +10,7 @@ import org.apache.spark.sql.test.SharedSparkSessionBase class FlintDelegatingSessionCatalogTest extends QueryTest with SharedSparkSessionBase { private val testTable = "mycatalog.default.flint_sql_test" + private val testTableWithoutCatalog = "default.flint_sql_test" override def beforeAll(): Unit = { super.beforeAll() @@ -18,30 +19,34 @@ class FlintDelegatingSessionCatalogTest extends QueryTest with SharedSparkSessio "spark.sql.catalog.mycatalog", "org.opensearch.sql.FlintDelegatingSessionCatalog") - // Create test table - spark.sql(s""" - | CREATE TABLE $testTable - | ( - | name STRING, - | age INT - | ) - | USING CSV - | OPTIONS ( - | header 'false', - | delimiter '\t' - | ) - |""".stripMargin) - - spark.sql(s""" - | INSERT INTO $testTable - | VALUES ('Hello', 30) - | """.stripMargin) + sql(s""" + | CREATE TABLE $testTable + | ( + | name STRING, + | age INT + | ) + | USING CSV + | OPTIONS ( + | header 'false', + | delimiter '\t' + | ) + |""".stripMargin) + + sql(s""" + | INSERT INTO $testTable + | VALUES ('Hello', 30) + | """.stripMargin) } - test("test read from customized catalog") { + test("query with customized catalog name") { + var result = sql(s"SELECT name, age FROM $testTable") + checkAnswer(result, Seq(Row("Hello", 30))) + } - val result = spark.sql(s"SELECT name, age FROM $testTable") + test("query without catalog name") { + sql("use mycatalog") + assert(sql("SHOW CATALOGS").collect === Array(Row("mycatalog"))) - checkAnswer(result, Seq(Row("Hello", 30))) + checkAnswer(sql(s"SELECT name, age FROM $testTableWithoutCatalog"), Seq(Row("Hello", 30))) } }