Class NumericTopNOperator
- All Implemented Interfaces:
Closeable,AutoCloseable,Operator,Releasable
ExternalSourceExec that has been narrowed to
[sortKey, _rowPosition] by the InsertExternalFieldExtraction rule.
The operator replaces TopNOperator for this specific plan shape: instead of
encoding each sort key into a BytesRef and ranking TopNRow objects in a
Lucene PriorityQueue, it ranks primitive long encodings
directly using PrimitiveTernaryHeap. The encoding maps the raw sort value to a long
such that "more competitive" corresponds to "larger encoded" — a min-heap of size K then
exactly holds the top-K most competitive rows, with the root being the rejection threshold
for the next incoming row.
Scope (PR 1, Tier 1):
- Exactly one sort key.
- Sort key
ElementTypeisElementType.LONG,ElementType.INT,ElementType.DOUBLE, orElementType.BOOLEAN. ESQL DATETIME and DATE_NANOS map to LONG at planning time, so they go through the LONG path. ESQL FLOAT, HALF_FLOAT and SCALED_FLOAT widen to DOUBLE on load so they reach this operator asDoubleBlock. - Input page has exactly 2 channels in this fixed order:
[sortKey, _rowPosition]. Enforced byLocalExecutionPlanner.tryBuildNumericTopN(), asserted at runtime. - Sort key may contain nulls and may be multi-valued. Multi-values are reduced to the
most-favourable single value for the configured direction (MV-min for ASC, MV-max for
DESC) — exactly the semantics the generic
TopNOperatorapplies via itsKeyExtractorForXfamily. An empty MV slot is treated as a null. SeeNumericSortKeyExtractorfor the per-type breakdown.
Out of scope (deferred PRs): multi-key sorts, byte-keyed sorts, UNSIGNED_LONG sort keys.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordFactory wired in byLocalExecutionPlanner.tryBuildNumericTopN().Nested classes/interfaces inherited from interface org.elasticsearch.compute.operator.Operator
Operator.OperatorFactory, Operator.Status -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intChannel of the synthetic_rowPositioncolumn in every input page.static final intChannel of the primary sort key in every input page.Fields inherited from interface org.elasticsearch.compute.operator.Operator
MIN_TARGET_PAGE_SIZE, NOT_BLOCKED, TARGET_PAGE_SIZE -
Method Summary
Modifier and TypeMethodDescriptionvoidadds an input page to the operator.booleanReturns true if the operator can produce more output pages without requiring additional input pages.voidclose()notifies the operator that it won't be used anymore (i.e.voidfinish()notifies the operator that it won't receive any more input pagesreturns non-null if output page available.booleanwhether the operator has finished processing all input pages and made the corresponding output pages availablebooleanwhether the given operator can accept more input pagesstatus()The status of the operator.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.compute.operator.Operator
isBlocked, tryPromote
-
Field Details
-
SORT_KEY_CHANNEL
public static final int SORT_KEY_CHANNELChannel of the primary sort key in every input page.- See Also:
-
ROW_POSITION_CHANNEL
public static final int ROW_POSITION_CHANNELChannel of the synthetic_rowPositioncolumn in every input page.- See Also:
-
-
Method Details
-
needsInput
public boolean needsInput()Description copied from interface:Operatorwhether the given operator can accept more input pages- Specified by:
needsInputin interfaceOperator
-
addInput
Description copied from interface:Operatoradds an input page to the operator. only called when needsInput() == true and isFinished() == false -
finish
public void finish()Description copied from interface:Operatornotifies the operator that it won't receive any more input pages -
isFinished
public boolean isFinished()Description copied from interface:Operatorwhether the operator has finished processing all input pages and made the corresponding output pages available- Specified by:
isFinishedin interfaceOperator
-
canProduceMoreDataWithoutExtraInput
public boolean canProduceMoreDataWithoutExtraInput()Description copied from interface:OperatorReturns true if the operator can produce more output pages without requiring additional input pages. This is useful for operators that buffer data or have internal state that can produce multiple output pages.Operators that do not buffer data should return
false- they cannot produce pages out of thin air. Examples of operators that may returntrue:- Operators with internal buffers (e.g.,
AsyncOperatorwith pending results) - Operators processing a single input page into multiple output pages
- Aggregation operators that buffer partial results
- Specified by:
canProduceMoreDataWithoutExtraInputin interfaceOperator- Returns:
trueif the operator has buffered data that can produce output,falseotherwise
- Operators with internal buffers (e.g.,
-
getOutput
Description copied from interface:Operatorreturns non-null if output page available. Only called when isFinished() == false -
close
public void close()Description copied from interface:Operatornotifies the operator that it won't be used anymore (i.e. none of the other methods called), and its resources can be cleaned up- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceOperator- Specified by:
closein interfaceReleasable
-
status
Description copied from interface:OperatorThe status of the operator. -
toString
-