Repository navigation
Expand file tree
/
Copy pathTableExpressionModifiers.h
More file actions
130 lines (104 loc) · 3.44 KB
/
Copy pathTableExpressionModifiers.h
File metadata and controls
130 lines (104 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#pragma once
#include <Parsers/ASTSampleRatio.h>
#include <Core/Streaming/CursorTree_fwd.h>
namespace DB
{
class ReadBuffer;
class WriteBuffer;
/** Modifiers that can be used for table, table function and subquery in JOIN TREE.
*
* Example: SELECT * FROM test_table SAMPLE 0.1 OFFSET 0.1 FINAL
*/
class TableExpressionModifiers
{
public:
using Rational = ASTSampleRatio::Rational;
struct StreamSettings
{
/// Null means "no cursor" (read from the beginning of the table).
CursorTreeNodePtr cursor_tree;
};
TableExpressionModifiers() = default;
TableExpressionModifiers(bool has_final_,
std::optional<Rational> sample_size_ratio_,
std::optional<Rational> sample_offset_ratio_,
std::optional<StreamSettings> stream_settings_ = {})
: has_final(has_final_)
, sample_size_ratio(sample_size_ratio_)
, sample_offset_ratio(sample_offset_ratio_)
, stream_settings(std::move(stream_settings_))
{}
/// Returns true if final is specified, false otherwise
bool hasFinal() const
{
return has_final;
}
/// Set has final value
void setHasFinal(bool value)
{
has_final = value;
}
/// Returns true if sample size ratio is specified, false otherwise
bool hasSampleSizeRatio() const
{
return sample_size_ratio.has_value();
}
/// Get sample size ratio
std::optional<Rational> getSampleSizeRatio() const
{
return sample_size_ratio;
}
/// Returns true if sample offset ratio is specified, false otherwise
bool hasSampleOffsetRatio() const
{
return sample_offset_ratio.has_value();
}
/// Get sample offset ratio
std::optional<Rational> getSampleOffsetRatio() const
{
return sample_offset_ratio;
}
/// Returns true if STREAM modifier is specified
bool hasStream() const
{
return stream_settings.has_value();
}
/// Get stream settings
const std::optional<StreamSettings> & getStreamSettings() const
{
return stream_settings;
}
/// Dump into buffer
void dump(WriteBuffer & buffer) const;
/// Update tree hash
void updateTreeHash(SipHash & hash_state) const;
/// Format for error message
String formatForErrorMessage() const;
private:
bool has_final = false;
std::optional<Rational> sample_size_ratio;
std::optional<Rational> sample_offset_ratio;
std::optional<StreamSettings> stream_settings;
};
void serializeRational(TableExpressionModifiers::Rational val, WriteBuffer & out);
TableExpressionModifiers::Rational deserializeRational(ReadBuffer & in);
inline bool operator==(const TableExpressionModifiers::StreamSettings & lhs, const TableExpressionModifiers::StreamSettings & rhs)
{
if ((lhs.cursor_tree == nullptr) != (rhs.cursor_tree == nullptr))
return false;
if (lhs.cursor_tree == nullptr)
return true;
return cursorTreeToMap(lhs.cursor_tree) == cursorTreeToMap(rhs.cursor_tree);
}
inline bool operator==(const TableExpressionModifiers & lhs, const TableExpressionModifiers & rhs)
{
return lhs.hasFinal() == rhs.hasFinal()
&& lhs.getSampleSizeRatio() == rhs.getSampleSizeRatio()
&& lhs.getSampleOffsetRatio() == rhs.getSampleOffsetRatio()
&& lhs.getStreamSettings() == rhs.getStreamSettings();
}
inline bool operator!=(const TableExpressionModifiers & lhs, const TableExpressionModifiers & rhs)
{
return !(lhs == rhs);
}
}