Skip to content
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 Flint describe index SQL support #1785

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ statement
;

skippingIndexStatement
: dropSkippingIndexStatement
: describeSkippingIndexStatement
| dropSkippingIndexStatement
;

describeSkippingIndexStatement
: (DESC | DESCRIBE) SKIPPING INDEX ON tableName=multipartIdentifier
;

dropSkippingIndexStatement
Expand Down
2 changes: 2 additions & 0 deletions flint/flint-spark-integration/src/main/antlr4/SparkSqlBase.g4
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ SKIPPING : 'SKIPPING';

SEMICOLON: ';';

DESC: 'DESC';
DESCRIBE: 'DESCRIBE';
DOT: '.';
DROP: 'DROP';
INDEX: 'INDEX';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.opensearch.flint.spark.sql

import org.opensearch.flint.spark.skipping.FlintSparkSkippingIndex.getSkippingIndexName
import org.opensearch.flint.spark.sql.FlintSparkSqlExtensionsParser.DropSkippingIndexStatementContext
import org.opensearch.flint.spark.sql.FlintSparkSqlExtensionsParser.{DescribeSkippingIndexStatementContext, DropSkippingIndexStatementContext}

import org.apache.spark.sql.catalyst.plans.logical.Command

Expand All @@ -15,15 +15,19 @@ import org.apache.spark.sql.catalyst.plans.logical.Command
*/
class FlintSparkSqlAstBuilder extends FlintSparkSqlExtensionsBaseVisitor[Command] {

override def visitDropSkippingIndexStatement(
ctx: DropSkippingIndexStatementContext): Command = {
override def visitDescribeSkippingIndexStatement(
ctx: DescribeSkippingIndexStatementContext): Command =
FlintSparkSqlCommand { flint =>
Seq.empty
}

override def visitDropSkippingIndexStatement(ctx: DropSkippingIndexStatementContext): Command =
FlintSparkSqlCommand { flint =>
val tableName = ctx.tableName.getText // TODO: handle schema name
val indexName = getSkippingIndexName(tableName)
flint.deleteIndex(indexName)
Seq.empty
}
}

override def aggregateResult(aggregate: Command, nextResult: Command): Command =
if (nextResult != null) nextResult else aggregate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,29 @@ class FlintSparkSqlSuite extends QueryTest with FlintSuite with OpenSearchSuite
|""".stripMargin)
}

test("drop skipping index") {
protected override def beforeEach(): Unit = {
super.beforeEach()

flint
.skippingIndex()
.onTable(testTable)
dai-chen marked this conversation as resolved.
Show resolved Hide resolved
.addPartitions("year")
.create()
}

protected override def afterEach(): Unit = {
super.afterEach()

flint.deleteIndex(testIndex)
}

test("describe skipping index") {
val result = sql(s"DESC SKIPPING INDEX ON $testTable")

checkAnswer(result, Seq())
}

test("drop skipping index") {
sql(s"DROP SKIPPING INDEX ON $testTable")

flint.describeIndex(testIndex) shouldBe empty
Expand Down
Loading