Class TranslatePromqlToEsqlPlan
java.lang.Object
org.elasticsearch.xpack.esql.rule.Rule<PromqlCommand,LogicalPlan>
org.elasticsearch.xpack.esql.rule.ParameterizedRule<PromqlCommand,LogicalPlan,LogicalOptimizerContext>
org.elasticsearch.xpack.esql.optimizer.rules.logical.OptimizerRules.ParameterizedOptimizerRule<PromqlCommand,LogicalOptimizerContext>
org.elasticsearch.xpack.esql.optimizer.rules.logical.promql.TranslatePromqlToEsqlPlan
public final class TranslatePromqlToEsqlPlan
extends OptimizerRules.ParameterizedOptimizerRule<PromqlCommand,LogicalOptimizerContext>
Translates PromQL logical plan into ESQL plan.
This rule runs before TranslateTimeSeriesAggregate to convert PromQL-specific plan
into standard ESQL nodes (TimeSeriesAggregate, Aggregate, Eval, etc.) that can then be further optimized.
Translation examples:
PromQL: rate(http_requests[5m])
Result: TimeSeriesAggregate[rate(value), groupBy=[step]]
PromQL: sum by (cluster) (rate(http_requests[5m]))
Result: TimeSeriesAggregate[sum(rate(value)), groupBy=[step, cluster]]
PromQL: avg(sum by (cluster) (rate(http_requests[5m])))
Result: Aggregate[avg(sum_result), groupBy=[step]]
\_ TimeSeriesAggregate[sum(rate(value)), groupBy=[step, cluster]]
PromQL: avg(ceil(sum by (cluster) (rate(http_requests[5m]))))
Result: Aggregate[avg(ceil_result), groupBy=[step]]
\_ Eval[ceil(sum_result)]
\_ TimeSeriesAggregate[sum(rate(value)), groupBy=[step, cluster]]
PromQL: time() - avg(sum by (cluster) (rate(http_requests[5m])))
Result: Eval[time() - avg_result]
\_ Aggregate[avg(sum_result), groupBy=[step]]
\_ TimeSeriesAggregate[sum(rate(value)), groupBy=[step, cluster]]
Translation mechanism:
Recursive descent via translateNode(). Each node returns a TranslationResult:
planthe LogicalPlan built so farexpressionreference to this node's output, composed into parent expressions
Selector: plan unchanged, expression = LastOverTime(field) or field referenceAcrossSeriesAggregate: plan = new Aggregate, expression = reference to aggregate outputPromqlFunctionCall: plan = Eval if child aggregated, expression = function(child expr)VectorBinaryOperator: plan = merged from both sides, expression = left op right
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected LogicalPlanrule(PromqlCommand promqlCommand, LogicalOptimizerContext context) static ExpressiontranslateLabelMatcher(Source source, Expression field, LabelMatcher matcher) Translates a single PromQL label matcher into an ESQL filter expression.Methods inherited from class org.elasticsearch.xpack.esql.optimizer.rules.logical.OptimizerRules.ParameterizedOptimizerRule
applyMethods inherited from class org.elasticsearch.xpack.esql.rule.ParameterizedRule
apply
-
Field Details
-
DEFAULT_LOOKBACK
-
-
Constructor Details
-
TranslatePromqlToEsqlPlan
public TranslatePromqlToEsqlPlan()
-
-
Method Details
-
rule
- Specified by:
rulein classOptimizerRules.ParameterizedOptimizerRule<PromqlCommand,LogicalOptimizerContext>
-
translateLabelMatcher
public static Expression translateLabelMatcher(Source source, Expression field, LabelMatcher matcher) Translates a single PromQL label matcher into an ESQL filter expression.- Parameters:
source- the source locationmatcher- the label matcher to translate- Returns:
- the ESQL Expression, or null if the matcher matches all or none
-