java.lang.Object
org.elasticsearch.compute.operator.topn.TopNOperator
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.lucene.util.Accountable, Operator, org.elasticsearch.core.Releasable

public class TopNOperator extends Object implements Operator, org.apache.lucene.util.Accountable
An operator that sorts "rows" of values by encoding the values to sort on, as bytes (using BytesRef). Each data type is encoded in a specific way, defined by methods of a TopNEncoder. All the values used to sort a specific row (think of column/block 3 and column/block 6) are converted/encoded in a byte array and the concatenated bytes are all compared in bulk. For now, the only values that have a special "treatment" when it comes to encoding are the text-based ones (text, keyword, ip, version). For each "special" encoding there is should be new TopNEncoder implementation. See TopNEncoder.UTF8 for encoding regular "text" and "keyword" data types. See LocalExecutionPlanner for which data type uses which encoder. This Operator will not be able to sort binary values (encoded as BytesRef) because the bytes used as separator and "null"s can appear as valid bytes inside a binary value.
  • Constructor Details

  • Method Details

    • needsInput

      public boolean needsInput()
      Description copied from interface: Operator
      whether the given operator can accept more input pages
      Specified by:
      needsInput in interface Operator
    • addInput

      public void addInput(Page page)
      Description copied from interface: Operator
      adds an input page to the operator. only called when needsInput() == true and isFinished() == false
      Specified by:
      addInput in interface Operator
    • finish

      public void finish()
      Description copied from interface: Operator
      notifies the operator that it won't receive any more input pages
      Specified by:
      finish in interface Operator
    • isFinished

      public boolean isFinished()
      Description copied from interface: Operator
      whether the operator has finished processing all input pages and made the corresponding output pages available
      Specified by:
      isFinished in interface Operator
    • getOutput

      public Page getOutput()
      Description copied from interface: Operator
      returns non-null if output page available. Only called when isFinished() == false
      Specified by:
      getOutput in interface Operator
    • close

      public void close()
      Description copied from interface: Operator
      notifies 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Operator
      Specified by:
      close in interface org.elasticsearch.core.Releasable
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface org.apache.lucene.util.Accountable
    • status

      public Operator.Status status()
      Description copied from interface: Operator
      The status of the operator.
      Specified by:
      status in interface Operator
    • toString

      public String toString()
      Overrides:
      toString in class Object