forked from opensearch-project/opensearch-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add covering index in Flint Spark API (opensearch-project#22)
* Refactor index builder Signed-off-by: Chen Dai <[email protected]> * Add covering index builder and empty impl Signed-off-by: Chen Dai <[email protected]> * Implement covering index metadata Signed-off-by: Chen Dai <[email protected]> * Implement covering index build Signed-off-by: Chen Dai <[email protected]> * Refactor IT class Signed-off-by: Chen Dai <[email protected]> * Rename build method Signed-off-by: Chen Dai <[email protected]> * Add more IT Signed-off-by: Chen Dai <[email protected]> * Add UT for new covering index class Signed-off-by: Chen Dai <[email protected]> * Refactor flint index name prefix and suffix Signed-off-by: Chen Dai <[email protected]> * Add comment Signed-off-by: Chen Dai <[email protected]> * Remove parse flint index name logic Signed-off-by: Chen Dai <[email protected]> --------- Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
10 changed files
with
558 additions
and
158 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
46 changes: 46 additions & 0 deletions
46
...-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexBuilder.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,46 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark | ||
|
||
import org.apache.spark.sql.catalog.Column | ||
|
||
/** | ||
* Flint Spark index builder base class. | ||
* | ||
* @param flint | ||
* Flint Spark API entrypoint | ||
*/ | ||
abstract class FlintSparkIndexBuilder(flint: FlintSpark) { | ||
|
||
/** Source table name */ | ||
protected var tableName: String = "" | ||
|
||
/** All columns of the given source table */ | ||
lazy protected val allColumns: Map[String, Column] = { | ||
require(tableName.nonEmpty, "Source table name is not provided") | ||
|
||
flint.spark.catalog | ||
.listColumns(tableName) | ||
.collect() | ||
.map(col => (col.name, col)) | ||
.toMap | ||
} | ||
|
||
/** | ||
* Create Flint index. | ||
*/ | ||
def create(): Unit = flint.createIndex(buildIndex()) | ||
|
||
/** | ||
* Build method for concrete builder class to implement | ||
*/ | ||
protected def buildIndex(): FlintSparkIndex | ||
|
||
protected def findColumn(colName: String): Column = | ||
allColumns.getOrElse( | ||
colName, | ||
throw new IllegalArgumentException(s"Column $colName does not exist")) | ||
} |
Oops, something went wrong.