Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test for FlintDelegatingSessionCatalog #50

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
}
}
Loading