-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Signed-off-by: Peng Huo <[email protected]> Signed-off-by: Chen Dai <[email protected]> Co-authored-by: Chen Dai <[email protected]>
- Loading branch information
Showing
29 changed files
with
389 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
flint-spark-integration/src/test/scala/org/apache/spark/sql/FlintCatalogSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.apache.spark.sql | ||
|
||
import org.mockito.Mockito.when | ||
import org.scalatestplus.mockito.MockitoSugar | ||
|
||
import org.apache.spark.SparkFunSuite | ||
import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogPlugin} | ||
import org.apache.spark.sql.flint.resolveCatalogName | ||
import org.apache.spark.sql.internal.{SessionState, SQLConf} | ||
import org.apache.spark.sql.internal.SQLConf.DEFAULT_CATALOG | ||
|
||
class FlintCatalogSuite extends SparkFunSuite with MockitoSugar { | ||
|
||
test("resolveCatalogName returns default catalog name for session catalog") { | ||
assertCatalog() | ||
.withCatalogName("spark_catalog") | ||
.withDefaultCatalog("glue") | ||
.registerCatalog("glue") | ||
.shouldResolveCatalogName("glue") | ||
} | ||
|
||
test("resolveCatalogName returns default catalog name for spark_catalog") { | ||
assertCatalog() | ||
.withCatalogName("spark_catalog") | ||
.withDefaultCatalog("spark_catalog") | ||
.registerCatalog("spark_catalog") | ||
.shouldResolveCatalogName("spark_catalog") | ||
} | ||
|
||
test("resolveCatalogName should return catalog name for non-session catalogs") { | ||
assertCatalog() | ||
.withCatalogName("custom_catalog") | ||
.withDefaultCatalog("custom_catalog") | ||
.registerCatalog("custom_catalog") | ||
.shouldResolveCatalogName("custom_catalog") | ||
} | ||
|
||
test( | ||
"resolveCatalogName should throw RuntimeException when default catalog is not registered") { | ||
assertCatalog() | ||
.withCatalogName("spark_catalog") | ||
.withDefaultCatalog("glue") | ||
.registerCatalog("unknown") | ||
.shouldThrowException() | ||
} | ||
|
||
private def assertCatalog(): AssertionHelper = { | ||
new AssertionHelper | ||
} | ||
|
||
private class AssertionHelper { | ||
private val spark = mock[SparkSession] | ||
private val catalog = mock[CatalogPlugin] | ||
private val sessionState = mock[SessionState] | ||
private val catalogManager = mock[CatalogManager] | ||
|
||
def withCatalogName(catalogName: String): AssertionHelper = { | ||
when(catalog.name()).thenReturn(catalogName) | ||
this | ||
} | ||
|
||
def withDefaultCatalog(catalogName: String): AssertionHelper = { | ||
val conf = new SQLConf | ||
conf.setConf(DEFAULT_CATALOG, catalogName) | ||
when(spark.conf).thenReturn(new RuntimeConfig(conf)) | ||
this | ||
} | ||
|
||
def registerCatalog(catalogName: String): AssertionHelper = { | ||
when(spark.sessionState).thenReturn(sessionState) | ||
when(sessionState.catalogManager).thenReturn(catalogManager) | ||
when(catalogManager.isCatalogRegistered(catalogName)).thenReturn(true) | ||
this | ||
} | ||
|
||
def shouldResolveCatalogName(expectedCatalogName: String): Unit = { | ||
assert(resolveCatalogName(spark, catalog) == expectedCatalogName) | ||
} | ||
|
||
def shouldThrowException(): Unit = { | ||
assertThrows[IllegalStateException] { | ||
resolveCatalogName(spark, catalog) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.