private function renameSelectFields(SelectQuery $query, $namesMap = null, $originalSource = null) {
        if($namesMap == null) {
            $namesMap = $this->getColumnNames();
        }
        $selectFields = &$query->getSelectFields();
        //en el caso que no se indique nada en el select, pongo los del mapa
        if (empty($selectFields)) {
            foreach ($namesMap as $aliasName => $columnName) {
                if (is_numeric($aliasName)) {
                    $selectItem = $columnName;
                } else if (empty($columnName) || $aliasName === $columnName) {
                    $selectItem = $aliasName;
                } else {
                    $selectItem = [$columnName, $aliasName];
                }
                $query->select($selectItem);
            }
        } else {
            //primer for para busqueda de * o tabla.* y agregado de campos
            $newSelectFields = [];
            foreach ($selectFields as $selectField) {
                $aliasName = $selectField instanceof stdClass ? trim($selectField->expression) : trim($selectField);
                if ($aliasName == '*') {
                    foreach ($namesMap as $aliasName => $columnName) {
                        if (is_numeric($aliasName)) {
                            $newSelectFields[$columnName] = $columnName;
                        } else {
                            $newSelectFields[$aliasName] = $aliasName;
                        }
                    }
                    continue;

                } else if (!empty($originalSource) && $aliasName == "$originalSource.*") {
                    foreach ($namesMap as $aliasName => $columnName) {
                        if (is_numeric($aliasName)) {
                            $newSelectFields["$originalSource.$columnName"] = "$originalSource.$columnName";
                        } else {
                            $newSelectFields["$originalSource.$aliasName"] = "$originalSource.$aliasName";
                        }
                    }
                    continue;

                } else {
                    $newSelectFields[$aliasName] = $selectField;
                }
            }
            if (!empty($newSelectFields)) {
                $query->selectFields(array_values($newSelectFields));
            }
            //segundo for para reemplazo de nombres
            foreach ($selectFields as &$field) {
                if ($field instanceof stdClass) {
                    $aliasName = $field->alias;
                    $columnName = $this->getFieldNewName($field->expression, $namesMap, $originalSource, $query->getTable());
                } else {
                    $aliasName = $field;
                    $columnName = $this->getFieldNewName($field, $namesMap, $originalSource, $query->getTable());
                }
                if($columnName != null) {
                    if ($columnName == $aliasName) {
                        $field = $columnName;
                    } else {
                        $field = new stdClass();
                        $field->expression = $columnName;
                        $field->alias = $aliasName;
                    }
                }
            }
        }
    }