Search in sources :

Example 1 with ItemExistsSubQuery

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

the class PlanUtil method rebuildSubQueryItem.

public static Item rebuildSubQueryItem(Item item) {
    if (!item.isWithSubQuery()) {
        return item;
    }
    BoolPtr reBuild = new BoolPtr(false);
    if (PlanUtil.isCmpFunc(item)) {
        Item res1 = rebuildBoolSubQuery(item, 0, reBuild);
        if (res1 != null) {
            return res1;
        }
        Item res2 = rebuildBoolSubQuery(item, 1, reBuild);
        if (res2 != null) {
            return res2;
        }
    } else if (item instanceof ItemInSubQuery) {
        ItemInSubQuery inSubItem = (ItemInSubQuery) item;
        if (inSubItem.getValue().size() == 0) {
            return genBoolItem(inSubItem.isNeg());
        } else {
            List<Item> args = new ArrayList<>(inSubItem.getValue().size() + 1);
            args.add(inSubItem.getLeftOperand());
            args.addAll(inSubItem.getValue());
            return new ItemFuncIn(args, inSubItem.isNeg());
        }
    } else if (item instanceof ItemExistsSubQuery) {
        ItemExistsSubQuery existsSubQuery = (ItemExistsSubQuery) item;
        Item result = existsSubQuery.getValue();
        if (result == null) {
            return genBoolItem(existsSubQuery.isNot());
        } else {
            return genBoolItem(!existsSubQuery.isNot());
        }
    } else if (item instanceof ItemCondAnd || item instanceof ItemCondOr) {
        for (int index = 0; index < item.getArgCount(); index++) {
            Item rebuildItem = rebuildSubQueryItem(item.arguments().get(index));
            item.arguments().set(index, rebuildItem);
            item.setItemName(null);
        }
    } else if (item instanceof ItemScalarSubQuery) {
        Item result = ((ItemScalarSubQuery) item).getValue();
        if (result == null || result.getResultItem() == null) {
            return new ItemFuncEqual(new ItemInt(1), new ItemInt(0));
        }
        return result.getResultItem();
    }
    if (!reBuild.get() && item instanceof ItemFunc) {
        return rebuildSubQueryFuncItem(item);
    }
    return item;
}
Also used : ItemCondAnd(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd) ItemExistsSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery) ItemCondOr(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr) ItemInSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) BoolPtr(com.actiontech.dble.plan.common.ptr.BoolPtr) ItemScalarSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)

Example 2 with ItemExistsSubQuery

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

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLExistsExpr x) {
    SQLSelectQuery sqlSelect = x.getSubQuery().getQuery();
    item = new ItemExistsSubQuery(currentDb, sqlSelect, x.isNot(), metaManager);
}
Also used : SQLSelectQuery(com.alibaba.druid.sql.ast.statement.SQLSelectQuery) ItemExistsSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery)

Aggregations

ItemExistsSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery)2 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1 ItemCondOr (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr)1 ItemInSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery)1 ItemScalarSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)1 BoolPtr (com.actiontech.dble.plan.common.ptr.BoolPtr)1 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)1