Class Sparkline
- All Implemented Interfaces:
NamedWriteable,Writeable,PostAnalysisPlanVerificationAware,PostAnalysisVerificationAware,Resolvable,AggregateMetricDoubleNativeSupport
Take this example:
| STATS mbo=SPARKLINE(MAX(bytes_out), @timestamp, 10, "2025-01-01", "2025-01-10"),
l1m=SPARKLINE( AVG(load_1m), @timestamp, 10, "2025-01-01", "2025-01-10")
BY hostname
Which should render something like:
┌────────────┬────────────┬────────────┐
│ mbo │ l1m │ hostname │
├────────────┼────────────┼────────────┤
│ ▁▂▄▇█▆▃▂▁▁ │ ▃▃▄▄▅▅▄▃▃▂ │ web-01 │
│ ▂▃▃▄▅▅▄▃▂▂ │ ▅▅▆▇█▇▆▅▄▃ │ web-02 │
│ ▁▁▂▂▂▃▃▂▂▁ │ ▂▂▃▄▅▆▅▄▃▂ │ db-primary │
└────────────┴────────────┴────────────┘
Elasticsearch doesn't paint this picture. Instead, it returns a dense array:
┌────────────────────────────────────────────────────────┬────────────────────────────────────────────────────┬────────────┐
│ mbo │ l1m │ hostname │
├────────────────────────────────────────────────────────┼────────────────────────────────────────────────────┼────────────┤
│ [120, 340, 630, 4800, 9800, 5100, 1200, 340, 120, 100] │ [1.2, 1.3, 1.8, 2.1, 2.4, 2.7, 2.1, 1.5, 1.2, 0.9] │ web-01 │
│ [240, 380, 380, 490, 620, 620, 490, 380, 240, 240] │ [2.4, 2.4, 2.9, 3.4, 3.8, 3.4, 2.9, 2.4, 1.8, 1.2] │ web-02 │
│ [ 50, 50, 80, 80, 80, 120, 120, 80, 80, 50] │ [0.8, 0.8, 1.2, 1.6, 2.0, 2.4, 2.0, 1.6, 1.2, 0.8] │ db-primary │
└────────────────────────────────────────────────────────┴────────────────────────────────────────────────────┴────────────┘
This is implemented as much as possible using standard bits of the compute engine
and ESQL like the Top agg. See the ReplaceSparklineAggregate rule
and SparklineGenerateEmptyBucketsOperator for special implementation bits.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
Expression.TypeResolutionNested classes/interfaces inherited from class org.elasticsearch.xpack.esql.core.tree.Node
Node.NodeStringFormatNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FunctionDefinitionstatic final NamedWriteableRegistry.EntryFields inherited from class org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction
NO_WINDOW, WINDOW_INTERVALFields inherited from class org.elasticsearch.xpack.esql.core.tree.Node
TO_STRING_MAX_LINES, TO_STRING_MAX_WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionSparkline(Source source, Expression field, Expression key, Expression buckets, Expression from, Expression to) Sparkline(Source source, Expression field, Expression filter, Expression window, Expression key, Expression buckets, Expression from, Expression to) -
Method Summary
Modifier and TypeMethodDescriptionbuckets()dataType()TheDataTypereturned by executing the tree rooted at this expression.from()info()Normally, you want to use one of the staticcreatemethods to implement this.key()voidpostAnalysisVerification(Failures failures) Allows the implementer to validate itself.replaceChildren(List<Expression> newChildren) protected Expression.TypeResolutionThe implementation ofExpression.typeResolved(), which is just a caching wrapper around this method.to()withFilter(Expression filter) Attach a filter to the aggregate function.Methods inherited from class org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction
aggregateInputReferences, equals, field, filter, hasFilter, hashCode, hasWindow, parameters, postAnalysisPlanVerification, readWindow, window, withField, withFilter, withFilter, withParameters, withWindow, writeToMethods inherited from class org.elasticsearch.xpack.esql.core.expression.function.Function
arguments, functionName, nodeString, nullableMethods inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
canonical, canonicalize, childrenResolved, fold, foldable, propertiesToString, references, resolved, semanticEquals, semanticHash, toString, toString, typeResolvedMethods inherited from class org.elasticsearch.xpack.esql.core.tree.Node
allMatch, anyMatch, children, collect, collect, collect, collectFirstChildren, collectLeaves, doCollectFirst, forEachDown, forEachDown, forEachDownMayReturnEarly, forEachProperty, forEachPropertyDown, forEachPropertyOnly, forEachPropertyUp, forEachUp, forEachUp, nodeName, nodeProperties, nodeString, replaceChildrenSameSize, source, sourceLocation, sourceText, toString, transformChildren, transformChildren, transformDown, transformDown, transformDown, transformDown, transformDownSkipBranch, transformNodeProps, transformPropertiesDown, transformPropertiesOnly, transformPropertiesUp, transformUp, transformUp, transformUpMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xpack.esql.capabilities.PostAnalysisVerificationAware
postAnalysisVerification
-
Field Details
-
ENTRY
-
DEFINITION
-
-
Constructor Details
-
Sparkline
public Sparkline(Source source, Expression field, Expression key, Expression buckets, Expression from, Expression to) -
Sparkline
public Sparkline(Source source, Expression field, Expression filter, Expression window, Expression key, Expression buckets, Expression from, Expression to)
-
-
Method Details
-
resolveType
Description copied from class:ExpressionThe implementation ofExpression.typeResolved(), which is just a caching wrapper around this method. See it's javadoc for what this method should return.Implementations will rarely interact with the
Expression.TypeResolutionclass directly, instead usually calling the utility methods onTypeResolutions.Implementations should fail if
Expression.childrenResolved()returnsfalse.- Overrides:
resolveTypein classAggregateFunction
-
postAnalysisVerification
Description copied from interface:PostAnalysisVerificationAwareAllows the implementer to validate itself. This usually involves checking its internal setup, which often means checking the parameters it received on construction: their data or syntactic type, class, their count, expressions' structure etc. The discovered failures are added to the givenFailuresobject.It is often more useful to perform the checks as extended as it makes sense, over stopping at the first failure. This will allow the author to progress faster to a correct query.
Example: the
Filterclass, which models the WHERE command, checks that the expression it filters on -condition- is of a Boolean or NULL type:@Override void postAnalysisVerification(Failures failures) { if (condition.dataType() != NULL && condition.dataType() != BOOLEAN) { failures.add(fail(condition, "Condition expression needs to be boolean, found [{}]", condition.dataType())); } }- Specified by:
postAnalysisVerificationin interfacePostAnalysisVerificationAware- Parameters:
failures- the object to add failures to.
-
getWriteableName
- Specified by:
getWriteableNamein interfaceNamedWriteable
-
dataType
Description copied from class:ExpressionTheDataTypereturned by executing the tree rooted at this expression. IfExpression.typeResolved()returns an error then the behavior of this method is undefined. It may return a valid type. Or it may throw an exception. Or it may return a totally nonsensical type.- Specified by:
dataTypein classExpression
-
info
Description copied from class:NodeNormally, you want to use one of the staticcreatemethods to implement this.For
QueryPlans, it is very important that the properties contain all of the expressions and references relevant to this node, and that all the properties are used in the provided constructor; otherwise query plan transformations likeQueryPlan#transformExpressionsOnly(Function)will not have an effect.- Specified by:
infoin classNode<Expression>
-
key
-
buckets
-
from
-
to
-
replaceChildren
- Specified by:
replaceChildrenin classNode<Expression>
-
withFilter
Description copied from class:AggregateFunctionAttach a filter to the aggregate function.- Specified by:
withFilterin classAggregateFunction
-