1#include <DataStreams/SizeLimits.h>
2#include <Common/formatReadable.h>
3#include <Common/Exception.h>
4#include <string>
5
6
7namespace DB
8{
9
10bool SizeLimits::check(UInt64 rows, UInt64 bytes, const char * what, int too_many_rows_exception_code, int too_many_bytes_exception_code) const
11{
12 if (overflow_mode == OverflowMode::THROW)
13 {
14 if (max_rows && rows > max_rows)
15 throw Exception("Limit for " + std::string(what) + " exceeded, max rows: " + formatReadableQuantity(max_rows)
16 + ", current rows: " + formatReadableQuantity(rows), too_many_rows_exception_code);
17
18 if (max_bytes && bytes > max_bytes)
19 throw Exception("Limit for " + std::string(what) + " exceeded, max bytes: " + formatReadableSizeWithBinarySuffix(max_bytes)
20 + ", current bytes: " + formatReadableSizeWithBinarySuffix(bytes), too_many_bytes_exception_code);
21
22 return true;
23 }
24
25 return softCheck(rows, bytes);
26}
27
28bool SizeLimits::softCheck(UInt64 rows, UInt64 bytes) const
29{
30 if (max_rows && rows > max_rows)
31 return false;
32 if (max_bytes && bytes > max_bytes)
33 return false;
34 return true;
35}
36
37bool SizeLimits::check(UInt64 rows, UInt64 bytes, const char * what, int exception_code) const
38{
39 return check(rows, bytes, what, exception_code, exception_code);
40}
41
42}
43