From 4ee6218d0de083b078348f8b21ddce5f001b2f65 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Thu, 2 Sep 2021 11:53:51 +0800 Subject: [PATCH 1/3] Add millisecond field for time map initialize. --- .../function/test/FunctionManagerTest.cpp | 21 +++++++++++++++---- src/common/time/TimeUtils.cpp | 18 ++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/common/function/test/FunctionManagerTest.cpp b/src/common/function/test/FunctionManagerTest.cpp index 817eb6ee15e..19ffe78ab6f 100644 --- a/src/common/function/test/FunctionManagerTest.cpp +++ b/src/common/function/test/FunctionManagerTest.cpp @@ -37,10 +37,12 @@ class FunctionManagerTest : public ::testing::Test { } auto res = result.value()(argsRef); if (res.type() != expect.type()) { - return ::testing::AssertionFailure() << "function return type check failed: " << expr; + return ::testing::AssertionFailure() << "function return type check failed, expect " + << expect.type() << ", got " << res.type(); } if (res != expect) { - return ::testing::AssertionFailure() << "function return value check failed: " << expr; + return ::testing::AssertionFailure() + << "function return value check failed, expect " << expect << ", got " << res; } return ::testing::AssertionSuccess(); } @@ -519,6 +521,15 @@ TEST_F(FunctionManagerTest, functionCall) { {Map({{"hour", 20}, {"minute", 9}, {"second", 15}})}, Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 0)))); } + { + TEST_FUNCTION(time, + {Map({{"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 10}, + {"microsecond", 15}})}, + Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 10015)))); + } // range [(0, 0, 0, 0), (23, 59, 59, 999999)] { TEST_FUNCTION(time, @@ -566,8 +577,10 @@ TEST_F(FunctionManagerTest, functionCall) { {"day", 15}, {"hour", 20}, {"minute", 9}, - {"second", 15}})}, - Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 0)))); + {"second", 15}, + {"millisecond", 10}, + {"microsecond", 15}})}, + Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 10015)))); } { TEST_FUNCTION(datetime, diff --git a/src/common/time/TimeUtils.cpp b/src/common/time/TimeUtils.cpp index 694ab6600a5..01045531ee1 100644 --- a/src/common/time/TimeUtils.cpp +++ b/src/common/time/TimeUtils.cpp @@ -55,11 +55,16 @@ constexpr int64_t kMaxTimestamp = std::numeric_limits::max() / 10000000 return Status::Error("Invalid second number `%ld'.", kv.second.getInt()); } dt.sec = kv.second.getInt(); + } else if (kv.first == "millisecond") { + if (kv.second.getInt() < 0 || kv.second.getInt() > 999) { + return Status::Error("Invalid millisecond number `%ld'.", kv.second.getInt()); + } + dt.microsec += kv.second.getInt() * 1000; } else if (kv.first == "microsecond") { - if (kv.second.getInt() < 0 || kv.second.getInt() > 999999) { + if (kv.second.getInt() < 0 || kv.second.getInt() > 999) { return Status::Error("Invalid microsecond number `%ld'.", kv.second.getInt()); } - dt.microsec = kv.second.getInt(); + dt.microsec += kv.second.getInt(); } else { return Status::Error("Invlaid parameter `%s'.", kv.first.c_str()); } @@ -125,11 +130,16 @@ constexpr int64_t kMaxTimestamp = std::numeric_limits::max() / 10000000 return Status::Error("Invalid second number `%ld'.", kv.second.getInt()); } t.sec = kv.second.getInt(); + } else if (kv.first == "millisecond") { + if (kv.second.getInt() < 0 || kv.second.getInt() > 999) { + return Status::Error("Invalid millisecond number `%ld'.", kv.second.getInt()); + } + t.microsec += kv.second.getInt() * 1000; } else if (kv.first == "microsecond") { - if (kv.second.getInt() < 0 || kv.second.getInt() > 999999) { + if (kv.second.getInt() < 0 || kv.second.getInt() > 999) { return Status::Error("Invalid microsecond number `%ld'.", kv.second.getInt()); } - t.microsec = kv.second.getInt(); + t.microsec += kv.second.getInt(); } else { return Status::Error("Invlaid parameter `%s'.", kv.first.c_str()); } From 296042f5082b66209b811a4001e75e52ebbc0079 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Fri, 3 Sep 2021 11:00:43 +0800 Subject: [PATCH 2/3] Add the tck case. --- tests/tck/features/mutate/InsertWithTimeType.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/tck/features/mutate/InsertWithTimeType.feature b/tests/tck/features/mutate/InsertWithTimeType.feature index 6dde75b6774..23bdc90b4b5 100644 --- a/tests/tck/features/mutate/InsertWithTimeType.feature +++ b/tests/tck/features/mutate/InsertWithTimeType.feature @@ -111,9 +111,9 @@ Feature: Insert with time-dependent types """ UPDATE VERTEX "test" SET - tag_date.f_date = Date("2018-03-04"), - tag_date.f_time = Time("22:01:00"), - tag_date.f_datetime = DateTime("2018-03-04T22:30:40") + tag_date.f_date = Date({year: 2018, month: 3, day: 4}), + tag_date.f_time = Time({hour: 22, minute: 1, second: 0, millisecond: 0, microsecond: 0}), + tag_date.f_datetime = DateTime({year: 2018, month: 3, day: 4, hour: 22, minute: 30, second: 40, millisecond: 0, microsecond: 0}) YIELD f_date, f_time, f_datetime; """ Then the result should be, in any order: From 117764af416cf5ca081a973411f092d653cc0c38 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Thu, 23 Sep 2021 13:48:58 +0800 Subject: [PATCH 3/3] Add some bound case. --- .../function/test/FunctionManagerTest.cpp | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/common/function/test/FunctionManagerTest.cpp b/src/common/function/test/FunctionManagerTest.cpp index 19ffe78ab6f..a02bc86a609 100644 --- a/src/common/function/test/FunctionManagerTest.cpp +++ b/src/common/function/test/FunctionManagerTest.cpp @@ -530,6 +530,33 @@ TEST_F(FunctionManagerTest, functionCall) { {"microsecond", 15}})}, Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 10015)))); } + { + TEST_FUNCTION(time, + {Map({{"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 999}, + {"microsecond", 999}})}, + Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 999999)))); + } + { + TEST_FUNCTION(time, + {Map({{"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 1000}, + {"microsecond", 999}})}, + Value::kNullBadData); + } + { + TEST_FUNCTION(time, + {Map({{"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 999}, + {"microsecond", 1000}})}, + Value::kNullBadData); + } // range [(0, 0, 0, 0), (23, 59, 59, 999999)] { TEST_FUNCTION(time, @@ -582,6 +609,42 @@ TEST_F(FunctionManagerTest, functionCall) { {"microsecond", 15}})}, Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 10015)))); } + { + TEST_FUNCTION(datetime, + {Map({{"year", 2020}, + {"month", 9}, + {"day", 15}, + {"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 999}, + {"microsecond", 999}})}, + Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 999999)))); + } + { + TEST_FUNCTION(datetime, + {Map({{"year", 2020}, + {"month", 9}, + {"day", 15}, + {"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 1000}, + {"microsecond", 999}})}, + Value::kNullBadData); + } + { + TEST_FUNCTION(datetime, + {Map({{"year", 2020}, + {"month", 9}, + {"day", 15}, + {"hour", 20}, + {"minute", 9}, + {"second", 15}, + {"millisecond", 999}, + {"microsecond", 1000}})}, + Value::kNullBadData); + } { TEST_FUNCTION(datetime, {Map({{"year", 2020},