2022-09-04 15:20:59 +00:00
|
|
|
#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
|
2022-09-04 15:20:59 +00:00
|
|
|
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
|
2022-09-04 15:20:59 +00:00
|
|
|
bool hasSampleSizeRatio() const
|
|
|
|
{
|
|
|
|
return sample_size_ratio.has_value();
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:25:27 +00:00
|
|
|
/// Get sample size ratio
|
2022-09-04 15:20:59 +00:00
|
|
|
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
|
2022-09-04 15:20:59 +00:00
|
|
|
bool hasSampleOffsetRatio() const
|
|
|
|
{
|
|
|
|
return sample_offset_ratio.has_value();
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:25:27 +00:00
|
|
|
/// Get sample offset ratio
|
2022-09-04 15:20:59 +00:00
|
|
|
std::optional<Rational> getSampleOffsetRatio() const
|
|
|
|
{
|
|
|
|
return sample_offset_ratio;
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:25:27 +00:00
|
|
|
/// Dump into buffer
|
2022-09-04 15:20:59 +00:00
|
|
|
void dump(WriteBuffer & buffer) const;
|
|
|
|
|
2022-10-19 10:25:27 +00:00
|
|
|
/// Update tree hash
|
2022-09-04 15:20:59 +00:00
|
|
|
void updateTreeHash(SipHash & hash_state) const;
|
|
|
|
|
2022-10-31 10:45:12 +00:00
|
|
|
/// Format for error message
|
|
|
|
String formatForErrorMessage() const;
|
|
|
|
|
2022-09-04 15:20:59 +00:00
|
|
|
private:
|
2022-10-19 10:25:27 +00:00
|
|
|
bool has_final = false;
|
2022-09-04 15:20:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|