Skip to content

Commit

Permalink
Refactored operation id (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gazizonoki authored Aug 30, 2024
1 parent 66fc8f0 commit 1c413d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
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

0 comments on commit 1c413d2

Please sign in to comment.