aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorromanenko-ii <romanenko-ii@yandex-team.ru>2022-02-10 16:50:37 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:37 +0300
commit5ca39c6275c4cb3911098b94ffa1516f68b7d5e8 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8
parent4ee92606ffd02329182167a0db41aae105a62c6c (diff)
downloadydb-5ca39c6275c4cb3911098b94ffa1516f68b7d5e8.tar.gz
Restoring authorship annotation for <romanenko-ii@yandex-team.ru>. Commit 2 of 2.
-rw-r--r--library/cpp/protobuf/util/pb_io.cpp38
-rw-r--r--library/cpp/protobuf/util/pb_io.h8
-rw-r--r--library/cpp/protobuf/util/pb_io_ut.cpp144
-rw-r--r--library/cpp/protobuf/util/ut/common_ut.proto16
-rw-r--r--ydb/library/yql/udfs/common/histogram/histogram_udf.cpp22
5 files changed, 114 insertions, 114 deletions
diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp
index 650d76cbab..6270ee0624 100644
--- a/library/cpp/protobuf/util/pb_io.cpp
+++ b/library/cpp/protobuf/util/pb_io.cpp
@@ -10,17 +10,17 @@
#include <util/generic/string.h>
#include <util/stream/file.h>
#include <util/stream/str.h>
-#include <util/string/cast.h>
+#include <util/string/cast.h>
namespace NProtoBuf {
-
- class TEnumIdValuePrinter : public google::protobuf::TextFormat::FastFieldValuePrinter {
- public:
- void PrintEnum(int32 val, const TString& /*name*/, google::protobuf::TextFormat::BaseTextGenerator* generator) const override {
- generator->PrintString(ToString(val));
- }
- };
-
+
+ class TEnumIdValuePrinter : public google::protobuf::TextFormat::FastFieldValuePrinter {
+ public:
+ void PrintEnum(int32 val, const TString& /*name*/, google::protobuf::TextFormat::BaseTextGenerator* generator) const override {
+ generator->PrintString(ToString(val));
+ }
+ };
+
void ParseFromBase64String(const TStringBuf dataBase64, Message& m, bool allowUneven) {
if (!m.ParseFromString(allowUneven ? Base64DecodeUneven(dataBase64) : Base64StrictDecode(dataBase64))) {
ythrow yexception() << "can't parse " << m.GetTypeName() << " from base64-encoded string";
@@ -108,16 +108,16 @@ void SerializeToTextFormat(const NProtoBuf::Message& m, const TString& fileName)
SerializeToTextFormat(m, stream);
}
-void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out) {
- google::protobuf::TextFormat::Printer printer;
- printer.SetDefaultFieldValuePrinter(new NProtoBuf::TEnumIdValuePrinter());
- NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out);
-
- if (!printer.Print(m, &adaptor)) {
- ythrow yexception() << "SerializeToTextFormatWithEnumId failed on Print";
- }
-}
-
+void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out) {
+ google::protobuf::TextFormat::Printer printer;
+ printer.SetDefaultFieldValuePrinter(new NProtoBuf::TEnumIdValuePrinter());
+ NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out);
+
+ if (!printer.Print(m, &adaptor)) {
+ ythrow yexception() << "SerializeToTextFormatWithEnumId failed on Print";
+ }
+}
+
void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out) {
google::protobuf::TextFormat::Printer printer;
printer.SetUseUtf8StringEscaping(true);
diff --git a/library/cpp/protobuf/util/pb_io.h b/library/cpp/protobuf/util/pb_io.h
index a3c204be64..493c84cb5f 100644
--- a/library/cpp/protobuf/util/pb_io.h
+++ b/library/cpp/protobuf/util/pb_io.h
@@ -52,10 +52,10 @@ void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out);
// with flags UseShortRepeatedPrimitives and UseUtf8StringEscaping set to true.
void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out);
-// Write a textual representation of the given message to the given output stream
-// use enum id instead of enum name for all enum fields.
-void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out);
-
+// Write a textual representation of the given message to the given output stream
+// use enum id instead of enum name for all enum fields.
+void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out);
+
enum class EParseFromTextFormatOption : ui64 {
// Unknown fields will be ignored by the parser
AllowUnknownField = 1
diff --git a/library/cpp/protobuf/util/pb_io_ut.cpp b/library/cpp/protobuf/util/pb_io_ut.cpp
index 9aa0d8d43a..875d6dc602 100644
--- a/library/cpp/protobuf/util/pb_io_ut.cpp
+++ b/library/cpp/protobuf/util/pb_io_ut.cpp
@@ -17,31 +17,31 @@ static NProtobufUtilUt::TTextTest GetCorrectMessage() {
return m;
}
-static NProtobufUtilUt::TTextEnumTest GetCorrectEnumMessage() {
- NProtobufUtilUt::TTextEnumTest m;
- m.SetSlot(NProtobufUtilUt::TTextEnumTest::EET_SLOT_1);
- return m;
-}
-
+static NProtobufUtilUt::TTextEnumTest GetCorrectEnumMessage() {
+ NProtobufUtilUt::TTextEnumTest m;
+ m.SetSlot(NProtobufUtilUt::TTextEnumTest::EET_SLOT_1);
+ return m;
+}
+
static const TString CORRECT_MESSAGE =
R"(Foo: 42
)";
-static const TString CORRECT_ENUM_NAME_MESSAGE =
- R"(Slot: EET_SLOT_1
-)";
-static const TString CORRECT_ENUM_ID_MESSAGE =
- R"(Slot: 1
-)";
+static const TString CORRECT_ENUM_NAME_MESSAGE =
+ R"(Slot: EET_SLOT_1
+)";
+static const TString CORRECT_ENUM_ID_MESSAGE =
+ R"(Slot: 1
+)";
static const TString INCORRECT_MESSAGE =
R"(Bar: 1
)";
-static const TString INCORRECT_ENUM_NAME_MESSAGE =
- R"(Slot: EET_SLOT_3
-)";
-static const TString INCORRECT_ENUM_ID_MESSAGE =
- R"(Slot: 3
-)";
+static const TString INCORRECT_ENUM_NAME_MESSAGE =
+ R"(Slot: EET_SLOT_3
+)";
+static const TString INCORRECT_ENUM_ID_MESSAGE =
+ R"(Slot: 3
+)";
static const TString CORRECT_BASE64_MESSAGE = "CCo,";
@@ -196,60 +196,60 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) {
}
}
- Y_UNIT_TEST(TestSerializeToTextFormatWithEnumId) {
- TTempDir tempDir;
- const TFsPath correctNameFileName = TFsPath{tempDir()} / "correct_name.pb.txt";
- const TFsPath incorrectNameFileName = TFsPath{tempDir()} / "incorrect_name.pb.txt";
- const TFsPath correctIdFileName = TFsPath{tempDir()} / "correct_id.pb.txt";
- const TFsPath incorrectIdFileName = TFsPath{tempDir()} / "incorrect_id.pb.txt";
-
- TFileOutput{correctNameFileName}.Write(CORRECT_ENUM_NAME_MESSAGE);
- TFileOutput{incorrectNameFileName}.Write(INCORRECT_ENUM_NAME_MESSAGE);
- TFileOutput{correctIdFileName}.Write(CORRECT_ENUM_ID_MESSAGE);
- TFileOutput{incorrectIdFileName}.Write(INCORRECT_ENUM_ID_MESSAGE);
-
- {
- NProtobufUtilUt::TTextEnumTest message;
- for (auto correct_message: {CORRECT_ENUM_ID_MESSAGE, CORRECT_ENUM_NAME_MESSAGE}) {
- TStringInput in{correct_message};
- UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(in, message));
- }
- }
- {
- NProtobufUtilUt::TTextEnumTest message;
- for (auto incorrect_message: {INCORRECT_ENUM_ID_MESSAGE, INCORRECT_ENUM_NAME_MESSAGE}) {
- TStringInput in{incorrect_message};
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(in, message), yexception);
- }
- }
- {
- const auto f = [](NProtobufUtilUt::TTextEnumTest& mm, const TString fileName) {
- mm = ParseFromTextFormat<NProtobufUtilUt::TTextEnumTest>(fileName);
- };
- for (auto fileName: {correctIdFileName, correctNameFileName}) {
- NProtobufUtilUt::TTextEnumTest m;
- UNIT_ASSERT_NO_EXCEPTION(f(m, fileName));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectEnumMessage(), m));
- }
- }
- {
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextEnumTest>(incorrectIdFileName), yexception);
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextEnumTest>(incorrectNameFileName), yexception);
- }
- {
- const auto original = GetCorrectEnumMessage();
- TStringStream out;
- UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out));
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_ENUM_NAME_MESSAGE);
- }
- {
- const auto original = GetCorrectEnumMessage();
- TStringStream out;
- UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormatWithEnumId(original, out));
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_ENUM_ID_MESSAGE);
- }
- }
-
+ Y_UNIT_TEST(TestSerializeToTextFormatWithEnumId) {
+ TTempDir tempDir;
+ const TFsPath correctNameFileName = TFsPath{tempDir()} / "correct_name.pb.txt";
+ const TFsPath incorrectNameFileName = TFsPath{tempDir()} / "incorrect_name.pb.txt";
+ const TFsPath correctIdFileName = TFsPath{tempDir()} / "correct_id.pb.txt";
+ const TFsPath incorrectIdFileName = TFsPath{tempDir()} / "incorrect_id.pb.txt";
+
+ TFileOutput{correctNameFileName}.Write(CORRECT_ENUM_NAME_MESSAGE);
+ TFileOutput{incorrectNameFileName}.Write(INCORRECT_ENUM_NAME_MESSAGE);
+ TFileOutput{correctIdFileName}.Write(CORRECT_ENUM_ID_MESSAGE);
+ TFileOutput{incorrectIdFileName}.Write(INCORRECT_ENUM_ID_MESSAGE);
+
+ {
+ NProtobufUtilUt::TTextEnumTest message;
+ for (auto correct_message: {CORRECT_ENUM_ID_MESSAGE, CORRECT_ENUM_NAME_MESSAGE}) {
+ TStringInput in{correct_message};
+ UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(in, message));
+ }
+ }
+ {
+ NProtobufUtilUt::TTextEnumTest message;
+ for (auto incorrect_message: {INCORRECT_ENUM_ID_MESSAGE, INCORRECT_ENUM_NAME_MESSAGE}) {
+ TStringInput in{incorrect_message};
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(in, message), yexception);
+ }
+ }
+ {
+ const auto f = [](NProtobufUtilUt::TTextEnumTest& mm, const TString fileName) {
+ mm = ParseFromTextFormat<NProtobufUtilUt::TTextEnumTest>(fileName);
+ };
+ for (auto fileName: {correctIdFileName, correctNameFileName}) {
+ NProtobufUtilUt::TTextEnumTest m;
+ UNIT_ASSERT_NO_EXCEPTION(f(m, fileName));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectEnumMessage(), m));
+ }
+ }
+ {
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextEnumTest>(incorrectIdFileName), yexception);
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextEnumTest>(incorrectNameFileName), yexception);
+ }
+ {
+ const auto original = GetCorrectEnumMessage();
+ TStringStream out;
+ UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out));
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_ENUM_NAME_MESSAGE);
+ }
+ {
+ const auto original = GetCorrectEnumMessage();
+ TStringStream out;
+ UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormatWithEnumId(original, out));
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_ENUM_ID_MESSAGE);
+ }
+ }
+
Y_UNIT_TEST(TestMergeFromTextFormat) {
//
// Tests cases below are identical to `Parse` tests
diff --git a/library/cpp/protobuf/util/ut/common_ut.proto b/library/cpp/protobuf/util/ut/common_ut.proto
index d9101498c9..9cf803ffbf 100644
--- a/library/cpp/protobuf/util/ut/common_ut.proto
+++ b/library/cpp/protobuf/util/ut/common_ut.proto
@@ -62,11 +62,11 @@ message TMergeTest {
message TTextTest {
optional uint32 Foo = 1;
}
-
-message TTextEnumTest {
- enum EnumTest {
- EET_SLOT_1 = 1;
- EET_SLOT_2 = 2;
- }
- optional EnumTest Slot = 1;
-}
+
+message TTextEnumTest {
+ enum EnumTest {
+ EET_SLOT_1 = 1;
+ EET_SLOT_2 = 2;
+ }
+ optional EnumTest Slot = 1;
+}
diff --git a/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp b/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp
index 6920f65431..3cbf685cc1 100644
--- a/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp
+++ b/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp
@@ -791,28 +791,28 @@ namespace {
double minValue = args[0].GetElement(HistogramIndexes.Min).Get<double>();
double maxValue = args[0].GetElement(HistogramIndexes.Max).Get<double>();
double area = args[1].GetOrDefault<double>(100.0);
- bool cdfNormalization = args[2].GetOrDefault<bool>(false);
+ bool cdfNormalization = args[2].GetOrDefault<bool>(false);
double sum = 0.0;
double weightsSum = 0.0;
- double lastBinFrequency = 0.0;
+ double lastBinFrequency = 0.0;
std::vector<TUnboxedValue> resultBins;
if (bins.HasFastListLength())
resultBins.reserve(bins.GetListLength());
auto binsIterator = bins.GetListIterator();
for (TUnboxedValue current; binsIterator.Next(current);) {
sum += current.GetElement(HistogramIndexes.Frequency).Get<double>();
- lastBinFrequency = current.GetElement(HistogramIndexes.Frequency).Get<double>();
+ lastBinFrequency = current.GetElement(HistogramIndexes.Frequency).Get<double>();
}
binsIterator = bins.GetListIterator();
for (TUnboxedValue current; binsIterator.Next(current);) {
TUnboxedValue* binFields = nullptr;
auto resultCurrent = valueBuilder->NewArray(HistogramIndexes.BinFieldsCount, binFields);
double frequency = current.GetElement(HistogramIndexes.Frequency).Get<double>();
- if (cdfNormalization) {
- frequency = area * frequency / lastBinFrequency;
- } else {
- frequency = area * frequency / sum;
- }
+ if (cdfNormalization) {
+ frequency = area * frequency / lastBinFrequency;
+ } else {
+ frequency = area * frequency / sum;
+ }
weightsSum += frequency;
binFields[HistogramIndexes.Frequency] = TUnboxedValuePod(frequency);
binFields[HistogramIndexes.Position] = current.GetElement(HistogramIndexes.Position);
@@ -835,10 +835,10 @@ namespace {
if (Name() == name) {
THistogramIndexes histogramIndexes(builder);
auto optionalDouble = builder.Optional()->Item<double>().Build();
- auto optionalCdfNormalization = builder.Optional()->Item<bool>().Build();
- builder.Args()->Add(histogramIndexes.ResultStructType).Flags(ICallablePayload::TArgumentFlags::AutoMap).Add(optionalDouble).Add(optionalCdfNormalization).Done().Returns(histogramIndexes.ResultStructType);
+ auto optionalCdfNormalization = builder.Optional()->Item<bool>().Build();
+ builder.Args()->Add(histogramIndexes.ResultStructType).Flags(ICallablePayload::TArgumentFlags::AutoMap).Add(optionalDouble).Add(optionalCdfNormalization).Done().Returns(histogramIndexes.ResultStructType);
builder.OptionalArgs(1);
- builder.OptionalArgs(2);
+ builder.OptionalArgs(2);
if (!typesOnly) {
builder.Implementation(new THistogramNormalize(histogramIndexes));
}