-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1c50ab
commit 2148dda
Showing
2 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
coordinator/src/test/scala/filodb.coordinator/queryplanner/LogicalPlanUtilsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package filodb.coordinator.queryplanner | ||
|
||
import filodb.coordinator.client.QueryCommands.FunctionalTargetSchemaProvider | ||
import filodb.core.TargetSchemaChange | ||
import filodb.core.query.ColumnFilter | ||
import filodb.core.query.Filter.Equals | ||
import filodb.prometheus.ast.TimeStepParams | ||
import filodb.prometheus.parse.Parser | ||
import filodb.query.LogicalPlan | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class LogicalPlanUtilsSpec extends AnyFunSpec with Matchers { | ||
it ("should correctly determine whether-or-not plan has same/unchanging target-schema columns") { | ||
val timeParamsSec = TimeStepParams(1000, 10, 10000) | ||
val timeParamsMs = TimeStepParams( | ||
1000 * timeParamsSec.start, | ||
1000 * timeParamsSec.step, | ||
1000 * timeParamsSec.end) | ||
val query = """foo{operand="lhs"} + bar{operand="rhs"}""" | ||
|
||
val getResult = (tschemaProviderFunc: Seq[ColumnFilter] => Seq[TargetSchemaChange]) => { | ||
val tschemaProvider = FunctionalTargetSchemaProvider(tschemaProviderFunc) | ||
val lp = Parser.queryRangeToLogicalPlan(query, timeParamsSec) | ||
LogicalPlanUtils.sameRawSeriesTargetSchemaColumns(lp, tschemaProvider, LogicalPlan.getRawSeriesFilters) | ||
} | ||
|
||
val unchangingSingle = (colFilters: Seq[ColumnFilter]) => { | ||
Seq(TargetSchemaChange(0, Seq("hello"))) | ||
} | ||
getResult(unchangingSingle) shouldEqual Some(Seq("hello")) | ||
|
||
val unchangingMultiple = (colFilters: Seq[ColumnFilter]) => { | ||
Seq(TargetSchemaChange(0, Seq("hello", "goodbye"))) | ||
} | ||
getResult(unchangingMultiple) shouldEqual Some(Seq("hello", "goodbye")) | ||
|
||
val changingSingle = (colFilters: Seq[ColumnFilter]) => { | ||
Seq(TargetSchemaChange(timeParamsMs.start + timeParamsMs.step, Seq("hello"))) | ||
} | ||
getResult(changingSingle) shouldEqual None | ||
|
||
val oneChanges = (colFilters: Seq[ColumnFilter]) => { | ||
if (colFilters.contains(ColumnFilter("operand", Equals("lhs")))) { | ||
Seq(TargetSchemaChange(0, Seq("hello"))) | ||
} else { | ||
Seq(TargetSchemaChange(timeParamsMs.start + timeParamsMs.step, Seq("hello"))) | ||
} | ||
} | ||
getResult(oneChanges) shouldEqual None | ||
|
||
val differentCols = (colFilters: Seq[ColumnFilter]) => { | ||
if (colFilters.contains(ColumnFilter("operand", Equals("lhs")))) { | ||
Seq(TargetSchemaChange(0, Seq("hello"))) | ||
} else { | ||
Seq(TargetSchemaChange(0, Seq("goodbye"))) | ||
} | ||
} | ||
getResult(differentCols) shouldEqual None | ||
} | ||
} |