-
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 create, drop and refresh covering index SQL support #32
Merged
dai-chen
merged 8 commits into
opensearch-project:main
from
dai-chen:add-covering-index-sql-support
Sep 20, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9a36ab
Separate out skipping index ast builder
dai-chen ee0ae9d
Add create index statement and IT
dai-chen bb5800c
Refactor Flint sql IT
dai-chen 1637cab
Refactor Flint AST builder for mix-in
dai-chen afe9d3e
Extract util methods from each AST builder
dai-chen ad7f353
Add refresh and drop statement support
dai-chen 8779c66
Update doc
dai-chen ae75241
Fix full table name in AST builder
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
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
75 changes: 75 additions & 0 deletions
75
...ain/scala/org/opensearch/flint/spark/sql/covering/FlintSparkCoveringIndexAstBuilder.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,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.sql.covering | ||
|
||
import org.antlr.v4.runtime.tree.RuleNode | ||
import org.opensearch.flint.spark.FlintSpark | ||
import org.opensearch.flint.spark.FlintSpark.RefreshMode | ||
import org.opensearch.flint.spark.covering.FlintSparkCoveringIndex | ||
import org.opensearch.flint.spark.sql.{FlintSparkSqlCommand, FlintSparkSqlExtensionsVisitor} | ||
import org.opensearch.flint.spark.sql.FlintSparkSqlAstBuilder.{getFullTableName, isAutoRefreshEnabled} | ||
import org.opensearch.flint.spark.sql.FlintSparkSqlExtensionsParser.{CreateCoveringIndexStatementContext, DropCoveringIndexStatementContext, RefreshCoveringIndexStatementContext} | ||
|
||
import org.apache.spark.sql.catalyst.plans.logical.Command | ||
|
||
/** | ||
* Flint Spark AST builder that builds Spark command for Flint covering index statement. | ||
*/ | ||
trait FlintSparkCoveringIndexAstBuilder extends FlintSparkSqlExtensionsVisitor[Command] { | ||
|
||
override def visitCreateCoveringIndexStatement( | ||
ctx: CreateCoveringIndexStatementContext): Command = { | ||
FlintSparkSqlCommand() { flint => | ||
val indexName = ctx.indexName.getText | ||
val tableName = ctx.tableName.getText | ||
val indexBuilder = | ||
flint | ||
.coveringIndex() | ||
.name(indexName) | ||
.onTable(tableName) | ||
|
||
ctx.indexColumns.multipartIdentifierProperty().forEach { indexColCtx => | ||
val colName = indexColCtx.multipartIdentifier().getText | ||
indexBuilder.addIndexColumns(colName) | ||
} | ||
indexBuilder.create() | ||
|
||
// Trigger auto refresh if enabled | ||
if (isAutoRefreshEnabled(ctx.propertyList())) { | ||
val flintIndexName = getFlintIndexName(flint, ctx.indexName, ctx.tableName) | ||
flint.refreshIndex(flintIndexName, RefreshMode.INCREMENTAL) | ||
} | ||
Seq.empty | ||
} | ||
} | ||
|
||
override def visitRefreshCoveringIndexStatement( | ||
ctx: RefreshCoveringIndexStatementContext): Command = { | ||
FlintSparkSqlCommand() { flint => | ||
val flintIndexName = getFlintIndexName(flint, ctx.indexName, ctx.tableName) | ||
flint.refreshIndex(flintIndexName, RefreshMode.FULL) | ||
Seq.empty | ||
} | ||
} | ||
|
||
override def visitDropCoveringIndexStatement( | ||
ctx: DropCoveringIndexStatementContext): Command = { | ||
FlintSparkSqlCommand() { flint => | ||
val flintIndexName = getFlintIndexName(flint, ctx.indexName, ctx.tableName) | ||
flint.deleteIndex(flintIndexName) | ||
Seq.empty | ||
} | ||
} | ||
|
||
private def getFlintIndexName( | ||
flint: FlintSpark, | ||
indexNameCtx: RuleNode, | ||
tableNameCtx: RuleNode): String = { | ||
val indexName = indexNameCtx.getText | ||
val fullTableName = getFullTableName(flint, tableNameCtx) | ||
FlintSparkCoveringIndex.getFlintIndexName(indexName, fullTableName) | ||
} | ||
} |
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.
it would be very helpful if u can add a diagram showing the content of the skipping index and how it relates to the original table ...
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.
Sure, I've created test for doc update. Will add doctest with examples in #28. Thanks!