Search in sources :

Example 11 with LongPtr

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

the class MyTime method myDoubleToDatetimeWithWarn.

/**
 * Convert double value to datetime value with a warning.
 *
 * @param db    The value to convert from.
 * @param flags Conversion flags.
 * @return False on success, true on error.
 * @param[out] ltime The variable to convert to.
 */
public static boolean myDoubleToDatetimeWithWarn(double db, MySQLTime ltime, long flags) {
    LongPtr warnings = new LongPtr(0);
    String sbd = String.valueOf(db);
    String[] sbds = sbd.split("\\.");
    long intPart = Long.parseLong(sbds[0]);
    long secondPart = 0;
    if (sbds.length == 2)
        secondPart = Long.parseLong(sbds[1]);
    if (numberToDatetime(intPart, ltime, flags, warnings) == -1) {
        ltime.setZeroTime(MySQLTimestampType.MYSQL_TIMESTAMP_ERROR);
        return true;
    } else if (ltime.getTimeType() == MySQLTimestampType.MYSQL_TIMESTAMP_DATE) {
        /**
         * Generate a warning in case of DATE with fractional part:
         * 20011231.1234 . '2001-12-31' unless the caller does not want the
         * warning: for example, CAST does.
         */
        if (secondPart != 0 && (flags & TIME_NO_DATE_FRAC_WARN) == 0) {
            warnings.set(warnings.get() | MYSQL_TIME_WARN_TRUNCATED);
        }
    } else if ((flags & TIME_NO_NSEC_ROUNDING) == 0) {
        ltime.setSecondPart(secondPart);
    }
    return false;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr)

Example 12 with LongPtr

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

the class ItemFuncFromDays method getDate.

@Override
public boolean getDate(MySQLTime ltime, long fuzzyDate) {
    long value = args.get(0).valInt().longValue();
    if ((nullValue = args.get(0).isNullValue()))
        return true;
    ltime.setZeroTime(ltime.getTimeType());
    LongPtr lpyear = new LongPtr(0);
    LongPtr lpmonth = new LongPtr(0);
    LongPtr lpday = new LongPtr(0);
    MyTime.getDateFromDaynr(value, lpyear, lpmonth, lpday);
    ltime.setYear(lpyear.get());
    ltime.setMonth(lpmonth.get());
    ltime.setDay(lpday.get());
    if ((nullValue = ((fuzzyDate & MyTime.TIME_NO_ZERO_DATE) != 0) && (ltime.getYear() == 0 || ltime.getMonth() == 0 || ltime.getDay() == 0)))
        return true;
    ltime.setTimeType(MySQLTimestampType.MYSQL_TIMESTAMP_DATE);
    return false;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr)

Example 13 with LongPtr

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

the class ItemFuncMakedate method getDate.

@Override
public /**
 * MAKEDATE(a,b) is a date function that creates a date value from a year
 * and day value.
 *
 * NOTES: As arguments are integers, we can't know if the year is a 2 digit
 * or 4 digit year. In this case we treat all years < 100 as 2 digit years.
 * Ie, this is not safe for dates between 0000-01-01 and 0099-12-31
 */
boolean getDate(MySQLTime ltime, long fuzzyDate) {
    long daynr = args.get(1).valInt().longValue();
    long year = args.get(0).valInt().longValue();
    long days;
    if (args.get(0).isNullValue() || args.get(1).isNullValue() || year < 0 || year > 9999 || daynr <= 0) {
        nullValue = true;
        return true;
    }
    if (year < 100)
        year = MyTime.year2000Handling(year);
    days = MyTime.calcDaynr(year, 1, 1) + daynr - 1;
    /* Day number from year 0 to 9999-12-31 */
    if (days >= 0 && days <= MyTime.MAX_DAY_NUMBER) {
        nullValue = false;
        LongPtr lpyear = new LongPtr(0);
        LongPtr lpmonth = new LongPtr(0);
        LongPtr lpday = new LongPtr(0);
        MyTime.getDateFromDaynr(days, lpyear, lpmonth, lpday);
        ltime.setYear(lpyear.get());
        ltime.setMonth(lpmonth.get());
        ltime.setDay(lpday.get());
        ltime.setNeg(false);
        ltime.setSecondPart(0);
        ltime.setSecond(0);
        ltime.setMinute(0);
        ltime.setHour(0);
        ltime.setTimeType(MySQLTimestampType.MYSQL_TIMESTAMP_DATE);
        return false;
    }
    nullValue = true;
    return true;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr)

Example 14 with LongPtr

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

the class ItemSumVariance method add.

@Override
public boolean add(RowDataPacket row, Object transObj) {
    if (transObj != null) {
        useTransObj = true;
        AggData other = (AggData) transObj;
        sumAi2 += other.sumAi2;
        sumA += other.sumA;
        count += other.count;
    } else {
        /*
             * Why use a temporary variable? We don't know if it is null until
             * we evaluate it, which has the side-effect of setting null_value .
             */
        double nr = args.get(0).valReal().doubleValue();
        // add for transObj
        sumA += nr;
        sumAi2 += nr * nr;
        // end add
        if (!args.get(0).isNullValue()) {
            DoublePtr rM = new DoublePtr(recurrenceM);
            DoublePtr rS = new DoublePtr(recurrenceS);
            LongPtr countPtr = new LongPtr(count);
            varianceFpRecurrenceNext(rM, rS, countPtr, nr);
            recurrenceM = rM.get();
            recurrenceS = rS.get();
            count = countPtr.get();
        }
    }
    return false;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) DoublePtr(com.actiontech.dble.plan.common.ptr.DoublePtr)

Example 15 with LongPtr

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

the class ItemFuncAddTime method valDatetime.

@Override
protected boolean valDatetime(MySQLTime time, long fuzzyDate) {
    MySQLTime lTime1 = new MySQLTime();
    MySQLTime lTime2 = new MySQLTime();
    boolean isTime = false;
    int lSign = sign;
    nullValue = false;
    if (cachedFieldType == FieldTypes.MYSQL_TYPE_DATETIME) /* TIMESTAMP function */
    {
        if (getArg0Date(lTime1, fuzzyDate) || args.get(1).getTime(lTime2) || lTime1.getTimeType() == MySQLTimestampType.MYSQL_TIMESTAMP_TIME || lTime2.getTimeType() != MySQLTimestampType.MYSQL_TIMESTAMP_TIME) {
            nullValue = true;
            return true;
        }
    } else /* ADDTIME function */
    {
        if (args.get(0).getTime(lTime1) || args.get(1).getTime(lTime2) || lTime2.getTimeType() == MySQLTimestampType.MYSQL_TIMESTAMP_DATETIME) {
            nullValue = true;
            return true;
        }
        isTime = (lTime1.getTimeType() == MySQLTimestampType.MYSQL_TIMESTAMP_TIME);
    }
    if (lTime1.isNeg() != lTime2.isNeg())
        lSign = -lSign;
    time.setZeroTime(time.getTimeType());
    LongPtr seconds = new LongPtr(0);
    LongPtr microseconds = new LongPtr(0);
    time.setNeg(MyTime.calcTimeDiff(lTime1, lTime2, -lSign, seconds, microseconds));
    /*
         * If first argument was negative and diff between arguments is non-zero
         * we need to swap sign to get proper result.
         */
    if (lTime1.isNeg() && (seconds.get() != 0 || microseconds.get() != 0))
        // Swap sign of result
        time.setNeg(!time.isNeg());
    if (!isTime && time.isNeg()) {
        nullValue = true;
        return true;
    }
    long days = seconds.get() / MyTime.SECONDS_IN_24H;
    MyTime.calcTimeFromSec(time, seconds.get() % MyTime.SECONDS_IN_24H, microseconds.get());
    if (!isTime) {
        LongPtr lpyear = new LongPtr(0);
        LongPtr lpmonth = new LongPtr(0);
        LongPtr lpday = new LongPtr(0);
        MyTime.getDateFromDaynr(days, lpyear, lpmonth, lpday);
        time.setYear(lpyear.get());
        time.setMonth(lpmonth.get());
        time.setDay(lpday.get());
        time.setTimeType(MySQLTimestampType.MYSQL_TIMESTAMP_DATETIME);
        if (time.getDay() != 0)
            return false;
        nullValue = true;
        return true;
    }
    time.setTimeType(MySQLTimestampType.MYSQL_TIMESTAMP_TIME);
    time.setHour(time.getHour() + days * 24);
    return false;
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime)

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