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

Refactored operation id #308

Merged
merged 3 commits into from
Aug 30, 2024
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
12 changes: 11 additions & 1 deletion include/ydb-cpp-sdk/library/operation_id/operation_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ class TOperationId {

TOperationId();
explicit TOperationId(const std::string& string, bool allowEmpty = false);

TOperationId(const TOperationId& other);
TOperationId(TOperationId&& other) = default;

TOperationId& operator=(const TOperationId& other);
TOperationId& operator=(TOperationId&& other) = default;

~TOperationId() = default;

EKind GetKind() const;
EKind& GetMutableKind();
void SetKind(const EKind& kind);

const TDataList& GetData() const;
TDataList& GetMutableData();
Expand All @@ -47,6 +56,7 @@ class TOperationId {

private:
bool IsValidKind(int kind);
void CopyData(const TOperationId::TDataList& otherData);

EKind Kind;
TDataList Data;
Expand Down
4 changes: 2 additions & 2 deletions include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TIssue;
using TIssuePtr = TIntrusivePtr<TIssue>;
class TIssue: public TThrRefBase {
std::vector<TIntrusivePtr<TIssue>> Children_;
std::string Message;
TString Message;
public:
TPosition Position;
TPosition EndPosition;
Expand Down Expand Up @@ -209,7 +209,7 @@ class TIssue: public TThrRefBase {
}

// Unsafe method. Doesn't call SanitizeNonAscii(Message)
std::string* MutableMessage() {
TString* MutableMessage() {
return &Message;
}

Expand Down
24 changes: 22 additions & 2 deletions src/library/operation_id/operation_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,32 @@ TOperationId::TOperationId(const std::string &string, bool allowEmpty) {
}
}

TOperationId::TOperationId(const TOperationId& other) {
Kind = other.Kind;
CopyData(other.Data);
}

TOperationId& TOperationId::operator=(const TOperationId& other) {
Kind = other.Kind;
Data.clear();
Index.clear();
CopyData(other.Data);
return *this;
}

void TOperationId::CopyData(const TOperationId::TDataList& otherData) {
for (const auto& data : otherData) {
Data.push_back(std::make_unique<TData>(data->Key, data->Value));
Index[data->Key].push_back(&Data.back()->Value);
}
}

TOperationId::EKind TOperationId::GetKind() const {
return Kind;
}

TOperationId::EKind& TOperationId::GetMutableKind() {
return Kind;
void TOperationId::SetKind(const EKind& kind) {
Kind = kind;
}

const TOperationId::TDataList& TOperationId::GetData() const {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/library/operation_id/operation_id_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Y_UNIT_TEST_SUITE(OperationIdTest) {

Y_UNIT_TEST(PreparedQueryIdCompatibleFormatter) {
TOperationId opId;
opId.GetMutableKind() = TOperationId::PREPARED_QUERY_ID;
opId.SetKind(TOperationId::PREPARED_QUERY_ID);
AddOptionalValue(opId, "id", PreparedQueryId);
auto result = opId.ToString();
UNIT_ASSERT_VALUES_EQUAL(FormatPreparedQueryIdCompat(PreparedQueryId), result);
Expand Down
Loading