Search in sources :

Example 1 with ArgComparator

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator in project dble by actiontech.

the class TwoTableComparator method compareRecursion.

private int compareRecursion(RowDataPacket o1, RowDataPacket o2, int i) {
    HandlerTool.initFields(leftFields, o1.fieldValues);
    HandlerTool.initFields(rightFields, o2.fieldValues);
    ArgComparator comparator = comparators.get(i);
    boolean isAsc = ascList.get(i);
    int rs;
    if (isAsc) {
        rs = comparator.compare();
    } else {
        rs = -1 * comparator.compare();
    }
    if (rs != 0 || ascList.size() == (i + 1)) {
        return rs;
    } else {
        return compareRecursion(o1, o2, i + 1);
    }
}
Also used : ArgComparator(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator)

Example 2 with ArgComparator

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator in project dble by actiontech.

the class ItemFuncCase method findItem.

/**
 * Find and return matching items for CASE or ELSE item if all compares are
 * failed or NULL if ELSE item isn't defined.
 * <p>
 * IMPLEMENTATION In order to do correct comparisons of the CASE expression
 * (the expression between CASE and the first WHEN) with each WHEN
 * expression several comparators are used. One for each result type. CASE
 * expression can be evaluated up to # of different result types are used.
 * To check whether the CASE expression already was evaluated for a
 * particular result type a bit mapped variable value_added_map is used.
 * Result types are mapped to it according to their int values i.e.
 * STRING_RESULT is mapped to bit 0, REAL_RESULT to bit 1, so on.
 *
 * @retval NULL Nothing found and there is no ELSE expression defined
 * @retval item Found item or ELSE item if defined and all comparisons are
 * failed
 */
private Item findItem() {
    if (firstExprNum == -1) {
        for (int i = 0; i < ncases; i += 2) {
            // No expression between CASE and the first WHEN
            if (args.get(i).valBool())
                return args.get(i + 1);
            continue;
        }
    } else {
        /* Compare every WHEN argument with it and return the first match */
        Item leftCmpItem = args.get(firstExprNum);
        if (leftCmpItem.isNull() || leftCmpItem.type() == ItemType.NULL_ITEM) {
            return elseExprNum != -1 ? args.get(elseExprNum) : null;
        }
        for (int i = 0; i < ncases; i += 2) {
            if (args.get(i).type() == ItemType.NULL_ITEM)
                continue;
            Item rightCmpItem = args.get(i);
            ArgComparator comparator = new ArgComparator(leftCmpItem, rightCmpItem);
            comparator.setCmpFunc(null, leftCmpItem, rightCmpItem, false);
            if (comparator.compare() == 0 && !rightCmpItem.isNullValue())
                return args.get(i + 1);
        }
    }
    // No, WHEN clauses all missed, return ELSE expression
    return elseExprNum != -1 ? args.get(elseExprNum) : null;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ArgComparator(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator)

Example 3 with ArgComparator

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator in project dble by actiontech.

the class ItemFuncIn method valInt.

@Override
public BigInteger valInt() {
    if ((nullValue = args.get(0).type() == Item.ItemType.NULL_ITEM))
        return BigInteger.ZERO;
    Item left = args.get(0);
    if (nullValue = left.type() == ItemType.NULL_ITEM) {
        return BigInteger.ZERO;
    }
    boolean haveNull = false;
    for (int i = 1; i < args.size(); i++) {
        Item right = args.get(i);
        if (right.type() == ItemType.NULL_ITEM) {
            haveNull = true;
            continue;
        }
        if (nullValue = left.isNullValue())
            return BigInteger.ZERO;
        ArgComparator cmp = new ArgComparator(left, right);
        cmp.setCmpFunc(this, left, right, false);
        if (cmp.compare() == 0 && !right.isNullValue())
            return !negated ? BigInteger.ONE : BigInteger.ZERO;
        haveNull |= right.isNull();
    }
    nullValue = haveNull;
    return (!nullValue && negated) ? BigInteger.ONE : BigInteger.ZERO;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ArgComparator(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator)

Aggregations

ArgComparator (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.util.ArgComparator)3 Item (com.actiontech.dble.plan.common.item.Item)2