Browse Source

Improved modify operations

Initial version
auzhegov 1 year ago
parent
commit
3ca8b54c96

+ 1 - 0
ydb/core/fq/libs/common/CMakeLists.darwin-x86_64.txt

@@ -26,5 +26,6 @@ target_sources(fq-libs-common PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/compression.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/debug_info.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/entity_id.cpp
+  ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/util.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/rows_proto_splitter.cpp
 )

+ 1 - 0
ydb/core/fq/libs/common/CMakeLists.linux-aarch64.txt

@@ -27,5 +27,6 @@ target_sources(fq-libs-common PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/compression.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/debug_info.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/entity_id.cpp
+  ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/util.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/rows_proto_splitter.cpp
 )

+ 1 - 0
ydb/core/fq/libs/common/CMakeLists.linux-x86_64.txt

@@ -27,5 +27,6 @@ target_sources(fq-libs-common PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/compression.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/debug_info.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/entity_id.cpp
+  ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/util.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/rows_proto_splitter.cpp
 )

+ 1 - 0
ydb/core/fq/libs/common/CMakeLists.windows-x86_64.txt

@@ -26,5 +26,6 @@ target_sources(fq-libs-common PRIVATE
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/compression.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/debug_info.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/entity_id.cpp
+  ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/util.cpp
   ${CMAKE_SOURCE_DIR}/ydb/core/fq/libs/common/rows_proto_splitter.cpp
 )

+ 38 - 0
ydb/core/fq/libs/common/util.cpp

@@ -0,0 +1,38 @@
+#include "util.h"
+
+#include <util/generic/string.h>
+#include <util/string/builder.h>
+#include <util/string/subst.h>
+
+namespace NFq {
+
+TString EscapeString(const TString& value,
+                     const TString& enclosingSeq,
+                     const TString& replaceWith) {
+    auto escapedValue = value;
+    SubstGlobal(escapedValue, enclosingSeq, replaceWith);
+    return escapedValue;
+}
+
+TString EscapeString(const TString& value, char enclosingChar) {
+    auto escapedValue = value;
+    SubstGlobal(escapedValue,
+                TString{enclosingChar},
+                TStringBuilder{} << '\\' << enclosingChar);
+    return escapedValue;
+}
+
+TString EncloseAndEscapeString(const TString& value, char enclosingChar) {
+    return TStringBuilder{} << enclosingChar << EscapeString(value, enclosingChar)
+                            << enclosingChar;
+}
+
+TString EncloseAndEscapeString(const TString& value,
+                               const TString& enclosingSeq,
+                               const TString& replaceWith) {
+    return TStringBuilder{} << enclosingSeq
+                            << EscapeString(value, enclosingSeq, replaceWith)
+                            << enclosingSeq;
+}
+
+} // namespace NFq

+ 24 - 0
ydb/core/fq/libs/common/util.h

@@ -5,7 +5,10 @@
 
 #include <google/protobuf/repeated_field.h>
 
+#include <library/cpp/iterator/mapped.h>
+#include <util/generic/string.h>
 #include <util/generic/vector.h>
+#include <util/string/join.h>
 
 namespace NFq {
 
@@ -22,4 +25,25 @@ TVector<TElement> VectorFromProto(const ::google::protobuf::RepeatedPtrField<TEl
     return { field.begin(), field.end() };
 }
 
+template <typename TIter, typename TFunc>
+TString JoinMapRange(TString delim, const TIter beg, const TIter end, const TFunc func) {
+    auto mappedBegin =
+        MakeMappedIterator(beg, func);
+    auto mappedEnd =
+        MakeMappedIterator(end, func);
+    return JoinRange(delim, mappedBegin, mappedEnd);
+}
+
+TString EscapeString(const TString& value,
+                     const TString& enclosingSeq,
+                     const TString& replaceWith);
+
+TString EscapeString(const TString& value, char enclosingChar);
+
+TString EncloseAndEscapeString(const TString& value, char enclosingChar);
+
+TString EncloseAndEscapeString(const TString& value,
+                               const TString& enclosingSeq,
+                               const TString& replaceWith);
+
 }  // namespace NFq

+ 1 - 0
ydb/core/fq/libs/common/ya.make

@@ -7,6 +7,7 @@ SRCS(
     debug_info.cpp
     entity_id.cpp
     entity_id.h
+    util.cpp
     rows_proto_splitter.cpp
     rows_proto_splitter.h
 )

+ 1 - 0
ydb/core/fq/libs/control_plane_proxy/actors/CMakeLists.darwin-x86_64.txt

@@ -16,6 +16,7 @@ target_link_libraries(libs-control_plane_proxy-actors PUBLIC
   yutil
   contrib-libs-fmt
   library-cpp-iterator
+  fq-libs-common
   libs-control_plane_proxy-events
   libs-control_plane_storage-events
   fq-libs-result_formatter

+ 1 - 0
ydb/core/fq/libs/control_plane_proxy/actors/CMakeLists.linux-aarch64.txt

@@ -17,6 +17,7 @@ target_link_libraries(libs-control_plane_proxy-actors PUBLIC
   yutil
   contrib-libs-fmt
   library-cpp-iterator
+  fq-libs-common
   libs-control_plane_proxy-events
   libs-control_plane_storage-events
   fq-libs-result_formatter

+ 1 - 0
ydb/core/fq/libs/control_plane_proxy/actors/CMakeLists.linux-x86_64.txt

@@ -17,6 +17,7 @@ target_link_libraries(libs-control_plane_proxy-actors PUBLIC
   yutil
   contrib-libs-fmt
   library-cpp-iterator
+  fq-libs-common
   libs-control_plane_proxy-events
   libs-control_plane_storage-events
   fq-libs-result_formatter

Some files were not shown because too many files changed in this diff