use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.
the class ItemExtract method valInt.
@Override
public BigInteger valInt() {
MySQLTime ltime = new MySQLTime();
int weekFormat;
long neg;
if (dateValue) {
if (getArg0Date(ltime, MyTime.TIME_FUZZY_DATE))
return BigInteger.ZERO;
neg = 1;
} else {
if (getArg0Time(ltime))
return BigInteger.ZERO;
neg = ltime.isNeg() ? -1 : 1;
}
switch(intType) {
case YEAR:
return BigInteger.valueOf(ltime.getYear());
case YEAR_MONTH:
return BigInteger.valueOf(ltime.getYear() * 100L + ltime.getMonth());
case QUARTER:
return BigInteger.valueOf((ltime.getMonth() + 2) / 3);
case MONTH:
return BigInteger.valueOf(ltime.getMonth());
case WEEK:
{
weekFormat = MyTime.WEEK_MONDAY_FIRST;
long ret = MyTime.calcWeek(ltime, MyTime.weekMode(weekFormat), new LongPtr(0));
return BigInteger.valueOf(ret);
}
case DAY:
return BigInteger.valueOf(ltime.getDay());
case DAY_HOUR:
return BigInteger.valueOf((ltime.getDay() * 100L + ltime.getHour()) * neg);
case DAY_MINUTE:
return (BigInteger.valueOf((ltime.getDay() * 10000L + ltime.getHour() * 100L + ltime.getMinute()) * neg));
case DAY_SECOND:
return BigInteger.valueOf((ltime.getDay() * 1000000L + (ltime.getHour() * 10000L + ltime.getMinute() * 100 + ltime.getSecond())) * neg);
case HOUR:
return BigInteger.valueOf(ltime.getHour() * neg);
case HOUR_MINUTE:
return BigInteger.valueOf((ltime.getHour() * 100 + ltime.getMinute()) * neg);
case HOUR_SECOND:
return BigInteger.valueOf((ltime.getHour() * 10000 + ltime.getMinute() * 100 + ltime.getSecond()) * neg);
case MINUTE:
return BigInteger.valueOf(ltime.getMinute() * neg);
case MINUTE_SECOND:
return BigInteger.valueOf((ltime.getMinute() * 100 + ltime.getSecond()) * neg);
case SECOND:
return BigInteger.valueOf(ltime.getSecond() * neg);
case MICROSECOND:
return BigInteger.valueOf(ltime.getSecondPart() * neg);
case DAY_MICROSECOND:
return BigInteger.valueOf(((ltime.getDay() * 1000000L + ltime.getHour() * 10000L + ltime.getMinute() * 100 + ltime.getSecond()) * 1000000L + ltime.getSecondPart()) * neg);
case HOUR_MICROSECOND:
return BigInteger.valueOf(((ltime.getHour() * 10000L + ltime.getMinute() * 100 + ltime.getSecond()) * 1000000L + ltime.getSecondPart()) * neg);
case MINUTE_MICROSECOND:
return BigInteger.valueOf((((ltime.getMinute() * 100 + ltime.getSecond())) * 1000000L + ltime.getSecondPart()) * neg);
case SECOND_MICROSECOND:
return BigInteger.valueOf((ltime.getSecond() * 1000000L + ltime.getSecondPart()) * neg);
default:
break;
}
// Impossible
return BigInteger.ZERO;
}
use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.
the class ItemFuncTimediff method getTime.
/**
* TIMEDIFF(t,s) is a time function that calculates the time value between a
* start and end time.
* <p>
* t and s: time_or_datetime_expression
*
* @param[out] l_time3 Result is stored here.
* @param[in] flags Not used in this class.
* @returns
* @retval false On succes
* @retval true On error
*/
@Override
public boolean getTime(MySQLTime ltime) {
MySQLTime lTime1 = new MySQLTime();
MySQLTime lTime2 = new MySQLTime();
int lSign = 1;
nullValue = false;
if ((args.get(0).isTemporalWithDate() && args.get(1).fieldType() == FieldTypes.MYSQL_TYPE_TIME) || (args.get(1).isTemporalWithDate() && args.get(0).fieldType() == FieldTypes.MYSQL_TYPE_TIME)) {
return nullValue = true;
}
if (args.get(0).isTemporalWithDate() || args.get(1).isTemporalWithDate()) {
if (args.get(0).getDate(lTime1, MyTime.TIME_FUZZY_DATE) || args.get(1).getDate(lTime2, MyTime.TIME_FUZZY_DATE))
return nullValue = true;
} else {
if (args.get(0).getTime(lTime1) || args.get(1).getTime(lTime2))
return nullValue = true;
}
if (lTime1.getTimeType() != lTime2.getTimeType()) {
// Incompatible types
return nullValue = true;
}
if (lTime1.isNeg() != lTime2.isNeg())
lSign = -lSign;
MySQLTime lTime3 = new MySQLTime();
LongPtr seconds = new LongPtr(0);
LongPtr microseconds = new LongPtr(0);
lTime3.setNeg(MyTime.calcTimeDiff(lTime1, lTime2, lSign, seconds, microseconds));
/*
* For MYSQL_TIMESTAMP_TIME only: 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
lTime3.setNeg(!lTime3.isNeg());
MyTime.calcTimeFromSec(lTime3, seconds.get(), microseconds.get());
return false;
}
use of com.actiontech.dble.plan.common.ptr.LongPtr in project dble by actiontech.
the class ItemFuncYearweek method valInt.
@Override
public BigInteger valInt() {
LongPtr year = new LongPtr(0);
long week;
MySQLTime ltime = new MySQLTime();
if (getArg0Date(ltime, MyTime.TIME_NO_ZERO_DATE))
return BigInteger.ZERO;
week = MyTime.calcWeek(ltime, (MyTime.weekMode(args.size() > 1 ? args.get(1).valInt().intValue() : 0) | MyTime.WEEK_YEAR), year);
return BigInteger.valueOf(week + year.get() * 100);
}
Aggregations