Skip to content

Commit

Permalink
for #2567, remove SelectItems.containStar
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Jul 13, 2019
1 parent c822f4c commit c2385f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Expand Up @@ -109,7 +109,7 @@ private void setIndexForOrderItem(final Map<String, Integer> columnLabelIndexMap
}

private Optional<String> getAlias(final String name) {
if (selectItems.isContainStar()) {
if (selectItems.isUnqualifiedShorthandItem()) {
return Optional.absent();
}
String rawName = SQLUtil.getExactlyValue(name);
Expand Down
Expand Up @@ -43,7 +43,18 @@ public final class SelectItems {

private final int selectListStopIndex;

private boolean containStar;
/**
* Judge is unqualified shorthand item or not.
*
* @return is unqualified shorthand item or not
*/
public boolean isUnqualifiedShorthandItem() {
if (1 != items.size()) {
return false;
}
SelectItem item = items.iterator().next();
return item instanceof ShorthandSelectItem && !((ShorthandSelectItem) item).getOwner().isPresent();
}

/**
* Find alias.
Expand Down
Expand Up @@ -65,10 +65,9 @@ public final class SelectItemsEngine {
public SelectItems createSelectItems(final SelectStatement selectStatement, final GroupBy groupBy, final OrderBy orderBy) {
SelectItemsSegment selectItemsSegment = getSelectItemsSegment(selectStatement);
Collection<SelectItem> items = getSelectItemList(selectItemsSegment, selectStatement);
items.addAll(getDerivedGroupByColumns(selectStatement, items, groupBy.getItems()));
items.addAll(getDerivedOrderByColumns(selectStatement, items, orderBy.getItems()));
SelectItems result = new SelectItems(items, selectItemsSegment.isDistinctRow(), selectItemsSegment.getStopIndex());
result.setContainStar(isUnqualifiedShorthandItem(items));
result.getItems().addAll(getDerivedGroupByColumns(selectStatement, items, groupBy));
result.getItems().addAll(getDerivedOrderByColumns(selectStatement, items, orderBy));
return result;
}

Expand All @@ -89,12 +88,12 @@ private Collection<SelectItem> getSelectItemList(final SelectItemsSegment select
return result;
}

private Collection<SelectItem> getDerivedGroupByColumns(final SelectStatement selectStatement, final Collection<SelectItem> selectItems, final Collection<OrderByItem> groupByItems) {
return getDerivedOrderColumns(selectStatement, selectItems, groupByItems, DerivedColumn.GROUP_BY_ALIAS);
private Collection<SelectItem> getDerivedGroupByColumns(final SelectStatement selectStatement, final Collection<SelectItem> selectItems, final GroupBy groupBy) {
return getDerivedOrderColumns(selectStatement, selectItems, groupBy.getItems(), DerivedColumn.GROUP_BY_ALIAS);
}

private Collection<SelectItem> getDerivedOrderByColumns(final SelectStatement selectStatement, final Collection<SelectItem> selectItems, final Collection<OrderByItem> orderByItems) {
return getDerivedOrderColumns(selectStatement, selectItems, orderByItems, DerivedColumn.ORDER_BY_ALIAS);
private Collection<SelectItem> getDerivedOrderByColumns(final SelectStatement selectStatement, final Collection<SelectItem> selectItems, final OrderBy orderBy) {
return getDerivedOrderColumns(selectStatement, selectItems, orderBy.getItems(), DerivedColumn.ORDER_BY_ALIAS);
}

private Collection<SelectItem> getDerivedOrderColumns(final SelectStatement selectStatement,
Expand Down

0 comments on commit c2385f5

Please sign in to comment.