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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice dfs algorithm.
I guess
planTreeStringRepresentationOfChildren
is a more clear name?

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