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

bug(coord): Adding ApplyLimitFunction support for cross-partition query routing #1833

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 @@ -209,6 +209,12 @@ object LogicalPlanParser {
}$ClosingCurlyBraces"
}

private def applyLimitToQuery(lp: ApplyLimitFunction): String = {
val periodicSeriesQuery = convertToQuery(lp.vectors)
s"$periodicSeriesQuery limit ${lp.limit}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious if limit 1 will return 1 time series or 2 time series at the end if we have two partition?

}

//scalastyle:off cyclomatic.complexity
def convertToQuery(logicalPlan: LogicalPlan): String = {
logicalPlan match {
case lp: RawSeries => rawSeriesLikeToQuery(lp, true)
Expand All @@ -229,8 +235,14 @@ object LogicalPlanParser {
case lp: SubqueryWithWindowing => subqueryWithWindowingToQuery(lp)
case lp: TopLevelSubquery => topLevelSubqueryToQuery(lp)
case lp: MetadataQueryPlan => metadataMatchToQuery(lp)
case _ => throw new UnsupportedOperationException(s"Logical plan to query not " +
s"supported for ${logicalPlan}")
case lp: ApplyLimitFunction => applyLimitToQuery(lp)
case lp: ApplyInstantFunctionRaw => throw new UnsupportedOperationException(s"Logical plan to PromQL not " +
s"supported for $lp")
case lp: RawChunkMeta => throw new UnsupportedOperationException(s"Logical plan to PromQL not " +
s"supported for $lp")
case lp: TsCardinalities => throw new UnsupportedOperationException(s"Logical plan to PromQL not " +
s"supported for $lp")
// do not add default case here as we want to generate compile error when a new logical plan is added
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class LogicalPlanParserSpec extends AnyFunSpec with Matchers {

it("should generate query from LogicalPlan") {
parseAndAssertResult("""http_requests_total{job="app"}""") ()
parseAndAssertResult("""http_requests_total{job="app"} limit 1""") ()
parseAndAssertResult("""sum(http_requests_total{job="app"}) limit 1""") ()
parseAndAssertResult("""sum(http_requests_total{job="app"})""") ()
parseAndAssertResult("""sum(count(http_requests_total{job="app"}))""")()
parseAndAssertResult("""sum(http_requests_total{job="app",instance="inst-1"}) by (instance)""")()
Expand Down
Loading