<commit_before><?php

namespace WebinoData\Paginator\Adapter;

use WebinoData\DataSelect;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;

class WebinoDataSelect extends DbSelect
{
    protected $dataSelect;
    protected $service;
    protected $overflow = 0;

    public function __construct(DataSelect $select, $service)
    {
        parent::__construct($select->getSqlSelect(), $service->getAdapter());

        $this->dataSelect = $select;
        $this->service    = $service;
    }

    public function setOverflow($overflow)
    {
        $this->overflow = $overflow;
        return $this;
    }

    /**
     * Returns an array of items for a page.
     *
     * @param  int $offset           Page offset
     * @param  int $itemCountPerPage Number of items per page
     * @return array
     */
    public function getItems($offset, $itemCountPerPage)
    {
        $select = clone $this->dataSelect;
        $select->offset($offset);
        $select->limit($itemCountPerPage + $this->overflow);

        return $this->service->fetchWith($select);
    }
}<commit_msg>Fixed paginator adapter count() when group by<commit_after><?php

namespace WebinoData\Paginator\Adapter;

use WebinoData\DataSelect;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;

class WebinoDataSelect extends DbSelect
{
    protected $dataSelect;
    protected $service;
    protected $overflow = 0;

    public function __construct(DataSelect $select, $service)
    {
        parent::__construct($select->getSqlSelect(), $service->getAdapter());

        $this->dataSelect = $select;
        $this->service    = $service;
    }

    public function setOverflow($overflow)
    {
        $this->overflow = $overflow;
        return $this;
    }

    /**
     * Returns an array of items for a page.
     *
     * @param  int $offset           Page offset
     * @param  int $itemCountPerPage Number of items per page
     * @return array
     */
    public function getItems($offset, $itemCountPerPage)
    {
        $select = clone $this->dataSelect;
        $select->offset($offset);
        $select->limit($itemCountPerPage + $this->overflow);

        return $this->service->fetchWith($select);
    }

    /**
     * Returns the total number of rows in the result set
     *
     * @return int
     */
    public function count()
    {
        if ($this->rowCount !== null) {
            return $this->rowCount;
        }

        $select = clone $this->select;
        $select->reset(Select::COLUMNS);
        $select->reset(Select::LIMIT);
        $select->reset(Select::OFFSET);
        $select->reset(Select::ORDER);

        // get join information, clear, and repopulate without columns
        $joins = $select->getRawState(Select::JOINS);
        $select->reset(Select::JOINS);
        foreach ($joins as $join) {
            $select->join($join['name'], $join['on'], array(), $join['type']);
        }

        $select->columns(array('c' => new Expression('COUNT(*)')));

        $sql = 'SELECT COUNT(*) as c FROM(' . $this->sql->getSqlStringForSqlObject($select) . ') AS x';

        $statement = $this->sql->getAdapter()->createStatement($sql);
        $result    = $statement->execute();
        $row       = $result->current();

        $this->rowCount = $row['c'];

        return $this->rowCount;
    }
}
{'fraction_non_alphanumeric': 0.1408325952170062, 'fraction_numerical': 0.000590493061706525, 'mean_word_length': 2.566315789473684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '1082194', 'n_tokens_mistral': 995, 'n_tokens_neox': 971, 'n_words': 224}