Search in sources :

Example 6 with Item

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();
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 7 with Item

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();
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Example 8 with Item

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);
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 9 with Item

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);
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)

Example 10 with Item

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);
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Aggregations

Item (com.actiontech.dble.plan.common.item.Item)122 ArrayList (java.util.ArrayList)26 Order (com.actiontech.dble.plan.Order)16 PlanNode (com.actiontech.dble.plan.node.PlanNode)14 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)10 ItemField (com.actiontech.dble.plan.common.item.ItemField)10 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)7 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)7 Test (org.junit.Test)7 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)6 JoinNode (com.actiontech.dble.plan.node.JoinNode)6 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)6 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)5 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)4 ItemString (com.actiontech.dble.plan.common.item.ItemString)4 BigDecimal (java.math.BigDecimal)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 NamedField (com.actiontech.dble.plan.NamedField)3