2015-11-19 21:34:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2021-05-04 22:42:14 +00:00
|
|
|
|
2015-11-19 21:34:53 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Sampling factor in the form 0.1 or 1/10.
|
|
|
|
* It's important to save it as a rational number without converting it to IEEE-754.
|
2015-11-19 21:34:53 +00:00
|
|
|
*/
|
|
|
|
class ASTSampleRatio : public IAST
|
|
|
|
{
|
|
|
|
public:
|
2017-05-27 17:27:16 +00:00
|
|
|
using BigNum = __uint128_t; /// Must contain the result of multiplying two UInt64.
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
struct Rational
|
|
|
|
{
|
|
|
|
BigNum numerator = 0;
|
|
|
|
BigNum denominator = 1;
|
|
|
|
};
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Rational ratio;
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
explicit ASTSampleRatio(const Rational & ratio_) : ratio(ratio_) {}
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2018-12-07 12:34:40 +00:00
|
|
|
String getID(char delim) const override { return "SampleRatio" + (delim + toString(ratio)); }
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr clone() const override { return std::make_shared<ASTSampleRatio>(*this); }
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static String toString(BigNum num);
|
|
|
|
static String toString(Rational ratio);
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2020-11-09 16:05:40 +00:00
|
|
|
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
|
2015-11-19 21:34:53 +00:00
|
|
|
};
|
|
|
|
|
2022-09-04 15:20:59 +00:00
|
|
|
inline bool operator==(const ASTSampleRatio::Rational & lhs, const ASTSampleRatio::Rational & rhs)
|
|
|
|
{
|
|
|
|
return lhs.numerator == rhs.numerator && lhs.denominator == rhs.denominator;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const ASTSampleRatio::Rational & lhs, const ASTSampleRatio::Rational & rhs)
|
|
|
|
{
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2015-11-19 21:34:53 +00:00
|
|
|
}
|