Skip to content

Commit

Permalink
add IT tests for additional filters
Browse files Browse the repository at this point in the history
Signed-off-by: YANGDB <yang.db.dev@gmail.com>
  • Loading branch information
YANG-DB committed Sep 7, 2023
1 parent 7db7213 commit 32573ab
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package org.opensearch.flint.spark

import org.apache.spark.sql.QueryTest
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedRelation, UnresolvedStar}
import org.apache.spark.sql.catalyst.expressions.{EqualTo, Literal}
import org.apache.spark.sql.catalyst.expressions.{EqualTo, GreaterThan, Literal, Not}
import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project}
import org.apache.spark.sql.streaming.StreamTest

Expand Down Expand Up @@ -103,6 +103,24 @@ class FlintSparkPPLITSuite
assert(expectedPlan === logicalPlan)
}

test("create ppl simple age literal greater than filter query with two fields result test") {
val frame = sql(
s"""
| source = $testTable age>25 | fields name, age
| """.stripMargin)

// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
// Define the expected logical plan
val table = UnresolvedRelation(Seq("default","flint_ppl_tst"))
val filterExpr = GreaterThan(UnresolvedAttribute("age"), Literal(25))
val filterPlan = Filter(filterExpr, table)
val projectList = Seq(UnresolvedAttribute("name"),UnresolvedAttribute("age"))
val expectedPlan = Project(projectList, filterPlan)
// Compare the two plans
assert(expectedPlan === logicalPlan)
}

test("create ppl simple name literal equal filter query with two fields result test") {
val frame = sql(
s"""
Expand All @@ -119,5 +137,23 @@ class FlintSparkPPLITSuite
val expectedPlan = Project(projectList, filterPlan)
// Compare the two plans
assert(expectedPlan === logicalPlan)
}

test("create ppl simple name literal not equal filter query with two fields result test") {
val frame = sql(
s"""
| source = $testTable name!='George' | fields name, age
| """.stripMargin)

// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
// Define the expected logical plan
val table = UnresolvedRelation(Seq("default","flint_ppl_tst"))
val filterExpr = Not(EqualTo(UnresolvedAttribute("name"), Literal("'George'")))
val filterPlan = Filter(filterExpr, table)
val projectList = Seq(UnresolvedAttribute("name"),UnresolvedAttribute("age"))
val expectedPlan = Project(projectList, filterPlan)
// Compare the two plans
assert(expectedPlan === logicalPlan)
}
}

0 comments on commit 32573ab

Please sign in to comment.