Class PrefixedPartitionsWriter

java.lang.Object
org.elasticsearch.index.codec.tsdb.PrefixedPartitionsWriter
All Implemented Interfaces:
SortedFieldObserver

public final class PrefixedPartitionsWriter extends Object implements SortedFieldObserver
Writes prefix-based partition metadata for the primary sort field during segment flush. Terms are grouped by their first PARTITION_PREFIX_BITS bits, and the starting document for each prefix group is recorded. This enables the query engine to partition work by prefix without scanning all doc values.

Usage is two-pass: first call onTerm(org.apache.lucene.util.BytesRef, long) for each term during the terms dict write, then call prepareForDocs() to compact the prefix-to-ordinal mapping, and finally call onDoc(int, long) for each ordinal during the numeric field write.


 // Pass 1: track terms during terms dict write
 PrefixedPartitionsWriter writer = new PrefixedPartitionsWriter();
 for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) {
     writer.onTerm(term, termsEnum.ord());
 }

 // Transition: compact prefix-to-ordinal mapping
 writer.prepareForDocs();

 // Pass 2: track start docs
 for (int doc = values.nextDoc(); doc != NO_MORE_DOCS; doc = values.nextDoc()) {
     writer.onDoc(doc, values.ordValue());
 }

 writer.flush(data, meta);
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final VarHandle
     
    static final int
     

    Fields inherited from interface org.elasticsearch.index.codec.tsdb.SortedFieldObserver

    NOOP
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    flush(org.apache.lucene.store.IndexOutput data, org.apache.lucene.store.IndexOutput meta)
    Writes accumulated metadata to the segment outputs.
    void
    onDoc(int docId, long ord)
    Called once per document during the numeric ordinals write.
    void
    onTerm(org.apache.lucene.util.BytesRef term, long ord)
    Called once per term during the terms dictionary write.
    void
    Called after all terms have been written and before the document pass begins.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PrefixedPartitionsWriter

      public PrefixedPartitionsWriter()
  • Method Details

    • onTerm

      public void onTerm(org.apache.lucene.util.BytesRef term, long ord)
      Description copied from interface: SortedFieldObserver
      Called once per term during the terms dictionary write.
      Specified by:
      onTerm in interface SortedFieldObserver
      Parameters:
      term - the term bytes
      ord - the term ordinal
    • prepareForDocs

      public void prepareForDocs()
      Description copied from interface: SortedFieldObserver
      Called after all terms have been written and before the document pass begins.
      Specified by:
      prepareForDocs in interface SortedFieldObserver
    • onDoc

      public void onDoc(int docId, long ord)
      Description copied from interface: SortedFieldObserver
      Called once per document during the numeric ordinals write.
      Specified by:
      onDoc in interface SortedFieldObserver
      Parameters:
      docId - the document ID
      ord - the ordinal value for this document
    • flush

      public void flush(org.apache.lucene.store.IndexOutput data, org.apache.lucene.store.IndexOutput meta) throws IOException
      Description copied from interface: SortedFieldObserver
      Writes accumulated metadata to the segment outputs.
      Specified by:
      flush in interface SortedFieldObserver
      Parameters:
      data - the data output stream
      meta - the metadata output stream
      Throws:
      IOException