From 84737dade0b11644c8fbd4356103fee5ff0f2475 Mon Sep 17 00:00:00 2001 From: Chen Dai Date: Mon, 8 Jul 2024 12:09:46 -0700 Subject: [PATCH] Add more UT Signed-off-by: Chen Dai --- .../covering/ApplyFlintSparkCoveringIndex.scala | 2 +- .../ApplyFlintSparkCoveringIndexSuite.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndex.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndex.scala index 3bdac3c3d..90cbdd0da 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndex.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndex.scala @@ -41,7 +41,7 @@ class ApplyFlintSparkCoveringIndex(flint: FlintSpark) } else { // Iterate each sub plan tree in the given plan plan transform { - case filter @ Filter(condition, Relation(sourceRelation)) if isConjunction(condition) => + case filter @ Filter(condition, Relation(sourceRelation)) => doApply(plan, sourceRelation, Some(condition)) .map(newRelation => filter.copy(child = newRelation)) .getOrElse(filter) diff --git a/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndexSuite.scala b/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndexSuite.scala index 0d0bc805e..530539161 100644 --- a/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndexSuite.scala +++ b/flint-spark-integration/src/test/scala/org/opensearch/flint/spark/covering/ApplyFlintSparkCoveringIndexSuite.scala @@ -120,6 +120,18 @@ class ApplyFlintSparkCoveringIndexSuite extends FlintSuite with Matchers { } } + test("should not apply if covering index with disjunction filtering condition") { + assertFlintQueryRewriter + .withQuery(s"SELECT name FROM $testTable WHERE name = 'A' AND age > 30") + .withIndex( + new FlintSparkCoveringIndex( + indexName = "partial", + tableName = testTable, + indexedColumns = Map("name" -> "string", "age" -> "int"), + filterCondition = Some("name = 'A' OR age > 30"))) + .assertIndexNotUsed(testTable) + } + test("should not apply if covering index is logically deleted") { assertFlintQueryRewriter .withQuery(s"SELECT name FROM $testTable") @@ -156,6 +168,8 @@ class ApplyFlintSparkCoveringIndexSuite extends FlintSuite with Matchers { s"SELECT name, age FROM $testTable", s"SELECT age, name FROM $testTable", s"SELECT name FROM $testTable WHERE age = 30", + s"SELECT name FROM $testTable WHERE name = 'A' AND age = 30", + s"SELECT name FROM $testTable WHERE name = 'A' OR age = 30", s"SELECT SUBSTR(name, 1) FROM $testTable WHERE ABS(age) = 30", s"SELECT COUNT(*) FROM $testTable GROUP BY age", s"SELECT name, COUNT(*) FROM $testTable WHERE age > 30 GROUP BY name",