Class FrameSupportTemplate

java.lang.Object
org.apache.drill.exec.physical.impl.window.FrameSupportTemplate
All Implemented Interfaces:
WindowFramer

public abstract class FrameSupportTemplate extends Object implements WindowFramer
WindowFramer implementation that supports the FRAME clause.
According to the SQL specification, FIRST_VALUE, LAST_VALUE and all aggregate functions support the FRAME clause. This class will handle such functions even if the FRAME clause is not present.
  • Constructor Details

    • FrameSupportTemplate

      public FrameSupportTemplate()
  • Method Details

    • setup

      public void setup(List<WindowDataBatch> batches, VectorContainer container, OperatorContext oContext, boolean requireFullPartition, WindowPOP popConfig) throws SchemaChangeException
      Specified by:
      setup in interface WindowFramer
      Throws:
      SchemaChangeException
    • doWork

      public void doWork() throws SchemaChangeException
      processes all rows of the first batch.
      Specified by:
      doWork in interface WindowFramer
      Throws:
      SchemaChangeException
    • getOutputCount

      public int getOutputCount()
      Specified by:
      getOutputCount in interface WindowFramer
      Returns:
      number rows processed in last batch
    • cleanup

      public void cleanup()
      Specified by:
      cleanup in interface WindowFramer
    • toString

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

      public abstract void evaluatePeer(@Named("index") int index)
      called once for each peer row of the current frame.
      Parameters:
      index - of row to aggregate
    • setupEvaluatePeer

      public abstract void setupEvaluatePeer(@Named("incoming") VectorAccessible incoming, @Named("outgoing") VectorAccessible outgoing) throws SchemaChangeException
      Throws:
      SchemaChangeException
    • setupReadLastValue

      public abstract void setupReadLastValue(@Named("incoming") VectorAccessible incoming, @Named("outgoing") VectorAccessible outgoing) throws SchemaChangeException
      Throws:
      SchemaChangeException
    • writeLastValue

      public abstract void writeLastValue(@Named("index") int index, @Named("outIndex") int outIndex)
    • setupSaveFirstValue

      public abstract void setupSaveFirstValue(@Named("incoming") VectorAccessible incoming, @Named("outgoing") VectorAccessible outgoing) throws SchemaChangeException
      Throws:
      SchemaChangeException
    • saveFirstValue

      public abstract void saveFirstValue(@Named("index") int index)
    • setupWriteFirstValue

      public abstract void setupWriteFirstValue(@Named("incoming") VectorAccessible incoming, @Named("outgoing") VectorAccessible outgoing)
    • outputRow

      public abstract void outputRow(@Named("outIndex") int outIndex)
      called once for each row after we evaluate all peer rows. Used to write a value in the row
      Parameters:
      outIndex - index of row
    • setupPartition

      public abstract void setupPartition(@Named("incoming") WindowDataBatch incoming, @Named("outgoing") VectorAccessible outgoing) throws SchemaChangeException
      Called once per partition, before processing the partition. Used to setup read/write vectors
      Parameters:
      incoming - batch we will read from
      outgoing - batch we will be writing to
      Throws:
      SchemaChangeException
    • resetValues

      public abstract boolean resetValues()
      reset all window functions
    • isSamePartition

      public abstract boolean isSamePartition(@Named("b1Index") int b1Index, @Named("b1") VectorAccessible b1, @Named("b2Index") int b2Index, @Named("b2") VectorAccessible b2)
      compares two rows from different batches (can be the same), if they have the same value for the partition by expression
      Specified by:
      isSamePartition in interface WindowFramer
      Parameters:
      b1Index - index of first row
      b1 - batch for first row
      b2Index - index of second row
      b2 - batch for second row
      Returns:
      true if the rows are in the same partition
    • isPeer

      public abstract boolean isPeer(@Named("b1Index") int b1Index, @Named("b1") VectorAccessible b1, @Named("b2Index") int b2Index, @Named("b2") VectorAccessible b2)
      compares two rows from different batches (can be the same), if they have the same value for the order by expression
      Specified by:
      isPeer in interface WindowFramer
      Parameters:
      b1Index - index of first row
      b1 - batch for first row
      b2Index - index of second row
      b2 - batch for second row
      Returns:
      true if the rows are in the same partition