Skip to content

Commit de7545d

Browse files
committed
Better range serialization
1 parent 5a8aba7 commit de7545d

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

src/Core/Range.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Core/Range.h>
33
#include <IO/Operators.h>
44
#include <IO/WriteBufferFromString.h>
5+
#include <IO/ReadBufferFromString.h>
56
#include <Common/FieldVisitorToString.h>
67
#include <Common/FieldAccurateComparison.h>
78

@@ -345,46 +346,27 @@ String Range::toString() const
345346
return str.str();
346347
}
347348

348-
String Range::dump() const
349+
String Range::serialize() const
349350
{
350351
WriteBufferFromOwnString str;
351352

352-
str << (left_included ? '[' : '(') << left.dump() << ",";
353-
str << right.dump() << (right_included ? ']' : ')');
353+
str << left_included << right_included;
354+
writeFieldBinary(left, str);
355+
writeFieldBinary(right, str);
354356

355357
return str.str();
356358
}
357359

358-
void Range::restoreFromDump(const String & range)
360+
void Range::deserialize(const String & range)
359361
{
360362
if (range.empty())
361363
throw Exception(ErrorCodes::INCORRECT_DATA, "Empty range dump");
362364

363-
if (range[0] == '[')
364-
left_included = true;
365-
else if (range[0] == '(')
366-
left_included = false;
367-
else
368-
throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect range: {}", range);
369-
370-
if (range[range.size() - 1] == ']')
371-
right_included = true;
372-
else if (range[range.size() - 1] == ')')
373-
right_included = false;
374-
else
375-
throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect range: {}", range);
376-
377-
/// TODO: Strings with comma
378-
auto separator = range.find(',');
379-
if (separator == std::string::npos || separator == range.size())
380-
throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect range: {}", range);
381-
382-
std::string_view l(range.data() + 1, separator - 1);
383-
std::string_view r(range.data() + separator + 1, range.size() - separator - 2);
365+
ReadBufferFromOwnString str(range);
384366

385-
/// TODO: "Decimal64_'1596962100.000000'" can't be parsed by some reason
386-
left = Field::restoreFromDump(std::string_view(range.data() + 1, separator - 1));
387-
right = Field::restoreFromDump(std::string_view(range.data() + separator + 1, range.size() - separator - 2));
367+
str >> left_included >> right_included;
368+
left = readFieldBinary(str);
369+
right = readFieldBinary(str);
388370
}
389371

390372
Hyperrectangle intersect(const Hyperrectangle & a, const Hyperrectangle & b)

src/Core/Range.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ struct Range
117117

118118
String toString() const;
119119

120-
String dump() const;
121-
void restoreFromDump(const String & range);
120+
String serialize() const;
121+
void deserialize(const String & range);
122122
};
123123

124124
Range intersect(const Range & a, const Range & b);

src/Storages/ObjectStorage/DataLakes/IDataLakeMetadata.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ DataFileMetaInfo::DataFileMetaInfo(Poco::JSON::Object::Ptr file_info)
112112
std::string r = column->get("range");
113113
try
114114
{
115-
range.restoreFromDump(r);
115+
range.deserialize(r);
116116
column_info.hyperrectangle = std::move(range);
117117
}
118118
catch (const Exception & e)
@@ -151,7 +151,7 @@ Poco::JSON::Object::Ptr DataFileMetaInfo::toJson() const
151151
if (column.second.nulls_count.has_value())
152152
column_info->set("nulls", column.second.nulls_count.value());
153153
if (column.second.hyperrectangle.has_value())
154-
column_info->set("range", column.second.hyperrectangle.value().dump());
154+
column_info->set("range", column.second.hyperrectangle.value().serialize());
155155

156156
columns->add(column_info);
157157
}

0 commit comments

Comments
 (0)