Skip to content

Commit 1c413d2

Browse files
authored
Refactored operation id (#308)
1 parent 66fc8f0 commit 1c413d2

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

include/ydb-cpp-sdk/library/operation_id/operation_id.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@ class TOperationId {
3535

3636
TOperationId();
3737
explicit TOperationId(const std::string& string, bool allowEmpty = false);
38+
39+
TOperationId(const TOperationId& other);
40+
TOperationId(TOperationId&& other) = default;
41+
42+
TOperationId& operator=(const TOperationId& other);
43+
TOperationId& operator=(TOperationId&& other) = default;
44+
45+
~TOperationId() = default;
46+
3847
EKind GetKind() const;
39-
EKind& GetMutableKind();
48+
void SetKind(const EKind& kind);
4049

4150
const TDataList& GetData() const;
4251
TDataList& GetMutableData();
@@ -47,6 +56,7 @@ class TOperationId {
4756

4857
private:
4958
bool IsValidKind(int kind);
59+
void CopyData(const TOperationId::TDataList& otherData);
5060

5161
EKind Kind;
5262
TDataList Data;

include/ydb-cpp-sdk/library/yql_common/issue/yql_issue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class TIssue;
112112
using TIssuePtr = TIntrusivePtr<TIssue>;
113113
class TIssue: public TThrRefBase {
114114
std::vector<TIntrusivePtr<TIssue>> Children_;
115-
std::string Message;
115+
TString Message;
116116
public:
117117
TPosition Position;
118118
TPosition EndPosition;
@@ -209,7 +209,7 @@ class TIssue: public TThrRefBase {
209209
}
210210

211211
// Unsafe method. Doesn't call SanitizeNonAscii(Message)
212-
std::string* MutableMessage() {
212+
TString* MutableMessage() {
213213
return &Message;
214214
}
215215

src/library/operation_id/operation_id.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,32 @@ TOperationId::TOperationId(const std::string &string, bool allowEmpty) {
120120
}
121121
}
122122

123+
TOperationId::TOperationId(const TOperationId& other) {
124+
Kind = other.Kind;
125+
CopyData(other.Data);
126+
}
127+
128+
TOperationId& TOperationId::operator=(const TOperationId& other) {
129+
Kind = other.Kind;
130+
Data.clear();
131+
Index.clear();
132+
CopyData(other.Data);
133+
return *this;
134+
}
135+
136+
void TOperationId::CopyData(const TOperationId::TDataList& otherData) {
137+
for (const auto& data : otherData) {
138+
Data.push_back(std::make_unique<TData>(data->Key, data->Value));
139+
Index[data->Key].push_back(&Data.back()->Value);
140+
}
141+
}
142+
123143
TOperationId::EKind TOperationId::GetKind() const {
124144
return Kind;
125145
}
126146

127-
TOperationId::EKind& TOperationId::GetMutableKind() {
128-
return Kind;
147+
void TOperationId::SetKind(const EKind& kind) {
148+
Kind = kind;
129149
}
130150

131151
const TOperationId::TDataList& TOperationId::GetData() const {

tests/unit/library/operation_id/operation_id_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Y_UNIT_TEST_SUITE(OperationIdTest) {
1818

1919
Y_UNIT_TEST(PreparedQueryIdCompatibleFormatter) {
2020
TOperationId opId;
21-
opId.GetMutableKind() = TOperationId::PREPARED_QUERY_ID;
21+
opId.SetKind(TOperationId::PREPARED_QUERY_ID);
2222
AddOptionalValue(opId, "id", PreparedQueryId);
2323
auto result = opId.ToString();
2424
UNIT_ASSERT_VALUES_EQUAL(FormatPreparedQueryIdCompat(PreparedQueryId), result);

0 commit comments

Comments
 (0)