use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.
the class ItemFuncNumhybrid method valDecimal.
@Override
public BigDecimal valDecimal() {
BigDecimal val = null;
if (hybridType == ItemResult.DECIMAL_RESULT) {
val = decimalOp();
} else if (hybridType == ItemResult.INT_RESULT) {
BigInteger result = intOp();
val = new BigDecimal(result);
} else if (hybridType == ItemResult.REAL_RESULT) {
BigDecimal result = realOp();
val = result;
} else if (hybridType == ItemResult.STRING_RESULT) {
FieldTypes i = fieldType();
if (i == FieldTypes.MYSQL_TYPE_DATE || i == FieldTypes.MYSQL_TYPE_DATETIME || i == FieldTypes.MYSQL_TYPE_TIMESTAMP) {
return valDecimalFromDate();
} else if (i == FieldTypes.MYSQL_TYPE_TIME) {
return valDecimalFromTime();
}
String res = strOp();
if (res == null)
return null;
try {
val = new BigDecimal(res);
} catch (Exception e) {
val = null;
}
}
return val;
}
use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.
the class ItemDateAddInterval method fixLengthAndDec.
@Override
public void fixLengthAndDec() {
FieldTypes arg0FieldType;
maybeNull = true;
/*
* The field type for the result of an Item_date function is defined as
* follows:
*
* - If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
* - If first arg is a MYSQL_TYPE_DATE and the interval type uses hours,
* minutes or seconds then type is MYSQL_TYPE_DATETIME. - Otherwise the
* result is MYSQL_TYPE_STRING (This is because you can't know if the
* string contains a DATE, MYSQL_TIME or DATETIME argument)
*/
arg0FieldType = args.get(0).fieldType();
int intervalDec = 0;
if (intType == MySqlIntervalUnit.MICROSECOND || intType == MySqlIntervalUnit.DAY_MICROSECOND || intType == MySqlIntervalUnit.HOUR_MICROSECOND || intType == MySqlIntervalUnit.MINUTE_MICROSECOND || intType == MySqlIntervalUnit.SECOND_MICROSECOND)
intervalDec = MyTime.DATETIME_MAX_DECIMALS;
else if (intType == MySqlIntervalUnit.SECOND && args.get(1).getDecimals() > 0)
intervalDec = Math.min(args.get(1).getDecimals(), MyTime.DATETIME_MAX_DECIMALS);
if (arg0FieldType == FieldTypes.MYSQL_TYPE_DATETIME || arg0FieldType == FieldTypes.MYSQL_TYPE_TIMESTAMP) {
int dec = Math.max(args.get(0).datetimePrecision(), intervalDec);
fixLengthAndDecAndCharsetDatetime(MyTime.MAX_DATETIME_WIDTH, dec);
cachedFieldType = FieldTypes.MYSQL_TYPE_DATETIME;
} else if (arg0FieldType == FieldTypes.MYSQL_TYPE_DATE) {
if (intType == MySqlIntervalUnit.YEAR || intType == MySqlIntervalUnit.QUARTER || intType == MySqlIntervalUnit.MONTH || intType == MySqlIntervalUnit.WEEK || intType == MySqlIntervalUnit.DAY || intType == MySqlIntervalUnit.YEAR_MONTH) {
cachedFieldType = FieldTypes.MYSQL_TYPE_DATE;
fixLengthAndDecAndCharsetDatetime(MyTime.MAX_DATE_WIDTH, 0);
} else {
cachedFieldType = FieldTypes.MYSQL_TYPE_DATETIME;
fixLengthAndDecAndCharsetDatetime(MyTime.MAX_DATE_WIDTH, intervalDec);
}
} else if (arg0FieldType == FieldTypes.MYSQL_TYPE_TIME) {
int dec = Math.max(args.get(0).timePrecision(), intervalDec);
cachedFieldType = FieldTypes.MYSQL_TYPE_TIME;
fixLengthAndDecAndCharsetDatetime(MyTime.MAX_TIME_WIDTH, dec);
} else {
cachedFieldType = FieldTypes.MYSQL_TYPE_STRING;
/* Behave as a usual string function when return type is VARCHAR. */
// fix_length_and_charset(MyTime.MAX_DATETIME_FULL_WIDTH);
}
}
use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.
the class ItemFuncCase method valStr.
@Override
public String valStr() {
FieldTypes i = fieldType();
if (i == FieldTypes.MYSQL_TYPE_DATETIME || i == FieldTypes.MYSQL_TYPE_TIMESTAMP) {
return valStringFromDatetime();
} else if (i == FieldTypes.MYSQL_TYPE_DATE) {
return valStringFromDate();
} else if (i == FieldTypes.MYSQL_TYPE_TIME) {
return valStringFromTime();
} else {
Item item = findItem();
if (item != null) {
String res;
if ((res = item.valStr()) != null) {
nullValue = false;
return res;
}
}
}
nullValue = true;
return null;
}
Aggregations