Skip to content

Commit

Permalink
add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Zhang committed Dec 18, 2023
1 parent af30a69 commit 670bce1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,25 @@ class PlannerHierarchySpec extends AnyFunSpec with Matchers with PlanValidationS
validatePlan(execPlan, expected)
}

it("Should be able to handle multiple unary signs.") {
it("Plan with unary expression should be equals to its binary counterpart2.") {
val unaryExpressions = List("""-foo{_ws_ = "demo", _ns_ = "localNs"}""", """+foo{_ws_ = "demo", _ns_ = "localNs"}""",
"""-(foo{_ws_ = "demo", _ns_ = "localNs"} - bar{_ws_ = "demo", _ns_ = "localNs"})""",
"""+(foo{_ws_ = "demo", _ns_ = "localNs"} - bar{_ws_ = "demo", _ns_ = "localNs"})""")
val binaryExpressions = List("""(0 -foo{_ws_ = "demo", _ns_ = "localNs"})""", """(0 + foo{_ws_ = "demo", _ns_ = "localNs"})""",
"""(0 -(foo{_ws_ = "demo", _ns_ = "localNs"} - bar{_ws_ = "demo", _ns_ = "localNs"}))""",
"""(0 + (foo{_ws_ = "demo", _ns_ = "localNs"} - bar{_ws_ = "demo", _ns_ = "localNs"}))""")
unaryExpressions.zip(binaryExpressions).foreach(
pair => {
val lp1 = Parser.queryRangeToLogicalPlan(pair._1, TimeStepParams(startSeconds, step, endSeconds), Antlr)
val execPlan1 = rootPlanner.materialize(lp1, QueryContext(origQueryParams = queryParams))
val lp2 = Parser.queryRangeToLogicalPlan(pair._2, TimeStepParams(startSeconds, step, endSeconds), Antlr)
val execPlan2 = rootPlanner.materialize(lp2, QueryContext(origQueryParams = queryParams))
validatePlan(execPlan1, execPlan2.printTree())
}
)
}

it("Should be able to handle multiple unary signs.") {
val lp = Parser.queryRangeToLogicalPlan(
"""-+---+-foo{_ws_ = "demo", _ns_ = "localNs"} > ---+--+--1""",
TimeStepParams(startSeconds, step, endSeconds), Antlr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ case class UnaryExpression(operator: Operator, operand: Expression) extends Expr
// eg. -foo is implemented through (0 - foo).
operand match {
case unaryExpression: UnaryExpression =>
// recursively convert unary expression to a binary expression.
// recursively convert a unary expression to a binary expression.
BinaryExpression(Scalar(0), operator, None, unaryExpression.convertUnaryExpression())
case _ =>
BinaryExpression(Scalar(0), operator, None, operand)
Expand Down

0 comments on commit 670bce1

Please sign in to comment.