Adds the group by list from a query to a query assembler.

@param \Aztech\Skwal\Visitor\Printer\Assembler\Select $assembler
@param \Aztech\Skwal\Query\Select $query
768304
private function appendGroupByList(\Aztech\Skwal\Visitor\Printer\Assembler\Select $assembler,\Aztech\Skwal\Query\Select $query)
    {
        $this->expressionVisitor->useAliases(false);
        
        $groupByList = array();
        
        foreach ($query->getGroupingColumns() as $groupingColumn) {
            $groupByList[] = $this->expressionVisitor->printExpression($groupingColumn);
        }
        
        $assembler->setGroupByList($groupByList);
    }
870709
protected function compileJoins(Builder $query, $joins)
    {
        $sql = array();

        $query->setBindings(array(), 'join');

        foreach ($joins as $join) {
            $table = $this->wrapTable($join->table);

            $clauses = array();

            foreach ($join->clauses as $clause) {
                $clauses[] = $this->compileJoinConstraint($clause);
            }

            foreach ($join->bindings as $binding) {
                $query->addBinding($binding, 'join');
            }

            $clauses[0] = $this->removeLeadingBoolean($clauses[0]);

            $clauses = implode(' ', $clauses);

            $type = $join->type;

            //
            $sql[] = "$type join $table on $clauses";
        }

        return implode(' ', $sql);
    }
781540
public function multiAggregate(Query $query, $extra)
    {
        $options = $query->getOptions();

        list($aggregate, $groupBy) = $extra;
        $groups                    = ['_id' => []];
        foreach ($groupBy as $field) {
            $groups['_id'][$field] = '$' . $field;
        }

        foreach ($aggregate as $fun => $field) {
            $groups[$field . '_' . $fun] = ['$' . $fun => '$' . $field];
        }
        $pipeline = [
            ['$match' => (object) $this->parseWhere($query, $options['where'])],
            ['$group' => $groups],
        ];
        $cmd = [
            'aggregate'    => $options['table'],
            'allowDiskUse' => true,
            'pipeline'     => $pipeline,
            'cursor'       => new \stdClass,
        ];

        foreach (['explain', 'collation', 'bypassDocumentValidation', 'readConcern'] as $option) {
            if (isset($options[$option])) {
                $cmd[$option] = $options[$option];
            }
        }
        $command = new Command($cmd);
        $this->log('group', $cmd);
        return $command;
    }
76594
public function rawSelect(Query $query, $join = 'all')
        {
            if (!$query instanceof Query) {
                $query = new Query($this);
            }

            $query->setupJoinTables($join);
            $query->generateSelectSQL();

            $resultset = Statement::getPreparedStatement($query)->execute();
            return ($resultset->count()) ? $resultset : null;
        }
643927
protected function checkOrder(Sql\Select $query)
    {
        $order  = $this->getEntityDescriptor()->getPrimaryKey()->getField();
        $order .= " DESC";
        if (null != $this->order) {
            $order = $this->order;
        }
        $query->order($order);
        return $this;
    }
428957
public function buildQuery($query)
	{
		foreach($this->children as $child)
		{
			if($child->master!==null)
				$child->_joined=true;
			elseif($child->relation instanceof CHasOneRelation || $child->relation instanceof CBelongsToRelation
				|| $this->_finder->joinAll || $child->relation->together || (!$this->_finder->baseLimited && $child->relation->together===null))
			{
				$child->_joined=true;
				$query->join($child);
				$child->buildQuery($query);
			}
		}
	}
393944
protected function compileJoins(Builder $query, $joins)
    {
        return collect($joins)->map(function ($join) use ($query) {
            $table = $this->wrapTable($join->table);

            $nestedJoins = is_null($join->joins) ? '' : ' '.$this->compileJoins($query, $join->joins);

            $tableAndNestedJoins = is_null($join->joins) ? $table : '('.$table.$nestedJoins.')';

            return trim("{$join->type} join {$tableAndNestedJoins} {$this->compileWheres($join)}");
        })->implode(' ');
    }
539753
public function runQuery($query)
	{
		$command=$query->createCommand($this->_builder);
		foreach($command->queryAll() as $row)
			$this->populateRecord($query,$row);
	}
1029292
public function unionAll(SelectQuery $query)
    {
        $instance = $this->selectQueryInstance();

        $instance->selectQuery()->unionAll($query);

        return $instance;
    }
657117
public function applyOrderBy(SelectQuery $query)
    {
        foreach ($this->sortColumns as $column => $direction) {
            $query->orderBy(
                $column,
                $direction === Query::SORT_ASC ? SelectQuery::ASC : SelectQuery::DESC
            );
        }
        // @todo Review needed
        // The following line was added because without it, loading sub user groups through the Public API
        // fails with the database error "Unknown column sort_column_0". The change does not break any
        // integration tests or legacy persistence tests, but it can break something else, so review is needed
        // Discussion: https://github.com/ezsystems/ezpublish-kernel/commit/8749d0977307858c3e2a7d82f3be90fa21973357#L1R102
        $this->sortColumns = array();
    }
200961
protected function makeGroupBy(Builder $query)
    {
        if ($groupBy = $this->getGroupBy()) {
            $query->groupBy($groupBy);
        } else {
            $driver = $this->getDatabaseDriver();

            if ($driver == 'sqlsrv') {
                $columns = $this->getTableColumns();
            } else {
                $columns = $this->getTable() . '.' .$this->primaryKey;
            }

            $query->groupBy($columns);

            $joins = array_keys(($this->getJoins()));

            foreach ($this->getColumns() as $column => $relevance) {
                array_map(function ($join) use ($column, $query) {
                    if (Str::contains($column, $join)) {
                        $query->groupBy($column);
                    }
                }, $joins);
            }
        }
    }
104873
private function applyFilters(AbstractQueryBuilder $query)
    {
        //GroupBy is only applicable to Select
        if ($query instanceof Select) {
            if (isset($this->groupByFields)) {
                $query->groupBy($this->groupByFields);
            }
            $this->joinRelationsToQuery($this->entity, $query, $this->with);
        }
        if (isset($this->where)) {
            $query->where($this->where);
        }
        foreach ($this->orderByFields as $field) {
            list($fieldName, $order) = $field;
            $query->orderBy($fieldName, $order);
        }
        if (empty($this->with)) {
            //Limits for joined queries are handled in a different way
            if (isset($this->limit)) {
                $query->setMaxResults($this->limit);
            }
            if (isset($this->offset)) {
                $query->setFirstResult($this->offset);
            }
        }

        return $query;
    }
503900
public function compileSelect(Builder $query) {
    $this->beforeGet($query);
    return $this->grammar->compileSelect($query);
  }
99601
public function aggregate(Query $query, $extra)
    {
        $options           = $query->getOptions();
        list($fun, $field) = $extra;

        if ('id' == $field && $this->connection->getConfig('pk_convert_id')) {
            $field = '_id';
        }

        $group = isset($options['group']) ? '$' . $options['group'] : null;

        $pipeline = [
            ['$match' => (object) $this->parseWhere($query, $options['where'])],
            ['$group' => ['_id' => $group, 'aggregate' => ['$' . $fun => '$' . $field]]],
        ];

        $cmd = [
            'aggregate'    => $options['table'],
            'allowDiskUse' => true,
            'pipeline'     => $pipeline,
            'cursor'       => new \stdClass,
        ];

        foreach (['explain', 'collation', 'bypassDocumentValidation', 'readConcern'] as $option) {
            if (isset($options[$option])) {
                $cmd[$option] = $options[$option];
            }
        }

        $command = new Command($cmd);

        $this->log('aggregate', $cmd);

        return $command;
    }
108157
public function compileSelect(Builder $query)
    {
        $original = $query->columns;

        if (is_null($query->columns)) {
            $query->columns = ['*'];
        }

        $sql = trim($this->concatenate($this->compileComponents($query)));

        $query->columns = $original;

        return $sql;
    }
191354
protected function load(Select $query) : array
    {
        $rows = $this->connection->load($query);

        return $this->mapper->loadAll($this->loadingContext, $rows->getRows());
    }
852409
protected function compileDeleteWithJoins(Builder $query, $table, $where) {
        $joins = $this->compileJoins($query);

        $alias = strpos(strtolower($table), ' as ') !== false
            ? explode(' as ', $table)[1] : $table;

        return trim("delete {$alias} from {$table}{$joins} {$where}");
    }