ClickHouse/src/Analyzer/TableExpressionModifiers.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.1 KiB
C++
Raw Normal View History

#pragma once
#include <Parsers/ASTSampleRatio.h>
namespace DB
{
/** 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;
TableExpressionModifiers(bool has_final_,
std::optional<Rational> sample_size_ratio_,
std::optional<Rational> sample_offset_ratio_)
: has_final(has_final_)
, sample_size_ratio(sample_size_ratio_)
, sample_offset_ratio(sample_offset_ratio_)
{}
2022-10-19 10:25:27 +00:00
/// Returns true if final is specified, false otherwise
bool hasFinal() const
{
return has_final;
}
2023-02-22 14:51:13 +00:00
/// Set has final value
void setHasFinal(bool value)
{
has_final = value;
}
2022-10-19 10:25:27 +00:00
/// Returns true if sample size ratio is specified, false otherwise
bool hasSampleSizeRatio() const
{
return sample_size_ratio.has_value();
}
2022-10-19 10:25:27 +00:00
/// Get sample size ratio
std::optional<Rational> getSampleSizeRatio() const
{
return sample_size_ratio;
}
2022-10-19 10:25:27 +00:00
/// Returns true if sample offset ratio is specified, false otherwise
bool hasSampleOffsetRatio() const
{
return sample_offset_ratio.has_value();
}
2022-10-19 10:25:27 +00:00
/// Get sample offset ratio
std::optional<Rational> getSampleOffsetRatio() const
{
return sample_offset_ratio;
}
2022-10-19 10:25:27 +00:00
/// Dump into buffer
void dump(WriteBuffer & buffer) const;
2022-10-19 10:25:27 +00:00
/// Update tree hash
void updateTreeHash(SipHash & hash_state) const;
2022-10-31 10:45:12 +00:00
/// Format for error message
String formatForErrorMessage() const;
private:
2022-10-19 10:25:27 +00:00
bool has_final = false;
std::optional<Rational> sample_size_ratio;
std::optional<Rational> sample_offset_ratio;
};
inline bool operator==(const TableExpressionModifiers & lhs, const TableExpressionModifiers & rhs)
{
return lhs.hasFinal() == rhs.hasFinal() && lhs.getSampleSizeRatio() == rhs.getSampleSizeRatio() && lhs.getSampleOffsetRatio() == rhs.getSampleOffsetRatio();
}
inline bool operator!=(const TableExpressionModifiers & lhs, const TableExpressionModifiers & rhs)
{
return !(lhs == rhs);
}
}