use of com.actiontech.dble.plan.Order in project dble by actiontech.
the class PlanNode method groupBy.
public PlanNode groupBy(Item c, SQLOrderingSpecification sortOrder) {
Order order = new Order(c, sortOrder);
this.groups.add(order);
return this;
}
use of com.actiontech.dble.plan.Order in project dble by actiontech.
the class PlanNode method copySelfTo.
protected final void copySelfTo(PlanNode to) {
to.setAlias(this.alias);
to.setDistinct(this.isDistinct);
for (Item selected : this.getColumnsSelected()) {
Item copySel = selected.cloneItem();
copySel.setItemName(selected.getItemName());
to.columnsSelected.add(copySel);
}
for (Order groupBy : this.getGroupBys()) {
to.groups.add(groupBy.copy());
}
for (Order orderBy : this.getOrderBys()) {
to.orderBys.add(orderBy.copy());
}
to.whereFilter = this.whereFilter == null ? null : this.whereFilter.cloneItem();
to.havingFilter = this.havingFilter == null ? null : havingFilter.cloneItem();
to.setLimitFrom(this.limitFrom);
to.setLimitTo(this.limitTo);
to.setSql(this.getSql());
to.setSubQuery(subQuery);
to.setCorrelatedSubQuery(correlatedSubQuery);
to.setUnGlobalTableCount(unGlobalTableCount);
to.setNoshardNode(noshardNode);
}
use of com.actiontech.dble.plan.Order in project dble by actiontech.
the class BaseHandlerBuilder method mergeOrderBy.
/**
* try to merger the order of 'order by' syntax to columnsSelected
*
* @param columnsSelected
* @param orderBys
* @return
*/
private List<Order> mergeOrderBy(List<Item> columnsSelected, List<Order> orderBys) {
List<Integer> orderIndexes = new ArrayList<>();
List<Order> newOrderByList = new ArrayList<>();
for (Order orderBy : orderBys) {
Item column = orderBy.getItem();
int index = columnsSelected.indexOf(column);
if (index < 0)
return null;
else
orderIndexes.add(index);
Order newOrderBy = new Order(columnsSelected.get(index), orderBy.getSortOrder());
newOrderByList.add(newOrderBy);
}
for (int index = 0; index < columnsSelected.size(); index++) {
if (!orderIndexes.contains(index)) {
Order newOrderBy = new Order(columnsSelected.get(index), SQLOrderingSpecification.ASC);
newOrderByList.add(newOrderBy);
}
}
return newOrderByList;
}
use of com.actiontech.dble.plan.Order in project dble by actiontech.
the class GlobalVisitor method buildGroupBy.
protected void buildGroupBy(PlanNode query) {
boolean first = true;
if (query.getGroupBys() != null && query.getGroupBys().size() > 0) {
sqlBuilder.append(" GROUP BY ");
for (Order group : query.getGroupBys()) {
if (first)
first = false;
else
sqlBuilder.append(",");
Item groupCol = group.getItem();
String pdName = "";
if (groupCol.basicConstItem())
pdName = "'" + groupCol.toString() + "'";
if (pdName.isEmpty())
pdName = visitUnSelPushDownName(groupCol, true);
sqlBuilder.append(pdName).append(" ").append(group.getSortOrder());
}
}
}
use of com.actiontech.dble.plan.Order in project dble by actiontech.
the class MultiNodeSelectHandler method mergeFieldEof.
private void mergeFieldEof(List<byte[]> fields, BackendConnection conn) throws IOException {
fieldCount = fields.size();
List<FieldPacket> fieldPackets = new ArrayList<>();
for (byte[] field : fields) {
this.netOutBytes += field.length;
FieldPacket fieldPacket = new FieldPacket();
fieldPacket.read(field);
if (rrs.getSchema() != null) {
fieldPacket.setDb(rrs.getSchema().getBytes());
}
if (rrs.getTableAlias() != null) {
fieldPacket.setTable(rrs.getTableAlias().getBytes());
}
if (rrs.getTable() != null) {
fieldPacket.setOrgTable(rrs.getTable().getBytes());
}
fieldPackets.add(fieldPacket);
}
List<Order> orderBys = new ArrayList<>();
for (String groupBy : rrs.getGroupByCols()) {
ItemField itemField = new ItemField(rrs.getSchema(), rrs.getTableAlias(), groupBy);
orderBys.add(new Order(itemField));
}
rowComparator = new RowDataComparator(fieldPackets, orderBys);
outputHandler.fieldEofResponse(null, null, fieldPackets, null, false, conn);
}
Aggregations