-
Notifications
You must be signed in to change notification settings - Fork 33
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 materialized view in Flint Spark API #71
Merged
dai-chen
merged 18 commits into
opensearch-project:main
from
dai-chen:add-mv-api-on-new-metadata
Oct 18, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4fe2983
Implement MV metadata on refactored Flint metadata
dai-chen 8348750
Split build API and add IT for MV
dai-chen 0b205ca
Add IT for incremental refresh
dai-chen 37d213b
Refactor build API with optional StreamingRefresh interface
dai-chen 827bc7f
Add javadoc and remove useless BatchRefresh interface
dai-chen 744e4e1
Fluent data frame API chain
dai-chen 24067fa
Add more javadoc
dai-chen 2325f03
Add UT for build function
dai-chen b8168d2
Add UT for build stream function
dai-chen b63208a
More readability by implicit class
dai-chen 78b8902
Add more IT
dai-chen ede5a84
Refactor MV build stream
dai-chen e327590
Add more javadoc and comment
dai-chen 6aed6da
Move remaining deserialize logic to new Factory class
dai-chen 4d9175e
Add implicit class for options
dai-chen 1bfce3b
Qualify MV name
dai-chen 2778d68
Fix qualified mv name check
dai-chen bf5f577
Merge branch 'main' into add-mv-api-on-new-metadata
dai-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 83 additions & 0 deletions
83
...-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexFactory.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,83 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark | ||
|
||
import scala.collection.JavaConverters.mapAsScalaMapConverter | ||
|
||
import org.opensearch.flint.core.metadata.FlintMetadata | ||
import org.opensearch.flint.spark.covering.FlintSparkCoveringIndex | ||
import org.opensearch.flint.spark.covering.FlintSparkCoveringIndex.COVERING_INDEX_TYPE | ||
import org.opensearch.flint.spark.mv.FlintSparkMaterializedView | ||
import org.opensearch.flint.spark.mv.FlintSparkMaterializedView.MV_INDEX_TYPE | ||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingIndex | ||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingIndex.SKIPPING_INDEX_TYPE | ||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingStrategy.SkippingKind | ||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingStrategy.SkippingKind.{MIN_MAX, PARTITION, VALUE_SET} | ||
import org.opensearch.flint.spark.skipping.minmax.MinMaxSkippingStrategy | ||
import org.opensearch.flint.spark.skipping.partition.PartitionSkippingStrategy | ||
import org.opensearch.flint.spark.skipping.valueset.ValueSetSkippingStrategy | ||
|
||
/** | ||
* Flint Spark index factory that encapsulates specific Flint index instance creation. This is for | ||
* internal code use instead of user facing API. | ||
*/ | ||
object FlintSparkIndexFactory { | ||
|
||
/** | ||
* Creates Flint index from generic Flint metadata. | ||
* | ||
* @param metadata | ||
* Flint metadata | ||
* @return | ||
* Flint index | ||
*/ | ||
def create(metadata: FlintMetadata): FlintSparkIndex = { | ||
val indexOptions = FlintSparkIndexOptions( | ||
metadata.options.asScala.mapValues(_.asInstanceOf[String]).toMap) | ||
|
||
// Convert generic Map[String,AnyRef] in metadata to specific data structure in Flint index | ||
metadata.kind match { | ||
case SKIPPING_INDEX_TYPE => | ||
val strategies = metadata.indexedColumns.map { colInfo => | ||
val skippingKind = SkippingKind.withName(getString(colInfo, "kind")) | ||
val columnName = getString(colInfo, "columnName") | ||
val columnType = getString(colInfo, "columnType") | ||
|
||
skippingKind match { | ||
case PARTITION => | ||
PartitionSkippingStrategy(columnName = columnName, columnType = columnType) | ||
case VALUE_SET => | ||
ValueSetSkippingStrategy(columnName = columnName, columnType = columnType) | ||
case MIN_MAX => | ||
MinMaxSkippingStrategy(columnName = columnName, columnType = columnType) | ||
case other => | ||
throw new IllegalStateException(s"Unknown skipping strategy: $other") | ||
} | ||
} | ||
FlintSparkSkippingIndex(metadata.source, strategies, indexOptions) | ||
case COVERING_INDEX_TYPE => | ||
FlintSparkCoveringIndex( | ||
metadata.name, | ||
metadata.source, | ||
metadata.indexedColumns.map { colInfo => | ||
getString(colInfo, "columnName") -> getString(colInfo, "columnType") | ||
}.toMap, | ||
indexOptions) | ||
case MV_INDEX_TYPE => | ||
FlintSparkMaterializedView( | ||
metadata.name, | ||
metadata.source, | ||
metadata.indexedColumns.map { colInfo => | ||
getString(colInfo, "columnName") -> getString(colInfo, "columnType") | ||
}.toMap, | ||
indexOptions) | ||
} | ||
} | ||
|
||
private def getString(map: java.util.Map[String, AnyRef], key: String): String = { | ||
map.get(key).asInstanceOf[String] | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in which case df is not empty? seems, skipping/covering/mv are all empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not empty when incremental refresh in foreach batch style (incremental refresh on skipping/covering index). In this case, the
df
is data frame for each micro batch.https://github.com/dai-chen/opensearch-spark/blob/add-mv-api-on-new-metadata/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSpark.scala#L153