|
2 | 2 | #include <Core/Range.h> |
3 | 3 | #include <IO/Operators.h> |
4 | 4 | #include <IO/WriteBufferFromString.h> |
| 5 | +#include <IO/ReadBufferFromString.h> |
5 | 6 | #include <Common/FieldVisitorToString.h> |
6 | 7 | #include <Common/FieldAccurateComparison.h> |
7 | 8 |
|
@@ -345,46 +346,27 @@ String Range::toString() const |
345 | 346 | return str.str(); |
346 | 347 | } |
347 | 348 |
|
348 | | -String Range::dump() const |
| 349 | +String Range::serialize() const |
349 | 350 | { |
350 | 351 | WriteBufferFromOwnString str; |
351 | 352 |
|
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); |
354 | 356 |
|
355 | 357 | return str.str(); |
356 | 358 | } |
357 | 359 |
|
358 | | -void Range::restoreFromDump(const String & range) |
| 360 | +void Range::deserialize(const String & range) |
359 | 361 | { |
360 | 362 | if (range.empty()) |
361 | 363 | throw Exception(ErrorCodes::INCORRECT_DATA, "Empty range dump"); |
362 | 364 |
|
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); |
384 | 366 |
|
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); |
388 | 370 | } |
389 | 371 |
|
390 | 372 | Hyperrectangle intersect(const Hyperrectangle & a, const Hyperrectangle & b) |
|
0 commit comments