From d33e2c39ad09876b7af07dd08cb5f1587c63ceb2 Mon Sep 17 00:00:00 2001 From: HuangWei Date: Tue, 16 Apr 2024 10:53:17 +0800 Subject: [PATCH] fix: ddl parser get dup col keys (#3873) --- src/base/ddl_parser.cc | 6 ++++-- src/base/ddl_parser_test.cc | 39 +++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/base/ddl_parser.cc b/src/base/ddl_parser.cc index 4f3d631a1fc..d0aa30d168c 100644 --- a/src/base/ddl_parser.cc +++ b/src/base/ddl_parser.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include "codec/schema_codec.h" #include "google/protobuf/util/message_differencer.h" @@ -441,6 +442,7 @@ std::vector DDLParser::ValidateSQLInRequest(const std::string& sql, void IndexMapBuilder::Report(absl::string_view db, absl::string_view table, absl::Span keys, absl::string_view ts, const PhysicalOpNode* expr_node) { // we encode table, keys and ts to one string + // keys may be dup, dedup in encode auto index = Encode(db, table, keys, ts); if (index.empty()) { LOG(WARNING) << "index encode failed for table " << db << "." << table; @@ -604,8 +606,8 @@ MultiDBIndexMap IndexMapBuilder::ToMap() { std::string IndexMapBuilder::Encode(absl::string_view db, absl::string_view table, absl::Span keys, absl::string_view ts) { // children are ColumnRefNode - std::vector cols(keys.begin(), keys.end()); - std::sort(cols.begin(), cols.end()); + // dedup and sort keys + std::set cols(keys.begin(), keys.end()); if (cols.empty()) { return {}; } diff --git a/src/base/ddl_parser_test.cc b/src/base/ddl_parser_test.cc index be35b17934e..acb27fdd042 100644 --- a/src/base/ddl_parser_test.cc +++ b/src/base/ddl_parser_test.cc @@ -15,6 +15,7 @@ */ #include "base/ddl_parser.h" + #include #include "absl/cleanup/cleanup.h" @@ -50,7 +51,7 @@ std::ostream& operator<<(std::ostream& os, const std::map // a human readable string for one index: key1,key2,...;ts;. (ts is optional and only one, if no ts, it should be -// key;;) : type,abs_value,lat_value, e.g. abs,10,0 lat,0,20 abs&lat,10,20 abs||lat,10,20 +// key;;) : type,abs_value,lat_value, e.g. abs,10,0 lat,0,20 absandlat,10,20 absorlat,10,20 void CheckEqual(const IndexMap& map, std::map>&& readable_map) { auto error_message = [](const IndexMap& map, const std::map>& readable) { std::stringstream ss; @@ -121,7 +122,7 @@ void CheckEqual(const IndexMap& map, std::map