From 75222303cf15ce8090adaa08d422f124819d5e88 Mon Sep 17 00:00:00 2001 From: Alex Theimer Date: Mon, 2 Oct 2023 22:10:47 -0700 Subject: [PATCH] add replaceFilters predicate --- query/src/main/scala/filodb/query/LogicalPlan.scala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/query/src/main/scala/filodb/query/LogicalPlan.scala b/query/src/main/scala/filodb/query/LogicalPlan.scala index e6740e758c..2cef01b19a 100644 --- a/query/src/main/scala/filodb/query/LogicalPlan.scala +++ b/query/src/main/scala/filodb/query/LogicalPlan.scala @@ -21,9 +21,15 @@ sealed trait LogicalPlan { def isTimeSplittable: Boolean = true /** - * Replace filters present in logical plan + * Replace filters present in logical plan. + * Optionally accepts a predicate to conditionally replace filters. + * @param shouldReplace when a plan returns false, no filters in its subtree are updated. */ - def replaceFilters(filters: Seq[ColumnFilter]): LogicalPlan = { + def replaceFilters(filters: Seq[ColumnFilter], + shouldReplace: LogicalPlan => Boolean = (plan) => true): LogicalPlan = { + if (!shouldReplace.apply(this)) { + return this + } this match { case n: LabelCardinality => n.copy(filters = filters) case p: PeriodicSeriesPlan => p.replacePeriodicSeriesFilters(filters)