Search in sources :

Example 1 with LongPtr

use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.

the class ArgComparator method setCmpFunc.

public int setCmpFunc(ItemFunc ownerarg, Item a1, Item a2, Item.ItemResult type) {
    owner = ownerarg;
    setNull = setNull && (ownerarg != null);
    a = a1;
    b = a2;
    LongPtr constValue = new LongPtr(-1);
    if (canCompareAsDates(a, b, constValue)) {
        // atype = a.fieldType();
        // btype = b.fieldType();
        isNullsEq = isOwnerEqualFunc();
        func = new CompareDatetime();
        getValueAFunc = new GetDatetimeValue();
        getValueBFunc = new GetDatetimeValue();
        setcmpcontextfordatetime();
        return 0;
    } else if (type == Item.ItemResult.STRING_RESULT && a.fieldType() == FieldTypes.MYSQL_TYPE_TIME && b.fieldType() == FieldTypes.MYSQL_TYPE_TIME) {
        isNullsEq = isOwnerEqualFunc();
        func = new CompareDatetime();
        getValueAFunc = new GetTimeValue();
        getValueBFunc = new GetTimeValue();
        setcmpcontextfordatetime();
        return 0;
    } else if (type == Item.ItemResult.STRING_RESULT && a.resultType() == Item.ItemResult.STRING_RESULT && b.resultType() == Item.ItemResult.STRING_RESULT) {
    // see item_cmpfunc.cc line1054
    } else if (tryYearCmpFunc(type)) {
        return 0;
    }
    return setCompareFunc(ownerarg, type);
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr)

Example 2 with LongPtr

use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.

the class ItemFuncMinMax method valInt.

@Override
public BigInteger valInt() {
    long value = 0;
    if (compareAsDates) {
        LongPtr result = new LongPtr(0);
        cmpDatetimes(result);
        return BigInteger.valueOf(MyTime.longlongFromDatetimePacked(datetimeItem.fieldType(), result.get()));
    }
    /*
         * TS-TODO: val_str decides which type to use using cmp_type. val_int,
     * val_decimal, val_real do not check cmp_type and decide data type
     * according to the method type. This is probably not good:
     *
     * mysql> select least('11', '2'), least('11', '2')+0,
     * concat(least(11,2));
     * +------------------+--------------------+---------------------+ |
     * least('11', '2') | least('11', '2')+0 | concat(least(11,2)) |
     * +------------------+--------------------+---------------------+ | 11
     * | 2 | 2 |
     * +------------------+--------------------+---------------------+ 1 row
     * in set (0.00 sec)
     *
     * Should not the second column return 11? I.e. compare as strings and
     * return '11', then convert to number.
     */
    for (int i = 0; i < args.size(); i++) {
        if (i == 0)
            value = args.get(i).valInt().longValue();
        else {
            long tmp = args.get(i).valInt().longValue();
            if (!args.get(i).isNull() && (tmp < value ? cmpSign : -cmpSign) > 0)
                value = tmp;
        }
        if ((nullValue = args.get(i).isNull()))
            break;
    }
    return BigInteger.valueOf(value);
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr)

Example 3 with LongPtr

use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.

the class ItemFuncMinMax method getTime.

@Override
public boolean getTime(MySQLTime ltime) {
    assert (fixed);
    if (compareAsDates) {
        LongPtr result = new LongPtr(0);
        cmpDatetimes(result);
        if (nullValue)
            return true;
        MyTime.timeFromLonglongPacked(ltime, datetimeItem.fieldType(), result.get());
        MyTime.datetimeToTime(ltime);
        return false;
    }
    FieldTypes i = fieldType();
    if (i == FieldTypes.MYSQL_TYPE_TIME) {
        LongPtr result = new LongPtr(0);
        cmpTimes(result);
        if (nullValue)
            return true;
        MyTime.timeFromLonglongTimePacked(ltime, result.get());
        return false;
    } else if (i == FieldTypes.MYSQL_TYPE_DATE || i == FieldTypes.MYSQL_TYPE_TIMESTAMP || i == FieldTypes.MYSQL_TYPE_DATETIME) {
        // Should have been processed in "compare_as_dates"
        assert (false);
        return getTimeFromNonTemporal(ltime);
    } else {
        return getTimeFromNonTemporal(ltime);
    }
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes)

Example 4 with LongPtr

use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.

the class ItemFuncMinMax method valDecimal.

@Override
public BigDecimal valDecimal() {
    BigDecimal res = null, tmp;
    if (compareAsDates) {
        LongPtr value = new LongPtr(0);
        cmpDatetimes(value);
        return MyTime.myDecimalFromDatetimePacked(datetimeItem.fieldType(), value.get());
    }
    for (int i = 0; i < args.size(); i++) {
        if (i == 0)
            res = args.get(i).valDecimal();
        else {
            // Zero if NULL
            tmp = args.get(i).valDecimal();
            if (tmp != null && tmp.compareTo(res) * cmpSign < 0) {
                res = tmp;
            }
        }
        if ((nullValue = args.get(i).isNull())) {
            res = null;
            break;
        }
    }
    return res;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) BigDecimal(java.math.BigDecimal)

Example 5 with LongPtr

use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.

the class ItemFuncMinMax method getDate.

@Override
public boolean getDate(MySQLTime ltime, long fuzzydate) {
    assert (fixed);
    if (compareAsDates) {
        LongPtr result = new LongPtr(0);
        cmpDatetimes(result);
        if (nullValue)
            return true;
        MyTime.timeFromLonglongPacked(ltime, datetimeItem.fieldType(), result.get());
        LongPtr warnings = new LongPtr(0);
        return MyTime.checkDate(ltime, ltime.isNonZeroDate(), fuzzydate, warnings);
    }
    FieldTypes i = fieldType();
    if (i == FieldTypes.MYSQL_TYPE_TIME) {
        return getDateFromTime(ltime);
    } else if (i == FieldTypes.MYSQL_TYPE_DATETIME || i == FieldTypes.MYSQL_TYPE_TIMESTAMP || i == FieldTypes.MYSQL_TYPE_DATE) {
        // Should have been processed in "compare_as_dates"
        assert (false);
        return getDateFromNonTemporal(ltime, fuzzydate);
    } else {
        return getDateFromNonTemporal(ltime, fuzzydate);
    }
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes)

Aggregations

LongPtr (com.actiontech.dble.plan.common.ptr.LongPtr)23 MySQLTime (com.actiontech.dble.plan.common.time.MySQLTime)6 BigDecimal (java.math.BigDecimal)3 FieldTypes (com.actiontech.dble.plan.common.item.FieldTypes)2 MyLocale (com.actiontech.dble.plan.common.locale.MyLocale)1 BoolPtr (com.actiontech.dble.plan.common.ptr.BoolPtr)1 DoublePtr (com.actiontech.dble.plan.common.ptr.DoublePtr)1 BigInteger (java.math.BigInteger)1