Search in sources :

Example 16 with ItemField

use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.

the class ERJoinChooser method getERKey.

private ERTable getERKey(PlanNode tn, Item c) {
    if (!(c instanceof ItemField))
        return null;
    if (tn.type() != PlanNode.PlanNodeType.TABLE && !PlanUtil.isERNode(tn)) {
        return null;
    }
    Pair<TableNode, ItemField> pair = PlanUtil.findColumnInTableLeaf((ItemField) c, tn);
    if (pair == null)
        return null;
    TableNode tableNode = pair.getKey();
    ItemField col = pair.getValue();
    ERTable cm = new ERTable(tableNode.getSchema(), tableNode.getPureName(), col.getItemName());
    if (tn.type() == PlanNode.PlanNodeType.TABLE) {
        return cm;
    } else {
        List<ERTable> erList = ((JoinNode) tn).getERkeys();
        for (ERTable cerKey : erList) {
            if (isErRelation(cm, cerKey))
                return cm;
        }
        return null;
    }
}
Also used : JoinNode(com.actiontech.dble.plan.node.JoinNode) TableNode(com.actiontech.dble.plan.node.TableNode) ERTable(com.actiontech.dble.config.model.ERTable) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 17 with ItemField

use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.

the class HandlerTool method createPushDownGroupBy.

// ------------------------------- helper methods ------------------------
/**
 * 1.count(id) : count(id) = sum[count(id) 0...n];
 * 2.sum(id): sum(id) = sum[sum(id) 0...n];
 * 3.avg(id) avg(id) = sum[sum(id) 0...n]/sum[count(id) 0...n];
 *
 * @param sumFunction aggregate function name
 * @param fields
 * @return
 */
protected static Item createPushDownGroupBy(ItemSum sumFunction, List<Field> fields, int startIndex) {
    String funName = sumFunction.funcName().toUpperCase();
    String colName = sumFunction.getItemName();
    String pdName = sumFunction.getPushDownName();
    Item ret = null;
    List<Item> args = new ArrayList<>();
    if (funName.equalsIgnoreCase("AVG")) {
        String colNameSum = colName.replace(funName + "(", "SUM(");
        String colNameCount = colName.replace(funName + "(", "COUNT(");
        Item sumFuncSum = new ItemField(null, null, colNameSum);
        sumFuncSum.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("SUM")));
        Item sumFuncCount = new ItemField(null, null, colNameCount);
        sumFuncCount.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("COUNT")));
        Item itemSum = createFieldItem(sumFuncSum, fields, startIndex);
        Item itemCount = createFieldItem(sumFuncCount, fields, startIndex);
        args.add(itemSum);
        args.add(itemCount);
    } else if (funName.equalsIgnoreCase("STD") || funName.equalsIgnoreCase("STDDEV_POP") || funName.equalsIgnoreCase("STDDEV_SAMP") || funName.equalsIgnoreCase("STDDEV") || funName.equalsIgnoreCase("VAR_POP") || funName.equalsIgnoreCase("VAR_SAMP") || funName.equalsIgnoreCase("VARIANCE")) {
        // variance: v[0]:count,v[1]:sum,v[2]:variance(locally)
        String colNameCount = colName.replace(funName + "(", "COUNT(");
        String colNameSum = colName.replace(funName + "(", "SUM(");
        String colNameVar = colName.replace(funName + "(", "VARIANCE(");
        Item sumFuncCount = new ItemField(null, null, colNameCount);
        sumFuncCount.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("COUNT")));
        Item sumFuncSum = new ItemField(null, null, colNameSum);
        sumFuncSum.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("SUM")));
        Item sumFuncVar = new ItemField(null, null, colNameVar);
        sumFuncVar.setPushDownName(pdName.replace(MysqlVisitor.getMadeAggAlias(funName), MysqlVisitor.getMadeAggAlias("VARIANCE")));
        Item itemCount = createFieldItem(sumFuncCount, fields, startIndex);
        Item itemSum = createFieldItem(sumFuncSum, fields, startIndex);
        Item itemVar = createFieldItem(sumFuncVar, fields, startIndex);
        args.add(itemCount);
        args.add(itemSum);
        args.add(itemVar);
    } else {
        Item subItem = createFieldItem(sumFunction, fields, startIndex);
        args.add(subItem);
    }
    ret = sumFunction.reStruct(args, true, fields);
    ret.setItemName(sumFunction.getPushDownName() == null ? sumFunction.getItemName() : sumFunction.getPushDownName());
    return ret;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ArrayList(java.util.ArrayList) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 18 with ItemField

use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.

the class HandlerTool method createFieldItem.

protected static ItemField createFieldItem(Item col, List<Field> fields, int startIndex) {
    int index = findField(col, fields, startIndex);
    if (index < 0)
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "field not found:" + col);
    ItemField ret = new ItemField(fields.get(index));
    ret.setItemName(col.getPushDownName() == null ? col.getItemName() : col.getPushDownName());
    return ret;
}
Also used : ItemField(com.actiontech.dble.plan.common.item.ItemField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 19 with ItemField

use of com.actiontech.dble.plan.common.item.ItemField in project dble by actiontech.

the class HandlerTool method findField.

/**
 * findField in sel from start
 *
 * @param sel
 * @param fields
 * @param startIndex
 * @return
 */
public static int findField(Item sel, List<Field> fields, int startIndex) {
    String selName = (sel.getPushDownName() == null ? sel.getItemName() : sel.getPushDownName());
    selName = selName.trim();
    String tableName = sel.getTableName();
    for (int index = startIndex; index < fields.size(); index++) {
        Field field = fields.get(index);
        // field.name==null if '' push down
        String colName2 = field.getName() == null ? null : field.getName().trim();
        String tableName2 = field.getTable();
        if (sel instanceof ItemField && !StringUtil.equalsWithEmpty(tableName, tableName2)) {
            continue;
        }
        if (selName.equalsIgnoreCase(colName2)) {
            return index;
        }
    }
    return -1;
}
Also used : Field(com.actiontech.dble.plan.common.field.Field) ItemField(com.actiontech.dble.plan.common.item.ItemField) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 20 with ItemField

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

Aggregations

ItemField (com.actiontech.dble.plan.common.item.ItemField)20 Item (com.actiontech.dble.plan.common.item.Item)10 NamedField (com.actiontech.dble.plan.NamedField)6 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)4 ArrayList (java.util.ArrayList)4 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)3 JoinNode (com.actiontech.dble.plan.node.JoinNode)3 TableNode (com.actiontech.dble.plan.node.TableNode)3 ERTable (com.actiontech.dble.config.model.ERTable)2 Order (com.actiontech.dble.plan.Order)2 Field (com.actiontech.dble.plan.common.field.Field)2 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 QueryNode (com.actiontech.dble.plan.node.QueryNode)1 List (java.util.List)1