<commit_before>package com.facebook.presto.operator;

import com.facebook.presto.block.Block;
import com.facebook.presto.tuple.TupleInfo;

import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

public class LimitOperator
        implements Operator
{
    private final Operator source;
    private final long limit;

    public LimitOperator(Operator source, long limit)
    {
        checkNotNull(source, "source is null");
        checkArgument(limit >= 0, "limit must be at least zero");

        this.source = source;
        this.limit = limit;
    }

    @Override
    public int getChannelCount()
    {
        return source.getChannelCount();
    }

    @Override
    public List<TupleInfo> getTupleInfos()
    {
        return source.getTupleInfos();
    }

    @Override
    public PageIterator iterator(OperatorStats operatorStats)
    {
        return new LimitIterator(source.iterator(operatorStats), limit);
    }

    private static class LimitIterator
            extends AbstractPageIterator
    {
        private final PageIterator sourceIterator;
        private long remainingLimit;

        private LimitIterator(PageIterator sourceIterator, long limit)
        {
            super(sourceIterator.getTupleInfos());
            this.sourceIterator = sourceIterator;
            this.remainingLimit = limit;
        }

        @Override
        protected Page computeNext()
        {
            if (!sourceIterator.hasNext() || remainingLimit <= 0) {<commit_msg>Check for limit before source iterator<commit_after>package com.facebook.presto.operator;

import com.facebook.presto.block.Block;
import com.facebook.presto.tuple.TupleInfo;

import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

public class LimitOperator
        implements Operator
{
    private final Operator source;
    private final long limit;

    public LimitOperator(Operator source, long limit)
    {
        checkNotNull(source, "source is null");
        checkArgument(limit >= 0, "limit must be at least zero");

        this.source = source;
        this.limit = limit;
    }

    @Override
    public int getChannelCount()
    {
        return source.getChannelCount();
    }

    @Override
    public List<TupleInfo> getTupleInfos()
    {
        return source.getTupleInfos();
    }

    @Override
    public PageIterator iterator(OperatorStats operatorStats)
    {
        return new LimitIterator(source.iterator(operatorStats), limit);
    }

    private static class LimitIterator
            extends AbstractPageIterator
    {
        private final PageIterator sourceIterator;
        private long remainingLimit;

        private LimitIterator(PageIterator sourceIterator, long limit)
        {
            super(sourceIterator.getTupleInfos());
            this.sourceIterator = sourceIterator;
            this.remainingLimit = limit;
        }

        @Override
        protected Page computeNext()
        {
            if (remainingLimit <= 0 || !sourceIterator.hasNext()) {
{'fraction_non_alphanumeric': 0.07959887182701347, 'fraction_numerical': 0.0012535255405828893, 'mean_word_length': 2.703016241299304, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465634', 'n_tokens_mistral': 825, 'n_tokens_neox': 800, 'n_words': 205}