java.lang.Object
org.elasticsearch.compute.data.Page
All Implemented Interfaces:
Writeable

public final class Page extends Object implements Writeable
A page is a column-oriented data abstraction that allows data to be passed between operators in batches.

A page has a fixed number of positions (or rows), exposed via getPositionCount(). It is further composed of a number of Blocks, which represent the columnar data. The number of blocks can be retrieved via getBlockCount(), and the respective blocks can be retrieved via their index getBlock(int).

Pages are immutable and can be passed between threads.

  • Constructor Details

    • Page

      public Page(Block... blocks)
      Creates a new page with the given blocks. Every block has the same number of positions.
      Parameters:
      blocks - the blocks
      Throws:
      IllegalArgumentException - if all blocks do not have the same number of positions
    • Page

      public Page(int positionCount, Block... blocks)
      Creates a new page with the given positionCount and blocks. Assumes that every block has the same number of positions as the positionCount that's passed in - there is no validation of this.
      Parameters:
      positionCount - the block position count
      blocks - the blocks
    • Page

      public Page(StreamInput in) throws IOException
      Throws:
      IOException
  • Method Details

    • getBlock

      public <B extends Block> B getBlock(int blockIndex)
      Returns the block at the given block index.
      Parameters:
      blockIndex - the block index
      Returns:
      the block
    • appendBlock

      public Page appendBlock(Block block)
      Creates a new page, appending the given block to the existing blocks in this Page.
      Parameters:
      block - the block to append
      Returns:
      a new Page with the block appended
      Throws:
      IllegalArgumentException - if the given block does not have the same number of positions as the blocks in this Page
    • appendBlocks

      public Page appendBlocks(Block[] toAdd)
      Creates a new page, appending the given blocks to the existing blocks in this Page.
      Parameters:
      toAdd - the blocks to append
      Returns:
      a new Page with the block appended
      Throws:
      IllegalArgumentException - if one of the given blocks does not have the same number of positions as the blocks in this Page
    • appendPage

      public Page appendPage(Page toAdd)
      Creates a new page, appending the blocks of the given block to the existing blocks in this Page.
      Parameters:
      toAdd - the page to append
      Returns:
      a new Page
      Throws:
      IllegalArgumentException - if any blocks of the given page does not have the same number of positions as the blocks in this Page
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPositionCount

      public int getPositionCount()
      Returns the number of positions (rows) in this page.
      Returns:
      the number of positions
    • getBlockCount

      public int getBlockCount()
      Returns the number of blocks in this page. Blocks can then be retrieved via getBlock(int) where channel ranges from 0 to getBlockCount.
      Returns:
      the number of blocks in this page
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • ramBytesUsedByBlocks

      public long ramBytesUsedByBlocks()
    • releaseBlocks

      public void releaseBlocks()
      Release all blocks in this page, decrementing any breakers accounting for these blocks.
    • allowPassingToDifferentDriver

      public void allowPassingToDifferentDriver()
      Before passing a Page to another Driver, it is necessary to switch the owning block factories of its Blocks to their parents, which are associated with the global circuit breaker. This ensures that when the new driver releases this Page, it returns memory directly to the parent block factory instead of the local block factory. This is important because the local block factory is not thread safe and doesn't support simultaneous access by more than one thread.
    • shallowCopy

      public Page shallowCopy()
    • projectBlocks

      public Page projectBlocks(int[] blockMapping)
      Returns a new page with blocks in the containing Blocks shifted around or removed. The new Page will have as many blocks as the length of the provided array. Those blocks will be set to the block at the position of the value of each entry in the parameter.