diff options
author | vvvv <vvvv@yandex-team.com> | 2024-11-01 22:10:01 +0300 |
---|---|---|
committer | vvvv <vvvv@yandex-team.com> | 2024-11-01 22:47:05 +0300 |
commit | c7a2455f0892bcac6cbd01773c9a54b17efda0ed (patch) | |
tree | fdc26c2414d876c38239a7a60de3b379cfa283c1 | |
parent | 0958dbb9b614bd9256e4d6f772fb94c3af3d74b0 (diff) | |
download | ydb-c7a2455f0892bcac6cbd01773c9a54b17efda0ed.tar.gz |
Split ydb part from yql/public/issue YQL-19206
init
commit_hash:8b939f1c7e04aa3a20226fc112bedb27bc29f54d
-rw-r--r-- | yql/essentials/public/issue/ya.make | 1 | ||||
-rw-r--r-- | yql/essentials/public/issue/yql_issue_message.cpp | 115 | ||||
-rw-r--r-- | yql/essentials/public/issue/yql_issue_message.h | 3 | ||||
-rw-r--r-- | yql/essentials/public/issue/yql_issue_message_impl.h | 96 | ||||
-rw-r--r-- | yql/essentials/public/issue/yql_issue_ut.cpp | 109 |
5 files changed, 97 insertions, 227 deletions
diff --git a/yql/essentials/public/issue/ya.make b/yql/essentials/public/issue/ya.make index 79f4d3e539..f376c8bcda 100644 --- a/yql/essentials/public/issue/ya.make +++ b/yql/essentials/public/issue/ya.make @@ -12,7 +12,6 @@ PEERDIR( contrib/libs/protobuf library/cpp/colorizer library/cpp/resource - contrib/ydb/public/api/protos yql/essentials/public/issue/protos yql/essentials/utils ) diff --git a/yql/essentials/public/issue/yql_issue_message.cpp b/yql/essentials/public/issue/yql_issue_message.cpp index 757bba3946..d759edf432 100644 --- a/yql/essentials/public/issue/yql_issue_message.cpp +++ b/yql/essentials/public/issue/yql_issue_message.cpp @@ -1,12 +1,9 @@ #include "yql_issue_message.h" +#include "yql_issue_message_impl.h" #include <yql/essentials/public/issue/protos/issue_message.pb.h> -#include <contrib/ydb/public/api/protos/ydb_issue_message.pb.h> -#include <util/generic/deque.h> #include <util/generic/yexception.h> -#include <util/stream/output.h> -#include <util/string/join.h> #include <tuple> @@ -14,107 +11,16 @@ namespace NYql { using namespace NIssue::NProto; -template<typename TIssueMessage> -TIssue IssueFromMessage(const TIssueMessage& issueMessage) { - TIssue topIssue; - TDeque<std::pair<TIssue*, const TIssueMessage*>> queue; - queue.push_front(std::make_pair(&topIssue, &issueMessage)); - while (!queue.empty()) { - TIssue& issue = *queue.back().first; - const auto& message = *queue.back().second; - queue.pop_back(); - TPosition position(message.position().column(), message.position().row(), message.position().file()); - TPosition endPosition(message.end_position().column(), message.end_position().row()); - if (position.HasValue()) { - if (endPosition.HasValue()) { - issue = TIssue(position, endPosition, message.message()); - } else { - issue = TIssue(position, message.message()); - } - } else { - issue = TIssue(message.message()); - } - - for (const auto& subMessage : message.issues()) { - auto subIssue = new TIssue(); - issue.AddSubIssue(subIssue); - queue.push_front(std::make_pair(subIssue, &subMessage)); - } - - issue.SetCode(message.issue_code(), static_cast<ESeverity>(message.severity())); - } - return topIssue; -} - -template<typename TIssueMessage> -void IssuesFromMessage(const ::google::protobuf::RepeatedPtrField<TIssueMessage> &message, TIssues &issues) { - issues.Clear(); - if (message.size()) { - issues.Reserve(message.size()); - for (auto &x : message) - issues.AddIssue(IssueFromMessage(x)); - } -} - -template<typename TIssueMessage> -void IssueToMessage(const TIssue& topIssue, TIssueMessage* issueMessage) { - TDeque<std::pair<const TIssue*, TIssueMessage*>> queue; - queue.push_front(std::make_pair(&topIssue, issueMessage)); - while (!queue.empty()) { - const TIssue& issue = *queue.back().first; - auto& message = *queue.back().second; - queue.pop_back(); - if (issue.Position) { - auto& position = *message.mutable_position(); - position.set_row(issue.Position.Row); - position.set_column(issue.Position.Column); - position.set_file(issue.Position.File); - } - if (issue.EndPosition) { - auto& endPosition = *message.mutable_end_position(); - endPosition.set_row(issue.EndPosition.Row); - endPosition.set_column(issue.EndPosition.Column); - } - message.set_message(issue.GetMessage()); - message.set_issue_code(issue.GetCode()); - message.set_severity(issue.GetSeverity()); - - for (auto subIssue : issue.GetSubIssues()) { - TIssueMessage* subMessage = message.add_issues(); - queue.push_front(std::make_pair(subIssue.Get(), subMessage)); - } - } -} - -template<typename TIssueMessage> -void IssuesToMessage(const TIssues& issues, ::google::protobuf::RepeatedPtrField<TIssueMessage> *message) { - message->Clear(); - if (!issues) - return; - message->Reserve(issues.Size()); - for (const auto &issue : issues) { - IssueToMessage(issue, message->Add()); - } -} - -template -TIssue IssueFromMessage<Ydb::Issue::IssueMessage>(const Ydb::Issue::IssueMessage& issueMessage); template TIssue IssueFromMessage<NYql::NIssue::NProto::IssueMessage>(const NYql::NIssue::NProto::IssueMessage& issueMessage); template -void IssuesFromMessage<Ydb::Issue::IssueMessage>(const ::google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage>& message, TIssues& issues); -template void IssuesFromMessage<NYql::NIssue::NProto::IssueMessage>(const ::google::protobuf::RepeatedPtrField<NYql::NIssue::NProto::IssueMessage>& message, TIssues& issues); template -void IssueToMessage<Ydb::Issue::IssueMessage>(const TIssue& topIssue, Ydb::Issue::IssueMessage* issueMessage); -template void IssueToMessage<NYql::NIssue::NProto::IssueMessage>(const TIssue& topIssue, NYql::NIssue::NProto::IssueMessage* issueMessage); template -void IssuesToMessage<Ydb::Issue::IssueMessage>(const TIssues& issues, ::google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage>* message); -template void IssuesToMessage<NYql::NIssue::NProto::IssueMessage>(const TIssues& issues, ::google::protobuf::RepeatedPtrField<NYql::NIssue::NProto::IssueMessage>* message); NIssue::NProto::IssueMessage IssueToMessage(const TIssue& topIssue) { @@ -123,27 +29,8 @@ NIssue::NProto::IssueMessage IssueToMessage(const TIssue& topIssue) { return issueMessage; } -TString IssueToBinaryMessage(const TIssue& issue) { - TString result; - Ydb::Issue::IssueMessage protobuf; - IssueToMessage(issue, &protobuf); - Y_PROTOBUF_SUPPRESS_NODISCARD protobuf.SerializeToString(&result); - return result; -} - -TIssue IssueFromBinaryMessage(const TString& binaryMessage) { - Ydb::Issue::IssueMessage protobuf; - if (!protobuf.ParseFromString(binaryMessage)) { - ythrow yexception() << "unable to parse binary string as issue protobuf"; - } - return IssueFromMessage(protobuf); -} - } -Y_DECLARE_OUT_SPEC(, google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage>, stream, issues) { - stream << JoinSeq("", issues); -} Y_DECLARE_OUT_SPEC(, google::protobuf::RepeatedPtrField<NYql::NIssue::NProto::IssueMessage>, stream, issues) { stream << JoinSeq("", issues); }
\ No newline at end of file diff --git a/yql/essentials/public/issue/yql_issue_message.h b/yql/essentials/public/issue/yql_issue_message.h index a3cb63e4f4..be1d1a45bb 100644 --- a/yql/essentials/public/issue/yql_issue_message.h +++ b/yql/essentials/public/issue/yql_issue_message.h @@ -31,7 +31,4 @@ void IssueToMessage(const TIssue& topIssue, TIssueMessage* message); template<typename TIssueMessage> void IssuesToMessage(const TIssues& issues, ::google::protobuf::RepeatedPtrField<TIssueMessage>* message); -TString IssueToBinaryMessage(const TIssue& issue); -TIssue IssueFromBinaryMessage(const TString& binaryMessage); - } diff --git a/yql/essentials/public/issue/yql_issue_message_impl.h b/yql/essentials/public/issue/yql_issue_message_impl.h new file mode 100644 index 0000000000..c59134e183 --- /dev/null +++ b/yql/essentials/public/issue/yql_issue_message_impl.h @@ -0,0 +1,96 @@ +#pragma once + +#include "yql_issue_message.h" + +#include <util/generic/deque.h> +#include <util/string/join.h> +#include <util/stream/output.h> + +namespace NYql { + +using namespace NIssue::NProto; + +template<typename TIssueMessage> +TIssue IssueFromMessage(const TIssueMessage& issueMessage) { + TIssue topIssue; + TDeque<std::pair<TIssue*, const TIssueMessage*>> queue; + queue.push_front(std::make_pair(&topIssue, &issueMessage)); + while (!queue.empty()) { + TIssue& issue = *queue.back().first; + const auto& message = *queue.back().second; + queue.pop_back(); + TPosition position(message.position().column(), message.position().row(), message.position().file()); + TPosition endPosition(message.end_position().column(), message.end_position().row()); + if (position.HasValue()) { + if (endPosition.HasValue()) { + issue = TIssue(position, endPosition, message.message()); + } else { + issue = TIssue(position, message.message()); + } + } else { + issue = TIssue(message.message()); + } + + for (const auto& subMessage : message.issues()) { + auto subIssue = new TIssue(); + issue.AddSubIssue(subIssue); + queue.push_front(std::make_pair(subIssue, &subMessage)); + } + + issue.SetCode(message.issue_code(), static_cast<ESeverity>(message.severity())); + } + return topIssue; +} + +template<typename TIssueMessage> +void IssuesFromMessage(const ::google::protobuf::RepeatedPtrField<TIssueMessage> &message, TIssues &issues) { + issues.Clear(); + if (message.size()) { + issues.Reserve(message.size()); + for (auto &x : message) + issues.AddIssue(IssueFromMessage(x)); + } +} + +template<typename TIssueMessage> +void IssueToMessage(const TIssue& topIssue, TIssueMessage* issueMessage) { + TDeque<std::pair<const TIssue*, TIssueMessage*>> queue; + queue.push_front(std::make_pair(&topIssue, issueMessage)); + while (!queue.empty()) { + const TIssue& issue = *queue.back().first; + auto& message = *queue.back().second; + queue.pop_back(); + if (issue.Position) { + auto& position = *message.mutable_position(); + position.set_row(issue.Position.Row); + position.set_column(issue.Position.Column); + position.set_file(issue.Position.File); + } + if (issue.EndPosition) { + auto& endPosition = *message.mutable_end_position(); + endPosition.set_row(issue.EndPosition.Row); + endPosition.set_column(issue.EndPosition.Column); + } + message.set_message(issue.GetMessage()); + message.set_issue_code(issue.GetCode()); + message.set_severity(issue.GetSeverity()); + + for (auto subIssue : issue.GetSubIssues()) { + TIssueMessage* subMessage = message.add_issues(); + queue.push_front(std::make_pair(subIssue.Get(), subMessage)); + } + } +} + +template<typename TIssueMessage> +void IssuesToMessage(const TIssues& issues, ::google::protobuf::RepeatedPtrField<TIssueMessage> *message) { + message->Clear(); + if (!issues) + return; + message->Reserve(issues.Size()); + for (const auto &issue : issues) { + IssueToMessage(issue, message->Add()); + } +} + +} diff --git a/yql/essentials/public/issue/yql_issue_ut.cpp b/yql/essentials/public/issue/yql_issue_ut.cpp index 02f917fa54..551c965ccf 100644 --- a/yql/essentials/public/issue/yql_issue_ut.cpp +++ b/yql/essentials/public/issue/yql_issue_ut.cpp @@ -4,7 +4,6 @@ #include <library/cpp/testing/unittest/registar.h> #include <yql/essentials/public/issue/protos/issue_message.pb.h> #include <yql/essentials/public/issue/yql_issue_message.h> -#include <contrib/ydb/public/api/protos/ydb_issue_message.pb.h> #include <library/cpp/unicode/normalization/normalization.h> @@ -18,38 +17,6 @@ using namespace google::protobuf; using namespace NYql; -void ensureMessageTypesSame(const Descriptor* a, const Descriptor* b, THashSet<TString>* visitedTypes); -void ensureFieldDescriptorsSame(const FieldDescriptor* a, const FieldDescriptor* b, THashSet<TString>* visitedTypes) { - UNIT_ASSERT(a); - UNIT_ASSERT(b); - - UNIT_ASSERT_VALUES_EQUAL(FieldDescriptor::TypeName(a->type()), FieldDescriptor::TypeName(b->type())); - UNIT_ASSERT_VALUES_EQUAL((int)a->label(), (int)b->label()); - UNIT_ASSERT_VALUES_EQUAL(a->name(), b->name()); - UNIT_ASSERT_VALUES_EQUAL(a->number(), b->number()); - UNIT_ASSERT_VALUES_EQUAL(a->is_repeated(), b->is_repeated()); - UNIT_ASSERT_VALUES_EQUAL(a->is_packed(), b->is_packed()); - UNIT_ASSERT_VALUES_EQUAL(a->index(), b->index()); - if (a->type() == FieldDescriptor::TYPE_MESSAGE || a->type() == FieldDescriptor::TYPE_GROUP) { - ensureMessageTypesSame(a->message_type(), b->message_type(), visitedTypes); - } -} - -void ensureMessageTypesSame(const Descriptor* a, const Descriptor* b, THashSet<TString>* visitedTypes) { - UNIT_ASSERT(a); - UNIT_ASSERT(b); - if (!visitedTypes->insert(a->name()).second) { - return; - } - - UNIT_ASSERT_VALUES_EQUAL(a->name(), b->name()); - UNIT_ASSERT_VALUES_EQUAL(a->field_count(), b->field_count()); - - for (int i = 0; i < a->field_count(); i++) { - ensureFieldDescriptorsSame(a->field(i), b->field(i), visitedTypes); - } -} - Y_UNIT_TEST_SUITE(IssueTest) { Y_UNIT_TEST(Ascii) { TIssue issue1("ัะตัั abc"); @@ -63,27 +30,6 @@ Y_UNIT_TEST_SUITE(IssueTest) { } } -Y_UNIT_TEST_SUITE(IssueProtoTest) { - Y_UNIT_TEST(KikimrYqlSameLayout) { - Ydb::Issue::IssueMessage yqlIssue; - NYql::NIssue::NProto::IssueMessage kikimrIssue; - THashSet<TString> visitedTypes; - ensureMessageTypesSame(yqlIssue.GetDescriptor(), kikimrIssue.GetDescriptor(), &visitedTypes); - } - - Y_UNIT_TEST(BinarySerialization) { - TIssue issueTo("root_issue"); - TString bin = IssueToBinaryMessage(issueTo); - TIssue issueFrom = IssueFromBinaryMessage(bin); - UNIT_ASSERT_EQUAL(issueTo, issueFrom); - } - - Y_UNIT_TEST(WrongBinStringException) { - UNIT_ASSERT_EXCEPTION(IssueFromBinaryMessage("qqq"), yexception); - } -} - - Y_UNIT_TEST_SUITE(TextWalkerTest) { Y_UNIT_TEST(BasicTest) { TPosition pos; @@ -167,61 +113,6 @@ Y_UNIT_TEST_SUITE(ToOneLineStringTest) { } } -Y_UNIT_TEST_SUITE(ToStreamTest) { - template <typename TIssueMessage> - void CheckSerializationToStream(const TIssues& issues, const TString& expected) { - google::protobuf::RepeatedPtrField<TIssueMessage> protoIssues; - IssuesToMessage(issues, &protoIssues); - TStringBuilder stream; - stream << protoIssues; - UNIT_ASSERT_STRINGS_EQUAL(stream, expected); - }; - - Y_UNIT_TEST(OneMessageTest) { - TIssues issues; - issues.AddIssue("error"); - CheckSerializationToStream<Ydb::Issue::IssueMessage>(issues, "{ message: \"error\" severity: 1 }"); - CheckSerializationToStream<NYql::NIssue::NProto::IssueMessage>(issues, "{ message: \"error\" issue_code: 0 severity: 1 }"); - } - - Y_UNIT_TEST(SubIssuesTest) { - TIssue issue(TPosition(12, 34, "file.abc"), "error"); - TIssue subissue("suberror"); - subissue.AddSubIssue(MakeIntrusive<TIssue>("subsuberror")); - issue.AddSubIssue(MakeIntrusive<TIssue>(subissue)); - TIssues issues; - issues.AddIssue(issue); - CheckSerializationToStream<Ydb::Issue::IssueMessage>(issues, "{ position { row: 34 column: 12 file: \"file.abc\" } message: \"error\" end_position { row: 34 column: 12 } severity: 1 issues { message: \"suberror\" severity: 1 issues { message: \"subsuberror\" severity: 1 } } }"); - CheckSerializationToStream<NYql::NIssue::NProto::IssueMessage>(issues, "{ position { row: 34 column: 12 file: \"file.abc\" } message: \"error\" end_position { row: 34 column: 12 } issue_code: 0 severity: 1 issues { message: \"suberror\" issue_code: 0 severity: 1 issues { message: \"subsuberror\" issue_code: 0 severity: 1 } } }"); - } - - Y_UNIT_TEST(ManyIssuesTest) { - TIssue issue(TPosition(12, 34, "file.abc"), "error"); - issue.AddSubIssue(MakeIntrusive<TIssue>("suberror")); - TIssues issues; - issues.AddIssue(issue); - issues.AddIssue(TPosition(100, 2, "abc.file"), "my message"); - CheckSerializationToStream<Ydb::Issue::IssueMessage>(issues, "{ position { row: 34 column: 12 file: \"file.abc\" } message: \"error\" end_position { row: 34 column: 12 } severity: 1 issues { message: \"suberror\" severity: 1 } }{ position { row: 2 column: 100 file: \"abc.file\" } message: \"my message\" end_position { row: 2 column: 100 } severity: 1 }"); - CheckSerializationToStream<NYql::NIssue::NProto::IssueMessage>(issues, "{ position { row: 34 column: 12 file: \"file.abc\" } message: \"error\" end_position { row: 34 column: 12 } issue_code: 0 severity: 1 issues { message: \"suberror\" issue_code: 0 severity: 1 } }{ position { row: 2 column: 100 file: \"abc.file\" } message: \"my message\" end_position { row: 2 column: 100 } issue_code: 0 severity: 1 }"); - } -} - -Y_UNIT_TEST_SUITE(ToMessage) { - Y_UNIT_TEST(NonUtf8) { - const TString nonUtf8String = "\x7f\xf8\xf7\xff\xf8\x1f\xff\xf2\xaf\xbf\xfe\xfa\xf5\x7f\xfe\xfa\x27\x20\x7d\x20\x5d\x2e"; - UNIT_ASSERT(!IsUtf(nonUtf8String)); - TIssue issue; - issue.SetMessage(nonUtf8String); - - Ydb::Issue::IssueMessage msg; - IssueToMessage(issue, &msg); - TString serialized; - UNIT_ASSERT(msg.SerializeToString(&serialized)); - Ydb::Issue::IssueMessage msg2; - UNIT_ASSERT(msg2.ParseFromString(serialized)); - } -} - Y_UNIT_TEST_SUITE(EscapeNonUtf8) { Y_UNIT_TEST(Escape) { const TString nonUtf8String = "\xfe\xfa\xf5\xc2"; |