use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class MysqlVisitor method buildWhere.
/* change where to replaceable */
protected void buildWhere(PlanNode planNode) {
if (!visited)
replaceableSqlBuilder.getCurrentElement().setRepString(replaceableWhere);
StringBuilder whereBuilder = new StringBuilder();
Item filter = planNode.getWhereFilter();
if (filter != null) {
String pdName = visitUnSelPushDownName(filter, false);
whereBuilder.append(" where ").append(pdName);
}
replaceableWhere.set(whereBuilder.toString());
// refresh sqlbuilder
sqlBuilder = replaceableSqlBuilder.getCurrentElement().getSb();
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class AllAnySubQueryHandler method fieldEofResponse.
@Override
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
if (terminate.get()) {
return;
}
lock.lock();
try {
// create field for first time
if (this.fieldPackets.isEmpty()) {
this.fieldPackets = fieldPackets;
sourceField = HandlerTool.createField(this.fieldPackets.get(0));
Item select = itemSubQuery.getSelect();
select.setPushDownName(select.getAlias());
Item tmpItem = HandlerTool.createItem(select, Collections.singletonList(this.sourceField), 0, isAllPushDown(), type());
itemSubQuery.setFiled(tmpItem);
rowComparator = new RowDataComparator(this.fieldPackets, Collections.singletonList(new Order(select)), this.isAllPushDown(), this.type());
}
} finally {
lock.unlock();
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class SingleRowSubQueryHandler method setSubQueryFiled.
private void setSubQueryFiled() {
Item select = itemSubQuery.getSelect();
select.setPushDownName(select.getAlias());
Item tmpItem = HandlerTool.createItem(select, Collections.singletonList(this.sourceField), 0, isAllPushDown(), type());
itemSubQuery.setValue(tmpItem);
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class PushDownVisitor method buildSelect.
protected void buildSelect(PlanNode query) {
sqlBuilder.append("select ");
if (query.isDistinct()) {
sqlBuilder.append("DISTINCT ");
}
List<Item> columns = query.getColumnsRefered();
if (columns.size() == 0) {
sqlBuilder.append("1");
return;
}
for (Item col : columns) {
if (existUnPushDownGroup && col.type().equals(Item.ItemType.SUM_FUNC_ITEM))
continue;
if ((col.type().equals(Item.ItemType.FUNC_ITEM) || col.type().equals(Item.ItemType.COND_ITEM)) && col.isWithSumFunc())
continue;
String pdName = visitPushDownNameSel(col);
if (// it's null when duplicate column
StringUtils.isEmpty(pdName))
continue;
if (col.type().equals(Item.ItemType.SUM_FUNC_ITEM)) {
ItemSum funCol = (ItemSum) col;
String funName = funCol.funcName().toUpperCase();
String colName = pdName;
ItemSum.SumFuncType i = funCol.sumType();
if (i == ItemSum.SumFuncType.AVG_FUNC) {
String colNameSum = colName.replace(funName + "(", "SUM(");
colNameSum = colNameSum.replace(getMadeAggAlias(funName), getMadeAggAlias("SUM"));
String colNameCount = colName.replace(funName + "(", "COUNT(");
colNameCount = colNameCount.replace(getMadeAggAlias(funName), getMadeAggAlias("COUNT"));
sqlBuilder.append(colNameSum).append(",").append(colNameCount).append(",");
continue;
} else if (i == ItemSum.SumFuncType.STD_FUNC || i == ItemSum.SumFuncType.VARIANCE_FUNC) {
String colNameCount = colName.replace(funName + "(", "COUNT(");
colNameCount = colNameCount.replace(getMadeAggAlias(funName), getMadeAggAlias("COUNT"));
String colNameSum = colName.replace(funName + "(", "SUM(");
colNameSum = colNameSum.replace(getMadeAggAlias(funName), getMadeAggAlias("SUM"));
String colNameVar = colName.replace(funName + "(", "VARIANCE(");
colNameVar = colNameVar.replace(getMadeAggAlias(funName), getMadeAggAlias("VARIANCE"));
sqlBuilder.append(colNameCount).append(",").append(colNameSum).append(",").append(colNameVar).append(",");
continue;
}
}
sqlBuilder.append(pdName);
sqlBuilder.append(",");
}
sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class PushDownVisitor method buildOrderBy.
protected void buildOrderBy(PlanNode query) {
/* if group by exists,it must merge as "group by"'s order,so don't push down order */
boolean realPush = query.getGroupBys().isEmpty();
if (query.getOrderBys().size() > 0) {
if (realPush)
sqlBuilder.append(" ORDER BY ");
for (Order order : query.getOrderBys()) {
Item orderByCol = order.getItem();
String pdName = "";
if (orderByCol.basicConstItem())
pdName = "'" + orderByCol.toString() + "'";
if (pdName.isEmpty())
pdName = visitUnSelPushDownName(orderByCol, true);
if (realPush) {
pushDownOrderBy.add(order.copy());
sqlBuilder.append(pdName).append(" ").append(order.getSortOrder()).append(",");
}
}
if (realPush)
sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
}
}
Aggregations