All Implemented Interfaces:
LogicalOperator, PipelineOperator<RecordPort>, RecordPipelineOperator

public class LimitRows extends AbstractRecordCompositeOperator
Truncates a flow to a fixed number of records. The output is a "window" on the original input. This operator is most often used on the output of a sort, reducing the original unsorted data to the top N (as measured by the sort criteria).

By default, all records are passed through unless explicitly specified.

  • Constructor Details

    • LimitRows

      public LimitRows()
      Performs no truncation of the input flow.
    • LimitRows

      public LimitRows(long count)
      Truncates incoming data to the first N records of the input.
      Parameters:
      count - the number of records to pass through
    • LimitRows

      public LimitRows(long skip, long count)
      Truncates incoming data to the first N records following a specified record. Records prior to the start position are discarded; if the input contains insufficient records to reach the starting point, the output will contain no records.
      Parameters:
      skip - the record at which to start passing through records. Indices are zero-based; that is, the first record is at index 0.
      count - the number of records to pass through
  • Method Details

    • getInput

      public RecordPort getInput()
      Description copied from interface: PipelineOperator
      Returns the input port
      Specified by:
      getInput in interface PipelineOperator<RecordPort>
      Overrides:
      getInput in class AbstractRecordCompositeOperator
      Returns:
      the input port
    • getOutput

      public RecordPort getOutput()
      Description copied from interface: PipelineOperator
      Returns the output port
      Specified by:
      getOutput in interface PipelineOperator<RecordPort>
      Overrides:
      getOutput in class AbstractRecordCompositeOperator
      Returns:
      the output port
    • getCount

      public long getCount()
      Gets the maximum number of records which will be output.
      Returns:
      the limit on the number of output records
    • setCount

      public void setCount(long count)
      Sets the maximum number of records which will be output.
      Parameters:
      count - the limit on the number of output records.
      Throws:
      InvalidPropertyValueException - if count <= 0
    • getSkip

      public long getSkip()
      Gets the number of input records to skip before outputting records.
      Returns:
      the index of the first record to pass through
    • setSkip

      public void setSkip(long skip)
      Sets the number of input records to skip before outputting records.
      Parameters:
      skip - the index of the first record to pass through
      Throws:
      InvalidPropertyValueException - if count < 0
    • compose

      protected void compose(CompositionContext ctx)
      Description copied from class: CompositeOperator
      Compose the body of this operator. Implementations should do the following:
      1. Perform any validation of configuration, input types, etc
      2. Instantiate and configure sub-operators, adding them to the provided context via the method OperatorComposable.add(O)
      3. Create necessary connections via the method OperatorComposable.connect(P, P). This includes connections from the composite's input ports to sub-operators, connections between sub-operators, and connections from sub-operators output ports to the composite's output ports
      Specified by:
      compose in class CompositeOperator
      Parameters:
      ctx - the context