Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix](VecDateTimeValue) eat the value of microsecond in function from_date_format_str #13446

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,12 @@ bool VecDateTimeValue::from_date_format_str(const char* format, int format_len,
break;
// Micro second
case 'f':
// _microsecond is removed, but need to eat this val
tmp = val + min(6, val_end - val);
if (!str_to_int64(val, &tmp, &int_value)) {
return false;
}
val = tmp;
break;
// AM/PM
case 'p':
Expand Down
21 changes: 21 additions & 0 deletions be/test/vec/runtime/vdatetime_value_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,27 @@ TEST(VDateTimeValueTest, date_diff_test) {
EXPECT_TRUE(datetime_diff<TimeUnit::MINUTE>(date_v2_1, date_v2_2) == 31 * 24 * 60);
EXPECT_TRUE(datetime_diff<TimeUnit::SECOND>(date_v2_1, date_v2_2) == 31 * 24 * 60 * 60);
}

{
VecDateTimeValue date_v2_1;
std::string origin_date1 = "2022-05-24 06:00:00";
std::string date_format1 = "%Y-%m-%d %H:%i:%s";
EXPECT_TRUE(date_v2_1.from_date_format_str(date_format1.data(), date_format1.size(),
origin_date1.data(), origin_date1.size()));

VecDateTimeValue date_v2_2;
std::string origin_date2 = "2022-06-24 06:00:00.123 AM";
std::string date_format2 = "%Y-%m-%d %h:%i:%s.%f %p";
EXPECT_TRUE(date_v2_2.from_date_format_str(date_format2.data(), date_format2.size(),
origin_date2.data(), origin_date2.size()));

EXPECT_TRUE(datetime_diff<TimeUnit::DAY>(date_v2_1, date_v2_2) == 31);
EXPECT_TRUE(datetime_diff<TimeUnit::YEAR>(date_v2_1, date_v2_2) == 0);
EXPECT_TRUE(datetime_diff<TimeUnit::MONTH>(date_v2_1, date_v2_2) == 1);
EXPECT_TRUE(datetime_diff<TimeUnit::HOUR>(date_v2_1, date_v2_2) == 31 * 24);
EXPECT_TRUE(datetime_diff<TimeUnit::MINUTE>(date_v2_1, date_v2_2) == 31 * 24 * 60);
EXPECT_TRUE(datetime_diff<TimeUnit::SECOND>(date_v2_1, date_v2_2) == 31 * 24 * 60 * 60);
}
}

TEST(VDateTimeValueTest, date_v2_to_string_test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ February
-- !sql --
2014-12-21T12:34:56

-- !sql --
2014-12-21T12:34:56

-- !sql --
2004-10-18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ suite("test_date_function") {
sql """ insert into ${tableName} values ("2014-12-21 12:34:56") """
qt_sql """ select str_to_date(test_datetime, '%Y-%m-%d %H:%i:%s') from ${tableName}; """
qt_sql """ select str_to_date("2014-12-21 12:34%3A56", '%Y-%m-%d %H:%i%%3A%s'); """
qt_sql """ select str_to_date("2014-12-21 12:34:56.789 PM", '%Y-%m-%d %h:%i:%s.%f %p'); """
qt_sql """ select str_to_date('200442 Monday', '%X%V %W') """
sql """ truncate table ${tableName} """
sql """ insert into ${tableName} values ("2020-09-01") """
Expand Down