[New Featrue] Support Vectorization Execution Engine Interface For Doris (#6329)
1. FE vectorized plan code 2. Function register vec function 3. Diff function nullable type 4. New thirdparty code and new thrift struct
This commit is contained in:
@ -62,6 +62,29 @@ bool TimestampFunctions::check_format(const StringVal& format, DateTimeValue& t)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string TimestampFunctions::convert_format(const std::string& format) {
|
||||
switch (format.size()) {
|
||||
case 8:
|
||||
if (strncmp(format.c_str(), "yyyyMMdd", 8) == 0) {
|
||||
return std::string("%Y%m%d");
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if (strncmp(format.c_str(), "yyyy-MM-dd", 10) == 0) {
|
||||
return std::string("%Y-%m-%d");
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
if (strncmp(format.c_str(), "yyyy-MM-dd HH:mm:ss", 19) == 0) {
|
||||
return std::string("%Y-%m-%d %H:%i:%s");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
StringVal TimestampFunctions::convert_format(FunctionContext* ctx, const StringVal& format) {
|
||||
switch (format.len) {
|
||||
case 8:
|
||||
@ -438,61 +461,7 @@ BigIntVal TimestampFunctions::timestamp_diff(FunctionContext* ctx, const DateTim
|
||||
DateTimeValue ts_value1 = DateTimeValue::from_datetime_val(ts_val1);
|
||||
DateTimeValue ts_value2 = DateTimeValue::from_datetime_val(ts_val2);
|
||||
|
||||
switch (unit) {
|
||||
case YEAR: {
|
||||
int year = (ts_value2.year() - ts_value1.year());
|
||||
if (year > 0) {
|
||||
year -= (ts_value2.to_int64() % 10000000000 - ts_value1.to_int64() % 10000000000) < 0;
|
||||
} else if (year < 0) {
|
||||
year += (ts_value2.to_int64() % 10000000000 - ts_value1.to_int64() % 10000000000) > 0;
|
||||
}
|
||||
return year;
|
||||
}
|
||||
case MONTH: {
|
||||
int month = (ts_value2.year() - ts_value1.year()) * 12 +
|
||||
(ts_value2.month() - ts_value1.month());
|
||||
if (month > 0) {
|
||||
month -= (ts_value2.to_int64() % 100000000 - ts_value1.to_int64() % 100000000) < 0;
|
||||
} else if (month < 0) {
|
||||
month += (ts_value2.to_int64() % 100000000 - ts_value1.to_int64() % 100000000) > 0;
|
||||
}
|
||||
return month;
|
||||
}
|
||||
case WEEK: {
|
||||
int day = ts_value2.daynr() - ts_value1.daynr();
|
||||
if (day > 0) {
|
||||
day -= ts_value2.time_part_diff(ts_value1) < 0;
|
||||
} else if (day < 0) {
|
||||
day += ts_value2.time_part_diff(ts_value1) > 0;
|
||||
}
|
||||
return day / 7;
|
||||
}
|
||||
case DAY: {
|
||||
int day = ts_value2.daynr() - ts_value1.daynr();
|
||||
if (day > 0) {
|
||||
day -= ts_value2.time_part_diff(ts_value1) < 0;
|
||||
} else if (day < 0) {
|
||||
day += ts_value2.time_part_diff(ts_value1) > 0;
|
||||
}
|
||||
return day;
|
||||
}
|
||||
case HOUR: {
|
||||
int64_t second = ts_value2.second_diff(ts_value1);
|
||||
int64_t hour = second / 60 / 60;
|
||||
return hour;
|
||||
}
|
||||
case MINUTE: {
|
||||
int64_t second = ts_value2.second_diff(ts_value1);
|
||||
int64_t minute = second / 60;
|
||||
return minute;
|
||||
}
|
||||
case SECOND: {
|
||||
int64_t second = ts_value2.second_diff(ts_value1);
|
||||
return second;
|
||||
}
|
||||
default:
|
||||
return BigIntVal::null();
|
||||
}
|
||||
return DateTimeValue::datetime_diff<unit>(ts_value1, ts_value2);
|
||||
}
|
||||
|
||||
void TimestampFunctions::format_prepare(doris_udf::FunctionContext* context,
|
||||
@ -575,10 +544,10 @@ DateTimeVal from_olap_datetime(uint64_t datetime) {
|
||||
static const DateTimeVal FIRST_DAY = from_olap_datetime(19700101000000);
|
||||
static const DateTimeVal FIRST_SUNDAY = from_olap_datetime(19700104000000);
|
||||
|
||||
#define TIME_ROUND(UNIT, unit, ORIGIN) \
|
||||
_TR_4(FLOOR, floor, UNIT, unit) \
|
||||
_TR_4(CEIL, ceil, UNIT, unit) _TR_5(FLOOR, floor, UNIT, unit, ORIGIN) \
|
||||
_TR_5(CEIL, ceil, UNIT, unit, ORIGIN)
|
||||
#define TIME_ROUND(UNIT, unit, ORIGIN) \
|
||||
_TR_4(FLOOR, floor, UNIT, unit) \
|
||||
_TR_4(CEIL, ceil, UNIT, unit) \
|
||||
_TR_5(FLOOR, floor, UNIT, unit, ORIGIN) _TR_5(CEIL, ceil, UNIT, unit, ORIGIN)
|
||||
|
||||
TIME_ROUND(YEAR, year, FIRST_DAY)
|
||||
TIME_ROUND(MONTH, month, FIRST_DAY)
|
||||
|
||||
Reference in New Issue
Block a user