1#include "StopConditionsSet.h"
2#include <Common/Exception.h>
3
4namespace DB
5{
6
7namespace ErrorCodes
8{
9extern const int LOGICAL_ERROR;
10}
11
12void StopConditionsSet::loadFromConfig(const ConfigurationPtr & stop_conditions_view)
13{
14 Strings keys;
15 stop_conditions_view->keys(keys);
16
17 for (const std::string & key : keys)
18 {
19 if (key == "total_time_ms")
20 total_time_ms.value = stop_conditions_view->getUInt64(key);
21 else if (key == "rows_read")
22 rows_read.value = stop_conditions_view->getUInt64(key);
23 else if (key == "bytes_read_uncompressed")
24 bytes_read_uncompressed.value = stop_conditions_view->getUInt64(key);
25 else if (key == "iterations")
26 iterations.value = stop_conditions_view->getUInt64(key);
27 else if (key == "min_time_not_changing_for_ms")
28 min_time_not_changing_for_ms.value = stop_conditions_view->getUInt64(key);
29 else if (key == "max_speed_not_changing_for_ms")
30 max_speed_not_changing_for_ms.value = stop_conditions_view->getUInt64(key);
31 else if (key == "average_speed_not_changing_for_ms")
32 average_speed_not_changing_for_ms.value = stop_conditions_view->getUInt64(key);
33 else
34 throw Exception("Met unknown stop condition: " + key, ErrorCodes::LOGICAL_ERROR);
35
36 ++initialized_count;
37 }
38}
39
40void StopConditionsSet::reset()
41{
42 total_time_ms.fulfilled = false;
43 rows_read.fulfilled = false;
44 bytes_read_uncompressed.fulfilled = false;
45 iterations.fulfilled = false;
46 min_time_not_changing_for_ms.fulfilled = false;
47 max_speed_not_changing_for_ms.fulfilled = false;
48 average_speed_not_changing_for_ms.fulfilled = false;
49
50 fulfilled_count = 0;
51}
52
53void StopConditionsSet::report(UInt64 value, StopConditionsSet::StopCondition & condition)
54{
55 if (condition.value && !condition.fulfilled && value >= condition.value)
56 {
57 condition.fulfilled = true;
58 ++fulfilled_count;
59 }
60}
61
62
63
64}
65