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
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTSampleRatio() = default;
|
|
|
|
ASTSampleRatio(const StringRange range_) : IAST(range_) {}
|
|
|
|
ASTSampleRatio(const StringRange range_, Rational & ratio_) : IAST(range_), ratio(ratio_) {}
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getID() const override { return "SampleRatio_" + 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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
|
|
|
{
|
|
|
|
settings.ostr << toString(ratio);
|
|
|
|
}
|
2015-11-19 21:34:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|