Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.iplass.mtp.entity.query.SortSpec.NullOrderingSpec;
import org.iplass.mtp.entity.query.SortSpec.SortType;
import org.iplass.mtp.entity.query.condition.Condition;
import org.iplass.mtp.entity.query.value.ValueExpression;
import org.iplass.mtp.entity.query.value.primary.EntityField;
import org.iplass.mtp.entity.query.value.primary.Literal;
import org.iplass.mtp.impl.parser.ParseContext;
Expand Down Expand Up @@ -190,20 +191,21 @@ public Select getSelect() {
}
}
}
List<ValueExpression> fieldSelection = select.stream()
.<ValueExpression> map(EntityField::new)
.toList();
List<ValueExpression> orderBySelection = Optional.ofNullable(getOrderBy())
.stream()
.flatMap(orderBy -> orderBy.getSortSpecList()
.stream()
.map(SortSpec::getSortKey))
.toList();

// ソート条件のデータを取得カラムにしておかないと、DistinctでSQLエラーになる。
Comment thread
xtakahashi-hiroyuki marked this conversation as resolved.
OrderBy orderBy = getOrderBy();
if (orderBy != null) {
for (SortSpec sortSpec : orderBy.getSortSpecList()) {
String sortKey = sortSpec.getSortKey()
.toString();
if (!select.contains(sortKey))
addSearchProperty(select, sortKey);
}
}
boolean distinct = getConditionSection().isDistinct();
Select s = new Select().add(select.toArray());
s.setDistinct(distinct);
return s;
boolean isDistinct = getConditionSection().isDistinct();
return new Select(isDistinct, (isDistinct ? Stream.concat(fieldSelection.stream(), orderBySelection.stream()) : fieldSelection.stream())
.distinct()
.toList());
}

@Override
Expand Down
Loading