From de81e1b21654784b8b9e74b9c5d15f9d18faa0ae Mon Sep 17 00:00:00 2001 From: lgqss Date: Wed, 5 Jun 2024 18:58:51 +0800 Subject: [PATCH] fix fecherstore --- include/common/type_utils.h | 4 +--- src/common/datetime.cpp | 2 +- src/exec/fetcher_store.cpp | 4 +++- test/test_date_time.cpp | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/common/type_utils.h b/include/common/type_utils.h index 8e7c17d6..d13fa795 100644 --- a/include/common/type_utils.h +++ b/include/common/type_utils.h @@ -426,9 +426,7 @@ inline std::string to_mysql_type_full_string(pb::PrimitiveType type, case pb::STRING: return "varchar(1024)"; case pb::DATETIME: - if (float_precision_len == -1) { - return "datetime(6)"; - } else if (float_precision_len > 0 && float_precision_len <= 6) { + if (float_precision_len > 0 && float_precision_len <= 6) { return "datetime(" + std::to_string(float_precision_len) + ")"; } return "datetime"; diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 6622604f..bb45c62b 100755 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -55,7 +55,7 @@ std::string datetime_to_str(uint64_t datetime, int precision_len) { year, month, day, hour, minute, second, macrosec); if (precision_len > 0 and precision_len <=6) { buf[20 + precision_len] = '\0'; - } else if (precision_len == 0) { + } else if (precision_len == 0 || macrosec == 0/*兼容以前*/) { buf[19] = '\0'; } else { buf[26] = '\0'; diff --git a/src/exec/fetcher_store.cpp b/src/exec/fetcher_store.cpp index d675bc85..0fcb07a4 100755 --- a/src/exec/fetcher_store.cpp +++ b/src/exec/fetcher_store.cpp @@ -370,7 +370,9 @@ void OnRPCDone::select_addr() { FetcherStore::choose_opt_instance(_info.region_id(), _info.peers(), _addr, addr_status, nullptr); } _request.set_select_without_leader(true); - } else if (_op_type == pb::OP_SELECT && _state->txn_id == 0 && _client_conn->query_ctx->peer_index != -1) { + } else if (_op_type == pb::OP_SELECT && _state->txn_id == 0 + && _client_conn != nullptr + && _client_conn->query_ctx->peer_index != -1) { int64_t peer_index = _client_conn->query_ctx->peer_index; std::vector sorted_peers; // leader first sorted_peers.emplace_back(_info.leader()); diff --git a/test/test_date_time.cpp b/test/test_date_time.cpp index cd41a246..89176777 100644 --- a/test/test_date_time.cpp +++ b/test/test_date_time.cpp @@ -84,11 +84,11 @@ TEST(test_datetime_str, case_all) { EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:")), "2017-12-03 19:00:00"); EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19")), "2017-12-03 19:00:00"); EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000")), "2017-12-03 19:28:44"); - EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.1234567")), "2017-12-03 19:28:44.123456"); - EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.123")), "2017-12-03 19:28:44.123000"); + EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.1234567"), -1), "2017-12-03 19:28:44.123456"); + EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.123"), -1), "2017-12-03 19:28:44.123000"); - EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123")), "2017-12-03 19:28:44.000123"); - EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123456")), "2017-12-03 19:28:44.000123"); + EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123"), -1), "2017-12-03 19:28:44.000123"); + EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123456"), -1), "2017-12-03 19:28:44.000123"); EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 192:28:44")), "2017-12-03 19:00:00"); EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:284:44")), "2017-12-03 19:28:00"); @@ -100,8 +100,8 @@ TEST(test_datetime_str_other, case_all) { EXPECT_EQ(datetime_to_str(str_to_datetime("89-12-03 19:28:44")), "1989-12-03 19:28:44"); EXPECT_EQ(datetime_to_str(str_to_datetime("891203")), "1989-12-03 00:00:00"); EXPECT_EQ(datetime_to_str(str_to_datetime("19891203")), "1989-12-03 00:00:00"); - EXPECT_EQ(datetime_to_str(str_to_datetime("891203192844.111")), "1989-12-03 19:28:44.111000"); - EXPECT_EQ(datetime_to_str(str_to_datetime("19891203192844.111")), "1989-12-03 19:28:44.111000"); + EXPECT_EQ(datetime_to_str(str_to_datetime("891203192844.111"), -1), "1989-12-03 19:28:44.111000"); + EXPECT_EQ(datetime_to_str(str_to_datetime("19891203192844.111"), -1), "1989-12-03 19:28:44.111000"); std::cout << "tm:" << str_to_datetime("20111303") << std::endl; std::cout << "tm2:" << str_to_datetime("0000-00-00 00:00:00") << std::endl; std::cout << "tm3:" << datetime_to_timestamp(0) << std::endl;