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

eval: precompute expression string #1707

Merged
merged 1 commit into from
Oct 15, 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 @@ -124,14 +124,18 @@ object TimeSeriesMessage {
* Time series to use for the message.
* @param palette
* If defined then include presentation metadata.
* @param exprStr
* String view of the expression. Should match `expr`, but may be precomputed for
* group by expressions with many messages.
*/
def apply(
expr: StyleExpr,
context: EvalContext,
ts: TimeSeries,
palette: Option[String] = None
palette: Option[String] = None,
exprStr: Option[String] = None
): TimeSeriesMessage = {
val query = expr.toString
val query = exprStr.getOrElse(expr.toString)
val offset = Strings.toString(Duration.ofMillis(expr.offset))
val outputTags = ts.tags + (TagKey.offset -> offset)
val id = TaggedItem.computeId(outputTags + ("atlas.query" -> query)).toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ private[stream] class FinalExprEval(exprInterpreter: ExprInterpreter)
// Generate the time series and diagnostic output
val output = recipients.flatMap {
case (styleExpr, infos) =>
val exprStr = styleExpr.toString
val ids = infos.map(_.id)
// Use an identity map for the state to ensure that multiple equivalent stateful
// expressions, e.g. derivative(a) + derivative(a), will have isolated state.
Expand All @@ -221,7 +222,8 @@ private[stream] class FinalExprEval(exprInterpreter: ExprInterpreter)
styleExpr,
context,
t.withLabel(styleExpr.legend(t)),
info.palette
info.palette,
Some(exprStr)
)
new MessageEnvelope(info.id, ts)
}
Expand Down
Loading