Class LimitRows

  • 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 Detail

      • 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 Detail

      • 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