mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Move more things to private
This commit is contained in:
parent
59f73a2053
commit
2146ab4e4e
@ -8,6 +8,8 @@
|
|||||||
#include <Common/assert_cast.h>
|
#include <Common/assert_cast.h>
|
||||||
#include <Common/iota.h>
|
#include <Common/iota.h>
|
||||||
|
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
|
|
||||||
#include <base/sort.h>
|
#include <base/sort.h>
|
||||||
|
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <base/arithmeticOverflow.h>
|
#include <base/arithmeticOverflow.h>
|
||||||
#include <Core/Block.h>
|
#include <Core/Block.h>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <Core/AccurateComparison.h>
|
#include <Core/AccurateComparison.h>
|
||||||
#include <Core/callOnTypeIndex.h>
|
#include <Core/callOnTypeIndex.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
@ -124,8 +125,8 @@ private:
|
|||||||
if (decimal0 && decimal1)
|
if (decimal0 && decimal1)
|
||||||
{
|
{
|
||||||
auto result_type = DecimalUtils::binaryOpResult<false, false>(*decimal0, *decimal1);
|
auto result_type = DecimalUtils::binaryOpResult<false, false>(*decimal0, *decimal1);
|
||||||
shift.a = static_cast<CompareInt>(result_type.scaleFactorFor(decimal0->getTrait(), false).value);
|
shift.a = static_cast<CompareInt>(result_type.scaleFactorFor(DecimalUtils::DataTypeDecimalTrait<T>{decimal0->getPrecision(), decimal0->getScale()}, false).value);
|
||||||
shift.b = static_cast<CompareInt>(result_type.scaleFactorFor(decimal1->getTrait(), false).value);
|
shift.b = static_cast<CompareInt>(result_type.scaleFactorFor(DecimalUtils::DataTypeDecimalTrait<U>{decimal1->getPrecision(), decimal1->getScale()}, false).value);
|
||||||
}
|
}
|
||||||
else if (decimal0)
|
else if (decimal0)
|
||||||
shift.b = static_cast<CompareInt>(decimal0->getScaleMultiplier().value);
|
shift.b = static_cast<CompareInt>(decimal0->getScaleMultiplier().value);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Core/DecimalFunctions.h>
|
|
||||||
#include <Core/Types.h>
|
#include <Core/Types.h>
|
||||||
#include <Common/Exception.h>
|
#include <Common/Exception.h>
|
||||||
#include <Common/intExp.h>
|
#include <Common/intExp.h>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
#include <type_traits>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <Core/Settings.h>
|
#include <Core/Settings.h>
|
||||||
#include <DataTypes/DataTypeDecimalBase.h>
|
#include <DataTypes/DataTypeDecimalBase.h>
|
||||||
#include <Interpreters/Context.h>
|
#include <Interpreters/Context.h>
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
@ -14,6 +15,12 @@ namespace ErrorCodes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <is_decimal T>
|
||||||
|
constexpr size_t DataTypeDecimalBase<T>::maxPrecision()
|
||||||
|
{
|
||||||
|
return DecimalUtils::max_precision<T>;
|
||||||
|
}
|
||||||
|
|
||||||
bool decimalCheckComparisonOverflow(ContextPtr context)
|
bool decimalCheckComparisonOverflow(ContextPtr context)
|
||||||
{
|
{
|
||||||
return context->getSettingsRef()[Setting::decimal_check_overflow];
|
return context->getSettingsRef()[Setting::decimal_check_overflow];
|
||||||
@ -41,6 +48,18 @@ T DataTypeDecimalBase<T>::getScaleMultiplier(UInt32 scale_)
|
|||||||
return DecimalUtils::scaleMultiplier<typename T::NativeType>(scale_);
|
return DecimalUtils::scaleMultiplier<typename T::NativeType>(scale_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <is_decimal T>
|
||||||
|
T DataTypeDecimalBase<T>::wholePart(T x) const
|
||||||
|
{
|
||||||
|
return DecimalUtils::getWholePart(x, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <is_decimal T>
|
||||||
|
T DataTypeDecimalBase<T>::fractionalPart(T x) const
|
||||||
|
{
|
||||||
|
return DecimalUtils::getFractionalPart(x, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Explicit template instantiations.
|
/// Explicit template instantiations.
|
||||||
template class DataTypeDecimalBase<Decimal32>;
|
template class DataTypeDecimalBase<Decimal32>;
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <Core/TypeId.h>
|
|
||||||
#include <Core/DecimalFunctions.h>
|
|
||||||
#include <Columns/ColumnDecimal.h>
|
#include <Columns/ColumnDecimal.h>
|
||||||
#include <DataTypes/IDataType.h>
|
#include <Core/TypeId.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
|
#include <DataTypes/IDataType.h>
|
||||||
#include <Interpreters/Context_fwd.h>
|
#include <Interpreters/Context_fwd.h>
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ public:
|
|||||||
|
|
||||||
static constexpr bool is_parametric = true;
|
static constexpr bool is_parametric = true;
|
||||||
|
|
||||||
static constexpr size_t maxPrecision() { return DecimalUtils::max_precision<T>; }
|
static constexpr size_t maxPrecision();
|
||||||
|
|
||||||
DataTypeDecimalBase(UInt32 precision_, UInt32 scale_)
|
DataTypeDecimalBase(UInt32 precision_, UInt32 scale_)
|
||||||
: precision(precision_),
|
: precision(precision_),
|
||||||
@ -104,15 +103,8 @@ public:
|
|||||||
UInt32 getScale() const { return scale; }
|
UInt32 getScale() const { return scale; }
|
||||||
T getScaleMultiplier() const { return getScaleMultiplier(scale); }
|
T getScaleMultiplier() const { return getScaleMultiplier(scale); }
|
||||||
|
|
||||||
T wholePart(T x) const
|
T wholePart(T x) const;
|
||||||
{
|
T fractionalPart(T x) const;
|
||||||
return DecimalUtils::getWholePart(x, scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
T fractionalPart(T x) const
|
|
||||||
{
|
|
||||||
return DecimalUtils::getFractionalPart(x, scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
T maxWholeValue() const { return getScaleMultiplier(precision - scale) - T(1); }
|
T maxWholeValue() const { return getScaleMultiplier(precision - scale) - T(1); }
|
||||||
|
|
||||||
@ -147,11 +139,6 @@ public:
|
|||||||
|
|
||||||
static T getScaleMultiplier(UInt32 scale);
|
static T getScaleMultiplier(UInt32 scale);
|
||||||
|
|
||||||
DecimalUtils::DataTypeDecimalTrait<T> getTrait() const
|
|
||||||
{
|
|
||||||
return {precision, scale};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const UInt32 precision;
|
const UInt32 precision;
|
||||||
const UInt32 scale;
|
const UInt32 scale;
|
||||||
@ -167,45 +154,11 @@ inline const DataTypeDecimalBase<T> * checkDecimalBase(const IDataType & data_ty
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool is_multiply, bool is_division, typename T, typename U, template <typename> typename DecimalType>
|
template <> constexpr size_t DataTypeDecimalBase<Decimal32>::maxPrecision() { return 9; };
|
||||||
inline auto decimalResultType(const DecimalType<T> & tx, const DecimalType<U> & ty)
|
template <> constexpr size_t DataTypeDecimalBase<Decimal64>::maxPrecision() { return 18; };
|
||||||
{
|
template <> constexpr size_t DataTypeDecimalBase<Decimal128>::maxPrecision() { return 38; };
|
||||||
const auto result_trait = DecimalUtils::binaryOpResult<is_multiply, is_division>(tx, ty);
|
template <> constexpr size_t DataTypeDecimalBase<Decimal256>::maxPrecision() { return 16; };
|
||||||
return DecimalType<typename decltype(result_trait)::FieldType>(result_trait.precision, result_trait.scale);
|
template <> constexpr size_t DataTypeDecimalBase<DateTime64>::maxPrecision() { return 18; };
|
||||||
}
|
|
||||||
|
|
||||||
template <bool is_multiply, bool is_division, typename T, typename U, template <typename> typename DecimalType>
|
|
||||||
inline DecimalType<T> decimalResultType(const DecimalType<T> & tx, const DataTypeNumber<U> & ty)
|
|
||||||
{
|
|
||||||
const auto result_trait = DecimalUtils::binaryOpResult<is_multiply, is_division>(tx, ty);
|
|
||||||
return DecimalType<typename decltype(result_trait)::FieldType>(result_trait.precision, result_trait.scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <bool is_multiply, bool is_division, typename T, typename U, template <typename> typename DecimalType>
|
|
||||||
inline DecimalType<U> decimalResultType(const DataTypeNumber<T> & tx, const DecimalType<U> & ty)
|
|
||||||
{
|
|
||||||
const auto result_trait = DecimalUtils::binaryOpResult<is_multiply, is_division>(tx, ty);
|
|
||||||
return DecimalType<typename decltype(result_trait)::FieldType>(result_trait.precision, result_trait.scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <template <typename> typename DecimalType>
|
|
||||||
inline DataTypePtr createDecimal(UInt64 precision_value, UInt64 scale_value)
|
|
||||||
{
|
|
||||||
if (precision_value < DecimalUtils::min_precision || precision_value > DecimalUtils::max_precision<Decimal256>)
|
|
||||||
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Wrong precision: it must be between {} and {}, got {}",
|
|
||||||
DecimalUtils::min_precision, DecimalUtils::max_precision<Decimal256>, precision_value);
|
|
||||||
|
|
||||||
if (scale_value > precision_value)
|
|
||||||
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Negative scales and scales larger than precision are not supported");
|
|
||||||
|
|
||||||
if (precision_value <= DecimalUtils::max_precision<Decimal32>)
|
|
||||||
return std::make_shared<DecimalType<Decimal32>>(precision_value, scale_value);
|
|
||||||
if (precision_value <= DecimalUtils::max_precision<Decimal64>)
|
|
||||||
return std::make_shared<DecimalType<Decimal64>>(precision_value, scale_value);
|
|
||||||
if (precision_value <= DecimalUtils::max_precision<Decimal128>)
|
|
||||||
return std::make_shared<DecimalType<Decimal128>>(precision_value, scale_value);
|
|
||||||
return std::make_shared<DecimalType<Decimal256>>(precision_value, scale_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern template class DataTypeDecimalBase<Decimal32>;
|
extern template class DataTypeDecimalBase<Decimal32>;
|
||||||
extern template class DataTypeDecimalBase<Decimal64>;
|
extern template class DataTypeDecimalBase<Decimal64>;
|
||||||
@ -213,4 +166,23 @@ extern template class DataTypeDecimalBase<Decimal128>;
|
|||||||
extern template class DataTypeDecimalBase<Decimal256>;
|
extern template class DataTypeDecimalBase<Decimal256>;
|
||||||
extern template class DataTypeDecimalBase<DateTime64>;
|
extern template class DataTypeDecimalBase<DateTime64>;
|
||||||
|
|
||||||
|
template <template <typename> typename DecimalType>
|
||||||
|
inline DataTypePtr createDecimal(UInt64 precision_value, UInt64 scale_value)
|
||||||
|
{
|
||||||
|
if (precision_value < 1 || precision_value > DataTypeDecimalBase<Decimal256>::maxPrecision())
|
||||||
|
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Wrong precision: it must be between {} and {}, got {}",
|
||||||
|
1, DataTypeDecimalBase<Decimal256>::maxPrecision(), precision_value);
|
||||||
|
|
||||||
|
if (scale_value > precision_value)
|
||||||
|
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Negative scales and scales larger than precision are not supported");
|
||||||
|
|
||||||
|
if (precision_value <= DataTypeDecimalBase<Decimal32>::maxPrecision())
|
||||||
|
return std::make_shared<DecimalType<Decimal32>>(precision_value, scale_value);
|
||||||
|
if (precision_value <= DataTypeDecimalBase<Decimal64>::maxPrecision())
|
||||||
|
return std::make_shared<DecimalType<Decimal64>>(precision_value, scale_value);
|
||||||
|
if (precision_value <= DataTypeDecimalBase<Decimal128>::maxPrecision())
|
||||||
|
return std::make_shared<DecimalType<Decimal128>>(precision_value, scale_value);
|
||||||
|
return std::make_shared<DecimalType<Decimal256>>(precision_value, scale_value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -111,13 +111,13 @@ DataTypePtr convertMySQLDataType(MultiEnum<MySQLDataTypesSupport> type_support,
|
|||||||
}
|
}
|
||||||
else if (type_support.isSet(MySQLDataTypesSupport::DECIMAL) && (type_name == "numeric" || type_name == "decimal"))
|
else if (type_support.isSet(MySQLDataTypesSupport::DECIMAL) && (type_name == "numeric" || type_name == "decimal"))
|
||||||
{
|
{
|
||||||
if (precision <= DecimalUtils::max_precision<Decimal32>)
|
if (precision <= DataTypeDecimalBase<Decimal32>::maxPrecision())
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal32>>(precision, scale);
|
res = std::make_shared<DataTypeDecimal<Decimal32>>(precision, scale);
|
||||||
else if (precision <= DecimalUtils::max_precision<Decimal64>)
|
else if (precision <= DataTypeDecimalBase<Decimal64>::maxPrecision())
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal64>>(precision, scale);
|
res = std::make_shared<DataTypeDecimal<Decimal64>>(precision, scale);
|
||||||
else if (precision <= DecimalUtils::max_precision<Decimal128>)
|
else if (precision <= DataTypeDecimalBase<Decimal128>::maxPrecision())
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal128>>(precision, scale);
|
res = std::make_shared<DataTypeDecimal<Decimal128>>(precision, scale);
|
||||||
else if (precision <= DecimalUtils::max_precision<Decimal256>)
|
else if (precision <= DataTypeDecimalBase<Decimal256>::maxPrecision())
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal256>>(precision, scale);
|
res = std::make_shared<DataTypeDecimal<Decimal256>>(precision, scale);
|
||||||
}
|
}
|
||||||
else if (type_name == "point")
|
else if (type_name == "point")
|
||||||
|
@ -76,6 +76,30 @@ namespace ErrorCodes
|
|||||||
extern const int SIZES_OF_ARRAYS_DONT_MATCH;
|
extern const int SIZES_OF_ARRAYS_DONT_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
template <bool is_multiply, bool is_division, typename T, typename U, template <typename> typename DecimalType>
|
||||||
|
inline auto decimalResultType(const DecimalType<T> & tx, const DecimalType<U> & ty)
|
||||||
|
{
|
||||||
|
const auto result_trait = DecimalUtils::binaryOpResult<is_multiply, is_division>(tx, ty);
|
||||||
|
return DecimalType<typename decltype(result_trait)::FieldType>(result_trait.precision, result_trait.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <bool is_multiply, bool is_division, typename T, typename U, template <typename> typename DecimalType>
|
||||||
|
inline DecimalType<T> decimalResultType(const DecimalType<T> & tx, const DataTypeNumber<U> & ty)
|
||||||
|
{
|
||||||
|
const auto result_trait = DecimalUtils::binaryOpResult<is_multiply, is_division>(tx, ty);
|
||||||
|
return DecimalType<typename decltype(result_trait)::FieldType>(result_trait.precision, result_trait.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <bool is_multiply, bool is_division, typename T, typename U, template <typename> typename DecimalType>
|
||||||
|
inline DecimalType<U> decimalResultType(const DataTypeNumber<T> & tx, const DecimalType<U> & ty)
|
||||||
|
{
|
||||||
|
const auto result_trait = DecimalUtils::binaryOpResult<is_multiply, is_division>(tx, ty);
|
||||||
|
return DecimalType<typename decltype(result_trait)::FieldType>(result_trait.precision, result_trait.scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace traits_
|
namespace traits_
|
||||||
{
|
{
|
||||||
struct InvalidType; /// Used to indicate undefined operation
|
struct InvalidType; /// Used to indicate undefined operation
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Core/callOnTypeIndex.h>
|
#include <Core/callOnTypeIndex.h>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypesDecimal.h>
|
#include <DataTypes/DataTypesDecimal.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <Functions/FunctionHelpers.h>
|
#include <Functions/FunctionHelpers.h>
|
||||||
#include <DataTypes/DataTypeDateTime64.h>
|
#include <DataTypes/DataTypeDateTime64.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
#include <Interpreters/Context.h>
|
#include <Interpreters/Context.h>
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#if USE_ULID
|
#if USE_ULID
|
||||||
|
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <Columns/ColumnFixedString.h>
|
#include <Columns/ColumnFixedString.h>
|
||||||
#include <Columns/ColumnString.h>
|
#include <Columns/ColumnString.h>
|
||||||
#include <Columns/ColumnsDateTime.h>
|
#include <Columns/ColumnsDateTime.h>
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <Columns/IColumn.h>
|
#include <Columns/IColumn.h>
|
||||||
#include <Common/DateLUT.h>
|
#include <Common/DateLUT.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <DataTypes/DataTypeDate.h>
|
#include <DataTypes/DataTypeDate.h>
|
||||||
#include <DataTypes/DataTypeDate32.h>
|
#include <DataTypes/DataTypeDate32.h>
|
||||||
#include <DataTypes/DataTypeDateTime.h>
|
#include <DataTypes/DataTypeDateTime.h>
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <Columns/ColumnDecimal.h>
|
#include <Columns/ColumnDecimal.h>
|
||||||
#include <Columns/ColumnConst.h>
|
#include <Columns/ColumnConst.h>
|
||||||
#include <Common/intExp.h>
|
#include <Common/intExp.h>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <Columns/ColumnDecimal.h>
|
#include <Columns/ColumnDecimal.h>
|
||||||
#include <Columns/ColumnsDateTime.h>
|
#include <Columns/ColumnsDateTime.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <Interpreters/castColumn.h>
|
#include <Interpreters/castColumn.h>
|
||||||
|
|
||||||
#include <Common/DateLUT.h>
|
#include <Common/DateLUT.h>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#if USE_ARROW || USE_PARQUET
|
#if USE_ARROW || USE_PARQUET
|
||||||
|
|
||||||
|
#include <Core/DecimalFunctions.h>
|
||||||
#include <Columns/ColumnFixedString.h>
|
#include <Columns/ColumnFixedString.h>
|
||||||
#include <Columns/ColumnNullable.h>
|
#include <Columns/ColumnNullable.h>
|
||||||
#include <Columns/ColumnString.h>
|
#include <Columns/ColumnString.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user