GroupBy statement.

@param array|string $fields
string|array field name or list of field names as array

@return \Core\Data\Connectors\Db\QueryBuilder\QueryBuilder
343631
public function GroupBy($fields): QueryBuilder
    {
        if (is_array($fields)) {
            $fields = implode(', ', $field);
        }
        
        $this->group_by = $fields;
        
        return $this;
    }
20990
public function fields(array $fields)
    {
        $newFields = array();
        $this->fields = '';
        $this->fieldsArguments = array();

        foreach ($fields as $field) {
            if (is_scalar($field)) {
                $newFields[] = '?f:alias:.?f';
                $this->fieldsArguments[] = $field;
            } else {
                if (!isset($field[0]) or !isset($field[1]) or !is_array($field[1])) {
                    throw new \BadMethodCallException('Must be exist 0 and 1 index in array and second one must be an array');
                }
                $newFields[] = $field[0];
                $this->fieldsArguments = array_merge($this->fieldsArguments, $field[1]);
            }
        }

        $this->fields = implode(', ', $newFields);

        return $this;
    }
563575
protected function parseGroupBy($schema, $fields = null)
    {
        $outArray = [];
        if (!empty($fields)) {
            foreach ($fields as $field) {
                if ($fieldInfo = $schema->getColumn($field, true)) {
                    $outArray[] = $fieldInfo->name;
                } else {
                    if (false !== strpos($field, ';')) {
                        throw new BadRequestException('Invalid group by clause in request.');
                    }
                    $outArray[] = DB::raw($field); // todo better checks on group by clause
                }
            }
        }

        return $outArray;
    }
1035597
public function whereNotNull($fields)
    {
        if (!is_array($fields)) {
            $fields = [$fields];
        }

        $exp = $this->newExpr();

        foreach ($fields as $field) {
            $exp->isNotNull($field);
        }

        return $this->where($exp);
    }
1297352
public function groupBy($field)
    {
        $field = $this->addTablePrefix($field);
        $this->addStatement('groupBys', $field);
        return $this;
    }
959403
public function group($fields)
    {
        if (!$fields) {
            return $this;
        }
        if ($fields = is_array($fields) ? $fields : func_get_args()) {
            $this->_parts['group'] = array_merge($this->_parts['group'], array_fill_keys($fields, true));
        }
        return $this;
    }
1188232
public function select($fields)
    {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $fields = $this->addTablePrefix($fields);
        $this->addStatement('selects', $fields);
        return $this;
    }
446414
public function select(...$fields) {
        $sql = new Query(...$fields);
        $sql->setDialect($this->dialect);

        return $sql;
    }
134778
public function groupBy(...$groups)
    {
        foreach ($groups as $group) {
            $this->groups = array_merge((array) $this->groups, is_array($group) ? $group : [$group]);
        }

        return $this;
    }
174803
public function setFields(array $fields)
    {
        $this->fields = [];

        foreach ($fields as $type => $field) {
            //Remove empty and repeated fields
            $this->fields[$type] = array_unique(array_filter(explode(',', $field)));
        }

        return $this;
    }
729799
public function addParamsGrouping($fields = [])
    {
        if (is_array($fields) && !empty($fields))
        {
            $this->groupingParams = array_merge(is_array($this->groupingParams) ? $this->groupingParams : [], $fields);
        }
    }
539768
public function sort(array $fields)
	{
		$sortFields = [];
		foreach ($fields as $field => $value) {
			// Simplest form, just a field name.
			if (is_numeric($field) && !is_array($value)) {
				$sortFields[] = $value;
			} // Field with direction and/or other options.
			else {
				$sortFields[] = [$field => $value];
			}
		}

		$this->set('sort', $sortFields);

		return $this;
	}
479231
public function groupBy(...$keys)
    {
        $data = [];

        while ($row = $this->getNextRow()) {

            $position = &$data;

            foreach ($keys as $key) {
                if (is_callable($key)) {
                    $value = $key($row);
                } else {
                    $value = $row[$key];
                }

                if (!array_key_exists($value, $position)) {
                    $position[$value] = [];
                }
                $position = &$position[$value];
            }

            $position[] = $row;
            unset($position);
        }

        return $data;
    }
1036463
public function fields(array $fields)
    {
        foreach ($fields as $field) {
            if ($field instanceof Mapper) {
                $this->addFieldFromMapper($field);
                continue;
            }
            $this->fields[] = $field;
        }

        return $this;
    }
731139
public function groupBy(...$groups)
    {
        foreach (func_get_args() as $arg) {
            $this->query->group($arg)->ungroup()->map(function ($doc) {
                return $doc('reduction')->nth(0);
            });
        }

        return $this;
    }
684374
public function select($fields)
    {
        if (!$fields) {
            return $this;
        }

        if (is_string($fields)) {
            $fields = (array)preg_split('#[\s,]+#', $fields, -1, PREG_SPLIT_NO_EMPTY);
        }

        if ($fields) {
            $this->_projection_alias = [];

            if (isset($fields[count($fields) - 1])) {
                $this->_projection = array_fill_keys($fields, 1);
            } else {
                $projection = [];
                foreach ($fields as $k => $v) {
                    if (is_int($k)) {
                        $projection[$v] = 1;
                    } else {
                        $this->_projection_alias[$k] = $v;
                        $projection[$v] = 1;
                    }
                }
                $this->_projection = $projection;
            }

            if (!isset($this->_projection['_id'])) {
                $this->_projection['_id'] = false;
            }
        }

        return $this;
    }
484049
public function fields($fields)
    {
        if (is_array($fields) || $fields === null) {
            $this->fields = $fields;
        } else {
            $this->fields = func_get_args();
        }
        return $this;
    }