Skip to content

Commit

Permalink
add more test for FlintDelegatingSessionCatalog
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <[email protected]>
  • Loading branch information
penghuo committed Sep 27, 2023
2 parents 0305481 + 2f22bf2 commit a1b0079
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ public final void setDelegateCatalog(CatalogPlugin delegate) {
// do nothing
}

/**
* Using V2SessionCatalog name: spark_catalog.
*/
@Override
public String name() {
return delegate.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)))
}
}

0 comments on commit a1b0079

Please sign in to comment.