Skip to content

Commit

Permalink
dedup or clauses when normalizing (#1504)
Browse files Browse the repository at this point in the history
Update the expression normalization to dedup OR clauses if
the conditions are the same.
  • Loading branch information
brharrington authored Dec 14, 2022
1 parent 9a59fca commit 8e7368c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ object ExprApi {
Query.And(q1, q2)
}
}
.distinct
.sortWith(_.toString < _.toString) // order OR clauses
.reduce { (q1, q2) =>
Query.Or(q1, q2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ class ExprApiSuite extends MUnitRouteSuite {
assertEquals(normalize(expr), List(expected))
}

test("normalize duplicate or clauses") {
val expr = "name,a,:eq,name,b,:eq,:or,name,a,:eq,:or"
val expected = "name,a,:eq,name,b,:eq,:or,:sum"
assertEquals(normalize(expr), List(expected))
}

test("normalize simplify query") {
val input = "app,foo,:eq,name,cpuUser,:eq,:and,:true,:and,:sum"
val expected = "app,foo,:eq,name,cpuUser,:eq,:and,:sum"
Expand Down

0 comments on commit 8e7368c

Please sign in to comment.