-
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.
Fix catalog name missing in Flint index name (#48)
* Change to qualified name in Flint Spark index API layer Signed-off-by: Chen Dai <[email protected]> * Qualify table name in Flint SQL layer Signed-off-by: Chen Dai <[email protected]> * Add more IT Signed-off-by: Chen Dai <[email protected]> * Reuse Spark utility method for parsing Signed-off-by: Chen Dai <[email protected]> * Update javadoc Signed-off-by: Chen Dai <[email protected]> * Fix catalog plugin name issue Signed-off-by: Chen Dai <[email protected]> --------- Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
16 changed files
with
380 additions
and
79 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
77 changes: 77 additions & 0 deletions
77
flint-spark-integration/src/main/scala/org/apache/spark/sql/flint/package.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,77 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.apache.spark.sql | ||
|
||
import org.apache.spark.sql.connector.catalog._ | ||
|
||
/** | ||
* Flint utility methods that rely on access to private code in Spark SQL package. | ||
*/ | ||
package object flint { | ||
|
||
/** | ||
* Qualify a given table name. | ||
* | ||
* @param spark | ||
* Spark session | ||
* @param tableName | ||
* table name maybe qualified or not | ||
* @return | ||
* qualified table name in catalog.database.table format | ||
*/ | ||
def qualifyTableName(spark: SparkSession, tableName: String): String = { | ||
val (catalog, ident) = parseTableName(spark, tableName) | ||
|
||
// Tricky that our Flint delegate catalog's name has to be spark_catalog | ||
// so we have to find its actual name in CatalogManager | ||
val catalogMgr = spark.sessionState.catalogManager | ||
val catalogName = | ||
catalogMgr | ||
.listCatalogs(Some("*")) | ||
.find(catalogMgr.catalog(_) == catalog) | ||
.getOrElse(catalog.name()) | ||
|
||
s"$catalogName.${ident.namespace.mkString(".")}.${ident.name}" | ||
} | ||
|
||
/** | ||
* Parse a given table name into its catalog and table identifier. | ||
* | ||
* @param spark | ||
* Spark session | ||
* @param tableName | ||
* table name maybe qualified or not | ||
* @return | ||
* Spark catalog and table identifier | ||
*/ | ||
def parseTableName(spark: SparkSession, tableName: String): (CatalogPlugin, Identifier) = { | ||
// Create a anonymous class to access CatalogAndIdentifier | ||
new LookupCatalog { | ||
override protected val catalogManager: CatalogManager = spark.sessionState.catalogManager | ||
|
||
def parseTableName(): (CatalogPlugin, Identifier) = { | ||
val parts = tableName.split("\\.").toSeq | ||
parts match { | ||
case CatalogAndIdentifier(catalog, ident) => (catalog, ident) | ||
} | ||
} | ||
}.parseTableName() | ||
} | ||
|
||
/** | ||
* Load table for the given table identifier in the catalog. | ||
* | ||
* @param catalog | ||
* Spark catalog | ||
* @param ident | ||
* table identifier | ||
* @return | ||
* Spark table | ||
*/ | ||
def loadTable(catalog: CatalogPlugin, ident: Identifier): Option[Table] = { | ||
CatalogV2Util.loadTable(catalog, ident) | ||
} | ||
} |
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
Oops, something went wrong.