public function aggregate(Query $query, $function, $field) {
        $query->fields(
            Query::func(strtoupper($function), [$field => Func::FIELD])->asAlias('aggregate')
        );

        $results = $this->getDriver()
            ->setContext('read')
            ->executeQuery($query)
            ->find();

        if (isset($results[0])) {
            return (int) $results[0]['aggregate'];
        }

        return 0;
    }