diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/sql/covering/FlintSparkCoveringIndexAstBuilder.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/sql/covering/FlintSparkCoveringIndexAstBuilder.scala index 689dfaefc..e05d5da64 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/sql/covering/FlintSparkCoveringIndexAstBuilder.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/sql/covering/FlintSparkCoveringIndexAstBuilder.scala @@ -28,7 +28,7 @@ trait FlintSparkCoveringIndexAstBuilder extends FlintSparkSqlExtensionsVisitor[A ctx: CreateCoveringIndexStatementContext): Command = { FlintSparkSqlCommand() { flint => val indexName = ctx.indexName.getText - val tableName = ctx.tableName.getText + val tableName = getFullTableName(flint, ctx.tableName) val indexBuilder = flint .coveringIndex() diff --git a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkCoveringIndexSqlITSuite.scala b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkCoveringIndexSqlITSuite.scala index 9fb580b60..3be51f573 100644 --- a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkCoveringIndexSqlITSuite.scala +++ b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkCoveringIndexSqlITSuite.scala @@ -67,6 +67,46 @@ class FlintSparkCoveringIndexSqlITSuite extends FlintSparkSuite { indexData.count() shouldBe 2 } + test("create covering index on table without database name") { + sql(s"CREATE INDEX $testIndex ON covering_sql_test (name)") + + flint.describeIndex(testFlintIndex) shouldBe defined + } + + test("create covering index on table in other database") { + sql("CREATE SCHEMA sample") + sql("USE sample") + + // Create index without database name specified + sql("CREATE TABLE test1 (name STRING) USING CSV") + sql(s"CREATE INDEX $testIndex ON sample.test1 (name)") + + // Create index with database name specified + sql("CREATE TABLE test2 (name STRING) USING CSV") + sql(s"CREATE INDEX $testIndex ON sample.test2 (name)") + + try { + flint.describeIndex(s"flint_spark_catalog_sample_test1_${testIndex}_index") shouldBe defined + flint.describeIndex(s"flint_spark_catalog_sample_test2_${testIndex}_index") shouldBe defined + } finally { + sql("DROP DATABASE sample CASCADE") + } + } + + test("create covering index on table in other database than current") { + sql("CREATE SCHEMA sample") + sql("USE sample") + + // Specify database "default" in table name instead of current "sample" database + sql(s"CREATE INDEX $testIndex ON $testTable (name)") + + try { + flint.describeIndex(testFlintIndex) shouldBe defined + } finally { + sql("DROP DATABASE sample CASCADE") + } + } + test("show all covering index on the source table") { flint .coveringIndex() diff --git a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala index 226b6e371..fc70f340f 100644 --- a/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala +++ b/integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkSkippingIndexSqlITSuite.scala @@ -114,14 +114,7 @@ class FlintSparkSkippingIndexSqlITSuite extends FlintSparkSuite { } test("create skipping index on table without database name") { - sql(s""" - | CREATE SKIPPING INDEX ON skipping_sql_test - | ( - | year PARTITION, - | name VALUE_SET, - | age MIN_MAX - | ) - | """.stripMargin) + sql("CREATE SKIPPING INDEX ON skipping_sql_test ( year PARTITION )") flint.describeIndex(testIndex) shouldBe defined } @@ -129,10 +122,35 @@ class FlintSparkSkippingIndexSqlITSuite extends FlintSparkSuite { test("create skipping index on table in other database") { sql("CREATE SCHEMA sample") sql("USE sample") - sql("CREATE TABLE test (name STRING) USING CSV") - sql("CREATE SKIPPING INDEX ON test (name VALUE_SET)") - flint.describeIndex("flint_spark_catalog_sample_test_skipping_index") shouldBe defined + // Create index without database name specified + sql("CREATE TABLE test1 (name STRING) USING CSV") + sql("CREATE SKIPPING INDEX ON test1 (name VALUE_SET)") + + // Create index with database name specified + sql("CREATE TABLE test2 (name STRING) USING CSV") + sql("CREATE SKIPPING INDEX ON sample.test2 (name VALUE_SET)") + + try { + flint.describeIndex("flint_spark_catalog_sample_test1_skipping_index") shouldBe defined + flint.describeIndex("flint_spark_catalog_sample_test2_skipping_index") shouldBe defined + } finally { + sql("DROP DATABASE sample CASCADE") + } + } + + test("create skipping index on table in other database than current") { + sql("CREATE SCHEMA sample") + sql("USE sample") + + // Specify database "default" in table name instead of current "sample" database + sql(s"CREATE SKIPPING INDEX ON $testTable (name VALUE_SET)") + + try { + flint.describeIndex(testIndex) shouldBe defined + } finally { + sql("DROP DATABASE sample CASCADE") + } } test("should return empty if no skipping index to describe") {