Search in sources :

Example 1 with NamedField

use of com.actiontech.dble.plan.NamedField in project dble by actiontech.

the class ItemField method getMergeNodeColumn.

private Item getMergeNodeColumn(String tmpFieldTable, String tmpFieldName, PlanNode planNode) {
    // select union only found in outerfields
    Item column;
    if (StringUtils.isEmpty(getTableName())) {
        PlanNode firstNode = planNode.getChild();
        boolean found = false;
        for (NamedField coutField : firstNode.getOuterFields().keySet()) {
            if (tmpFieldName.equalsIgnoreCase(coutField.getName())) {
                if (!found) {
                    tmpFieldTable = coutField.getTable();
                    found = true;
                } else {
                    throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "(42S22", "Unknown column '" + tmpFieldName + "' in 'order clause'");
                }
            }
        }
        column = planNode.getOuterFields().get(new NamedField(tmpFieldTable, tmpFieldName, null));
    } else {
        throw new MySQLOutPutException(ErrorCode.ER_TABLENAME_NOT_ALLOWED_HERE, "42000", "Table '" + getTableName() + "' from one of the SELECTs cannot be used in global ORDER clause");
    }
    return column;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) NamedField(com.actiontech.dble.plan.NamedField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 2 with NamedField

use of com.actiontech.dble.plan.NamedField in project dble by actiontech.

the class ItemField method fixFields.

@Override
public Item fixFields(NameResolutionContext context) {
    if (this.isWild())
        return this;
    String tmpFieldTable = null;
    String tmpFieldName = getItemName();
    PlanNode planNode = context.getPlanNode();
    if (context.getPlanNode().type() == PlanNodeType.MERGE) {
        return getMergeNodeColumn(tmpFieldTable, tmpFieldName, planNode);
    }
    Item column = null;
    if (context.isFindInSelect()) {
        // try to find in selectlist
        if (StringUtils.isEmpty(getTableName())) {
            for (NamedField namedField : planNode.getOuterFields().keySet()) {
                if (StringUtils.equalsIgnoreCase(tmpFieldName, namedField.getName())) {
                    if (column == null) {
                        column = planNode.getOuterFields().get(namedField);
                    } else
                        throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "42S22", "duplicate column:" + this);
                }
            }
        } else {
            tmpFieldTable = getTableName();
            column = planNode.getOuterFields().get(new NamedField(tmpFieldTable, tmpFieldName, null));
        }
    }
    if (column != null && context.isSelectFirst()) {
        return column;
    }
    // find from inner fields
    Item columnFromMeta = null;
    if (StringUtils.isEmpty(getTableName())) {
        for (NamedField namedField : planNode.getInnerFields().keySet()) {
            if (StringUtils.equalsIgnoreCase(tmpFieldName, namedField.getName())) {
                if (columnFromMeta == null) {
                    tmpFieldTable = namedField.getTable();
                    NamedField coutField = planNode.getInnerFields().get(new NamedField(tmpFieldTable, tmpFieldName, null));
                    this.tableName = namedField.getTable();
                    getReferTables().clear();
                    this.getReferTables().add(coutField.planNode);
                    columnFromMeta = this;
                } else {
                    if (planNode.type() == PlanNodeType.JOIN) {
                        JoinNode jn = (JoinNode) planNode;
                        if (jn.getUsingFields() != null && jn.getUsingFields().contains(columnFromMeta.getItemName().toLowerCase())) {
                            continue;
                        }
                    }
                    throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "42S22", "duplicate column:" + this);
                }
            }
        }
    } else {
        tmpFieldTable = getTableName();
        NamedField tmpField = new NamedField(tmpFieldTable, tmpFieldName, null);
        if (planNode.getInnerFields().containsKey(tmpField)) {
            NamedField coutField = planNode.getInnerFields().get(tmpField);
            getReferTables().clear();
            getReferTables().add(coutField.planNode);
            this.tableName = tmpField.getTable();
            columnFromMeta = this;
        }
    }
    if (columnFromMeta != null) {
        return columnFromMeta;
    } else if (column == null)
        throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "42S22", "column " + this + " not found");
    else {
        return column;
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) NamedField(com.actiontech.dble.plan.NamedField) JoinNode(com.actiontech.dble.plan.node.JoinNode) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 3 with NamedField

use of com.actiontech.dble.plan.NamedField in project dble by actiontech.

the class JoinNode method getFieldList.

private List<String> getFieldList(PlanNode node) {
    List<String> fields = new ArrayList<>();
    Set<String> checkDup = new HashSet<>();
    for (NamedField field : node.getOuterFields().keySet()) {
        String fieldName = field.getName().toLowerCase();
        if (checkDup.contains(fieldName)) {
            throw new MySQLOutPutException(ErrorCode.ER_DUP_FIELDNAME, "42S21", " Duplicate column name '" + fieldName + "'");
        }
        checkDup.add(fieldName);
        fields.add(fieldName);
    }
    return fields;
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 4 with NamedField

use of com.actiontech.dble.plan.NamedField in project dble by actiontech.

the class JoinNode method findTbNameByUsing.

private String findTbNameByUsing(PlanNode node, String using) {
    String table = node.getCombinedName();
    if (table != null) {
        return table;
    }
    boolean found = false;
    for (NamedField field : node.getOuterFields().keySet()) {
        if (field.getName().equalsIgnoreCase(using)) {
            if (!found) {
                found = true;
                table = field.getTable();
            } else {
                throw new MySQLOutPutException(ErrorCode.ER_NON_UNIQ_ERROR, "23000", " Column '" + using + "' in from clause is ambiguous");
            }
        }
    }
    return table;
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 5 with NamedField

use of com.actiontech.dble.plan.NamedField in project dble by actiontech.

the class PlanNode method dealSingleStarColumn.

protected void dealSingleStarColumn(List<Item> newSels) {
    for (NamedField field : innerFields.keySet()) {
        ItemField col = new ItemField(null, field.getTable(), field.getName());
        newSels.add(col);
    }
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Aggregations

NamedField (com.actiontech.dble.plan.NamedField)15 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)9 ItemField (com.actiontech.dble.plan.common.item.ItemField)6 Item (com.actiontech.dble.plan.common.item.Item)3 PlanNode (com.actiontech.dble.plan.node.PlanNode)3 StructureMeta (com.actiontech.dble.meta.protocol.StructureMeta)1 JoinNode (com.actiontech.dble.plan.node.JoinNode)1 TableNode (com.actiontech.dble.plan.node.TableNode)1 ArrayList (java.util.ArrayList)1