fix bug about expr second microsecond hour month year

This commit is contained in:
obdev
2023-06-13 08:53:56 +00:00
committed by ob-robot
parent 1d7696516a
commit 68af9e5cf9
2 changed files with 14 additions and 2 deletions

View File

@ -1998,6 +1998,10 @@ int ObTimeConverter::str_to_ob_time_without_date(const ObString &str, ObTime &ob
const char *end = pos + str.length(); const char *end = pos + str.length();
// find first digit. // find first digit.
for (; pos < end && isspace(*pos); ++pos) {} for (; pos < end && isspace(*pos); ++pos) {}
if (pos >= end) {
ret = OB_INVALID_DATE_FORMAT;
LOG_WARN("invalid argument, all spaces", K(ret));
}
const char *first_digit = pos; const char *first_digit = pos;
if (pos < end && !('-' == *pos || isdigit(*pos))){ if (pos < end && !('-' == *pos || isdigit(*pos))){
for (int i = 0; OB_SUCC(ret) && i < TOTAL_PART_CNT; ++i) { for (int i = 0; OB_SUCC(ret) && i < TOTAL_PART_CNT; ++i) {
@ -2013,7 +2017,7 @@ int ObTimeConverter::str_to_ob_time_without_date(const ObString &str, ObTime &ob
bool has_done = false; bool has_done = false;
// maybe it is an whole datetime string. // maybe it is an whole datetime string.
if (end - first_digit >= 12) { if (end - first_digit >= 12) {
ret = str_to_ob_time_with_date(str, ob_time, scale, false, 0); ret = str_to_ob_time_with_date(str, ob_time, scale, true, 0);
if ((DT_TYPE_NONE & ob_time.mode_) || OB_INVALID_DATE_FORMAT == ret) { if ((DT_TYPE_NONE & ob_time.mode_) || OB_INVALID_DATE_FORMAT == ret) {
ob_time.mode_ &= (~DT_TYPE_NONE); ob_time.mode_ &= (~DT_TYPE_NONE);
for (int i = 0; i < DATETIME_PART_CNT; ++i) { for (int i = 0; i < DATETIME_PART_CNT; ++i) {
@ -2098,6 +2102,14 @@ int ObTimeConverter::str_to_ob_time_without_date(const ObString &str, ObTime &ob
if (NULL != scale) { if (NULL != scale) {
*scale = static_cast<int16_t>(MIN(digits.len_, 6)); *scale = static_cast<int16_t>(MIN(digits.len_, 6));
} }
// '2:59:59.9999999' ---> '03:00:00.000000'
const int64_t *part_max = DT_PART_BASE;
for (int i = DATETIME_PART_CNT - 1; OB_SUCC(ret) && i > DATE_PART_CNT; i--) {
if (ob_time.parts_[i] == part_max[i]) {
ob_time.parts_[i] = 0;
ob_time.parts_[i - 1]++;
}
}
} }
} }
} }

View File

@ -308,7 +308,7 @@ ObExprYear::~ObExprYear() {}
int ObExprYear::calc_year(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum) int ObExprYear::calc_year(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{ {
return ObExprTimeBase::calc(expr, ctx, expr_datum, DT_YEAR, true); return ObExprTimeBase::calc(expr, ctx, expr_datum, DT_YEAR, true, true);
} }
ObExprMonth::ObExprMonth(ObIAllocator &alloc) ObExprMonth::ObExprMonth(ObIAllocator &alloc)