Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(query): Adding supporting function to get the logical plan tree in string form #1894

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,17 @@ object LogicalPlanUtils extends StrictLogging {
.distinct
.map(_.toSeq)
}

def getLogicalPlanTreeStringRepresentation(logicalPlan: LogicalPlan) : String = {
// iterate over all the children of the logical plan and get the string representation
val children = logicalPlan match {
sandeep6189 marked this conversation as resolved.
Show resolved Hide resolved
case nl: NonLeafLogicalPlan => nl.children.map(getLogicalPlanTreeStringRepresentation)
case _ => Seq()
}
if (children.isEmpty) {
logicalPlan.getClass.getSimpleName
} else {
s"${logicalPlan.getClass.getSimpleName}(${children.mkString(",")})"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ class LogicalPlanUtilsSpec extends AnyFunSpec with Matchers {
getMaxLookbackInMillis(query1) shouldEqual 900000 // max of 15 and 10m
getMaxLookbackInMillis(query2) shouldEqual 300000 // default lookback is 5m
}

it ("getLogicalPlanTreeStringRepresentation should return result as expected") {
val timeParamsSec = TimeStepParams(1000, 10, 10000)
val query1 = """rate(test_metric{_ns_="test-ns", _ws_="test-ns", cluster="test1"}[15m]) + rate(test_metric{_ns_="test-ns", _ws_="test-ns", cluster="test1"}[10m])"""
val query2 = """test_metric{_ns_="test-ns", _ws_="test-ns", cluster="test1"} offset 1d * 1000"""
val lp = Parser.queryRangeToLogicalPlan(query1, timeParamsSec)
LogicalPlanUtils.getLogicalPlanTreeStringRepresentation(lp) shouldEqual "BinaryJoin(PeriodicSeriesWithWindowing(RawSeries),PeriodicSeriesWithWindowing(RawSeries))"
val lp2 = Parser.queryToLogicalPlan(query2, 100, 10)
LogicalPlanUtils.getLogicalPlanTreeStringRepresentation(lp2) shouldEqual "ScalarVectorBinaryOperation(PeriodicSeries(RawSeries),ScalarFixedDoublePlan)"
}
}
Loading