// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include namespace DB { /** 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. */ class ASTSampleRatio : public IAST { public: #ifdef __SIZEOF_INT128__ using BigNum = __uint128_t; /// Must contain the result of multiplying two UInt64. #else #warning "No uint128_t type. Sampling ratios cannot work correctly." using BigNum = uint64_t; #endif struct Rational { BigNum numerator = 0; BigNum denominator = 1; }; Rational ratio; ASTSampleRatio(Rational & ratio_) : ratio(ratio_) {} String getID() const override { return "SampleRatio_" + toString(ratio); } ASTPtr clone() const override { return std::make_shared(*this); } static String toString(BigNum num); static String toString(Rational ratio); void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override { settings.ostr << toString(ratio); } }; } // namespace DB