mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Merge branch 'master' of https://github.com/ClickHouse/ClickHouse into interactive-mode-for-clickhouse-local
This commit is contained in:
commit
6fba81191f
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -246,3 +246,6 @@
|
||||
[submodule "contrib/bzip2"]
|
||||
path = contrib/bzip2
|
||||
url = https://github.com/ClickHouse-Extras/bzip2.git
|
||||
[submodule "contrib/magic_enum"]
|
||||
path = contrib/magic_enum
|
||||
url = https://github.com/Neargye/magic_enum
|
||||
|
@ -85,6 +85,7 @@ target_link_libraries (common
|
||||
replxx
|
||||
cctz
|
||||
fmt
|
||||
magic_enum
|
||||
)
|
||||
|
||||
if (ENABLE_TESTS)
|
||||
|
157
base/common/Decimal.h
Normal file
157
base/common/Decimal.h
Normal file
@ -0,0 +1,157 @@
|
||||
#pragma once
|
||||
#include "common/extended_types.h"
|
||||
|
||||
#if !defined(NO_SANITIZE_UNDEFINED)
|
||||
#if defined(__clang__)
|
||||
#define NO_SANITIZE_UNDEFINED __attribute__((__no_sanitize__("undefined")))
|
||||
#else
|
||||
#define NO_SANITIZE_UNDEFINED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace DB
|
||||
{
|
||||
template <class> struct Decimal;
|
||||
class DateTime64;
|
||||
|
||||
using Decimal32 = Decimal<Int32>;
|
||||
using Decimal64 = Decimal<Int64>;
|
||||
using Decimal128 = Decimal<Int128>;
|
||||
using Decimal256 = Decimal<Int256>;
|
||||
|
||||
template <class T>
|
||||
concept is_decimal =
|
||||
std::is_same_v<T, Decimal32>
|
||||
|| std::is_same_v<T, Decimal64>
|
||||
|| std::is_same_v<T, Decimal128>
|
||||
|| std::is_same_v<T, Decimal256>
|
||||
|| std::is_same_v<T, DateTime64>;
|
||||
|
||||
template <class T>
|
||||
concept is_over_big_int =
|
||||
std::is_same_v<T, Int128>
|
||||
|| std::is_same_v<T, UInt128>
|
||||
|| std::is_same_v<T, Int256>
|
||||
|| std::is_same_v<T, UInt256>
|
||||
|| std::is_same_v<T, Decimal128>
|
||||
|| std::is_same_v<T, Decimal256>;
|
||||
|
||||
template <class T> struct NativeTypeT { using Type = T; };
|
||||
template <is_decimal T> struct NativeTypeT<T> { using Type = typename T::NativeType; };
|
||||
template <class T> using NativeType = typename NativeTypeT<T>::Type;
|
||||
|
||||
/// Own FieldType for Decimal.
|
||||
/// It is only a "storage" for decimal.
|
||||
/// To perform operations, you also have to provide a scale (number of digits after point).
|
||||
template <typename T>
|
||||
struct Decimal
|
||||
{
|
||||
using NativeType = T;
|
||||
|
||||
constexpr Decimal() = default;
|
||||
constexpr Decimal(Decimal<T> &&) = default;
|
||||
constexpr Decimal(const Decimal<T> &) = default;
|
||||
|
||||
constexpr Decimal(const T & value_): value(value_) {}
|
||||
|
||||
template <typename U>
|
||||
constexpr Decimal(const Decimal<U> & x): value(x.value) {}
|
||||
|
||||
constexpr Decimal<T> & operator = (Decimal<T> &&) = default;
|
||||
constexpr Decimal<T> & operator = (const Decimal<T> &) = default;
|
||||
|
||||
constexpr operator T () const { return value; }
|
||||
|
||||
template <typename U>
|
||||
constexpr U convertTo() const
|
||||
{
|
||||
if constexpr (is_decimal<U>)
|
||||
return convertTo<typename U::NativeType>();
|
||||
else
|
||||
return static_cast<U>(value);
|
||||
}
|
||||
|
||||
const Decimal<T> & operator += (const T & x) { value += x; return *this; }
|
||||
const Decimal<T> & operator -= (const T & x) { value -= x; return *this; }
|
||||
const Decimal<T> & operator *= (const T & x) { value *= x; return *this; }
|
||||
const Decimal<T> & operator /= (const T & x) { value /= x; return *this; }
|
||||
const Decimal<T> & operator %= (const T & x) { value %= x; return *this; }
|
||||
|
||||
template <typename U> const Decimal<T> & operator += (const Decimal<U> & x) { value += x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator -= (const Decimal<U> & x) { value -= x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator *= (const Decimal<U> & x) { value *= x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator /= (const Decimal<U> & x) { value /= x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator %= (const Decimal<U> & x) { value %= x.value; return *this; }
|
||||
|
||||
/// This is to avoid UB for sumWithOverflow()
|
||||
void NO_SANITIZE_UNDEFINED addOverflow(const T & x) { value += x; }
|
||||
|
||||
T value;
|
||||
};
|
||||
|
||||
template <typename T> inline bool operator< (const Decimal<T> & x, const Decimal<T> & y) { return x.value < y.value; }
|
||||
template <typename T> inline bool operator> (const Decimal<T> & x, const Decimal<T> & y) { return x.value > y.value; }
|
||||
template <typename T> inline bool operator<= (const Decimal<T> & x, const Decimal<T> & y) { return x.value <= y.value; }
|
||||
template <typename T> inline bool operator>= (const Decimal<T> & x, const Decimal<T> & y) { return x.value >= y.value; }
|
||||
template <typename T> inline bool operator== (const Decimal<T> & x, const Decimal<T> & y) { return x.value == y.value; }
|
||||
template <typename T> inline bool operator!= (const Decimal<T> & x, const Decimal<T> & y) { return x.value != y.value; }
|
||||
|
||||
template <typename T> inline Decimal<T> operator+ (const Decimal<T> & x, const Decimal<T> & y) { return x.value + y.value; }
|
||||
template <typename T> inline Decimal<T> operator- (const Decimal<T> & x, const Decimal<T> & y) { return x.value - y.value; }
|
||||
template <typename T> inline Decimal<T> operator* (const Decimal<T> & x, const Decimal<T> & y) { return x.value * y.value; }
|
||||
template <typename T> inline Decimal<T> operator/ (const Decimal<T> & x, const Decimal<T> & y) { return x.value / y.value; }
|
||||
template <typename T> inline Decimal<T> operator- (const Decimal<T> & x) { return -x.value; }
|
||||
|
||||
/// Distinguishable type to allow function resolution/deduction based on value type,
|
||||
/// but also relatively easy to convert to/from Decimal64.
|
||||
class DateTime64 : public Decimal64
|
||||
{
|
||||
public:
|
||||
using Base = Decimal64;
|
||||
using Base::Base;
|
||||
using NativeType = Base::NativeType;
|
||||
|
||||
constexpr DateTime64(const Base & v): Base(v) {}
|
||||
};
|
||||
}
|
||||
|
||||
constexpr DB::UInt64 max_uint_mask = std::numeric_limits<DB::UInt64>::max();
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename T>
|
||||
struct hash<DB::Decimal<T>>
|
||||
{
|
||||
size_t operator()(const DB::Decimal<T> & x) const { return hash<T>()(x.value); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<DB::Decimal128>
|
||||
{
|
||||
size_t operator()(const DB::Decimal128 & x) const
|
||||
{
|
||||
return std::hash<DB::Int64>()(x.value >> 64)
|
||||
^ std::hash<DB::Int64>()(x.value & max_uint_mask);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<DB::DateTime64>
|
||||
{
|
||||
size_t operator()(const DB::DateTime64 & x) const
|
||||
{
|
||||
return std::hash<DB::DateTime64::NativeType>()(x);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<DB::Decimal256>
|
||||
{
|
||||
size_t operator()(const DB::Decimal256 & x) const
|
||||
{
|
||||
// FIXME temp solution
|
||||
return std::hash<DB::Int64>()(static_cast<DB::Int64>(x.value >> 64 & max_uint_mask))
|
||||
^ std::hash<DB::Int64>()(static_cast<DB::Int64>(x.value & max_uint_mask));
|
||||
}
|
||||
};
|
||||
}
|
38
base/common/EnumReflection.h
Normal file
38
base/common/EnumReflection.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
template <class T> concept is_enum = std::is_enum_v<T>;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <is_enum E, class F, size_t ...I>
|
||||
constexpr void static_for(F && f, std::index_sequence<I...>)
|
||||
{
|
||||
(std::forward<F>(f)(std::integral_constant<E, magic_enum::enum_value<E>(I)>()) , ...);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over enum values in compile-time (compile-time switch/case, loop unrolling).
|
||||
*
|
||||
* @example static_for<E>([](auto enum_value) { return template_func<enum_value>(); }
|
||||
* ^ enum_value can be used as a template parameter
|
||||
*/
|
||||
template <is_enum E, class F>
|
||||
constexpr void static_for(F && f)
|
||||
{
|
||||
constexpr size_t count = magic_enum::enum_count<E>();
|
||||
detail::static_for<E>(std::forward<F>(f), std::make_index_sequence<count>());
|
||||
}
|
||||
|
||||
/// Enable printing enum values as strings via fmt + magic_enum
|
||||
template <is_enum T>
|
||||
struct fmt::formatter<T> : fmt::formatter<std::string_view>
|
||||
{
|
||||
constexpr auto format(T value, auto& format_context)
|
||||
{
|
||||
return formatter<string_view>::format(magic_enum::enum_name(value), format_context);
|
||||
}
|
||||
};
|
@ -41,22 +41,14 @@ template <> struct is_unsigned<UInt256> { static constexpr bool value = true; };
|
||||
template <typename T>
|
||||
inline constexpr bool is_unsigned_v = is_unsigned<T>::value;
|
||||
|
||||
template <class T> concept is_integer =
|
||||
std::is_integral_v<T>
|
||||
|| std::is_same_v<T, Int128>
|
||||
|| std::is_same_v<T, UInt128>
|
||||
|| std::is_same_v<T, Int256>
|
||||
|| std::is_same_v<T, UInt256>;
|
||||
|
||||
/// TODO: is_integral includes char, char8_t and wchar_t.
|
||||
template <typename T>
|
||||
struct is_integer
|
||||
{
|
||||
static constexpr bool value = std::is_integral_v<T>;
|
||||
};
|
||||
|
||||
template <> struct is_integer<Int128> { static constexpr bool value = true; };
|
||||
template <> struct is_integer<UInt128> { static constexpr bool value = true; };
|
||||
template <> struct is_integer<Int256> { static constexpr bool value = true; };
|
||||
template <> struct is_integer<UInt256> { static constexpr bool value = true; };
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool is_integer_v = is_integer<T>::value;
|
||||
|
||||
template <class T> concept is_floating_point = std::is_floating_point_v<T>;
|
||||
|
||||
template <typename T>
|
||||
struct is_arithmetic
|
||||
|
@ -36,18 +36,7 @@
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <char s0>
|
||||
inline bool is_in(char x)
|
||||
{
|
||||
return x == s0;
|
||||
}
|
||||
|
||||
template <char s0, char s1, char... tail>
|
||||
inline bool is_in(char x)
|
||||
{
|
||||
return x == s0 || is_in<s1, tail...>(x);
|
||||
}
|
||||
template <char ...chars> constexpr bool is_in(char x) { return ((x == chars) || ...); }
|
||||
|
||||
#if defined(__SSE2__)
|
||||
template <char s0>
|
||||
@ -67,16 +56,10 @@ inline __m128i mm_is_in(__m128i bytes)
|
||||
#endif
|
||||
|
||||
template <bool positive>
|
||||
bool maybe_negate(bool x)
|
||||
{
|
||||
if constexpr (positive)
|
||||
return x;
|
||||
else
|
||||
return !x;
|
||||
}
|
||||
constexpr bool maybe_negate(bool x) { return x == positive; }
|
||||
|
||||
template <bool positive>
|
||||
uint16_t maybe_negate(uint16_t x)
|
||||
constexpr uint16_t maybe_negate(uint16_t x)
|
||||
{
|
||||
if constexpr (positive)
|
||||
return x;
|
||||
@ -149,12 +132,13 @@ template <bool positive, ReturnMode return_mode, size_t num_chars,
|
||||
char c05 = 0, char c06 = 0, char c07 = 0, char c08 = 0,
|
||||
char c09 = 0, char c10 = 0, char c11 = 0, char c12 = 0,
|
||||
char c13 = 0, char c14 = 0, char c15 = 0, char c16 = 0>
|
||||
inline const char * find_first_symbols_sse42_impl(const char * const begin, const char * const end)
|
||||
inline const char * find_first_symbols_sse42(const char * const begin, const char * const end)
|
||||
{
|
||||
const char * pos = begin;
|
||||
|
||||
#if defined(__SSE4_2__)
|
||||
#define MODE (_SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT)
|
||||
constexpr int mode = _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT;
|
||||
|
||||
__m128i set = _mm_setr_epi8(c01, c02, c03, c04, c05, c06, c07, c08, c09, c10, c11, c12, c13, c14, c15, c16);
|
||||
|
||||
for (; pos + 15 < end; pos += 16)
|
||||
@ -163,16 +147,15 @@ inline const char * find_first_symbols_sse42_impl(const char * const begin, cons
|
||||
|
||||
if constexpr (positive)
|
||||
{
|
||||
if (_mm_cmpestrc(set, num_chars, bytes, 16, MODE))
|
||||
return pos + _mm_cmpestri(set, num_chars, bytes, 16, MODE);
|
||||
if (_mm_cmpestrc(set, num_chars, bytes, 16, mode))
|
||||
return pos + _mm_cmpestri(set, num_chars, bytes, 16, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_mm_cmpestrc(set, num_chars, bytes, 16, MODE | _SIDD_NEGATIVE_POLARITY))
|
||||
return pos + _mm_cmpestri(set, num_chars, bytes, 16, MODE | _SIDD_NEGATIVE_POLARITY);
|
||||
if (_mm_cmpestrc(set, num_chars, bytes, 16, mode | _SIDD_NEGATIVE_POLARITY))
|
||||
return pos + _mm_cmpestri(set, num_chars, bytes, 16, mode | _SIDD_NEGATIVE_POLARITY);
|
||||
}
|
||||
}
|
||||
#undef MODE
|
||||
#endif
|
||||
|
||||
for (; pos < end; ++pos)
|
||||
@ -197,20 +180,15 @@ inline const char * find_first_symbols_sse42_impl(const char * const begin, cons
|
||||
}
|
||||
|
||||
|
||||
template <bool positive, ReturnMode return_mode, char... symbols>
|
||||
inline const char * find_first_symbols_sse42(const char * begin, const char * end)
|
||||
{
|
||||
return find_first_symbols_sse42_impl<positive, return_mode, sizeof...(symbols), symbols...>(begin, end);
|
||||
}
|
||||
|
||||
/// NOTE No SSE 4.2 implementation for find_last_symbols_or_null. Not worth to do.
|
||||
|
||||
template <bool positive, ReturnMode return_mode, char... symbols>
|
||||
inline const char * find_first_symbols_dispatch(const char * begin, const char * end)
|
||||
requires(0 <= sizeof...(symbols) && sizeof...(symbols) <= 16)
|
||||
{
|
||||
#if defined(__SSE4_2__)
|
||||
if (sizeof...(symbols) >= 5)
|
||||
return find_first_symbols_sse42<positive, return_mode, symbols...>(begin, end);
|
||||
return find_first_symbols_sse42<positive, return_mode, sizeof...(symbols), symbols...>(begin, end);
|
||||
else
|
||||
#endif
|
||||
return find_first_symbols_sse2<positive, return_mode, symbols...>(begin, end);
|
||||
|
@ -15,15 +15,15 @@ private:
|
||||
public:
|
||||
using UnderlyingType = T;
|
||||
template <class Enable = typename std::is_copy_constructible<T>::type>
|
||||
explicit StrongTypedef(const T & t_) : t(t_) {}
|
||||
constexpr explicit StrongTypedef(const T & t_) : t(t_) {}
|
||||
template <class Enable = typename std::is_move_constructible<T>::type>
|
||||
explicit StrongTypedef(T && t_) : t(std::move(t_)) {}
|
||||
constexpr explicit StrongTypedef(T && t_) : t(std::move(t_)) {}
|
||||
|
||||
template <class Enable = typename std::is_default_constructible<T>::type>
|
||||
StrongTypedef(): t() {}
|
||||
constexpr StrongTypedef(): t() {}
|
||||
|
||||
StrongTypedef(const Self &) = default;
|
||||
StrongTypedef(Self &&) = default;
|
||||
constexpr StrongTypedef(const Self &) = default;
|
||||
constexpr StrongTypedef(Self &&) = default;
|
||||
|
||||
Self & operator=(const Self &) = default;
|
||||
Self & operator=(Self &&) = default;
|
||||
|
@ -192,4 +192,29 @@ elseif (COMPILER_GCC)
|
||||
# For some reason (bug in gcc?) macro 'GCC diagnostic ignored "-Wstringop-overflow"' doesn't help.
|
||||
add_cxx_compile_options(-Wno-stringop-overflow)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11)
|
||||
# reinterpretAs.cpp:182:31: error: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type
|
||||
# ‘using ToFieldType = using FieldType = using UUID = struct StrongTypedef<wide::integer<128, unsigned int>, DB::UUIDTag>’
|
||||
# {aka ‘struct StrongTypedef<wide::integer<128, unsigned int>, DB::UUIDTag>’} from an array of ‘const char8_t’
|
||||
add_cxx_compile_options(-Wno-error=class-memaccess)
|
||||
|
||||
# Maybe false positive...
|
||||
# In file included from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/memory:673,
|
||||
# In function ‘void std::__1::__libcpp_operator_delete(_Args ...) [with _Args = {void*, long unsigned int}]’,
|
||||
# inlined from ‘void std::__1::__do_deallocate_handle_size(void*, size_t, _Args ...) [with _Args = {}]’ at /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/new:271:34,
|
||||
# inlined from ‘void std::__1::__libcpp_deallocate(void*, size_t, size_t)’ at /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/new:285:41,
|
||||
# inlined from ‘constexpr void std::__1::allocator<_Tp>::deallocate(_Tp*, size_t) [with _Tp = char]’ at /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/memory:849:39,
|
||||
# inlined from ‘static constexpr void std::__1::allocator_traits<_Alloc>::deallocate(std::__1::allocator_traits<_Alloc>::allocator_type&, std::__1::allocator_traits<_Alloc>::pointer, std::__1::allocator_traits<_Alloc>::size_type) [with _Alloc = std::__1::allocator<char>]’ at /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/__memory/allocator_traits.h:476:24,
|
||||
# inlined from ‘std::__1::basic_string<_CharT, _Traits, _Allocator>::~basic_string() [with _CharT = char; _Traits = std::__1::char_traits<char>; _Allocator = std::__1::allocator<char>]’ at /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/string:2219:35,
|
||||
# inlined from ‘std::__1::basic_string<_CharT, _Traits, _Allocator>::~basic_string() [with _CharT = char; _Traits = std::__1::char_traits<char>; _Allocator = std::__1::allocator<char>]’ at /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/string:2213:1,
|
||||
# inlined from ‘DB::JSONBuilder::JSONMap::Pair::~Pair()’ at /home/jakalletti/ClickHouse/ClickHouse/src/Common/JSONBuilder.h:90:12,
|
||||
# inlined from ‘void DB::JSONBuilder::JSONMap::add(std::__1::string, DB::JSONBuilder::ItemPtr)’ at /home/jakalletti/ClickHouse/ClickHouse/src/Common/JSONBuilder.h:97:68,
|
||||
# inlined from ‘virtual void DB::ExpressionStep::describeActions(DB::JSONBuilder::JSONMap&) const’ at /home/jakalletti/ClickHouse/ClickHouse/src/Processors/QueryPlan/ExpressionStep.cpp:102:12:
|
||||
# /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/new:247:20: error: ‘void operator delete(void*, size_t)’ called on a pointer to an unallocated object ‘7598543875853023301’ [-Werror=free-nonheap-object]
|
||||
add_cxx_compile_options(-Wno-error=free-nonheap-object)
|
||||
|
||||
# AggregateFunctionAvg.h:203:100: error: ‘this’ pointer is null [-Werror=nonnull]
|
||||
add_cxx_compile_options(-Wno-error=nonnull)
|
||||
endif()
|
||||
endif ()
|
||||
|
1
contrib/CMakeLists.txt
vendored
1
contrib/CMakeLists.txt
vendored
@ -33,6 +33,7 @@ endif()
|
||||
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL 1)
|
||||
|
||||
add_subdirectory (abseil-cpp-cmake)
|
||||
add_subdirectory (magic-enum-cmake)
|
||||
add_subdirectory (boost-cmake)
|
||||
add_subdirectory (cctz-cmake)
|
||||
add_subdirectory (consistent-hashing)
|
||||
|
2
contrib/abseil-cpp
vendored
2
contrib/abseil-cpp
vendored
@ -1 +1 @@
|
||||
Subproject commit 4f3b686f86c3ebaba7e4e926e62a79cb1c659a54
|
||||
Subproject commit b004a8a02418b83de8b686caa0b0f6e39ac2191f
|
2
contrib/fastops
vendored
2
contrib/fastops
vendored
@ -1 +1 @@
|
||||
Subproject commit 88752a5e03cf34639a4a37a4b41d8b463fffd2b5
|
||||
Subproject commit 012b777df9e2d145a24800a6c8c3d4a0249bb09e
|
2
contrib/llvm
vendored
2
contrib/llvm
vendored
@ -1 +1 @@
|
||||
Subproject commit e5751459412bce1391fb7a2e9bbc01e131bf72f1
|
||||
Subproject commit f30bbecef78b75b527e257c1304d0be2f2f95975
|
3
contrib/magic-enum-cmake/CMakeLists.txt
Normal file
3
contrib/magic-enum-cmake/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
set (LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/magic_enum")
|
||||
add_library (magic_enum INTERFACE)
|
||||
target_include_directories(magic_enum INTERFACE ${LIBRARY_DIR}/include)
|
1
contrib/magic_enum
vendored
Submodule
1
contrib/magic_enum
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 38f86e4d093cfc9034a140d37de2168e3951bef3
|
2
contrib/rocksdb
vendored
2
contrib/rocksdb
vendored
@ -1 +1 @@
|
||||
Subproject commit b6480c69bf3ab6e298e0d019a07fd4f69029b26a
|
||||
Subproject commit 5ea892c8673e6c5a052887653673b967d44cc59b
|
11
debian/clickhouse-server.init
vendored
11
debian/clickhouse-server.init
vendored
@ -3,10 +3,17 @@
|
||||
# Provides: clickhouse-server
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Required-Start: $network
|
||||
# Required-Stop: $network
|
||||
# Should-Start: $time $network
|
||||
# Should-Stop: $network
|
||||
# Short-Description: Yandex clickhouse-server daemon
|
||||
### END INIT INFO
|
||||
#
|
||||
# NOTES:
|
||||
# - Should-* -- script can start if the listed facilities are missing, unlike Required-*
|
||||
#
|
||||
# For the documentation [1]:
|
||||
#
|
||||
# [1]: https://wiki.debian.org/LSBInitScripts
|
||||
|
||||
CLICKHOUSE_USER=clickhouse
|
||||
CLICKHOUSE_GROUP=${CLICKHOUSE_USER}
|
||||
|
8
debian/clickhouse-server.service
vendored
8
debian/clickhouse-server.service
vendored
@ -1,7 +1,12 @@
|
||||
[Unit]
|
||||
Description=ClickHouse Server (analytic DBMS for big data)
|
||||
Requires=network-online.target
|
||||
After=network-online.target
|
||||
# NOTE: that After/Wants=time-sync.target is not enough, you need to ensure
|
||||
# that the time was adjusted already, if you use systemd-timesyncd you are
|
||||
# safe, but if you use ntp or some other daemon, you should configure it
|
||||
# additionaly.
|
||||
After=time-sync.target network-online.target
|
||||
Wants=time-sync.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
@ -16,4 +21,5 @@ LimitNOFILE=500000
|
||||
CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE
|
||||
|
||||
[Install]
|
||||
# ClickHouse should not start from the rescue shell (rescue.target).
|
||||
WantedBy=multi-user.target
|
||||
|
4
debian/rules
vendored
4
debian/rules
vendored
@ -36,8 +36,8 @@ endif
|
||||
|
||||
CMAKE_FLAGS += -DENABLE_UTILS=0
|
||||
|
||||
DEB_CC ?= $(shell which gcc-10 gcc-9 gcc | head -n1)
|
||||
DEB_CXX ?= $(shell which g++-10 g++-9 g++ | head -n1)
|
||||
DEB_CC ?= $(shell which gcc-11 gcc-10 gcc-9 gcc | head -n1)
|
||||
DEB_CXX ?= $(shell which g++-11 g++-10 g++-9 g++ | head -n1)
|
||||
|
||||
ifdef DEB_CXX
|
||||
DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
|
||||
|
@ -41,8 +41,6 @@ RUN apt-get update \
|
||||
ccache \
|
||||
cmake \
|
||||
curl \
|
||||
g++-10 \
|
||||
gcc-10 \
|
||||
gdb \
|
||||
git \
|
||||
gperf \
|
||||
@ -104,15 +102,10 @@ RUN wget -nv "https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.0
|
||||
# Download toolchain for FreeBSD 11.3
|
||||
RUN wget -nv https://clickhouse-datasets.s3.yandex.net/toolchains/toolchains/freebsd-11.3-toolchain.tar.xz
|
||||
|
||||
# NOTE: For some reason we have outdated version of gcc-10 in ubuntu 20.04 stable.
|
||||
# Current workaround is to use latest version proposed repo. Remove as soon as
|
||||
# gcc-10.2 appear in stable repo.
|
||||
RUN echo 'deb http://archive.ubuntu.com/ubuntu/ focal-proposed restricted main multiverse universe' > /etc/apt/sources.list.d/proposed-repositories.list
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install gcc-10 g++-10 --yes
|
||||
|
||||
RUN rm /etc/apt/sources.list.d/proposed-repositories.list && apt-get update
|
||||
# NOTE: Seems like gcc-11 is too new for ubuntu20 repository
|
||||
RUN add-apt-repository ppa:ubuntu-toolchain-r/test --yes \
|
||||
&& apt-get update \
|
||||
&& apt-get install gcc-11 g++-11 --yes
|
||||
|
||||
|
||||
COPY build.sh /
|
||||
|
@ -57,15 +57,11 @@ RUN apt-get update \
|
||||
tzdata \
|
||||
--yes --no-install-recommends
|
||||
|
||||
# NOTE: For some reason we have outdated version of gcc-10 in ubuntu 20.04 stable.
|
||||
# Current workaround is to use latest version proposed repo. Remove as soon as
|
||||
# gcc-10.2 appear in stable repo.
|
||||
RUN echo 'deb http://archive.ubuntu.com/ubuntu/ focal-proposed restricted main multiverse universe' > /etc/apt/sources.list.d/proposed-repositories.list
|
||||
# NOTE: Seems like gcc-11 is too new for ubuntu20 repository
|
||||
RUN add-apt-repository ppa:ubuntu-toolchain-r/test --yes \
|
||||
&& apt-get update \
|
||||
&& apt-get install gcc-11 g++-11 --yes
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install gcc-10 g++-10 --yes --no-install-recommends
|
||||
|
||||
RUN rm /etc/apt/sources.list.d/proposed-repositories.list && apt-get update
|
||||
|
||||
# This symlink required by gcc to find lld compiler
|
||||
RUN ln -s /usr/bin/lld-${LLVM_VERSION} /usr/bin/ld.lld
|
||||
|
@ -205,7 +205,7 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--build-type", choices=("debug", ""), default="")
|
||||
parser.add_argument("--compiler", choices=("clang-11", "clang-11-darwin", "clang-11-darwin-aarch64", "clang-11-aarch64",
|
||||
"clang-12", "clang-12-darwin", "clang-12-darwin-aarch64", "clang-12-aarch64",
|
||||
"clang-11-freebsd", "clang-12-freebsd", "gcc-10"), default="clang-12")
|
||||
"clang-11-freebsd", "clang-12-freebsd", "gcc-11"), default="clang-12")
|
||||
parser.add_argument("--sanitizer", choices=("address", "thread", "memory", "undefined", ""), default="")
|
||||
parser.add_argument("--unbundled", action="store_true")
|
||||
parser.add_argument("--split-binary", action="store_true")
|
||||
|
@ -159,6 +159,7 @@ function clone_submodules
|
||||
cd "$FASTTEST_SOURCE"
|
||||
|
||||
SUBMODULES_TO_UPDATE=(
|
||||
contrib/magic_enum
|
||||
contrib/abseil-cpp
|
||||
contrib/boost
|
||||
contrib/zlib-ng
|
||||
|
@ -76,7 +76,7 @@ cd ClickHouse
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_C_COMPILER=$(brew --prefix gcc)/bin/gcc-10 -DCMAKE_CXX_COMPILER=$(brew --prefix gcc)/bin/g++-10 -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
|
||||
cmake -DCMAKE_C_COMPILER=$(brew --prefix gcc)/bin/gcc-11 -DCMAKE_CXX_COMPILER=$(brew --prefix gcc)/bin/g++-11 -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
|
||||
cmake --build . --config RelWithDebInfo
|
||||
cd ..
|
||||
```
|
||||
|
@ -74,7 +74,7 @@ $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/
|
||||
$ rm -rf build
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake -DCMAKE_C_COMPILER=$(brew --prefix gcc)/bin/gcc-10 -DCMAKE_CXX_COMPILER=$(brew --prefix gcc)/bin/g++-10 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_JEMALLOC=OFF ..
|
||||
$ cmake -DCMAKE_C_COMPILER=$(brew --prefix gcc)/bin/gcc-11 -DCMAKE_CXX_COMPILER=$(brew --prefix gcc)/bin/g++-11 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_JEMALLOC=OFF ..
|
||||
$ cmake --build . --config RelWithDebInfo
|
||||
$ cd ..
|
||||
```
|
||||
|
@ -21,11 +21,9 @@
|
||||
namespace DB
|
||||
{
|
||||
struct Settings;
|
||||
template <typename T>
|
||||
using DecimalOrVectorCol = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
|
||||
template <typename T> constexpr bool DecimalOrExtendedInt =
|
||||
IsDecimalNumber<T>
|
||||
is_decimal<T>
|
||||
|| std::is_same_v<T, Int128>
|
||||
|| std::is_same_v<T, Int256>
|
||||
|| std::is_same_v<T, UInt128>
|
||||
@ -44,7 +42,7 @@ struct AvgFraction
|
||||
/// Invoked only is either Numerator or Denominator are Decimal.
|
||||
Float64 NO_SANITIZE_UNDEFINED divideIfAnyDecimal(UInt32 num_scale, UInt32 denom_scale [[maybe_unused]]) const
|
||||
{
|
||||
if constexpr (IsDecimalNumber<Numerator> && IsDecimalNumber<Denominator>)
|
||||
if constexpr (is_decimal<Numerator> && is_decimal<Denominator>)
|
||||
{
|
||||
// According to the docs, num(S1) / denom(S2) would have scale S1
|
||||
|
||||
@ -60,7 +58,7 @@ struct AvgFraction
|
||||
/// Numerator is always casted to Float64 to divide correctly if the denominator is not Float64.
|
||||
Float64 num_converted;
|
||||
|
||||
if constexpr (IsDecimalNumber<Numerator>)
|
||||
if constexpr (is_decimal<Numerator>)
|
||||
num_converted = DecimalUtils::convertTo<Float64>(numerator, num_scale);
|
||||
else
|
||||
num_converted = static_cast<Float64>(numerator); /// all other types, including extended integral.
|
||||
@ -68,7 +66,7 @@ struct AvgFraction
|
||||
std::conditional_t<DecimalOrExtendedInt<Denominator>,
|
||||
Float64, Denominator> denom_converted;
|
||||
|
||||
if constexpr (IsDecimalNumber<Denominator>)
|
||||
if constexpr (is_decimal<Denominator>)
|
||||
denom_converted = DecimalUtils::convertTo<Float64>(denominator, denom_scale);
|
||||
else if constexpr (DecimalOrExtendedInt<Denominator>)
|
||||
/// no way to divide Float64 and extended integral type without an explicit cast.
|
||||
@ -139,7 +137,7 @@ public:
|
||||
|
||||
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override
|
||||
{
|
||||
if constexpr (IsDecimalNumber<Numerator> || IsDecimalNumber<Denominator>)
|
||||
if constexpr (is_decimal<Numerator> || is_decimal<Denominator>)
|
||||
assert_cast<ColumnVector<Float64> &>(to).getData().push_back(
|
||||
this->data(place).divideIfAnyDecimal(num_scale, denom_scale));
|
||||
else
|
||||
@ -222,7 +220,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using AvgFieldType = std::conditional_t<IsDecimalNumber<T>,
|
||||
using AvgFieldType = std::conditional_t<is_decimal<T>,
|
||||
std::conditional_t<std::is_same_v<T, Decimal256>, Decimal256, Decimal128>,
|
||||
NearestFieldType<T>>;
|
||||
|
||||
@ -239,7 +237,7 @@ public:
|
||||
|
||||
void NO_SANITIZE_UNDEFINED add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena *) const final
|
||||
{
|
||||
this->data(place).numerator += static_cast<const DecimalOrVectorCol<T> &>(*columns[0]).getData()[row_num];
|
||||
this->data(place).numerator += static_cast<const ColumnVectorOrDecimal<T> &>(*columns[0]).getData()[row_num];
|
||||
++this->data(place).denominator;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace DB
|
||||
struct Settings;
|
||||
|
||||
template <typename T>
|
||||
using AvgWeightedFieldType = std::conditional_t<IsDecimalNumber<T>,
|
||||
using AvgWeightedFieldType = std::conditional_t<is_decimal<T>,
|
||||
std::conditional_t<std::is_same_v<T, Decimal256>, Decimal256, Decimal128>,
|
||||
std::conditional_t<DecimalOrExtendedInt<T>,
|
||||
Float64, // no way to do UInt128 * UInt128, better cast to Float64
|
||||
@ -34,10 +34,10 @@ public:
|
||||
|
||||
void NO_SANITIZE_UNDEFINED add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
const auto& weights = static_cast<const DecimalOrVectorCol<Weight> &>(*columns[1]);
|
||||
const auto& weights = static_cast<const ColumnVectorOrDecimal<Weight> &>(*columns[1]);
|
||||
|
||||
this->data(place).numerator += static_cast<Numerator>(
|
||||
static_cast<const DecimalOrVectorCol<Value> &>(*columns[0]).getData()[row_num]) *
|
||||
static_cast<const ColumnVectorOrDecimal<Value> &>(*columns[0]).getData()[row_num]) *
|
||||
static_cast<Numerator>(weights.getData()[row_num]);
|
||||
|
||||
this->data(place).denominator += static_cast<Denominator>(weights.getData()[row_num]);
|
||||
|
@ -25,14 +25,14 @@ namespace
|
||||
template <typename T, typename LimitNumberOfElements>
|
||||
struct MovingSum
|
||||
{
|
||||
using Data = MovingSumData<std::conditional_t<IsDecimalNumber<T>, Decimal128, NearestFieldType<T>>>;
|
||||
using Data = MovingSumData<std::conditional_t<is_decimal<T>, Decimal128, NearestFieldType<T>>>;
|
||||
using Function = MovingImpl<T, LimitNumberOfElements, Data>;
|
||||
};
|
||||
|
||||
template <typename T, typename LimitNumberOfElements>
|
||||
struct MovingAvg
|
||||
{
|
||||
using Data = MovingAvgData<std::conditional_t<IsDecimalNumber<T>, Decimal128, Float64>>;
|
||||
using Data = MovingAvgData<std::conditional_t<is_decimal<T>, Decimal128, Float64>>;
|
||||
using Function = MovingImpl<T, LimitNumberOfElements, Data>;
|
||||
};
|
||||
|
||||
|
@ -87,18 +87,10 @@ class MovingImpl final
|
||||
public:
|
||||
using ResultT = typename Data::Accumulator;
|
||||
|
||||
using ColumnSource = std::conditional_t<IsDecimalNumber<T>,
|
||||
ColumnDecimal<T>,
|
||||
ColumnVector<T>>;
|
||||
using ColumnSource = ColumnVectorOrDecimal<T>;
|
||||
|
||||
/// Probably for overflow function in the future.
|
||||
using ColumnResult = std::conditional_t<IsDecimalNumber<ResultT>,
|
||||
ColumnDecimal<ResultT>,
|
||||
ColumnVector<ResultT>>;
|
||||
|
||||
using DataTypeResult = std::conditional_t<IsDecimalNumber<ResultT>,
|
||||
DataTypeDecimal<ResultT>,
|
||||
DataTypeNumber<ResultT>>;
|
||||
using ColumnResult = ColumnVectorOrDecimal<ResultT>;
|
||||
|
||||
explicit MovingImpl(const DataTypePtr & data_type_, UInt64 window_size_ = std::numeric_limits<UInt64>::max())
|
||||
: IAggregateFunctionDataHelper<Data, MovingImpl<T, Tlimit_num_elems, Data>>({data_type_}, {})
|
||||
@ -106,14 +98,7 @@ public:
|
||||
|
||||
String getName() const override { return Data::name; }
|
||||
|
||||
DataTypePtr getReturnType() const override
|
||||
{
|
||||
if constexpr (IsDecimalNumber<ResultT>)
|
||||
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeResult>(
|
||||
DataTypeResult::maxPrecision(), getDecimalScale(*this->argument_types.at(0))));
|
||||
else
|
||||
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeResult>());
|
||||
}
|
||||
DataTypePtr getReturnType() const override { return std::make_shared<DataTypeArray>(getReturnTypeElement()); }
|
||||
|
||||
void NO_SANITIZE_UNDEFINED add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||
{
|
||||
@ -196,6 +181,18 @@ public:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
auto getReturnTypeElement() const
|
||||
{
|
||||
if constexpr (!is_decimal<ResultT>)
|
||||
return std::make_shared<DataTypeNumber<ResultT>>();
|
||||
else
|
||||
{
|
||||
using Res = DataTypeDecimal<ResultT>;
|
||||
return std::make_shared<Res>(Res::maxPrecision(), getDecimalScale(*this->argument_types.at(0)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#undef AGGREGATE_FUNCTION_MOVING_MAX_ARRAY_SIZE
|
||||
|
@ -44,7 +44,7 @@ struct SingleValueDataFixed
|
||||
{
|
||||
private:
|
||||
using Self = SingleValueDataFixed;
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<T>;
|
||||
|
||||
bool has_value = false; /// We need to remember if at least one value has been passed. This is necessary for AggregateFunctionIf.
|
||||
T value;
|
||||
|
@ -67,10 +67,10 @@ class AggregateFunctionQuantile final : public IAggregateFunctionDataHelper<Data
|
||||
AggregateFunctionQuantile<Value, Data, Name, has_second_arg, FloatReturnType, returns_many>>
|
||||
{
|
||||
private:
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<Value>, ColumnDecimal<Value>, ColumnVector<Value>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<Value>;
|
||||
|
||||
static constexpr bool returns_float = !(std::is_same_v<FloatReturnType, void>);
|
||||
static_assert(!IsDecimalNumber<Value> || !returns_float);
|
||||
static_assert(!is_decimal<Value> || !returns_float);
|
||||
|
||||
QuantileLevels<Float64> levels;
|
||||
|
||||
|
72
src/AggregateFunctions/AggregateFunctionSparkbar.cpp
Normal file
72
src/AggregateFunctions/AggregateFunctionSparkbar.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include <AggregateFunctions/AggregateFunctionSparkbar.h>
|
||||
#include <AggregateFunctions/FactoryHelpers.h>
|
||||
#include <AggregateFunctions/Helpers.h>
|
||||
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct Settings;
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <template <typename, typename> class AggregateFunctionTemplate, typename Data, typename ... TArgs>
|
||||
static IAggregateFunction * createWithUIntegerOrTimeType(const std::string & name, const IDataType & argument_type, TArgs && ... args)
|
||||
{
|
||||
WhichDataType which(argument_type);
|
||||
if (which.idx == TypeIndex::Date || which.idx == TypeIndex::UInt16) return new AggregateFunctionTemplate<UInt16, Data>(std::forward<TArgs>(args)...);
|
||||
if (which.idx == TypeIndex::DateTime || which.idx == TypeIndex::UInt32) return new AggregateFunctionTemplate<UInt32, Data>(std::forward<TArgs>(args)...);
|
||||
if (which.idx == TypeIndex::UInt8) return new AggregateFunctionTemplate<UInt8, Data>(std::forward<TArgs>(args)...);
|
||||
if (which.idx == TypeIndex::UInt64) return new AggregateFunctionTemplate<UInt64, Data>(std::forward<TArgs>(args)...);
|
||||
if (which.idx == TypeIndex::UInt128) return new AggregateFunctionTemplate<UInt128, Data>(std::forward<TArgs>(args)...);
|
||||
if (which.idx == TypeIndex::UInt256) return new AggregateFunctionTemplate<UInt256, Data>(std::forward<TArgs>(args)...);
|
||||
throw Exception("The first argument type must be UInt or Date or DateTime for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
|
||||
template <typename ... TArgs>
|
||||
AggregateFunctionPtr createAggregateFunctionSparkbarImpl(const std::string & name, const IDataType & x_argument_type, const IDataType & y_argument_type, TArgs ... args)
|
||||
{
|
||||
WhichDataType which(y_argument_type);
|
||||
#define DISPATCH(TYPE) \
|
||||
if (which.idx == TypeIndex::TYPE) return AggregateFunctionPtr(createWithUIntegerOrTimeType<AggregateFunctionSparkbar, TYPE>(name, x_argument_type, std::forward<TArgs>(args)...));
|
||||
FOR_NUMERIC_TYPES(DISPATCH)
|
||||
#undef DISPATCH
|
||||
|
||||
throw Exception("The second argument type must be numeric for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
|
||||
|
||||
AggregateFunctionPtr createAggregateFunctionSparkbar(const std::string & name, const DataTypes & arguments, const Array & params, const Settings *)
|
||||
{
|
||||
assertBinary(name, arguments);
|
||||
|
||||
if (params.size() != 1 && params.size() != 3)
|
||||
throw Exception("The number of params does not match for aggregate function " + name, ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
if (params.size() == 3)
|
||||
{
|
||||
if (params.at(1).getType() != arguments[0]->getDefault().getType() || params.at(2).getType() != arguments[0]->getDefault().getType())
|
||||
{
|
||||
throw Exception("The second and third parameters are not the same type as the first arguments for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
}
|
||||
return createAggregateFunctionSparkbarImpl(name, *arguments[0], *arguments[1], arguments, params);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void registerAggregateFunctionSparkbar(AggregateFunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction("sparkbar", createAggregateFunctionSparkbar);
|
||||
}
|
||||
|
||||
}
|
309
src/AggregateFunctions/AggregateFunctionSparkbar.h
Normal file
309
src/AggregateFunctions/AggregateFunctionSparkbar.h
Normal file
@ -0,0 +1,309 @@
|
||||
#pragma once
|
||||
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <AggregateFunctions/IAggregateFunction.h>
|
||||
#include <common/range.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <Columns/ColumnString.h>
|
||||
#include <common/logger_useful.h>
|
||||
#include <IO/ReadBufferFromString.h>
|
||||
#include <Common/HashTable/HashMap.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
template<typename X, typename Y>
|
||||
struct AggregateFunctionSparkbarData
|
||||
{
|
||||
|
||||
using Points = HashMap<X, Y>;
|
||||
Points points;
|
||||
|
||||
X min_x = std::numeric_limits<X>::max();
|
||||
X max_x = std::numeric_limits<X>::lowest();
|
||||
|
||||
Y min_y = std::numeric_limits<Y>::max();
|
||||
Y max_y = std::numeric_limits<Y>::lowest();
|
||||
|
||||
void insert(const X & x, const Y & y)
|
||||
{
|
||||
auto result = points.insert({x, y});
|
||||
if (!result.second)
|
||||
result.first->getMapped() += y;
|
||||
}
|
||||
|
||||
void add(X x, Y y)
|
||||
{
|
||||
insert(x, y);
|
||||
min_x = std::min(x, min_x);
|
||||
max_x = std::max(x, max_x);
|
||||
min_y = std::min(y, min_y);
|
||||
max_y = std::max(y, max_y);
|
||||
}
|
||||
|
||||
void merge(const AggregateFunctionSparkbarData & other)
|
||||
{
|
||||
if (other.points.empty())
|
||||
return;
|
||||
|
||||
for (auto & point : other.points)
|
||||
insert(point.getKey(), point.getMapped());
|
||||
|
||||
min_x = std::min(other.min_x, min_x);
|
||||
max_x = std::max(other.max_x, max_x);
|
||||
min_y = std::min(other.min_y, min_y);
|
||||
max_y = std::max(other.max_y, max_y);
|
||||
}
|
||||
|
||||
void serialize(WriteBuffer & buf) const
|
||||
{
|
||||
writeBinary(min_x, buf);
|
||||
writeBinary(max_x, buf);
|
||||
writeBinary(min_y, buf);
|
||||
writeBinary(max_y, buf);
|
||||
writeVarUInt(points.size(), buf);
|
||||
|
||||
for (const auto & elem : points)
|
||||
{
|
||||
writeBinary(elem.getKey(), buf);
|
||||
writeBinary(elem.getMapped(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
void deserialize(ReadBuffer & buf)
|
||||
{
|
||||
readBinary(min_x, buf);
|
||||
readBinary(max_x, buf);
|
||||
readBinary(min_y, buf);
|
||||
readBinary(max_y, buf);
|
||||
size_t size;
|
||||
readVarUInt(size, buf);
|
||||
|
||||
/// TODO Protection against huge size
|
||||
X x;
|
||||
Y y;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
readBinary(x, buf);
|
||||
readBinary(y, buf);
|
||||
insert(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename X, typename Y>
|
||||
class AggregateFunctionSparkbar final
|
||||
: public IAggregateFunctionDataHelper<AggregateFunctionSparkbarData<X, Y>, AggregateFunctionSparkbar<X, Y>>
|
||||
{
|
||||
|
||||
private:
|
||||
size_t width;
|
||||
X min_x;
|
||||
X max_x;
|
||||
|
||||
String getBar(const UInt8 value) const
|
||||
{
|
||||
// ▁▂▃▄▅▆▇█
|
||||
switch (value)
|
||||
{
|
||||
case 1: return "▁";
|
||||
case 2: return "▂";
|
||||
case 3: return "▃";
|
||||
case 4: return "▄";
|
||||
case 5: return "▅";
|
||||
case 6: return "▆";
|
||||
case 7: return "▇";
|
||||
case 8: return "█";
|
||||
}
|
||||
return " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum value of y is rendered as the lowest height "▁",
|
||||
* the maximum value of y is rendered as the highest height "█", and the middle value will be rendered proportionally.
|
||||
* If a bucket has no y value, it will be rendered as " ".
|
||||
* If the actual number of buckets is greater than the specified bucket, it will be compressed by width.
|
||||
* For example, there are actually 11 buckets, specify 10 buckets, and divide the 11 buckets as follows (11/10):
|
||||
* 0.0-1.1, 1.1-2.2, 2.2-3.3, 3.3-4.4, 4.4-5.5, 5.5-6.6, 6.6-7.7, 7.7-8.8, 8.8-9.9, 9.9-11.
|
||||
* The y value of the first bucket will be calculated as follows:
|
||||
* the actual y value of the first position + the actual second position y*0.1, and the remaining y*0.9 is reserved for the next bucket.
|
||||
* The next bucket will use the last y*0.9 + the actual third position y*0.2, and the remaining y*0.8 will be reserved for the next bucket. And so on.
|
||||
*/
|
||||
String render(const AggregateFunctionSparkbarData<X, Y> & data) const
|
||||
{
|
||||
String value;
|
||||
if (data.points.empty() || !width)
|
||||
return value;
|
||||
X local_min_x = data.min_x;
|
||||
X local_max_x = data.max_x;
|
||||
size_t diff_x = local_max_x - local_min_x;
|
||||
if ((diff_x + 1) <= width)
|
||||
{
|
||||
Y min_y = data.min_y;
|
||||
Y max_y = data.max_y;
|
||||
Float64 diff_y = max_y - min_y;
|
||||
|
||||
if (diff_y)
|
||||
{
|
||||
for (size_t i = 0; i <= diff_x; ++i)
|
||||
{
|
||||
auto it = data.points.find(local_min_x + i);
|
||||
bool found = it != data.points.end();
|
||||
value += getBar(found ? static_cast<UInt8>(std::round(((it->getMapped() - min_y) / diff_y) * 7) + 1) : 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i <= diff_x; ++i)
|
||||
value += getBar(data.points.has(local_min_x + i) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// begin reshapes to width buckets
|
||||
Float64 multiple_d = (diff_x + 1) / static_cast<Float64>(width);
|
||||
|
||||
std::optional<Float64> min_y;
|
||||
std::optional<Float64> max_y;
|
||||
|
||||
std::optional<Float64> new_y;
|
||||
std::vector<std::optional<Float64>> newPoints;
|
||||
newPoints.reserve(width);
|
||||
|
||||
std::pair<size_t, Float64> bound{0, 0.0};
|
||||
size_t cur_bucket_num = 0;
|
||||
// upper bound for bucket
|
||||
auto upperBound = [&](size_t bucket_num)
|
||||
{
|
||||
bound.second = (bucket_num + 1) * multiple_d;
|
||||
bound.first = std::floor(bound.second);
|
||||
};
|
||||
upperBound(cur_bucket_num);
|
||||
for (size_t i = 0; i <= (diff_x + 1); ++i)
|
||||
{
|
||||
if (i == bound.first) // is bound
|
||||
{
|
||||
Float64 proportion = bound.second - bound.first;
|
||||
auto it = data.points.find(local_min_x + i);
|
||||
bool found = (it != data.points.end());
|
||||
if (found)
|
||||
new_y = new_y.value_or(0) + it->getMapped() * proportion;
|
||||
|
||||
if (new_y)
|
||||
{
|
||||
Float64 avg_y = new_y.value() / multiple_d;
|
||||
|
||||
newPoints.emplace_back(avg_y);
|
||||
// If min_y has no value, or if the avg_y of the current bucket is less than min_y, update it.
|
||||
if (!min_y || avg_y < min_y)
|
||||
min_y = avg_y;
|
||||
if (!max_y || avg_y > max_y)
|
||||
max_y = avg_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
newPoints.emplace_back();
|
||||
}
|
||||
|
||||
// next bucket
|
||||
new_y = found ? ((1 - proportion) * it->getMapped()) : std::optional<Float64>();
|
||||
upperBound(++cur_bucket_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = data.points.find(local_min_x + i);
|
||||
if (it != data.points.end())
|
||||
new_y = new_y.value_or(0) + it->getMapped();
|
||||
}
|
||||
}
|
||||
|
||||
if (!min_y || !max_y) // No value is set
|
||||
return {};
|
||||
|
||||
Float64 diff_y = max_y.value() - min_y.value();
|
||||
|
||||
auto getBars = [&] (const std::optional<Float64> & point_y)
|
||||
{
|
||||
value += getBar(point_y ? static_cast<UInt8>(std::round(((point_y.value() - min_y.value()) / diff_y) * 7) + 1) : 0);
|
||||
};
|
||||
auto getBarsForConstant = [&] (const std::optional<Float64> & point_y)
|
||||
{
|
||||
value += getBar(point_y ? 1 : 0);
|
||||
};
|
||||
|
||||
if (diff_y)
|
||||
std::for_each(newPoints.begin(), newPoints.end(), getBars);
|
||||
else
|
||||
std::for_each(newPoints.begin(), newPoints.end(), getBarsForConstant);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
AggregateFunctionSparkbar(const DataTypes & arguments, const Array & params)
|
||||
: IAggregateFunctionDataHelper<AggregateFunctionSparkbarData<X, Y>, AggregateFunctionSparkbar>(
|
||||
arguments, params)
|
||||
{
|
||||
width = params.at(0).safeGet<UInt64>();
|
||||
if (params.size() == 3)
|
||||
{
|
||||
min_x = params.at(1).safeGet<X>();
|
||||
max_x = params.at(2).safeGet<X>();
|
||||
}
|
||||
else
|
||||
{
|
||||
min_x = std::numeric_limits<X>::min();
|
||||
max_x = std::numeric_limits<X>::max();
|
||||
}
|
||||
}
|
||||
|
||||
String getName() const override
|
||||
{
|
||||
return "sparkbar";
|
||||
}
|
||||
|
||||
DataTypePtr getReturnType() const override
|
||||
{
|
||||
return std::make_shared<DataTypeString>();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena * /*arena*/) const override
|
||||
{
|
||||
X x = assert_cast<const ColumnVector<X> *>(columns[0])->getData()[row_num];
|
||||
if (min_x <= x && x <= max_x)
|
||||
{
|
||||
Y y = assert_cast<const ColumnVector<Y> *>(columns[1])->getData()[row_num];
|
||||
this->data(place).add(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena * /*arena*/) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs));
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr __restrict place, WriteBuffer & buf) const override
|
||||
{
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
|
||||
bool allocatesMemoryInArena() const override { return false; }
|
||||
|
||||
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena * /*arena*/) const override
|
||||
{
|
||||
auto & to_column = assert_cast<ColumnString &>(to);
|
||||
const auto & data = this->data(place);
|
||||
const String & value = render(data);
|
||||
to_column.insertData(value.data(), value.size());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ struct StatFuncOneArg
|
||||
using Type1 = T;
|
||||
using Type2 = T;
|
||||
using ResultType = std::conditional_t<std::is_same_v<T, Float32>, Float32, Float64>;
|
||||
using Data = std::conditional_t<IsDecimalNumber<T>, VarMomentsDecimal<Decimal128, _level>, VarMoments<ResultType, _level>>;
|
||||
using Data = std::conditional_t<is_decimal<T>, VarMomentsDecimal<Decimal128, _level>, VarMoments<ResultType, _level>>;
|
||||
|
||||
static constexpr StatisticsFunctionKind kind = _kind;
|
||||
static constexpr UInt32 num_args = 1;
|
||||
@ -75,8 +75,8 @@ class AggregateFunctionVarianceSimple final
|
||||
public:
|
||||
using T1 = typename StatFunc::Type1;
|
||||
using T2 = typename StatFunc::Type2;
|
||||
using ColVecT1 = std::conditional_t<IsDecimalNumber<T1>, ColumnDecimal<T1>, ColumnVector<T1>>;
|
||||
using ColVecT2 = std::conditional_t<IsDecimalNumber<T2>, ColumnDecimal<T2>, ColumnVector<T2>>;
|
||||
using ColVecT1 = ColumnVectorOrDecimal<T1>;
|
||||
using ColVecT2 = ColumnVectorOrDecimal<T2>;
|
||||
using ResultType = typename StatFunc::ResultType;
|
||||
using ColVecResult = ColumnVector<ResultType>;
|
||||
|
||||
@ -132,7 +132,7 @@ public:
|
||||
static_cast<ResultType>(static_cast<const ColVecT2 &>(*columns[1]).getData()[row_num]));
|
||||
else
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T1>)
|
||||
if constexpr (is_decimal<T1>)
|
||||
{
|
||||
this->data(place).add(static_cast<ResultType>(
|
||||
static_cast<const ColVecT1 &>(*columns[0]).getData()[row_num].value));
|
||||
@ -163,7 +163,7 @@ public:
|
||||
const auto & data = this->data(place);
|
||||
auto & dst = static_cast<ColVecResult &>(to).getData();
|
||||
|
||||
if constexpr (IsDecimalNumber<T1>)
|
||||
if constexpr (is_decimal<T1>)
|
||||
{
|
||||
if constexpr (StatFunc::kind == StatisticsFunctionKind::varPop)
|
||||
dst.push_back(data.getPopulation(src_scale * 2));
|
||||
|
@ -20,10 +20,9 @@ template <typename T>
|
||||
struct SumSimple
|
||||
{
|
||||
/// @note It uses slow Decimal128 (cause we need such a variant). sumWithOverflow is faster for Decimal32/64
|
||||
using ResultType = std::conditional_t<IsDecimalNumber<T>,
|
||||
using ResultType = std::conditional_t<is_decimal<T>,
|
||||
std::conditional_t<std::is_same_v<T, Decimal256>, Decimal256, Decimal128>,
|
||||
NearestFieldType<T>>;
|
||||
// using ResultType = std::conditional_t<IsDecimalNumber<T>, Decimal128, NearestFieldType<T>>;
|
||||
using AggregateDataType = AggregateFunctionSumData<ResultType>;
|
||||
using Function = AggregateFunctionSum<T, ResultType, AggregateDataType, AggregateFunctionTypeSum>;
|
||||
};
|
||||
@ -47,7 +46,7 @@ struct SumKahan
|
||||
template <typename T> using AggregateFunctionSumSimple = typename SumSimple<T>::Function;
|
||||
template <typename T> using AggregateFunctionSumWithOverflow = typename SumSameType<T>::Function;
|
||||
template <typename T> using AggregateFunctionSumKahan =
|
||||
std::conditional_t<IsDecimalNumber<T>, typename SumSimple<T>::Function, typename SumKahan<T>::Function>;
|
||||
std::conditional_t<is_decimal<T>, typename SumSimple<T>::Function, typename SumKahan<T>::Function>;
|
||||
|
||||
|
||||
template <template <typename> class Function>
|
||||
|
@ -104,8 +104,8 @@ struct AggregateFunctionSumData
|
||||
const auto * end = ptr + count;
|
||||
|
||||
if constexpr (
|
||||
(is_integer_v<T> && !is_big_int_v<T>)
|
||||
|| (IsDecimalNumber<T> && !std::is_same_v<T, Decimal256> && !std::is_same_v<T, Decimal128>))
|
||||
(is_integer<T> && !is_big_int_v<T>)
|
||||
|| (is_decimal<T> && !std::is_same_v<T, Decimal256> && !std::is_same_v<T, Decimal128>))
|
||||
{
|
||||
/// For integers we can vectorize the operation if we replace the null check using a multiplication (by 0 for null, 1 for not null)
|
||||
/// https://quick-bench.com/q/MLTnfTvwC2qZFVeWHfOBR3U7a8I
|
||||
@ -334,9 +334,7 @@ class AggregateFunctionSum final : public IAggregateFunctionDataHelper<Data, Agg
|
||||
public:
|
||||
static constexpr bool DateTime64Supported = false;
|
||||
|
||||
using ResultDataType = std::conditional_t<IsDecimalNumber<T>, DataTypeDecimal<TResult>, DataTypeNumber<TResult>>;
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
using ColVecResult = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<TResult>, ColumnVector<TResult>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<T>;
|
||||
|
||||
String getName() const override
|
||||
{
|
||||
@ -361,10 +359,13 @@ public:
|
||||
|
||||
DataTypePtr getReturnType() const override
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
return std::make_shared<ResultDataType>(ResultDataType::maxPrecision(), scale);
|
||||
if constexpr (!is_decimal<T>)
|
||||
return std::make_shared<DataTypeNumber<TResult>>();
|
||||
else
|
||||
return std::make_shared<ResultDataType>();
|
||||
{
|
||||
using DataType = DataTypeDecimal<TResult>;
|
||||
return std::make_shared<DataType>(DataType::maxPrecision(), scale);
|
||||
}
|
||||
}
|
||||
|
||||
bool allocatesMemoryInArena() const override { return false; }
|
||||
@ -431,8 +432,7 @@ public:
|
||||
|
||||
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override
|
||||
{
|
||||
auto & column = assert_cast<ColVecResult &>(to);
|
||||
column.getData().push_back(this->data(place).get());
|
||||
castColumnToResult(to).getData().push_back(this->data(place).get());
|
||||
}
|
||||
|
||||
#if USE_EMBEDDED_COMPILER
|
||||
@ -511,6 +511,14 @@ public:
|
||||
|
||||
private:
|
||||
UInt32 scale;
|
||||
|
||||
static constexpr auto & castColumnToResult(IColumn & to)
|
||||
{
|
||||
if constexpr (is_decimal<T>)
|
||||
return assert_cast<ColumnDecimal<TResult> &>(to);
|
||||
else
|
||||
return assert_cast<ColumnVector<TResult> &>(to);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,8 +8,6 @@
|
||||
namespace DB
|
||||
{
|
||||
template <typename T>
|
||||
using DecimalOrNumberDataType = std::conditional_t<IsDecimalNumber<T>, DataTypeDecimal<AvgFieldType<T>>, DataTypeNumber<AvgFieldType<T>>>;
|
||||
template <typename T>
|
||||
class AggregateFunctionSumCount final : public AggregateFunctionAvgBase<AvgFieldType<T>, UInt64, AggregateFunctionSumCount<T>>
|
||||
{
|
||||
public:
|
||||
@ -20,20 +18,13 @@ public:
|
||||
|
||||
DataTypePtr getReturnType() const override
|
||||
{
|
||||
DataTypes types;
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
types.emplace_back(std::make_shared<DecimalOrNumberDataType<T>>(DecimalOrNumberDataType<T>::maxPrecision(), scale));
|
||||
else
|
||||
types.emplace_back(std::make_shared<DecimalOrNumberDataType<T>>());
|
||||
|
||||
types.emplace_back(std::make_shared<DataTypeUInt64>());
|
||||
|
||||
return std::make_shared<DataTypeTuple>(types);
|
||||
auto second_elem = std::make_shared<DataTypeUInt64>();
|
||||
return std::make_shared<DataTypeTuple>(DataTypes{getReturnTypeFirstElement(), std::move(second_elem)});
|
||||
}
|
||||
|
||||
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const final
|
||||
{
|
||||
assert_cast<DecimalOrVectorCol<AvgFieldType<T>> &>((assert_cast<ColumnTuple &>(to)).getColumn(0)).getData().push_back(
|
||||
assert_cast<ColumnVectorOrDecimal<AvgFieldType<T>> &>((assert_cast<ColumnTuple &>(to)).getColumn(0)).getData().push_back(
|
||||
this->data(place).numerator);
|
||||
|
||||
assert_cast<ColumnUInt64 &>((assert_cast<ColumnTuple &>(to)).getColumn(1)).getData().push_back(
|
||||
@ -42,7 +33,7 @@ public:
|
||||
|
||||
void NO_SANITIZE_UNDEFINED add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena *) const final
|
||||
{
|
||||
this->data(place).numerator += static_cast<const DecimalOrVectorCol<T> &>(*columns[0]).getData()[row_num];
|
||||
this->data(place).numerator += static_cast<const ColumnVectorOrDecimal<T> &>(*columns[0]).getData()[row_num];
|
||||
++this->data(place).denominator;
|
||||
}
|
||||
|
||||
@ -59,6 +50,19 @@ public:
|
||||
|
||||
private:
|
||||
UInt32 scale;
|
||||
|
||||
auto getReturnTypeFirstElement() const
|
||||
{
|
||||
using FieldType = AvgFieldType<T>;
|
||||
|
||||
if constexpr (!is_decimal<T>)
|
||||
return std::make_shared<DataTypeNumber<FieldType>>();
|
||||
else
|
||||
{
|
||||
using DataType = DataTypeDecimal<FieldType>;
|
||||
return std::make_shared<DataType>(DataType::maxPrecision(), scale);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public:
|
||||
continue;
|
||||
|
||||
decltype(merged_maps.begin()) it;
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
{
|
||||
// FIXME why is storing NearestFieldType not enough, and we
|
||||
// have to check for decimals again here?
|
||||
@ -217,7 +217,7 @@ public:
|
||||
new_values.resize(size);
|
||||
new_values[col] = value;
|
||||
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
{
|
||||
UInt32 scale = static_cast<const ColumnDecimal<T> &>(key_column).getData().getScale();
|
||||
merged_maps.emplace(DecimalField<T>(key, scale), std::move(new_values));
|
||||
@ -280,7 +280,7 @@ public:
|
||||
for (size_t col = 0; col < values_types.size(); ++col)
|
||||
values_serializations[col]->deserializeBinary(values[col], buf);
|
||||
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
merged_maps[key.get<DecimalField<T>>()] = values;
|
||||
else
|
||||
merged_maps[key.get<T>()] = values;
|
||||
@ -396,7 +396,7 @@ private:
|
||||
using Base = AggregateFunctionMapBase<T, Self, FieldVisitorSum, overflow, tuple_argument, true>;
|
||||
|
||||
/// ARCADIA_BUILD disallow unordered_set for big ints for some reason
|
||||
static constexpr const bool allow_hash = !OverBigInt<T>;
|
||||
static constexpr const bool allow_hash = !is_over_big_int<T>;
|
||||
using ContainerT = std::conditional_t<allow_hash, std::unordered_set<T>, std::set<T>>;
|
||||
|
||||
ContainerT keys_to_keep;
|
||||
|
@ -30,7 +30,7 @@ struct QuantileExactWeighted
|
||||
};
|
||||
|
||||
using Weight = UInt64;
|
||||
using UnderlyingType = typename NativeType<Value>::Type;
|
||||
using UnderlyingType = NativeType<Value>;
|
||||
using Hasher = std::conditional_t<std::is_same_v<Value, Decimal128>, Int128Hash, HashCRC32<UnderlyingType>>;
|
||||
|
||||
/// When creating, the hash table must be small.
|
||||
|
@ -121,7 +121,7 @@ public:
|
||||
{
|
||||
if (samples.empty())
|
||||
{
|
||||
if (DB::IsDecimalNumber<T>)
|
||||
if (DB::is_decimal<T>)
|
||||
return 0;
|
||||
return onEmpty<double>();
|
||||
}
|
||||
@ -134,7 +134,7 @@ public:
|
||||
size_t right_index = left_index + 1;
|
||||
if (right_index == samples.size())
|
||||
{
|
||||
if constexpr (DB::IsDecimalNumber<T>)
|
||||
if constexpr (DB::is_decimal<T>)
|
||||
return static_cast<double>(samples[left_index].value);
|
||||
else
|
||||
return static_cast<double>(samples[left_index]);
|
||||
@ -143,7 +143,7 @@ public:
|
||||
double left_coef = right_index - index;
|
||||
double right_coef = index - left_index;
|
||||
|
||||
if constexpr (DB::IsDecimalNumber<T>)
|
||||
if constexpr (DB::is_decimal<T>)
|
||||
return static_cast<double>(samples[left_index].value) * left_coef + static_cast<double>(samples[right_index].value) * right_coef;
|
||||
else
|
||||
return static_cast<double>(samples[left_index]) * left_coef + static_cast<double>(samples[right_index]) * right_coef;
|
||||
|
@ -50,6 +50,7 @@ void registerAggregateFunctionWelchTTest(AggregateFunctionFactory &);
|
||||
void registerAggregateFunctionStudentTTest(AggregateFunctionFactory &);
|
||||
void registerAggregateFunctionSingleValueOrNull(AggregateFunctionFactory &);
|
||||
void registerAggregateFunctionSequenceNextNode(AggregateFunctionFactory &);
|
||||
void registerAggregateFunctionSparkbar(AggregateFunctionFactory &);
|
||||
|
||||
class AggregateFunctionCombinatorFactory;
|
||||
void registerAggregateFunctionCombinatorIf(AggregateFunctionCombinatorFactory &);
|
||||
@ -119,6 +120,7 @@ void registerAggregateFunctions()
|
||||
registerWindowFunctions(factory);
|
||||
|
||||
registerAggregateFunctionIntervalLengthSum(factory);
|
||||
registerAggregateFunctionSparkbar(factory);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -506,8 +506,9 @@ static void pushBackAndCreateState(ColumnAggregateFunction::Container & data, Ar
|
||||
void ColumnAggregateFunction::insert(const Field & x)
|
||||
{
|
||||
if (x.getType() != Field::Types::AggregateFunctionState)
|
||||
throw Exception(String("Inserting field of type ") + x.getTypeName() + " into ColumnAggregateFunction. "
|
||||
"Expected " + Field::Types::toString(Field::Types::AggregateFunctionState), ErrorCodes::LOGICAL_ERROR);
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"Inserting field of type {} into ColumnAggregateFunction. Expected {}",
|
||||
x.getTypeName(), Field::Types::AggregateFunctionState);
|
||||
|
||||
const auto & field_name = x.get<const AggregateFunctionStateData &>().name;
|
||||
if (type_string != field_name)
|
||||
|
@ -57,9 +57,13 @@ public:
|
||||
*/
|
||||
static ColumnPtr wrap(ColumnPtr column)
|
||||
{
|
||||
/// The order of evaluation of function arguments is unspecified
|
||||
/// and could cause interacting with object in moved-from state
|
||||
const auto size = column->size();
|
||||
const auto bytes = column->allocatedBytes();
|
||||
return ColumnCompressed::create(
|
||||
column->size(),
|
||||
column->allocatedBytes(),
|
||||
size,
|
||||
bytes,
|
||||
[column = std::move(column)]{ return column; });
|
||||
}
|
||||
|
||||
@ -124,4 +128,3 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ template class DecimalPaddedPODArray<Decimal128>;
|
||||
template class DecimalPaddedPODArray<Decimal256>;
|
||||
template class DecimalPaddedPODArray<DateTime64>;
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
int ColumnDecimal<T>::compareAt(size_t n, size_t m, const IColumn & rhs_, int) const
|
||||
{
|
||||
auto & other = static_cast<const Self &>(rhs_);
|
||||
@ -50,7 +50,7 @@ int ColumnDecimal<T>::compareAt(size_t n, size_t m, const IColumn & rhs_, int) c
|
||||
return decimalLess<T>(b, a, other.scale, scale) ? 1 : (decimalLess<T>(a, b, scale, other.scale) ? -1 : 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::compareColumn(const IColumn & rhs, size_t rhs_row_num,
|
||||
PaddedPODArray<UInt64> * row_indexes, PaddedPODArray<Int8> & compare_results,
|
||||
int direction, int nan_direction_hint) const
|
||||
@ -59,13 +59,13 @@ void ColumnDecimal<T>::compareColumn(const IColumn & rhs, size_t rhs_row_num,
|
||||
compare_results, direction, nan_direction_hint);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
bool ColumnDecimal<T>::hasEqualValues() const
|
||||
{
|
||||
return this->template hasEqualValuesImpl<ColumnDecimal<T>>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
StringRef ColumnDecimal<T>::serializeValueIntoArena(size_t n, Arena & arena, char const *& begin) const
|
||||
{
|
||||
auto * pos = arena.allocContinue(sizeof(T), begin);
|
||||
@ -73,20 +73,20 @@ StringRef ColumnDecimal<T>::serializeValueIntoArena(size_t n, Arena & arena, cha
|
||||
return StringRef(pos, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
const char * ColumnDecimal<T>::deserializeAndInsertFromArena(const char * pos)
|
||||
{
|
||||
data.push_back(unalignedLoad<T>(pos));
|
||||
return pos + sizeof(T);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
const char * ColumnDecimal<T>::skipSerializedInArena(const char * pos) const
|
||||
{
|
||||
return pos + sizeof(T);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
UInt64 ColumnDecimal<T>::get64([[maybe_unused]] size_t n) const
|
||||
{
|
||||
if constexpr (sizeof(T) > sizeof(UInt64))
|
||||
@ -95,13 +95,13 @@ UInt64 ColumnDecimal<T>::get64([[maybe_unused]] size_t n) const
|
||||
return static_cast<NativeT>(data[n]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::updateHashWithValue(size_t n, SipHash & hash) const
|
||||
{
|
||||
hash.update(data[n].value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::updateWeakHash32(WeakHash32 & hash) const
|
||||
{
|
||||
auto s = data.size();
|
||||
@ -122,13 +122,13 @@ void ColumnDecimal<T>::updateWeakHash32(WeakHash32 & hash) const
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::updateHashFast(SipHash & hash) const
|
||||
{
|
||||
hash.update(reinterpret_cast<const char *>(data.data()), size() * sizeof(data[0]));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::getPermutation(bool reverse, size_t limit, int , IColumn::Permutation & res) const
|
||||
{
|
||||
#if 1 /// TODO: perf test
|
||||
@ -147,7 +147,7 @@ void ColumnDecimal<T>::getPermutation(bool reverse, size_t limit, int , IColumn:
|
||||
permutation(reverse, limit, res);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::updatePermutation(bool reverse, size_t limit, int, IColumn::Permutation & res, EqualRanges & equal_ranges) const
|
||||
{
|
||||
if (equal_ranges.empty())
|
||||
@ -228,7 +228,7 @@ void ColumnDecimal<T>::updatePermutation(bool reverse, size_t limit, int, IColum
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
ColumnPtr ColumnDecimal<T>::permute(const IColumn::Permutation & perm, size_t limit) const
|
||||
{
|
||||
size_t size = limit ? std::min(data.size(), limit) : data.size();
|
||||
@ -244,7 +244,7 @@ ColumnPtr ColumnDecimal<T>::permute(const IColumn::Permutation & perm, size_t li
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
MutableColumnPtr ColumnDecimal<T>::cloneResized(size_t size) const
|
||||
{
|
||||
auto res = this->create(0, scale);
|
||||
@ -268,7 +268,7 @@ MutableColumnPtr ColumnDecimal<T>::cloneResized(size_t size) const
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::insertData(const char * src, size_t /*length*/)
|
||||
{
|
||||
T tmp;
|
||||
@ -276,7 +276,7 @@ void ColumnDecimal<T>::insertData(const char * src, size_t /*length*/)
|
||||
data.emplace_back(tmp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::insertRangeFrom(const IColumn & src, size_t start, size_t length)
|
||||
{
|
||||
const ColumnDecimal & src_vec = assert_cast<const ColumnDecimal &>(src);
|
||||
@ -292,7 +292,7 @@ void ColumnDecimal<T>::insertRangeFrom(const IColumn & src, size_t start, size_t
|
||||
memcpy(data.data() + old_size, &src_vec.data[start], length * sizeof(data[0]));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
ColumnPtr ColumnDecimal<T>::filter(const IColumn::Filter & filt, ssize_t result_size_hint) const
|
||||
{
|
||||
size_t size = data.size();
|
||||
@ -321,19 +321,19 @@ ColumnPtr ColumnDecimal<T>::filter(const IColumn::Filter & filt, ssize_t result_
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::expand(const IColumn::Filter & mask, bool inverted)
|
||||
{
|
||||
expandDataByMask<T>(data, mask, inverted);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
ColumnPtr ColumnDecimal<T>::index(const IColumn & indexes, size_t limit) const
|
||||
{
|
||||
return selectIndexImpl(*this, indexes, limit);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
ColumnPtr ColumnDecimal<T>::replicate(const IColumn::Offsets & offsets) const
|
||||
{
|
||||
size_t size = data.size();
|
||||
@ -360,13 +360,13 @@ ColumnPtr ColumnDecimal<T>::replicate(const IColumn::Offsets & offsets) const
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::gather(ColumnGathererStream & gatherer)
|
||||
{
|
||||
gatherer.gather(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
ColumnPtr ColumnDecimal<T>::compress() const
|
||||
{
|
||||
size_t source_size = data.size() * sizeof(T);
|
||||
@ -390,7 +390,7 @@ ColumnPtr ColumnDecimal<T>::compress() const
|
||||
});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
void ColumnDecimal<T>::getExtremes(Field & min, Field & max) const
|
||||
{
|
||||
if (data.empty())
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <Core/DecimalFunctions.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <common/sort.h>
|
||||
#include <Core/TypeId.h>
|
||||
#include <Core/TypeName.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -59,11 +61,9 @@ extern template class DecimalPaddedPODArray<Decimal256>;
|
||||
extern template class DecimalPaddedPODArray<DateTime64>;
|
||||
|
||||
/// A ColumnVector for Decimals
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
class ColumnDecimal final : public COWHelper<ColumnVectorHelper, ColumnDecimal<T>>
|
||||
{
|
||||
static_assert(IsDecimalNumber<T>);
|
||||
|
||||
private:
|
||||
using Self = ColumnDecimal;
|
||||
friend class COWHelper<ColumnVectorHelper, Self>;
|
||||
@ -210,7 +210,12 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
template <class> class ColumnVector;
|
||||
template <class T> struct ColumnVectorOrDecimalT { using Col = ColumnVector<T>; };
|
||||
template <is_decimal T> struct ColumnVectorOrDecimalT<T> { using Col = ColumnDecimal<T>; };
|
||||
template <class T> using ColumnVectorOrDecimal = typename ColumnVectorOrDecimalT<T>::Col;
|
||||
|
||||
template <is_decimal T>
|
||||
template <typename Type>
|
||||
ColumnPtr ColumnDecimal<T>::indexImpl(const PaddedPODArray<Type> & indexes, size_t limit) const
|
||||
{
|
||||
|
@ -276,7 +276,10 @@ bool ColumnMap::structureEquals(const IColumn & rhs) const
|
||||
ColumnPtr ColumnMap::compress() const
|
||||
{
|
||||
auto compressed = nested->compress();
|
||||
return ColumnCompressed::create(size(), compressed->byteSize(), [compressed = std::move(compressed)]
|
||||
const auto byte_size = compressed->byteSize();
|
||||
/// The order of evaluation of function arguments is unspecified
|
||||
/// and could cause interacting with object in moved-from state
|
||||
return ColumnCompressed::create(size(), byte_size, [compressed = std::move(compressed)]
|
||||
{
|
||||
return ColumnMap::create(compressed->decompress());
|
||||
});
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <common/unaligned.h>
|
||||
#include <Core/Field.h>
|
||||
#include <Common/assert_cast.h>
|
||||
#include <Core/TypeId.h>
|
||||
#include <Core/TypeName.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -102,7 +104,7 @@ template <class U> struct CompareHelper<Float64, U> : public FloatCompareHelper<
|
||||
template <typename T>
|
||||
class ColumnVector final : public COWHelper<ColumnVectorHelper, ColumnVector<T>>
|
||||
{
|
||||
static_assert(!IsDecimalNumber<T>);
|
||||
static_assert(!is_decimal<T>);
|
||||
|
||||
private:
|
||||
using Self = ColumnVector;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <Columns/ColumnNothing.h>
|
||||
#include <Columns/ColumnsCommon.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <Columns/ColumnLowCardinality.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace DB
|
||||
@ -177,19 +178,21 @@ MaskInfo extractMaskFromConstOrNull(
|
||||
template <bool inverted>
|
||||
MaskInfo extractMaskImpl(
|
||||
PaddedPODArray<UInt8> & mask,
|
||||
const ColumnPtr & column,
|
||||
const ColumnPtr & col,
|
||||
UInt8 null_value,
|
||||
const PaddedPODArray<UInt8> * null_bytemap,
|
||||
PaddedPODArray<UInt8> * nulls = nullptr)
|
||||
{
|
||||
auto column = col->convertToFullColumnIfLowCardinality();
|
||||
|
||||
/// Special implementation for Null and Const columns.
|
||||
if (column->onlyNull() || checkAndGetColumn<ColumnConst>(*column))
|
||||
return extractMaskFromConstOrNull<inverted>(mask, column, null_value, nulls);
|
||||
|
||||
if (const auto * col = checkAndGetColumn<ColumnNullable>(*column))
|
||||
if (const auto * nullable_column = checkAndGetColumn<ColumnNullable>(*column))
|
||||
{
|
||||
const PaddedPODArray<UInt8> & null_map = col->getNullMapData();
|
||||
return extractMaskImpl<inverted>(mask, col->getNestedColumnPtr(), null_value, &null_map, nulls);
|
||||
const PaddedPODArray<UInt8> & null_map = nullable_column->getNullMapData();
|
||||
return extractMaskImpl<inverted>(mask, nullable_column->getNestedColumnPtr(), null_value, &null_map, nulls);
|
||||
}
|
||||
|
||||
MaskInfo mask_info;
|
||||
@ -314,3 +317,4 @@ void copyMask(const PaddedPODArray<UInt8> & from, PaddedPODArray<UInt8> & to)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,6 @@
|
||||
M(523, UNKNOWN_ROW_POLICY) \
|
||||
M(524, ALTER_OF_COLUMN_IS_FORBIDDEN) \
|
||||
M(525, INCORRECT_DISK_INDEX) \
|
||||
M(526, UNKNOWN_VOLUME_TYPE) \
|
||||
M(527, NO_SUITABLE_FUNCTION_IMPLEMENTATION) \
|
||||
M(528, CASSANDRA_INTERNAL_ERROR) \
|
||||
M(529, NOT_A_LEADER) \
|
||||
|
@ -1,39 +0,0 @@
|
||||
#include <Common/ExternalLoaderStatus.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
String toString(ExternalLoaderStatus status)
|
||||
{
|
||||
using Status = ExternalLoaderStatus;
|
||||
switch (status)
|
||||
{
|
||||
case Status::NOT_LOADED: return "NOT_LOADED";
|
||||
case Status::LOADED: return "LOADED";
|
||||
case Status::FAILED: return "FAILED";
|
||||
case Status::LOADING: return "LOADING";
|
||||
case Status::FAILED_AND_RELOADING: return "FAILED_AND_RELOADING";
|
||||
case Status::LOADED_AND_RELOADING: return "LOADED_AND_RELOADING";
|
||||
case Status::NOT_EXIST: return "NOT_EXIST";
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
std::vector<std::pair<String, Int8>> getStatusEnumAllPossibleValues()
|
||||
{
|
||||
using Status = ExternalLoaderStatus;
|
||||
return std::vector<std::pair<String, Int8>>{
|
||||
{toString(Status::NOT_LOADED), static_cast<Int8>(Status::NOT_LOADED)},
|
||||
{toString(Status::LOADED), static_cast<Int8>(Status::LOADED)},
|
||||
{toString(Status::FAILED), static_cast<Int8>(Status::FAILED)},
|
||||
{toString(Status::LOADING), static_cast<Int8>(Status::LOADING)},
|
||||
{toString(Status::LOADED_AND_RELOADING), static_cast<Int8>(Status::LOADED_AND_RELOADING)},
|
||||
{toString(Status::FAILED_AND_RELOADING), static_cast<Int8>(Status::FAILED_AND_RELOADING)},
|
||||
{toString(Status::NOT_EXIST), static_cast<Int8>(Status::NOT_EXIST)},
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, ExternalLoaderStatus status)
|
||||
{
|
||||
return out << toString(status);
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <ostream>
|
||||
#include <common/EnumReflection.h>
|
||||
#include <common/types.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
enum class ExternalLoaderStatus
|
||||
enum class ExternalLoaderStatus : Int8
|
||||
{
|
||||
NOT_LOADED, /// Object hasn't been tried to load. This is an initial state.
|
||||
LOADED, /// Object has been loaded successfully.
|
||||
@ -18,7 +17,14 @@ namespace DB
|
||||
NOT_EXIST, /// Object with this name wasn't found in the configuration.
|
||||
};
|
||||
|
||||
String toString(ExternalLoaderStatus status);
|
||||
std::vector<std::pair<String, Int8>> getStatusEnumAllPossibleValues();
|
||||
std::ostream & operator<<(std::ostream & out, ExternalLoaderStatus status);
|
||||
inline std::vector<std::pair<String, Int8>> getStatusEnumAllPossibleValues()
|
||||
{
|
||||
std::vector<std::pair<String, Int8>> out;
|
||||
out.reserve(magic_enum::enum_count<ExternalLoaderStatus>());
|
||||
|
||||
for (const auto & [value, str] : magic_enum::enum_entries<ExternalLoaderStatus>())
|
||||
out.emplace_back(std::string{str}, static_cast<Int8>(value));
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public:
|
||||
template <typename U, typename = std::enable_if_t<is_big_int_v<U>> >
|
||||
T operator() (const U & x) const
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
return static_cast<T>(static_cast<typename T::NativeType>(x));
|
||||
else if constexpr (std::is_same_v<T, UInt128>)
|
||||
throw Exception("No conversion to old UInt128 from " + demangle(typeid(U).name()), ErrorCodes::NOT_IMPLEMENTED);
|
||||
|
@ -197,12 +197,8 @@ inline size_t DefaultHash64(std::enable_if_t<(sizeof(T) > sizeof(UInt64)), T> ke
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct DefaultHash;
|
||||
|
||||
template <typename T>
|
||||
struct DefaultHash<T, std::enable_if_t<!DB::IsDecimalNumber<T>>>
|
||||
struct DefaultHash
|
||||
{
|
||||
size_t operator() (T key) const
|
||||
{
|
||||
@ -210,8 +206,8 @@ struct DefaultHash<T, std::enable_if_t<!DB::IsDecimalNumber<T>>>
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct DefaultHash<T, std::enable_if_t<DB::IsDecimalNumber<T>>>
|
||||
template <DB::is_decimal T>
|
||||
struct DefaultHash<T>
|
||||
{
|
||||
size_t operator() (T key) const
|
||||
{
|
||||
|
@ -9,23 +9,6 @@ namespace ErrorCodes
|
||||
extern const int SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
const char * IntervalKind::toString() const
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case IntervalKind::Second: return "Second";
|
||||
case IntervalKind::Minute: return "Minute";
|
||||
case IntervalKind::Hour: return "Hour";
|
||||
case IntervalKind::Day: return "Day";
|
||||
case IntervalKind::Week: return "Week";
|
||||
case IntervalKind::Month: return "Month";
|
||||
case IntervalKind::Quarter: return "Quarter";
|
||||
case IntervalKind::Year: return "Year";
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
||||
Int32 IntervalKind::toAvgSeconds() const
|
||||
{
|
||||
switch (kind)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/types.h>
|
||||
|
||||
#include <common/EnumReflection.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -24,7 +24,7 @@ struct IntervalKind
|
||||
IntervalKind(Kind kind_ = Second) : kind(kind_) {}
|
||||
operator Kind() const { return kind; }
|
||||
|
||||
const char * toString() const;
|
||||
constexpr std::string_view toString() const { return magic_enum::enum_name(kind); }
|
||||
|
||||
/// Returns number of seconds in one interval.
|
||||
/// For `Month`, `Quarter` and `Year` the function returns an average number of seconds.
|
||||
|
@ -33,7 +33,7 @@ using ItemPtr = std::unique_ptr<IItem>;
|
||||
class JSONString : public IItem
|
||||
{
|
||||
public:
|
||||
explicit JSONString(std::string value_) : value(std::move(value_)) {}
|
||||
JSONString(std::string_view value_) : value(value_) {}
|
||||
void format(const FormatSettings & settings, FormatContext & context) override;
|
||||
|
||||
private:
|
||||
@ -97,6 +97,7 @@ public:
|
||||
void add(std::string key, ItemPtr value) { values.emplace_back(Pair{.key = std::move(key), .value = std::move(value)}); }
|
||||
void add(std::string key, std::string value) { add(std::move(key), std::make_unique<JSONString>(std::move(value))); }
|
||||
void add(std::string key, const char * value) { add(std::move(key), std::make_unique<JSONString>(value)); }
|
||||
void add(std::string key, std::string_view value) { add(std::move(key), std::make_unique<JSONString>(value)); }
|
||||
void add(std::string key, bool value) { add(std::move(key), std::make_unique<JSONBool>(std::move(value))); }
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_arithmetic<T>::value, bool> = true>
|
||||
|
@ -187,7 +187,7 @@ struct RadixSortIntTraits
|
||||
|
||||
template <typename T>
|
||||
using RadixSortNumTraits = std::conditional_t<
|
||||
is_integer_v<T>,
|
||||
is_integer<T>,
|
||||
std::conditional_t<is_unsigned_v<T>, RadixSortUIntTraits<T>, RadixSortIntTraits<T>>,
|
||||
RadixSortFloatTraits<T>>;
|
||||
|
||||
|
@ -43,7 +43,7 @@ std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 defa
|
||||
|
||||
UInt16 port_number;
|
||||
ReadBufferFromMemory port_buf(port, end - port);
|
||||
if (!tryReadText<UInt16>(port_number, port_buf) || !port_buf.eof())
|
||||
if (!tryReadText(port_number, port_buf) || !port_buf.eof())
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"Illegal port passed to function parseAddress: {}", port);
|
||||
|
@ -13,22 +13,22 @@
|
||||
|
||||
static_assert(is_signed_v<Int128>);
|
||||
static_assert(!is_unsigned_v<Int128>);
|
||||
static_assert(is_integer_v<Int128>);
|
||||
static_assert(is_integer<Int128>);
|
||||
static_assert(sizeof(Int128) == 16);
|
||||
|
||||
static_assert(is_signed_v<Int256>);
|
||||
static_assert(!is_unsigned_v<Int256>);
|
||||
static_assert(is_integer_v<Int256>);
|
||||
static_assert(is_integer<Int256>);
|
||||
static_assert(sizeof(Int256) == 32);
|
||||
|
||||
static_assert(!is_signed_v<UInt128>);
|
||||
static_assert(is_unsigned_v<UInt128>);
|
||||
static_assert(is_integer_v<UInt128>);
|
||||
static_assert(is_integer<UInt128>);
|
||||
static_assert(sizeof(UInt128) == 16);
|
||||
|
||||
static_assert(!is_signed_v<UInt256>);
|
||||
static_assert(is_unsigned_v<UInt256>);
|
||||
static_assert(is_integer_v<UInt256>);
|
||||
static_assert(is_integer<UInt256>);
|
||||
static_assert(sizeof(UInt256) == 32);
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace DB
|
||||
|
||||
std::string CompressionCodecEncrypted::lastErrorString()
|
||||
{
|
||||
std::array<char, 1024> buffer;
|
||||
std::array<char, 1024> buffer{};
|
||||
ERR_error_string_n(ERR_get_error(), buffer.data(), buffer.size());
|
||||
return std::string(buffer.data());
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ auto SequentialGenerator = [](auto stride = 1)
|
||||
template <typename T>
|
||||
using uniform_distribution =
|
||||
typename std::conditional_t<std::is_floating_point_v<T>, std::uniform_real_distribution<T>,
|
||||
typename std::conditional_t<is_integer_v<T>, std::uniform_int_distribution<T>, void>>;
|
||||
typename std::conditional_t<is_integer<T>, std::uniform_int_distribution<T>, void>>;
|
||||
|
||||
|
||||
template <typename T = Int32>
|
||||
|
@ -33,7 +33,7 @@ bool lessOp(A a, B b)
|
||||
return false;
|
||||
|
||||
/// int vs int
|
||||
if constexpr (is_integer_v<A> && is_integer_v<B>)
|
||||
if constexpr (is_integer<A> && is_integer<B>)
|
||||
{
|
||||
/// same signedness
|
||||
if constexpr (is_signed_v<A> == is_signed_v<B>)
|
||||
@ -49,7 +49,7 @@ bool lessOp(A a, B b)
|
||||
}
|
||||
|
||||
/// int vs float
|
||||
if constexpr (is_integer_v<A> && std::is_floating_point_v<B>)
|
||||
if constexpr (is_integer<A> && std::is_floating_point_v<B>)
|
||||
{
|
||||
if constexpr (sizeof(A) <= 4)
|
||||
return static_cast<double>(a) < static_cast<double>(b);
|
||||
@ -57,7 +57,7 @@ bool lessOp(A a, B b)
|
||||
return DecomposedFloat<B>(b).greater(a);
|
||||
}
|
||||
|
||||
if constexpr (std::is_floating_point_v<A> && is_integer_v<B>)
|
||||
if constexpr (std::is_floating_point_v<A> && is_integer<B>)
|
||||
{
|
||||
if constexpr (sizeof(B) <= 4)
|
||||
return static_cast<double>(a) < static_cast<double>(b);
|
||||
@ -65,8 +65,8 @@ bool lessOp(A a, B b)
|
||||
return DecomposedFloat<A>(a).less(b);
|
||||
}
|
||||
|
||||
static_assert(is_integer_v<A> || std::is_floating_point_v<A>);
|
||||
static_assert(is_integer_v<B> || std::is_floating_point_v<B>);
|
||||
static_assert(is_integer<A> || std::is_floating_point_v<A>);
|
||||
static_assert(is_integer<B> || std::is_floating_point_v<B>);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ bool equalsOp(A a, B b)
|
||||
return false;
|
||||
|
||||
/// int vs int
|
||||
if constexpr (is_integer_v<A> && is_integer_v<B>)
|
||||
if constexpr (is_integer<A> && is_integer<B>)
|
||||
{
|
||||
/// same signedness
|
||||
if constexpr (is_signed_v<A> == is_signed_v<B>)
|
||||
@ -125,7 +125,7 @@ bool equalsOp(A a, B b)
|
||||
}
|
||||
|
||||
/// int vs float
|
||||
if constexpr (is_integer_v<A> && std::is_floating_point_v<B>)
|
||||
if constexpr (is_integer<A> && std::is_floating_point_v<B>)
|
||||
{
|
||||
if constexpr (sizeof(A) <= 4)
|
||||
return static_cast<double>(a) == static_cast<double>(b);
|
||||
@ -133,7 +133,7 @@ bool equalsOp(A a, B b)
|
||||
return DecomposedFloat<B>(b).equals(a);
|
||||
}
|
||||
|
||||
if constexpr (std::is_floating_point_v<A> && is_integer_v<B>)
|
||||
if constexpr (std::is_floating_point_v<A> && is_integer<B>)
|
||||
{
|
||||
if constexpr (sizeof(B) <= 4)
|
||||
return static_cast<double>(a) == static_cast<double>(b);
|
||||
|
@ -47,21 +47,21 @@ template <> struct ConstructDecInt<32> { using Type = Int256; };
|
||||
template <typename T, typename U>
|
||||
struct DecCompareInt
|
||||
{
|
||||
using Type = typename ConstructDecInt<(!IsDecimalNumber<U> || sizeof(T) > sizeof(U)) ? sizeof(T) : sizeof(U)>::Type;
|
||||
using Type = typename ConstructDecInt<(!is_decimal<U> || sizeof(T) > sizeof(U)) ? sizeof(T) : sizeof(U)>::Type;
|
||||
using TypeA = Type;
|
||||
using TypeB = Type;
|
||||
};
|
||||
|
||||
///
|
||||
template <typename A, typename B, template <typename, typename> typename Operation, bool _check_overflow = true,
|
||||
bool _actual = IsDecimalNumber<A> || IsDecimalNumber<B>>
|
||||
bool _actual = is_decimal<A> || is_decimal<B>>
|
||||
class DecimalComparison
|
||||
{
|
||||
public:
|
||||
using CompareInt = typename DecCompareInt<A, B>::Type;
|
||||
using Op = Operation<CompareInt, CompareInt>;
|
||||
using ColVecA = std::conditional_t<IsDecimalNumber<A>, ColumnDecimal<A>, ColumnVector<A>>;
|
||||
using ColVecB = std::conditional_t<IsDecimalNumber<B>, ColumnDecimal<B>, ColumnVector<B>>;
|
||||
using ColVecA = ColumnVectorOrDecimal<A>;
|
||||
using ColVecB = ColumnVectorOrDecimal<B>;
|
||||
|
||||
using ArrayA = typename ColVecA::Container;
|
||||
using ArrayB = typename ColVecB::Container;
|
||||
@ -116,7 +116,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
static std::enable_if_t<IsDecimalNumber<T> && IsDecimalNumber<U>, Shift>
|
||||
static std::enable_if_t<is_decimal<T> && is_decimal<U>, Shift>
|
||||
getScales(const DataTypePtr & left_type, const DataTypePtr & right_type)
|
||||
{
|
||||
const DataTypeDecimalBase<T> * decimal0 = checkDecimalBase<T>(*left_type);
|
||||
@ -138,7 +138,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
static std::enable_if_t<IsDecimalNumber<T> && !IsDecimalNumber<U>, Shift>
|
||||
static std::enable_if_t<is_decimal<T> && !is_decimal<U>, Shift>
|
||||
getScales(const DataTypePtr & left_type, const DataTypePtr &)
|
||||
{
|
||||
Shift shift;
|
||||
@ -149,7 +149,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
static std::enable_if_t<!IsDecimalNumber<T> && IsDecimalNumber<U>, Shift>
|
||||
static std::enable_if_t<!is_decimal<T> && is_decimal<U>, Shift>
|
||||
getScales(const DataTypePtr &, const DataTypePtr & right_type)
|
||||
{
|
||||
Shift shift;
|
||||
@ -222,13 +222,13 @@ private:
|
||||
static NO_INLINE UInt8 apply(A a, B b, CompareInt scale [[maybe_unused]])
|
||||
{
|
||||
CompareInt x;
|
||||
if constexpr (IsDecimalNumber<A>)
|
||||
if constexpr (is_decimal<A>)
|
||||
x = a.value;
|
||||
else
|
||||
x = a;
|
||||
|
||||
CompareInt y;
|
||||
if constexpr (IsDecimalNumber<B>)
|
||||
if constexpr (is_decimal<B>)
|
||||
y = b.value;
|
||||
else
|
||||
y = b;
|
||||
|
@ -223,16 +223,16 @@ inline typename DecimalType::NativeType getFractionalPart(const DecimalType & de
|
||||
template <typename To, typename DecimalType, typename ReturnType>
|
||||
ReturnType convertToImpl(const DecimalType & decimal, size_t scale, To & result)
|
||||
{
|
||||
using NativeT = typename DecimalType::NativeType;
|
||||
static constexpr bool throw_exception = std::is_same_v<ReturnType, void>;
|
||||
using DecimalNativeType = typename DecimalType::NativeType;
|
||||
static constexpr bool throw_exception = std::is_void_v<ReturnType>;
|
||||
|
||||
if constexpr (std::is_floating_point_v<To>)
|
||||
{
|
||||
result = static_cast<To>(decimal.value) / static_cast<To>(scaleMultiplier<NativeT>(scale));
|
||||
result = static_cast<To>(decimal.value) / static_cast<To>(scaleMultiplier<DecimalNativeType>(scale));
|
||||
}
|
||||
else if constexpr (is_integer_v<To> && (sizeof(To) >= sizeof(NativeT)))
|
||||
else if constexpr (is_integer<To> && (sizeof(To) >= sizeof(DecimalNativeType)))
|
||||
{
|
||||
NativeT whole = getWholePart(decimal, scale);
|
||||
DecimalNativeType whole = getWholePart(decimal, scale);
|
||||
|
||||
if constexpr (is_unsigned_v<To>)
|
||||
{
|
||||
@ -247,15 +247,14 @@ ReturnType convertToImpl(const DecimalType & decimal, size_t scale, To & result)
|
||||
|
||||
result = static_cast<To>(whole);
|
||||
}
|
||||
else if constexpr (is_integer_v<To>)
|
||||
else if constexpr (is_integer<To>)
|
||||
{
|
||||
using ToNativeT = typename NativeType<To>::Type;
|
||||
using CastTo = std::conditional_t<(is_big_int_v<NativeT> && std::is_same_v<ToNativeT, UInt8>), uint8_t, ToNativeT>;
|
||||
using CastTo = std::conditional_t<(is_big_int_v<DecimalNativeType> && std::is_same_v<To, UInt8>), uint8_t, To>;
|
||||
|
||||
const NativeT whole = getWholePart(decimal, scale);
|
||||
const DecimalNativeType whole = getWholePart(decimal, scale);
|
||||
|
||||
static const constexpr CastTo min_to = std::numeric_limits<ToNativeT>::min();
|
||||
static const constexpr CastTo max_to = std::numeric_limits<ToNativeT>::max();
|
||||
static const constexpr CastTo min_to = std::numeric_limits<To>::min();
|
||||
static const constexpr CastTo max_to = std::numeric_limits<To>::max();
|
||||
|
||||
if (whole < min_to || whole > max_to)
|
||||
{
|
||||
|
@ -487,11 +487,11 @@ template bool decimalLessOrEqual<DateTime64>(DateTime64 x, DateTime64 y, UInt32
|
||||
inline void writeText(const Null & x, WriteBuffer & buf)
|
||||
{
|
||||
if (x.isNegativeInfinity())
|
||||
writeText(std::string("-Inf"), buf);
|
||||
writeText("-Inf", buf);
|
||||
if (x.isPositiveInfinity())
|
||||
writeText(std::string("+Inf"), buf);
|
||||
writeText("+Inf", buf);
|
||||
else
|
||||
writeText(std::string("NULL"), buf);
|
||||
writeText("NULL", buf);
|
||||
}
|
||||
|
||||
String toString(const Field & x)
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <Core/UUID.h>
|
||||
#include <common/DayNum.h>
|
||||
#include <common/strong_typedef.h>
|
||||
|
||||
#include <common/EnumReflection.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -283,33 +283,6 @@ public:
|
||||
Map = 26,
|
||||
UUID = 27,
|
||||
};
|
||||
|
||||
static const char * toString(Which which)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case Null: return "Null";
|
||||
case UInt64: return "UInt64";
|
||||
case UInt128: return "UInt128";
|
||||
case UInt256: return "UInt256";
|
||||
case Int64: return "Int64";
|
||||
case Int128: return "Int128";
|
||||
case Int256: return "Int256";
|
||||
case UUID: return "UUID";
|
||||
case Float64: return "Float64";
|
||||
case String: return "String";
|
||||
case Array: return "Array";
|
||||
case Tuple: return "Tuple";
|
||||
case Map: return "Map";
|
||||
case Decimal32: return "Decimal32";
|
||||
case Decimal64: return "Decimal64";
|
||||
case Decimal128: return "Decimal128";
|
||||
case Decimal256: return "Decimal256";
|
||||
case AggregateFunctionState: return "AggregateFunctionState";
|
||||
}
|
||||
|
||||
throw Exception("Bad type of Field", ErrorCodes::BAD_TYPE_OF_FIELD);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -417,7 +390,8 @@ public:
|
||||
|
||||
|
||||
Types::Which getType() const { return which; }
|
||||
const char * getTypeName() const { return Types::toString(which); }
|
||||
|
||||
constexpr std::string_view getTypeName() const { return magic_enum::enum_name(which); }
|
||||
|
||||
bool isNull() const { return which == Types::Null; }
|
||||
template <typename T>
|
||||
@ -808,7 +782,8 @@ NearestFieldType<std::decay_t<T>> & Field::get()
|
||||
constexpr Field::Types::Which target = TypeToEnum<StoredType>::value;
|
||||
if (target != which
|
||||
&& (!isInt64OrUInt64FieldType(target) || !isInt64OrUInt64FieldType(which)))
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Invalid Field get from type {} to type {}", Types::toString(which), Types::toString(target));
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"Invalid Field get from type {} to type {}", which, target);
|
||||
#endif
|
||||
|
||||
StoredType * MAY_ALIAS ptr = reinterpret_cast<StoredType *>(&storage);
|
||||
@ -821,8 +796,11 @@ template <typename T>
|
||||
auto & Field::safeGet()
|
||||
{
|
||||
const Types::Which requested = TypeToEnum<NearestFieldType<std::decay_t<T>>>::value;
|
||||
|
||||
if (which != requested)
|
||||
throw Exception("Bad get: has " + std::string(getTypeName()) + ", requested " + std::string(Types::toString(requested)), ErrorCodes::BAD_GET);
|
||||
throw Exception(ErrorCodes::BAD_GET,
|
||||
"Bad get: has {}, requested {}", getTypeName(), requested);
|
||||
|
||||
return get<T>();
|
||||
}
|
||||
|
||||
@ -859,12 +837,6 @@ T safeGet(Field & field)
|
||||
return field.template safeGet<T>();
|
||||
}
|
||||
|
||||
template <> inline constexpr const char * TypeName<Array> = "Array";
|
||||
template <> inline constexpr const char * TypeName<Tuple> = "Tuple";
|
||||
template <> inline constexpr const char * TypeName<Map> = "Map";
|
||||
template <> inline constexpr const char * TypeName<AggregateFunctionStateData> = "AggregateFunctionState";
|
||||
|
||||
|
||||
template <typename T>
|
||||
Field::Field(T && rhs, enable_if_not_field_or_bool_or_stringlike_t<T>) //-V730
|
||||
{
|
||||
|
@ -499,7 +499,7 @@ class IColumn;
|
||||
M(UInt64, offset, 0, "Offset on read rows from the most 'end' result for select query", 0) \
|
||||
\
|
||||
M(UInt64, function_range_max_elements_in_block, 500000000, "Maximum number of values generated by function 'range' per block of data (sum of array sizes for every row in a block, see also 'max_block_size' and 'min_insert_block_size_rows'). It is a safety threshold.", 0) \
|
||||
M(ShortCircuitFunctionEvaluation, short_circuit_function_evaluation, ShortCircuitFunctionEvaluation::ENABLE, "Setting for short-circuit function evaluation configuration. Possible values: 'enable', 'disable', 'force_enable'", 0) \
|
||||
M(ShortCircuitFunctionEvaluation, short_circuit_function_evaluation, ShortCircuitFunctionEvaluation::ENABLE, "Setting for short-circuit function evaluation configuration. Possible values: 'enable' - use short-circuit function evaluation for functions that are suitable for it, 'disable' - disable short-circuit function evaluation, 'force_enable' - use short-circuit function evaluation for all functions.", 0) \
|
||||
\
|
||||
M(String, local_filesystem_read_method, "pread", "Method of reading data from local filesystem, one of: read, pread, mmap, pread_threadpool.", 0) \
|
||||
M(Bool, local_filesystem_read_prefetch, false, "Should use prefetching when reading data from local filesystem.", 0) \
|
||||
|
61
src/Core/TypeId.h
Normal file
61
src/Core/TypeId.h
Normal file
@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Types.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
/**
|
||||
* Obtain TypeIndex value from real type if possible.
|
||||
*
|
||||
* Returns TypeIndex::Nothing if type was not present in TypeIndex;
|
||||
* Returns TypeIndex element otherwise.
|
||||
*
|
||||
* @example TypeId<UInt8> == TypeIndex::UInt8
|
||||
* @example TypeId<MySuperType> == TypeIndex::Nothing
|
||||
*/
|
||||
template <class T> inline constexpr TypeIndex TypeId = TypeIndex::Nothing;
|
||||
|
||||
template <TypeIndex index> struct ReverseTypeIdT : std::false_type {};
|
||||
|
||||
/**
|
||||
* Obtain real type from TypeIndex if possible.
|
||||
*
|
||||
* Returns a type alias if is corresponds to TypeIndex value.
|
||||
* Yields a compiler error otherwise.
|
||||
*
|
||||
* @example ReverseTypeId<TypeIndex::UInt8> == UInt8
|
||||
*/
|
||||
template <TypeIndex index> using ReverseTypeId = typename ReverseTypeIdT<index>::T;
|
||||
template <TypeIndex index> constexpr bool HasReverseTypeId = ReverseTypeIdT<index>::value;
|
||||
|
||||
#define TYPEID_MAP(_A) \
|
||||
template <> inline constexpr TypeIndex TypeId<_A> = TypeIndex::_A; \
|
||||
template <> struct ReverseTypeIdT<TypeIndex::_A> : std::true_type { using T = _A; };
|
||||
|
||||
TYPEID_MAP(UInt8)
|
||||
TYPEID_MAP(UInt16)
|
||||
TYPEID_MAP(UInt32)
|
||||
TYPEID_MAP(UInt64)
|
||||
TYPEID_MAP(UInt128)
|
||||
TYPEID_MAP(UInt256)
|
||||
TYPEID_MAP(Int8)
|
||||
TYPEID_MAP(Int16)
|
||||
TYPEID_MAP(Int32)
|
||||
TYPEID_MAP(Int64)
|
||||
TYPEID_MAP(Int128)
|
||||
TYPEID_MAP(Int256)
|
||||
TYPEID_MAP(Float32)
|
||||
TYPEID_MAP(Float64)
|
||||
TYPEID_MAP(UUID)
|
||||
|
||||
TYPEID_MAP(Decimal32)
|
||||
TYPEID_MAP(Decimal64)
|
||||
TYPEID_MAP(Decimal128)
|
||||
TYPEID_MAP(Decimal256)
|
||||
TYPEID_MAP(DateTime64)
|
||||
|
||||
TYPEID_MAP(String)
|
||||
|
||||
struct Array;
|
||||
TYPEID_MAP(Array)
|
||||
}
|
39
src/Core/TypeName.h
Normal file
39
src/Core/TypeName.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Types.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
struct Array;
|
||||
struct Tuple;
|
||||
struct Map;
|
||||
struct AggregateFunctionStateData;
|
||||
|
||||
template <class T> constexpr const char * TypeName = "";
|
||||
|
||||
template <> inline constexpr const char * TypeName<UInt8> = "UInt8";
|
||||
template <> inline constexpr const char * TypeName<UInt16> = "UInt16";
|
||||
template <> inline constexpr const char * TypeName<UInt32> = "UInt32";
|
||||
template <> inline constexpr const char * TypeName<UInt64> = "UInt64";
|
||||
template <> inline constexpr const char * TypeName<UInt128> = "UInt128";
|
||||
template <> inline constexpr const char * TypeName<UInt256> = "UInt256";
|
||||
template <> inline constexpr const char * TypeName<Int8> = "Int8";
|
||||
template <> inline constexpr const char * TypeName<Int16> = "Int16";
|
||||
template <> inline constexpr const char * TypeName<Int32> = "Int32";
|
||||
template <> inline constexpr const char * TypeName<Int64> = "Int64";
|
||||
template <> inline constexpr const char * TypeName<Int128> = "Int128";
|
||||
template <> inline constexpr const char * TypeName<Int256> = "Int256";
|
||||
template <> inline constexpr const char * TypeName<Float32> = "Float32";
|
||||
template <> inline constexpr const char * TypeName<Float64> = "Float64";
|
||||
template <> inline constexpr const char * TypeName<String> = "String";
|
||||
template <> inline constexpr const char * TypeName<UUID> = "UUID";
|
||||
template <> inline constexpr const char * TypeName<Decimal32> = "Decimal32";
|
||||
template <> inline constexpr const char * TypeName<Decimal64> = "Decimal64";
|
||||
template <> inline constexpr const char * TypeName<Decimal128> = "Decimal128";
|
||||
template <> inline constexpr const char * TypeName<Decimal256> = "Decimal256";
|
||||
template <> inline constexpr const char * TypeName<DateTime64> = "DateTime64";
|
||||
template <> inline constexpr const char * TypeName<Array> = "Array";
|
||||
template <> inline constexpr const char * TypeName<Tuple> = "Tuple";
|
||||
template <> inline constexpr const char * TypeName<Map> = "Map";
|
||||
template <> inline constexpr const char * TypeName<AggregateFunctionStateData> = "AggregateFunctionState";
|
||||
}
|
250
src/Core/Types.h
250
src/Core/Types.h
@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <common/strong_typedef.h>
|
||||
#include <common/extended_types.h>
|
||||
#include <common/Decimal.h>
|
||||
#include <common/defines.h>
|
||||
|
||||
|
||||
@ -99,254 +99,6 @@ using Int256 = ::Int256;
|
||||
|
||||
STRONG_TYPEDEF(UInt128, UUID)
|
||||
|
||||
|
||||
template <typename T> constexpr const char * TypeName = "";
|
||||
|
||||
template <> inline constexpr const char * TypeName<UInt8> = "UInt8";
|
||||
template <> inline constexpr const char * TypeName<UInt16> = "UInt16";
|
||||
template <> inline constexpr const char * TypeName<UInt32> = "UInt32";
|
||||
template <> inline constexpr const char * TypeName<UInt64> = "UInt64";
|
||||
template <> inline constexpr const char * TypeName<UInt128> = "UInt128";
|
||||
template <> inline constexpr const char * TypeName<UInt256> = "UInt256";
|
||||
template <> inline constexpr const char * TypeName<Int8> = "Int8";
|
||||
template <> inline constexpr const char * TypeName<Int16> = "Int16";
|
||||
template <> inline constexpr const char * TypeName<Int32> = "Int32";
|
||||
template <> inline constexpr const char * TypeName<Int64> = "Int64";
|
||||
template <> inline constexpr const char * TypeName<Int128> = "Int128";
|
||||
template <> inline constexpr const char * TypeName<Int256> = "Int256";
|
||||
template <> inline constexpr const char * TypeName<Float32> = "Float32";
|
||||
template <> inline constexpr const char * TypeName<Float64> = "Float64";
|
||||
template <> inline constexpr const char * TypeName<String> = "String";
|
||||
template <> inline constexpr const char * TypeName<UUID> = "UUID";
|
||||
|
||||
/// TODO Try to remove it.
|
||||
template <typename T> constexpr TypeIndex TypeId = TypeIndex::Nothing;
|
||||
template <> inline constexpr TypeIndex TypeId<UInt8> = TypeIndex::UInt8;
|
||||
template <> inline constexpr TypeIndex TypeId<UInt16> = TypeIndex::UInt16;
|
||||
template <> inline constexpr TypeIndex TypeId<UInt32> = TypeIndex::UInt32;
|
||||
template <> inline constexpr TypeIndex TypeId<UInt64> = TypeIndex::UInt64;
|
||||
template <> inline constexpr TypeIndex TypeId<UInt128> = TypeIndex::UInt128;
|
||||
template <> inline constexpr TypeIndex TypeId<UInt256> = TypeIndex::UInt256;
|
||||
template <> inline constexpr TypeIndex TypeId<Int8> = TypeIndex::Int8;
|
||||
template <> inline constexpr TypeIndex TypeId<Int16> = TypeIndex::Int16;
|
||||
template <> inline constexpr TypeIndex TypeId<Int32> = TypeIndex::Int32;
|
||||
template <> inline constexpr TypeIndex TypeId<Int64> = TypeIndex::Int64;
|
||||
template <> inline constexpr TypeIndex TypeId<Int128> = TypeIndex::Int128;
|
||||
template <> inline constexpr TypeIndex TypeId<Int256> = TypeIndex::Int256;
|
||||
template <> inline constexpr TypeIndex TypeId<Float32> = TypeIndex::Float32;
|
||||
template <> inline constexpr TypeIndex TypeId<Float64> = TypeIndex::Float64;
|
||||
template <> inline constexpr TypeIndex TypeId<UUID> = TypeIndex::UUID;
|
||||
|
||||
|
||||
/// Not a data type in database, defined just for convenience.
|
||||
using Strings = std::vector<String>;
|
||||
|
||||
/// Own FieldType for Decimal.
|
||||
/// It is only a "storage" for decimal. To perform operations, you also have to provide a scale (number of digits after point).
|
||||
template <typename T>
|
||||
struct Decimal
|
||||
{
|
||||
using NativeType = T;
|
||||
|
||||
Decimal() = default;
|
||||
Decimal(Decimal<T> &&) = default;
|
||||
Decimal(const Decimal<T> &) = default;
|
||||
|
||||
Decimal(const T & value_)
|
||||
: value(value_)
|
||||
{}
|
||||
|
||||
template <typename U>
|
||||
Decimal(const Decimal<U> & x)
|
||||
: value(x.value)
|
||||
{}
|
||||
|
||||
constexpr Decimal<T> & operator = (Decimal<T> &&) = default;
|
||||
constexpr Decimal<T> & operator = (const Decimal<T> &) = default;
|
||||
|
||||
operator T () const { return value; }
|
||||
|
||||
template <typename U>
|
||||
U convertTo() const
|
||||
{
|
||||
/// no IsDecimalNumber defined yet
|
||||
if constexpr (std::is_same_v<U, Decimal<Int32>> ||
|
||||
std::is_same_v<U, Decimal<Int64>> ||
|
||||
std::is_same_v<U, Decimal<Int128>> ||
|
||||
std::is_same_v<U, Decimal<Int256>>)
|
||||
{
|
||||
return convertTo<typename U::NativeType>();
|
||||
}
|
||||
else
|
||||
return static_cast<U>(value);
|
||||
}
|
||||
|
||||
const Decimal<T> & operator += (const T & x) { value += x; return *this; }
|
||||
const Decimal<T> & operator -= (const T & x) { value -= x; return *this; }
|
||||
const Decimal<T> & operator *= (const T & x) { value *= x; return *this; }
|
||||
const Decimal<T> & operator /= (const T & x) { value /= x; return *this; }
|
||||
const Decimal<T> & operator %= (const T & x) { value %= x; return *this; }
|
||||
|
||||
template <typename U> const Decimal<T> & operator += (const Decimal<U> & x) { value += x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator -= (const Decimal<U> & x) { value -= x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator *= (const Decimal<U> & x) { value *= x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator /= (const Decimal<U> & x) { value /= x.value; return *this; }
|
||||
template <typename U> const Decimal<T> & operator %= (const Decimal<U> & x) { value %= x.value; return *this; }
|
||||
|
||||
/// This is to avoid UB for sumWithOverflow()
|
||||
void NO_SANITIZE_UNDEFINED addOverflow(const T & x) { value += x; }
|
||||
|
||||
T value;
|
||||
};
|
||||
|
||||
template <typename T> inline bool operator< (const Decimal<T> & x, const Decimal<T> & y) { return x.value < y.value; }
|
||||
template <typename T> inline bool operator> (const Decimal<T> & x, const Decimal<T> & y) { return x.value > y.value; }
|
||||
template <typename T> inline bool operator<= (const Decimal<T> & x, const Decimal<T> & y) { return x.value <= y.value; }
|
||||
template <typename T> inline bool operator>= (const Decimal<T> & x, const Decimal<T> & y) { return x.value >= y.value; }
|
||||
template <typename T> inline bool operator== (const Decimal<T> & x, const Decimal<T> & y) { return x.value == y.value; }
|
||||
template <typename T> inline bool operator!= (const Decimal<T> & x, const Decimal<T> & y) { return x.value != y.value; }
|
||||
|
||||
template <typename T> inline Decimal<T> operator+ (const Decimal<T> & x, const Decimal<T> & y) { return x.value + y.value; }
|
||||
template <typename T> inline Decimal<T> operator- (const Decimal<T> & x, const Decimal<T> & y) { return x.value - y.value; }
|
||||
template <typename T> inline Decimal<T> operator* (const Decimal<T> & x, const Decimal<T> & y) { return x.value * y.value; }
|
||||
template <typename T> inline Decimal<T> operator/ (const Decimal<T> & x, const Decimal<T> & y) { return x.value / y.value; }
|
||||
template <typename T> inline Decimal<T> operator- (const Decimal<T> & x) { return -x.value; }
|
||||
|
||||
using Decimal32 = Decimal<Int32>;
|
||||
using Decimal64 = Decimal<Int64>;
|
||||
using Decimal128 = Decimal<Int128>;
|
||||
using Decimal256 = Decimal<Int256>;
|
||||
|
||||
// Distinguishable type to allow function resolution/deduction based on value type,
|
||||
// but also relatively easy to convert to/from Decimal64.
|
||||
class DateTime64 : public Decimal64
|
||||
{
|
||||
public:
|
||||
using Base = Decimal64;
|
||||
using Base::Base;
|
||||
|
||||
DateTime64(const Base & v)
|
||||
: Base(v)
|
||||
{}
|
||||
};
|
||||
|
||||
template <> inline constexpr const char * TypeName<Decimal32> = "Decimal32";
|
||||
template <> inline constexpr const char * TypeName<Decimal64> = "Decimal64";
|
||||
template <> inline constexpr const char * TypeName<Decimal128> = "Decimal128";
|
||||
template <> inline constexpr const char * TypeName<Decimal256> = "Decimal256";
|
||||
template <> inline constexpr const char * TypeName<DateTime64> = "DateTime64";
|
||||
|
||||
template <> inline constexpr TypeIndex TypeId<Decimal32> = TypeIndex::Decimal32;
|
||||
template <> inline constexpr TypeIndex TypeId<Decimal64> = TypeIndex::Decimal64;
|
||||
template <> inline constexpr TypeIndex TypeId<Decimal128> = TypeIndex::Decimal128;
|
||||
template <> inline constexpr TypeIndex TypeId<Decimal256> = TypeIndex::Decimal256;
|
||||
template <> inline constexpr TypeIndex TypeId<DateTime64> = TypeIndex::DateTime64;
|
||||
|
||||
template <typename T> constexpr bool IsDecimalNumber = false;
|
||||
template <> inline constexpr bool IsDecimalNumber<Decimal32> = true;
|
||||
template <> inline constexpr bool IsDecimalNumber<Decimal64> = true;
|
||||
template <> inline constexpr bool IsDecimalNumber<Decimal128> = true;
|
||||
template <> inline constexpr bool IsDecimalNumber<Decimal256> = true;
|
||||
template <> inline constexpr bool IsDecimalNumber<DateTime64> = true;
|
||||
|
||||
template <typename T> struct NativeType { using Type = T; };
|
||||
template <> struct NativeType<Decimal32> { using Type = Int32; };
|
||||
template <> struct NativeType<Decimal64> { using Type = Int64; };
|
||||
template <> struct NativeType<Decimal128> { using Type = Int128; };
|
||||
template <> struct NativeType<Decimal256> { using Type = Int256; };
|
||||
template <> struct NativeType<DateTime64> { using Type = Int64; };
|
||||
|
||||
template <typename T> constexpr bool OverBigInt = false;
|
||||
template <> inline constexpr bool OverBigInt<Int128> = true;
|
||||
template <> inline constexpr bool OverBigInt<UInt128> = true;
|
||||
template <> inline constexpr bool OverBigInt<Int256> = true;
|
||||
template <> inline constexpr bool OverBigInt<UInt256> = true;
|
||||
template <> inline constexpr bool OverBigInt<Decimal128> = true;
|
||||
template <> inline constexpr bool OverBigInt<Decimal256> = true;
|
||||
|
||||
inline constexpr const char * getTypeName(TypeIndex idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case TypeIndex::Nothing: return "Nothing";
|
||||
case TypeIndex::UInt8: return "UInt8";
|
||||
case TypeIndex::UInt16: return "UInt16";
|
||||
case TypeIndex::UInt32: return "UInt32";
|
||||
case TypeIndex::UInt64: return "UInt64";
|
||||
case TypeIndex::UInt128: return "UInt128";
|
||||
case TypeIndex::UInt256: return "UInt256";
|
||||
case TypeIndex::Int8: return "Int8";
|
||||
case TypeIndex::Int16: return "Int16";
|
||||
case TypeIndex::Int32: return "Int32";
|
||||
case TypeIndex::Int64: return "Int64";
|
||||
case TypeIndex::Int128: return "Int128";
|
||||
case TypeIndex::Int256: return "Int256";
|
||||
case TypeIndex::Float32: return "Float32";
|
||||
case TypeIndex::Float64: return "Float64";
|
||||
case TypeIndex::Date: return "Date";
|
||||
case TypeIndex::Date32: return "Date32";
|
||||
case TypeIndex::DateTime: return "DateTime";
|
||||
case TypeIndex::DateTime64: return "DateTime64";
|
||||
case TypeIndex::String: return "String";
|
||||
case TypeIndex::FixedString: return "FixedString";
|
||||
case TypeIndex::Enum8: return "Enum8";
|
||||
case TypeIndex::Enum16: return "Enum16";
|
||||
case TypeIndex::Decimal32: return "Decimal32";
|
||||
case TypeIndex::Decimal64: return "Decimal64";
|
||||
case TypeIndex::Decimal128: return "Decimal128";
|
||||
case TypeIndex::Decimal256: return "Decimal256";
|
||||
case TypeIndex::UUID: return "UUID";
|
||||
case TypeIndex::Array: return "Array";
|
||||
case TypeIndex::Tuple: return "Tuple";
|
||||
case TypeIndex::Set: return "Set";
|
||||
case TypeIndex::Interval: return "Interval";
|
||||
case TypeIndex::Nullable: return "Nullable";
|
||||
case TypeIndex::Function: return "Function";
|
||||
case TypeIndex::AggregateFunction: return "AggregateFunction";
|
||||
case TypeIndex::LowCardinality: return "LowCardinality";
|
||||
case TypeIndex::Map: return "Map";
|
||||
}
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Specialization of `std::hash` for the Decimal<T> types.
|
||||
namespace std
|
||||
{
|
||||
template <typename T>
|
||||
struct hash<DB::Decimal<T>> { size_t operator()(const DB::Decimal<T> & x) const { return hash<T>()(x.value); } };
|
||||
|
||||
template <>
|
||||
struct hash<DB::Decimal128>
|
||||
{
|
||||
size_t operator()(const DB::Decimal128 & x) const
|
||||
{
|
||||
return std::hash<DB::Int64>()(x.value >> 64)
|
||||
^ std::hash<DB::Int64>()(x.value & std::numeric_limits<DB::UInt64>::max());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<DB::DateTime64>
|
||||
{
|
||||
size_t operator()(const DB::DateTime64 & x) const
|
||||
{
|
||||
return std::hash<std::decay_t<decltype(x)>::NativeType>()(x);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct hash<DB::Decimal256>
|
||||
{
|
||||
size_t operator()(const DB::Decimal256 & x) const
|
||||
{
|
||||
// temp solution
|
||||
static constexpr DB::UInt64 max_uint_mask = std::numeric_limits<DB::UInt64>::max();
|
||||
return std::hash<DB::Int64>()(static_cast<DB::Int64>(x.value >> 64 & max_uint_mask))
|
||||
^ std::hash<DB::Int64>()(static_cast<DB::Int64>(x.value & max_uint_mask));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ class DataTypeDateTime;
|
||||
class DataTypeDateTime64;
|
||||
template <typename T> class DataTypeEnum;
|
||||
template <typename T> class DataTypeNumber;
|
||||
template <typename T> class DataTypeDecimal;
|
||||
template <is_decimal T> class DataTypeDecimal;
|
||||
|
||||
|
||||
template <typename T, typename F, typename... ExtraArgs>
|
||||
|
@ -28,19 +28,19 @@ bool decimalCheckArithmeticOverflow(ContextPtr context)
|
||||
return context->getSettingsRef().decimal_check_overflow;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
Field DataTypeDecimalBase<T>::getDefault() const
|
||||
{
|
||||
return DecimalField(T(0), scale);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
MutableColumnPtr DataTypeDecimalBase<T>::createColumn() const
|
||||
{
|
||||
return ColumnType::create(0, scale);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
T DataTypeDecimalBase<T>::getScaleMultiplier(UInt32 scale_)
|
||||
{
|
||||
return DecimalUtils::scaleMultiplier<typename T::NativeType>(scale_);
|
||||
|
@ -53,11 +53,9 @@ inline UInt32 leastDecimalPrecisionFor(TypeIndex int_type)
|
||||
/// Operation between two decimals leads to Decimal(P, S), where
|
||||
/// P is one of (9, 18, 38, 76); equals to the maximum precision for the biggest underlying type of operands.
|
||||
/// S is maximum scale of operands. The allowed valuas are [0, precision]
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
class DataTypeDecimalBase : public IDataType
|
||||
{
|
||||
static_assert(IsDecimalNumber<T>);
|
||||
|
||||
public:
|
||||
using FieldType = T;
|
||||
using ColumnType = ColumnDecimal<T>;
|
||||
|
@ -134,7 +134,8 @@ Field DataTypeEnum<Type>::castToName(const Field & value_or_name) const
|
||||
return this->getNameForValue(static_cast<Type>(value)).toString();
|
||||
}
|
||||
else
|
||||
throw Exception(String("DataTypeEnum: Unsupported type of field ") + value_or_name.getTypeName(), ErrorCodes::BAD_TYPE_OF_FIELD);
|
||||
throw Exception(ErrorCodes::BAD_TYPE_OF_FIELD,
|
||||
"DataTypeEnum: Unsupported type of field {}", value_or_name.getTypeName());
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
@ -153,7 +154,8 @@ Field DataTypeEnum<Type>::castToValue(const Field & value_or_name) const
|
||||
return value;
|
||||
}
|
||||
else
|
||||
throw Exception(String("DataTypeEnum: Unsupported type of field ") + value_or_name.getTypeName(), ErrorCodes::BAD_TYPE_OF_FIELD);
|
||||
throw Exception(ErrorCodes::BAD_TYPE_OF_FIELD,
|
||||
"DataTypeEnum: Unsupported type of field {}", value_or_name.getTypeName());
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
DataTypeInterval(IntervalKind kind_) : kind(kind_) {}
|
||||
|
||||
std::string doGetName() const override { return std::string("Interval") + kind.toString(); }
|
||||
std::string doGetName() const override { return fmt::format("Interval{}", kind.toString()); }
|
||||
const char * getFamilyName() const override { return "Interval"; }
|
||||
TypeIndex getTypeId() const override { return TypeIndex::Interval; }
|
||||
|
||||
|
@ -28,13 +28,13 @@ MutableColumnPtr DataTypeNumberBase<T>::createColumn() const
|
||||
template <typename T>
|
||||
bool DataTypeNumberBase<T>::isValueRepresentedByInteger() const
|
||||
{
|
||||
return is_integer_v<T>;
|
||||
return is_integer<T>;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DataTypeNumberBase<T>::isValueRepresentedByUnsignedInteger() const
|
||||
{
|
||||
return is_integer_v<T> && is_unsigned_v<T>;
|
||||
return is_integer<T> && is_unsigned_v<T>;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,14 +25,14 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
std::string DataTypeDecimal<T>::doGetName() const
|
||||
{
|
||||
return fmt::format("Decimal({}, {})", this->precision, this->scale);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
bool DataTypeDecimal<T>::equals(const IDataType & rhs) const
|
||||
{
|
||||
if (auto * ptype = typeid_cast<const DataTypeDecimal<T> *>(&rhs))
|
||||
@ -40,14 +40,14 @@ bool DataTypeDecimal<T>::equals(const IDataType & rhs) const
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
DataTypePtr DataTypeDecimal<T>::promoteNumericType() const
|
||||
{
|
||||
using PromotedType = DataTypeDecimal<Decimal128>;
|
||||
return std::make_shared<PromotedType>(PromotedType::maxPrecision(), this->scale);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
T DataTypeDecimal<T>::parseFromString(const String & str) const
|
||||
{
|
||||
ReadBufferFromMemory buf(str.data(), str.size());
|
||||
@ -61,7 +61,7 @@ T DataTypeDecimal<T>::parseFromString(const String & str) const
|
||||
return x;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
SerializationPtr DataTypeDecimal<T>::doGetDefaultSerialization() const
|
||||
{
|
||||
return std::make_shared<SerializationDecimal<T>>(this->precision, this->scale);
|
||||
|
@ -24,11 +24,10 @@ namespace ErrorCodes
|
||||
/// Operation between two decimals leads to Decimal(P, S), where
|
||||
/// P is one of (9, 18, 38, 76); equals to the maximum precision for the biggest underlying type of operands.
|
||||
/// S is maximum scale of operands. The allowed valuas are [0, precision]
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
class DataTypeDecimal final : public DataTypeDecimalBase<T>
|
||||
{
|
||||
using Base = DataTypeDecimalBase<T>;
|
||||
static_assert(IsDecimalNumber<T>);
|
||||
|
||||
public:
|
||||
using typename Base::FieldType;
|
||||
@ -48,6 +47,11 @@ public:
|
||||
SerializationPtr doGetDefaultSerialization() const override;
|
||||
};
|
||||
|
||||
using DataTypeDecimal32 = DataTypeDecimal<Decimal32>;
|
||||
using DataTypeDecimal64 = DataTypeDecimal<Decimal64>;
|
||||
using DataTypeDecimal128 = DataTypeDecimal<Decimal128>;
|
||||
using DataTypeDecimal256 = DataTypeDecimal<Decimal256>;
|
||||
|
||||
template <typename T>
|
||||
inline const DataTypeDecimal<T> * checkDecimal(const IDataType & data_type)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <Common/COW.h>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <Core/Names.h>
|
||||
#include <Core/Types.h>
|
||||
#include <Core/TypeId.h>
|
||||
#include <DataTypes/DataTypeCustom.h>
|
||||
|
||||
|
||||
@ -490,7 +490,7 @@ template <typename DataType> constexpr bool IsDataTypeDateOrDateTime = false;
|
||||
|
||||
template <typename DataType> constexpr bool IsDataTypeDecimalOrNumber = IsDataTypeDecimal<DataType> || IsDataTypeNumber<DataType>;
|
||||
|
||||
template <typename T>
|
||||
template <is_decimal T>
|
||||
class DataTypeDecimal;
|
||||
|
||||
template <typename T>
|
||||
@ -501,7 +501,7 @@ class DataTypeDate32;
|
||||
class DataTypeDateTime;
|
||||
class DataTypeDateTime64;
|
||||
|
||||
template <typename T> constexpr bool IsDataTypeDecimal<DataTypeDecimal<T>> = true;
|
||||
template <is_decimal T> constexpr bool IsDataTypeDecimal<DataTypeDecimal<T>> = true;
|
||||
template <> inline constexpr bool IsDataTypeDecimal<DataTypeDateTime64> = true;
|
||||
|
||||
template <typename T> constexpr bool IsDataTypeNumber<DataTypeNumber<T>> = true;
|
||||
|
@ -172,14 +172,14 @@ template <typename A, typename B>
|
||||
struct ResultOfIf
|
||||
{
|
||||
static constexpr bool has_float = std::is_floating_point_v<A> || std::is_floating_point_v<B>;
|
||||
static constexpr bool has_integer = is_integer_v<A> || is_integer_v<B>;
|
||||
static constexpr bool has_integer = is_integer<A> || is_integer<B>;
|
||||
static constexpr bool has_signed = is_signed_v<A> || is_signed_v<B>;
|
||||
static constexpr bool has_unsigned = !is_signed_v<A> || !is_signed_v<B>;
|
||||
static constexpr bool has_big_int = is_big_int_v<A> || is_big_int_v<B>;
|
||||
|
||||
static constexpr size_t max_size_of_unsigned_integer = max(is_signed_v<A> ? 0 : sizeof(A), is_signed_v<B> ? 0 : sizeof(B));
|
||||
static constexpr size_t max_size_of_signed_integer = max(is_signed_v<A> ? sizeof(A) : 0, is_signed_v<B> ? sizeof(B) : 0);
|
||||
static constexpr size_t max_size_of_integer = max(is_integer_v<A> ? sizeof(A) : 0, is_integer_v<B> ? sizeof(B) : 0);
|
||||
static constexpr size_t max_size_of_integer = max(is_integer<A> ? sizeof(A) : 0, is_integer<B> ? sizeof(B) : 0);
|
||||
static constexpr size_t max_size_of_float = max(std::is_floating_point_v<A> ? sizeof(A) : 0, std::is_floating_point_v<B> ? sizeof(B) : 0);
|
||||
|
||||
using ConstructedType = typename Construct<has_signed, has_float,
|
||||
@ -190,9 +190,9 @@ struct ResultOfIf
|
||||
|
||||
using Type =
|
||||
std::conditional_t<std::is_same_v<A, B>, A,
|
||||
std::conditional_t<IsDecimalNumber<A> && IsDecimalNumber<B>,
|
||||
std::conditional_t<is_decimal<A> && is_decimal<B>,
|
||||
std::conditional_t<(sizeof(A) > sizeof(B)), A, B>,
|
||||
std::conditional_t<!IsDecimalNumber<A> && !IsDecimalNumber<B>,
|
||||
std::conditional_t<!is_decimal<A> && !is_decimal<B>,
|
||||
ConstructedType, Error>>>;
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ void SerializationNumber<T>::deserializeText(IColumn & column, ReadBuffer & istr
|
||||
{
|
||||
T x;
|
||||
|
||||
if constexpr (is_integer_v<T> && is_arithmetic_v<T>)
|
||||
if constexpr (is_integer<T> && is_arithmetic_v<T>)
|
||||
readIntTextUnsafe(x, istr);
|
||||
else
|
||||
readText(x, istr);
|
||||
|
@ -26,10 +26,8 @@ String getExceptionMessage(
|
||||
const String & message, size_t argument_index, const char * argument_name,
|
||||
const std::string & context_data_type_name, Field::Types::Which field_type)
|
||||
{
|
||||
return std::string("Parameter #") + std::to_string(argument_index) + " '"
|
||||
+ argument_name + "' for " + context_data_type_name
|
||||
+ message
|
||||
+ ", expected: " + Field::Types::toString(field_type) + " literal.";
|
||||
return fmt::format("Parameter #{} '{}' for {}{}, expected {} literal",
|
||||
argument_index, argument_name, context_data_type_name, message, field_type);
|
||||
}
|
||||
|
||||
template <typename T, ArgumentKind Kind>
|
||||
@ -49,7 +47,7 @@ getArgument(const ASTPtr & arguments, size_t argument_index, const char * argume
|
||||
else
|
||||
{
|
||||
if (argument && argument->value.getType() != field_type)
|
||||
throw Exception(getExceptionMessage(String(" has wrong type: ") + argument->value.getTypeName(),
|
||||
throw Exception(getExceptionMessage(fmt::format(" has wrong type: {}", argument->value.getTypeName()),
|
||||
argument_index, argument_name, context_data_type_name, field_type), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
else
|
||||
throw Exception(getExceptionMessage(" is missing", argument_index, argument_name, context_data_type_name, field_type),
|
||||
|
@ -240,8 +240,7 @@ public:
|
||||
using ColumnType =
|
||||
std::conditional_t<std::is_same_v<DictionaryAttributeType, Array>, ColumnArray,
|
||||
std::conditional_t<std::is_same_v<DictionaryAttributeType, String>, ColumnString,
|
||||
std::conditional_t<IsDecimalNumber<DictionaryAttributeType>, ColumnDecimal<DictionaryAttributeType>,
|
||||
ColumnVector<DictionaryAttributeType>>>>;
|
||||
ColumnVectorOrDecimal<DictionaryAttributeType>>>;
|
||||
|
||||
using ColumnPtr = typename ColumnType::MutablePtr;
|
||||
|
||||
@ -267,7 +266,7 @@ public:
|
||||
{
|
||||
return ColumnType::create(size);
|
||||
}
|
||||
else if constexpr (IsDecimalNumber<DictionaryAttributeType>)
|
||||
else if constexpr (is_decimal<DictionaryAttributeType>)
|
||||
{
|
||||
auto nested_type = removeNullable(dictionary_attribute.type);
|
||||
auto scale = getDecimalScale(*nested_type);
|
||||
|
@ -19,84 +19,37 @@ namespace DB
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int UNKNOWN_TYPE;
|
||||
extern const int ARGUMENT_OUT_OF_BOUND;
|
||||
extern const int TYPE_MISMATCH;
|
||||
extern const int BAD_ARGUMENTS;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
DictionaryTypedSpecialAttribute makeDictionaryTypedSpecialAttribute(
|
||||
const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix, const std::string & default_type)
|
||||
{
|
||||
const auto name = config.getString(config_prefix + ".name", "");
|
||||
const auto expression = config.getString(config_prefix + ".expression", "");
|
||||
DictionaryTypedSpecialAttribute makeDictionaryTypedSpecialAttribute(
|
||||
const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix, const std::string & default_type)
|
||||
{
|
||||
const auto name = config.getString(config_prefix + ".name", "");
|
||||
const auto expression = config.getString(config_prefix + ".expression", "");
|
||||
|
||||
if (name.empty() && !expression.empty())
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Element {}.name is empty");
|
||||
|
||||
const auto type_name = config.getString(config_prefix + ".type", default_type);
|
||||
return DictionaryTypedSpecialAttribute{std::move(name), std::move(expression), DataTypeFactory::instance().get(type_name)};
|
||||
}
|
||||
if (name.empty() && !expression.empty())
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Element {}.name is empty");
|
||||
|
||||
const auto type_name = config.getString(config_prefix + ".type", default_type);
|
||||
return DictionaryTypedSpecialAttribute{std::move(name), std::move(expression), DataTypeFactory::instance().get(type_name)};
|
||||
}
|
||||
|
||||
|
||||
AttributeUnderlyingType getAttributeUnderlyingType(const DataTypePtr & type)
|
||||
std::optional<AttributeUnderlyingType> maybeGetAttributeUnderlyingType(TypeIndex index)
|
||||
{
|
||||
auto type_index = type->getTypeId();
|
||||
|
||||
switch (type_index)
|
||||
switch (index) /// Special cases which do not map TypeIndex::T -> AttributeUnderlyingType::T
|
||||
{
|
||||
case TypeIndex::UInt8: return AttributeUnderlyingType::UInt8;
|
||||
case TypeIndex::UInt16: return AttributeUnderlyingType::UInt16;
|
||||
case TypeIndex::UInt32: return AttributeUnderlyingType::UInt32;
|
||||
case TypeIndex::UInt64: return AttributeUnderlyingType::UInt64;
|
||||
case TypeIndex::UInt128: return AttributeUnderlyingType::UInt128;
|
||||
case TypeIndex::UInt256: return AttributeUnderlyingType::UInt256;
|
||||
|
||||
case TypeIndex::Int8: return AttributeUnderlyingType::Int8;
|
||||
case TypeIndex::Int16: return AttributeUnderlyingType::Int16;
|
||||
case TypeIndex::Int32: return AttributeUnderlyingType::Int32;
|
||||
case TypeIndex::Int64: return AttributeUnderlyingType::Int64;
|
||||
case TypeIndex::Int128: return AttributeUnderlyingType::Int128;
|
||||
case TypeIndex::Int256: return AttributeUnderlyingType::Int256;
|
||||
|
||||
case TypeIndex::Float32: return AttributeUnderlyingType::Float32;
|
||||
case TypeIndex::Float64: return AttributeUnderlyingType::Float64;
|
||||
|
||||
case TypeIndex::Decimal32: return AttributeUnderlyingType::Decimal32;
|
||||
case TypeIndex::Decimal64: return AttributeUnderlyingType::Decimal64;
|
||||
case TypeIndex::Decimal128: return AttributeUnderlyingType::Decimal128;
|
||||
case TypeIndex::Decimal256: return AttributeUnderlyingType::Decimal256;
|
||||
|
||||
case TypeIndex::Date: return AttributeUnderlyingType::UInt16;
|
||||
case TypeIndex::DateTime: return AttributeUnderlyingType::UInt32;
|
||||
case TypeIndex::DateTime64: return AttributeUnderlyingType::UInt64;
|
||||
|
||||
case TypeIndex::UUID: return AttributeUnderlyingType::UUID;
|
||||
|
||||
case TypeIndex::String: return AttributeUnderlyingType::String;
|
||||
|
||||
case TypeIndex::Array: return AttributeUnderlyingType::Array;
|
||||
|
||||
case TypeIndex::Date: return AttributeUnderlyingType::UInt16;
|
||||
case TypeIndex::DateTime: return AttributeUnderlyingType::UInt32;
|
||||
case TypeIndex::DateTime64: return AttributeUnderlyingType::UInt64;
|
||||
default: break;
|
||||
}
|
||||
|
||||
throw Exception(ErrorCodes::UNKNOWN_TYPE, "Unknown type {} for dictionary attribute", type->getName());
|
||||
return magic_enum::enum_cast<AttributeUnderlyingType>(static_cast<TypeIndexUnderlying>(index));
|
||||
}
|
||||
|
||||
|
||||
std::string toString(AttributeUnderlyingType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
#define M(TYPE) case AttributeUnderlyingType::TYPE: return #TYPE;
|
||||
FOR_ATTRIBUTE_TYPES(M)
|
||||
#undef M
|
||||
}
|
||||
|
||||
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Unknown dictionary attribute type {}", toString(static_cast<int>(type)));
|
||||
}
|
||||
|
||||
|
||||
@ -152,7 +105,7 @@ DictionaryStructure::DictionaryStructure(const Poco::Util::AbstractConfiguration
|
||||
if (id && attribute.underlying_type != AttributeUnderlyingType::UInt64)
|
||||
throw Exception(ErrorCodes::TYPE_MISMATCH,
|
||||
"Hierarchical attribute type for dictionary with simple key must be UInt64. Actual {}",
|
||||
toString(attribute.underlying_type));
|
||||
attribute.underlying_type);
|
||||
|
||||
else if (key)
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Dictionary with complex key does not support hierarchy");
|
||||
@ -342,7 +295,12 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
|
||||
bool is_nullable = initial_type->isNullable();
|
||||
|
||||
auto non_nullable_type = removeNullable(initial_type);
|
||||
const auto underlying_type = getAttributeUnderlyingType(non_nullable_type);
|
||||
|
||||
const auto underlying_type_opt = maybeGetAttributeUnderlyingType(non_nullable_type->getTypeId());
|
||||
|
||||
if (!underlying_type_opt)
|
||||
throw Exception(ErrorCodes::UNKNOWN_TYPE,
|
||||
"Unknown type {} for dictionary attribute", non_nullable_type->getName());
|
||||
|
||||
const auto expression = config.getString(prefix + "expression", "");
|
||||
if (!expression.empty())
|
||||
@ -391,7 +349,7 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
|
||||
|
||||
res_attributes.emplace_back(DictionaryAttribute{
|
||||
name,
|
||||
underlying_type,
|
||||
*underlying_type_opt,
|
||||
initial_type,
|
||||
initial_type_serialization,
|
||||
expression,
|
||||
|
@ -11,53 +11,37 @@
|
||||
#include <IO/ReadBufferFromString.h>
|
||||
#include <DataTypes/IDataType.h>
|
||||
#include <Interpreters/IExternalLoadable.h>
|
||||
#include <common/EnumReflection.h>
|
||||
#include <Core/TypeId.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
/// GCC mistakenly warns about the names in enum class.
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#endif
|
||||
|
||||
|
||||
#define FOR_ATTRIBUTE_TYPES(M) \
|
||||
M(UInt8) \
|
||||
M(UInt16) \
|
||||
M(UInt32) \
|
||||
M(UInt64) \
|
||||
M(UInt128) \
|
||||
M(UInt256) \
|
||||
M(Int8) \
|
||||
M(Int16) \
|
||||
M(Int32) \
|
||||
M(Int64) \
|
||||
M(Int128) \
|
||||
M(Int256) \
|
||||
M(Float32) \
|
||||
M(Float64) \
|
||||
M(Decimal32) \
|
||||
M(Decimal64) \
|
||||
M(Decimal128) \
|
||||
M(Decimal256) \
|
||||
M(UUID) \
|
||||
M(String) \
|
||||
M(Array) \
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
using TypeIndexUnderlying = magic_enum::underlying_type_t<TypeIndex>;
|
||||
|
||||
enum class AttributeUnderlyingType
|
||||
// We need to be able to map TypeIndex -> AttributeUnderlyingType and AttributeUnderlyingType -> real type
|
||||
// The first can be done by defining AttributeUnderlyingType enum values to TypeIndex values and then performing
|
||||
// a enum_cast.
|
||||
// The second can be achieved by using ReverseTypeId
|
||||
#define map_item(__T) __T = static_cast<TypeIndexUnderlying>(TypeIndex::__T)
|
||||
|
||||
enum class AttributeUnderlyingType : TypeIndexUnderlying
|
||||
{
|
||||
#define M(TYPE) TYPE,
|
||||
FOR_ATTRIBUTE_TYPES(M)
|
||||
#undef M
|
||||
map_item(Int8), map_item(Int16), map_item(Int32), map_item(Int64), map_item(Int128), map_item(Int256),
|
||||
map_item(UInt8), map_item(UInt16), map_item(UInt32), map_item(UInt64), map_item(UInt128), map_item(UInt256),
|
||||
map_item(Float32), map_item(Float64),
|
||||
map_item(Decimal32), map_item(Decimal64), map_item(Decimal128), map_item(Decimal256),
|
||||
|
||||
map_item(UUID), map_item(String), map_item(Array)
|
||||
};
|
||||
|
||||
#undef map_item
|
||||
|
||||
AttributeUnderlyingType getAttributeUnderlyingType(const std::string & type);
|
||||
|
||||
std::string toString(AttributeUnderlyingType type);
|
||||
|
||||
/// Min and max lifetimes for a dictionary or it's entry
|
||||
/// Min and max lifetimes for a dictionary or its entry
|
||||
using DictionaryLifetime = ExternalLoadableLifetime;
|
||||
|
||||
/** Holds the description of a single dictionary attribute:
|
||||
@ -85,24 +69,23 @@ struct DictionaryAttribute final
|
||||
const bool is_nullable;
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
template <AttributeUnderlyingType type>
|
||||
struct DictionaryAttributeType
|
||||
{
|
||||
using AttributeType = Type;
|
||||
/// Converts @c type to it underlying type e.g. AttributeUnderlyingType::UInt8 -> UInt8
|
||||
using AttributeType = ReverseTypeId<
|
||||
static_cast<TypeIndex>(
|
||||
static_cast<TypeIndexUnderlying>(type))>;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
void callOnDictionaryAttributeType(AttributeUnderlyingType type, F && func)
|
||||
constexpr void callOnDictionaryAttributeType(AttributeUnderlyingType type, F && func)
|
||||
{
|
||||
switch (type)
|
||||
static_for<AttributeUnderlyingType>([type, func = std::forward<F>(func)](auto other)
|
||||
{
|
||||
#define M(TYPE) \
|
||||
case AttributeUnderlyingType::TYPE: \
|
||||
func(DictionaryAttributeType<TYPE>()); \
|
||||
break;
|
||||
FOR_ATTRIBUTE_TYPES(M)
|
||||
#undef M
|
||||
}
|
||||
if (type == other)
|
||||
func(DictionaryAttributeType<other>{});
|
||||
});
|
||||
};
|
||||
|
||||
struct DictionarySpecialAttribute final
|
||||
|
@ -12,23 +12,6 @@ namespace ErrorCodes
|
||||
extern const int NO_ELEMENTS_IN_CONFIG;
|
||||
extern const int INCONSISTENT_RESERVATIONS;
|
||||
extern const int NO_RESERVATIONS_PROVIDED;
|
||||
extern const int UNKNOWN_VOLUME_TYPE;
|
||||
}
|
||||
|
||||
String volumeTypeToString(VolumeType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case VolumeType::JBOD:
|
||||
return "JBOD";
|
||||
case VolumeType::RAID1:
|
||||
return "RAID1";
|
||||
case VolumeType::SINGLE_DISK:
|
||||
return "SINGLE_DISK";
|
||||
case VolumeType::UNKNOWN:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
throw Exception("Unknown volume type, please add it to DB::volumeTypeToString", ErrorCodes::UNKNOWN_VOLUME_TYPE);
|
||||
}
|
||||
|
||||
IVolume::IVolume(
|
||||
|
@ -16,8 +16,6 @@ enum class VolumeType
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
String volumeTypeToString(VolumeType t);
|
||||
|
||||
class IVolume;
|
||||
using VolumePtr = std::shared_ptr<IVolume>;
|
||||
using Volumes = std::vector<VolumePtr>;
|
||||
|
@ -81,7 +81,7 @@ struct DivideIntegralImpl
|
||||
|
||||
/// Otherwise overflow may occur due to integer promotion. Example: int8_t(-1) / uint64_t(2).
|
||||
/// NOTE: overflow is still possible when dividing large signed number to large unsigned number or vice-versa. But it's less harmful.
|
||||
if constexpr (is_integer_v<A> && is_integer_v<B> && (is_signed_v<A> || is_signed_v<B>))
|
||||
if constexpr (is_integer<A> && is_integer<B> && (is_signed_v<A> || is_signed_v<B>))
|
||||
{
|
||||
using SignedCastA = make_signed_t<CastA>;
|
||||
using SignedCastB = std::conditional_t<sizeof(A) <= sizeof(B), make_signed_t<CastB>, SignedCastA>;
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Common/assert_cast.h>
|
||||
#include <Common/FieldVisitorsAccurateComparison.h>
|
||||
#include <Common/TypeList.h>
|
||||
#include <common/map.h>
|
||||
|
||||
#if !defined(ARCADIA_BUILD)
|
||||
@ -183,14 +184,8 @@ namespace impl_
|
||||
|
||||
enum class OpCase { Vector, LeftConstant, RightConstant };
|
||||
|
||||
template <class T>
|
||||
inline constexpr const auto & undec(const T & x)
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
return x.value;
|
||||
else
|
||||
return x;
|
||||
}
|
||||
constexpr const auto & undec(const auto & x) { return x; }
|
||||
constexpr const auto & undec(const is_decimal auto & x) { return x.value; }
|
||||
|
||||
template <typename A, typename B, typename Op, typename OpResultType = typename Op::ResultType>
|
||||
struct BinaryOperation
|
||||
@ -301,19 +296,17 @@ struct DecimalBinaryOperation
|
||||
{
|
||||
private:
|
||||
using ResultType = OpResultType; // e.g. Decimal32
|
||||
using NativeResultType = typename NativeType<ResultType>::Type; // e.g. UInt32 for Decimal32
|
||||
using NativeResultType = NativeType<ResultType>; // e.g. UInt32 for Decimal32
|
||||
|
||||
using ResultContainerType = typename std::conditional_t<IsDecimalNumber<ResultType>,
|
||||
ColumnDecimal<ResultType>,
|
||||
ColumnVector<ResultType>>::Container;
|
||||
using ResultContainerType = typename ColumnVectorOrDecimal<ResultType>::Container;
|
||||
|
||||
public:
|
||||
template <OpCase op_case, bool is_decimal_a, bool is_decimal_b, class A, class B>
|
||||
static void NO_INLINE process(const A & a, const B & b, ResultContainerType & c,
|
||||
template <OpCase op_case, bool is_decimal_a, bool is_decimal_b>
|
||||
static void NO_INLINE process(const auto & a, const auto & b, ResultContainerType & c,
|
||||
NativeResultType scale_a, NativeResultType scale_b)
|
||||
{
|
||||
if constexpr (op_case == OpCase::LeftConstant) static_assert(!IsDecimalNumber<A>);
|
||||
if constexpr (op_case == OpCase::RightConstant) static_assert(!IsDecimalNumber<B>);
|
||||
if constexpr (op_case == OpCase::LeftConstant) static_assert(!is_decimal<decltype(a)>);
|
||||
if constexpr (op_case == OpCase::RightConstant) static_assert(!is_decimal<decltype(b)>);
|
||||
|
||||
size_t size;
|
||||
|
||||
@ -383,10 +376,8 @@ public:
|
||||
|
||||
template <bool is_decimal_a, bool is_decimal_b, class A, class B>
|
||||
static ResultType process(A a, B b, NativeResultType scale_a, NativeResultType scale_b)
|
||||
requires(!is_decimal<A> && !is_decimal<B>)
|
||||
{
|
||||
static_assert(!IsDecimalNumber<A>);
|
||||
static_assert(!IsDecimalNumber<B>);
|
||||
|
||||
if constexpr (is_division && is_decimal_b)
|
||||
return applyScaledDiv<is_decimal_a>(a, b, scale_a);
|
||||
else if constexpr (is_plus_minus_compare)
|
||||
@ -516,83 +507,34 @@ class FunctionBinaryArithmetic : public IFunction
|
||||
ContextPtr context;
|
||||
bool check_decimal_overflow = true;
|
||||
|
||||
template <typename F>
|
||||
static bool castType(const IDataType * type, F && f)
|
||||
static bool castType(const IDataType * type, auto && f)
|
||||
{
|
||||
return castTypeToEither<
|
||||
DataTypeUInt8,
|
||||
DataTypeUInt16,
|
||||
DataTypeUInt32,
|
||||
DataTypeUInt64,
|
||||
DataTypeUInt128,
|
||||
DataTypeUInt256,
|
||||
DataTypeInt8,
|
||||
DataTypeInt16,
|
||||
DataTypeInt32,
|
||||
DataTypeInt64,
|
||||
DataTypeInt128,
|
||||
DataTypeInt256,
|
||||
DataTypeFloat32,
|
||||
DataTypeFloat64,
|
||||
DataTypeDate,
|
||||
DataTypeDateTime,
|
||||
DataTypeDecimal<Decimal32>,
|
||||
DataTypeDecimal<Decimal64>,
|
||||
DataTypeDecimal<Decimal128>,
|
||||
DataTypeDecimal<Decimal256>,
|
||||
DataTypeFixedString
|
||||
>(type, std::forward<F>(f));
|
||||
}
|
||||
using Types = TypeList<
|
||||
DataTypeUInt8, DataTypeUInt16, DataTypeUInt32, DataTypeUInt64, DataTypeUInt128, DataTypeUInt256,
|
||||
DataTypeInt8, DataTypeInt16, DataTypeInt32, DataTypeInt64, DataTypeInt128, DataTypeInt256,
|
||||
DataTypeDecimal32, DataTypeDecimal64, DataTypeDecimal128, DataTypeDecimal256,
|
||||
DataTypeDate, DataTypeDateTime,
|
||||
DataTypeFixedString>;
|
||||
|
||||
template <typename F>
|
||||
static bool castTypeNoFloats(const IDataType * type, F && f)
|
||||
{
|
||||
return castTypeToEither<
|
||||
DataTypeUInt8,
|
||||
DataTypeUInt16,
|
||||
DataTypeUInt32,
|
||||
DataTypeUInt64,
|
||||
DataTypeUInt128,
|
||||
DataTypeUInt256,
|
||||
DataTypeInt8,
|
||||
DataTypeInt16,
|
||||
DataTypeInt32,
|
||||
DataTypeInt64,
|
||||
DataTypeInt128,
|
||||
DataTypeInt256,
|
||||
DataTypeDate,
|
||||
DataTypeDateTime,
|
||||
DataTypeDecimal<Decimal32>,
|
||||
DataTypeDecimal<Decimal64>,
|
||||
DataTypeDecimal<Decimal128>,
|
||||
DataTypeDecimal<Decimal256>,
|
||||
DataTypeFixedString
|
||||
>(type, std::forward<F>(f));
|
||||
using Floats = TypeList<DataTypeFloat32, DataTypeFloat64>;
|
||||
|
||||
using ValidTypes = std::conditional_t<valid_on_float_arguments,
|
||||
typename TypeListConcat<Types, Floats>::Type,
|
||||
Types>;
|
||||
|
||||
return castTypeToEitherTL<ValidTypes>(type, std::forward<decltype(f)>(f));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
static bool castBothTypes(const IDataType * left, const IDataType * right, F && f)
|
||||
{
|
||||
if constexpr (valid_on_float_arguments)
|
||||
return castType(left, [&](const auto & left_)
|
||||
{
|
||||
return castType(left, [&](const auto & left_)
|
||||
return castType(right, [&](const auto & right_)
|
||||
{
|
||||
return castType(right, [&](const auto & right_)
|
||||
{
|
||||
return f(left_, right_);
|
||||
});
|
||||
return f(left_, right_);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return castTypeNoFloats(left, [&](const auto & left_)
|
||||
{
|
||||
return castTypeNoFloats(right, [&](const auto & right_)
|
||||
{
|
||||
return f(left_, right_);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static FunctionOverloadResolverPtr
|
||||
@ -632,7 +574,9 @@ class FunctionBinaryArithmetic : public IFunction
|
||||
std::string function_name;
|
||||
if (interval_data_type)
|
||||
{
|
||||
function_name = String(is_plus ? "add" : "subtract") + interval_data_type->getKind().toString() + 's';
|
||||
function_name = fmt::format("{}{}s",
|
||||
is_plus ? "add" : "subtract",
|
||||
interval_data_type->getKind().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -785,23 +729,22 @@ class FunctionBinaryArithmetic : public IFunction
|
||||
return function->execute(new_arguments, result_type, input_rows_count);
|
||||
}
|
||||
|
||||
template <typename T, typename ResultDataType, typename CC, typename C>
|
||||
static auto helperGetOrConvert(const CC & col_const, const C & col)
|
||||
template <typename T, typename ResultDataType>
|
||||
static auto helperGetOrConvert(const auto & col_const, const auto & col)
|
||||
{
|
||||
using ResultType = typename ResultDataType::FieldType;
|
||||
using NativeResultType = typename NativeType<ResultType>::Type;
|
||||
using NativeResultType = NativeType<ResultType>;
|
||||
|
||||
if constexpr (IsFloatingPoint<ResultDataType> && IsDecimalNumber<T>)
|
||||
if constexpr (IsFloatingPoint<ResultDataType> && is_decimal<T>)
|
||||
return DecimalUtils::convertTo<NativeResultType>(col_const->template getValue<T>(), col.getScale());
|
||||
else if constexpr (IsDecimalNumber<T>)
|
||||
else if constexpr (is_decimal<T>)
|
||||
return col_const->template getValue<T>().value;
|
||||
else
|
||||
return col_const->template getValue<T>();
|
||||
}
|
||||
|
||||
template <OpCase op_case, bool left_decimal, bool right_decimal, typename OpImpl, typename OpImplCheck,
|
||||
typename L, typename R, typename VR, typename SA, typename SB>
|
||||
void helperInvokeEither(const L& left, const R& right, VR& vec_res, SA scale_a, SB scale_b) const
|
||||
template <OpCase op_case, bool left_decimal, bool right_decimal, typename OpImpl, typename OpImplCheck>
|
||||
void helperInvokeEither(const auto& left, const auto& right, auto& vec_res, auto scale_a, auto scale_b) const
|
||||
{
|
||||
if (check_decimal_overflow)
|
||||
OpImplCheck::template process<op_case, left_decimal, right_decimal>(left, right, vec_res, scale_a, scale_b);
|
||||
@ -809,27 +752,25 @@ class FunctionBinaryArithmetic : public IFunction
|
||||
OpImpl::template process<op_case, left_decimal, right_decimal>(left, right, vec_res, scale_a, scale_b);
|
||||
}
|
||||
|
||||
template <class LeftDataType, class RightDataType, class ResultDataType,
|
||||
class L, class R, class CL, class CR>
|
||||
template <class LeftDataType, class RightDataType, class ResultDataType>
|
||||
ColumnPtr executeNumericWithDecimal(
|
||||
const L & left, const R & right,
|
||||
const auto & left, const auto & right,
|
||||
const ColumnConst * const col_left_const, const ColumnConst * const col_right_const,
|
||||
const CL * const col_left, const CR * const col_right,
|
||||
const auto * const col_left, const auto * const col_right,
|
||||
size_t col_left_size) const
|
||||
{
|
||||
using T0 = typename LeftDataType::FieldType;
|
||||
using T1 = typename RightDataType::FieldType;
|
||||
using ResultType = typename ResultDataType::FieldType;
|
||||
|
||||
using NativeResultType = typename NativeType<ResultType>::Type;
|
||||
using NativeResultType = NativeType<ResultType>;
|
||||
using OpImpl = DecimalBinaryOperation<Op, ResultType, false>;
|
||||
using OpImplCheck = DecimalBinaryOperation<Op, ResultType, true>;
|
||||
|
||||
using ColVecResult = std::conditional_t<IsDecimalNumber<ResultType>,
|
||||
ColumnDecimal<ResultType>, ColumnVector<ResultType>>;
|
||||
using ColVecResult = ColumnVectorOrDecimal<ResultType>;
|
||||
|
||||
static constexpr const bool left_is_decimal = IsDecimalNumber<T0>;
|
||||
static constexpr const bool right_is_decimal = IsDecimalNumber<T1>;
|
||||
static constexpr const bool left_is_decimal = is_decimal<T0>;
|
||||
static constexpr const bool right_is_decimal = is_decimal<T1>;
|
||||
static constexpr const bool result_is_decimal = IsDataTypeDecimal<ResultDataType>;
|
||||
|
||||
typename ColVecResult::MutablePtr col_res = nullptr;
|
||||
@ -1176,9 +1117,9 @@ public:
|
||||
using T0 = typename LeftDataType::FieldType;
|
||||
using T1 = typename RightDataType::FieldType;
|
||||
using ResultType = typename ResultDataType::FieldType;
|
||||
using ColVecT0 = std::conditional_t<IsDecimalNumber<T0>, ColumnDecimal<T0>, ColumnVector<T0>>;
|
||||
using ColVecT1 = std::conditional_t<IsDecimalNumber<T1>, ColumnDecimal<T1>, ColumnVector<T1>>;
|
||||
using ColVecResult = std::conditional_t<IsDecimalNumber<ResultType>, ColumnDecimal<ResultType>, ColumnVector<ResultType>>;
|
||||
using ColVecT0 = ColumnVectorOrDecimal<T0>;
|
||||
using ColVecT1 = ColumnVectorOrDecimal<T1>;
|
||||
using ColVecResult = ColumnVectorOrDecimal<ResultType>;
|
||||
|
||||
const auto * const col_left_raw = arguments[0].column.get();
|
||||
const auto * const col_right_raw = arguments[1].column.get();
|
||||
|
@ -68,13 +68,13 @@ const ColumnConst * checkAndGetColumnConstStringOrFixedString(const IColumn * co
|
||||
|
||||
/// Transform anything to Field.
|
||||
template <typename T>
|
||||
inline std::enable_if_t<!IsDecimalNumber<T>, Field> toField(const T & x)
|
||||
Field toField(const T & x)
|
||||
{
|
||||
return Field(NearestFieldType<T>(x));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::enable_if_t<IsDecimalNumber<T>, Field> toField(const T & x, UInt32 scale)
|
||||
template <is_decimal T>
|
||||
Field toField(const T & x, UInt32 scale)
|
||||
{
|
||||
return Field(NearestFieldType<T>(x, scale));
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ private:
|
||||
using Types = std::decay_t<decltype(types)>;
|
||||
using Type = typename Types::RightType;
|
||||
using ReturnType = std::conditional_t<Impl::always_returns_float64 || !std::is_floating_point_v<Type>, Float64, Type>;
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<Type>, ColumnDecimal<Type>, ColumnVector<Type>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<Type>;
|
||||
|
||||
const auto col_vec = checkAndGetColumn<ColVecType>(col.column.get());
|
||||
return (res = execute<Type, ReturnType>(col_vec)) != nullptr;
|
||||
|
@ -38,8 +38,8 @@ template <typename A, typename Op>
|
||||
struct UnaryOperationImpl
|
||||
{
|
||||
using ResultType = typename Op::ResultType;
|
||||
using ColVecA = std::conditional_t<IsDecimalNumber<A>, ColumnDecimal<A>, ColumnVector<A>>;
|
||||
using ColVecC = std::conditional_t<IsDecimalNumber<ResultType>, ColumnDecimal<ResultType>, ColumnVector<ResultType>>;
|
||||
using ColVecA = ColumnVectorOrDecimal<A>;
|
||||
using ColVecC = ColumnVectorOrDecimal<ResultType>;
|
||||
using ArrayA = typename ColVecA::Container;
|
||||
using ArrayC = typename ColVecC::Container;
|
||||
|
||||
|
@ -106,8 +106,9 @@ private:
|
||||
else if (buckets_field.getType() == Field::Types::UInt64)
|
||||
num_buckets = checkBucketsRange(buckets_field.get<UInt64>());
|
||||
else
|
||||
throw Exception("Illegal type " + String(buckets_field.getTypeName()) + " of the second argument of function " + getName(),
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of the second argument of function {}",
|
||||
buckets_field.getTypeName(), getName());
|
||||
|
||||
const auto & hash_col = arguments[0].column;
|
||||
const IDataType * hash_type = arguments[0].type.get();
|
||||
|
@ -764,7 +764,7 @@ template <typename FromDataType, typename Name>
|
||||
struct ConvertImpl<FromDataType, std::enable_if_t<!std::is_same_v<FromDataType, DataTypeString>, DataTypeString>, Name, ConvertDefaultBehaviorTag>
|
||||
{
|
||||
using FromFieldType = typename FromDataType::FieldType;
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<FromFieldType>, ColumnDecimal<FromFieldType>, ColumnVector<FromFieldType>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<FromFieldType>;
|
||||
|
||||
static ColumnPtr execute(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/)
|
||||
{
|
||||
@ -1699,9 +1699,9 @@ private:
|
||||
using RightT = typename RightDataType::FieldType;
|
||||
|
||||
static constexpr bool bad_left =
|
||||
IsDecimalNumber<LeftT> || std::is_floating_point_v<LeftT> || is_big_int_v<LeftT> || is_signed_v<LeftT>;
|
||||
is_decimal<LeftT> || std::is_floating_point_v<LeftT> || is_big_int_v<LeftT> || is_signed_v<LeftT>;
|
||||
static constexpr bool bad_right =
|
||||
IsDecimalNumber<RightT> || std::is_floating_point_v<RightT> || is_big_int_v<RightT> || is_signed_v<RightT>;
|
||||
is_decimal<RightT> || std::is_floating_point_v<RightT> || is_big_int_v<RightT> || is_signed_v<RightT>;
|
||||
|
||||
/// Disallow int vs UUID conversion (but support int vs UInt128 conversion)
|
||||
if constexpr ((bad_left && std::is_same_v<RightDataType, DataTypeUUID>) ||
|
||||
@ -2585,8 +2585,9 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception{"Conversion from " + std::string(getTypeName(from_type_index)) + " to " + to_type->getName() + " is not supported",
|
||||
ErrorCodes::CANNOT_CONVERT_TYPE};
|
||||
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE,
|
||||
"Conversion from {} to {} is not supported",
|
||||
from_type_index, to_type->getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2695,8 +2696,9 @@ private:
|
||||
return nullable_column_wrapper(arguments, result_type, column_nullable, input_rows_count);
|
||||
}
|
||||
else
|
||||
throw Exception{"Conversion from " + std::string(getTypeName(type_index)) + " to " + to_type->getName() + " is not supported",
|
||||
ErrorCodes::CANNOT_CONVERT_TYPE};
|
||||
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE,
|
||||
"Conversion from {} to {} is not supported",
|
||||
type_index, to_type->getName());
|
||||
}
|
||||
|
||||
return result_column;
|
||||
|
@ -635,7 +635,7 @@ private:
|
||||
template <typename FromType>
|
||||
ColumnPtr executeType(const ColumnsWithTypeAndName & arguments) const
|
||||
{
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<FromType>, ColumnDecimal<FromType>, ColumnVector<FromType>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<FromType>;
|
||||
|
||||
if (const ColVecType * col_from = checkAndGetColumn<ColVecType>(arguments[0].column.get()))
|
||||
{
|
||||
@ -762,7 +762,7 @@ private:
|
||||
template <typename FromType, bool first>
|
||||
void executeIntType(const IColumn * column, typename ColumnVector<ToType>::Container & vec_to) const
|
||||
{
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<FromType>, ColumnDecimal<FromType>, ColumnVector<FromType>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<FromType>;
|
||||
|
||||
if (const ColVecType * col_from = checkAndGetColumn<ColVecType>(column))
|
||||
{
|
||||
@ -819,7 +819,7 @@ private:
|
||||
template <typename FromType, bool first>
|
||||
void executeBigIntType(const IColumn * column, typename ColumnVector<ToType>::Container & vec_to) const
|
||||
{
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<FromType>, ColumnDecimal<FromType>, ColumnVector<FromType>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<FromType>;
|
||||
|
||||
if (const ColVecType * col_from = checkAndGetColumn<ColVecType>(column))
|
||||
{
|
||||
|
@ -522,7 +522,7 @@ public:
|
||||
else if (!accurate::convertNumeric(element.getDouble(), value))
|
||||
return false;
|
||||
}
|
||||
else if (element.isBool() && is_integer_v<NumberType> && convert_bool_to_integer)
|
||||
else if (element.isBool() && is_integer<NumberType> && convert_bool_to_integer)
|
||||
{
|
||||
value = static_cast<NumberType>(element.getBool());
|
||||
}
|
||||
|
@ -315,11 +315,11 @@ template <typename T, RoundingMode rounding_mode, ScaleMode scale_mode>
|
||||
struct FloatRoundingImpl
|
||||
{
|
||||
private:
|
||||
static_assert(!IsDecimalNumber<T>);
|
||||
static_assert(!is_decimal<T>);
|
||||
|
||||
using Op = FloatRoundingComputation<T, rounding_mode, scale_mode>;
|
||||
using Data = std::array<T, Op::data_count>;
|
||||
using ColumnType = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
using ColumnType = ColumnVector<T>;
|
||||
using Container = typename ColumnType::Container;
|
||||
|
||||
public:
|
||||
@ -413,12 +413,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template <typename T, RoundingMode rounding_mode, TieBreakingMode tie_breaking_mode>
|
||||
template <is_decimal T, RoundingMode rounding_mode, TieBreakingMode tie_breaking_mode>
|
||||
class DecimalRoundingImpl
|
||||
{
|
||||
private:
|
||||
static_assert(IsDecimalNumber<T>);
|
||||
|
||||
using NativeType = typename T::NativeType;
|
||||
using Op = IntegerRoundingComputation<NativeType, rounding_mode, ScaleMode::Negative, tie_breaking_mode>;
|
||||
using Container = typename ColumnDecimal<T>::Container;
|
||||
@ -453,15 +451,16 @@ public:
|
||||
/** Select the appropriate processing algorithm depending on the scale.
|
||||
*/
|
||||
template <typename T, RoundingMode rounding_mode, TieBreakingMode tie_breaking_mode>
|
||||
class Dispatcher
|
||||
struct Dispatcher
|
||||
{
|
||||
template <ScaleMode scale_mode>
|
||||
using FunctionRoundingImpl = std::conditional_t<std::is_floating_point_v<T>,
|
||||
FloatRoundingImpl<T, rounding_mode, scale_mode>,
|
||||
IntegerRoundingImpl<T, rounding_mode, scale_mode, tie_breaking_mode>>;
|
||||
|
||||
static ColumnPtr apply(const ColumnVector<T> * col, Scale scale_arg)
|
||||
static ColumnPtr apply(const IColumn * col_general, Scale scale_arg)
|
||||
{
|
||||
const auto * const col = checkAndGetColumn<ColumnVector<T>>(col_general);
|
||||
auto col_res = ColumnVector<T>::create();
|
||||
|
||||
typename ColumnVector<T>::Container & vec_res = col_res->getData();
|
||||
@ -488,9 +487,15 @@ class Dispatcher
|
||||
|
||||
return col_res;
|
||||
}
|
||||
};
|
||||
|
||||
static ColumnPtr apply(const ColumnDecimal<T> * col, Scale scale_arg)
|
||||
template <is_decimal T, RoundingMode rounding_mode, TieBreakingMode tie_breaking_mode>
|
||||
struct Dispatcher<T, rounding_mode, tie_breaking_mode>
|
||||
{
|
||||
public:
|
||||
static ColumnPtr apply(const IColumn * col_general, Scale scale_arg)
|
||||
{
|
||||
const auto * const col = checkAndGetColumn<ColumnDecimal<T>>(col_general);
|
||||
const typename ColumnDecimal<T>::Container & vec_src = col->getData();
|
||||
|
||||
auto col_res = ColumnDecimal<T>::create(vec_src.size(), vec_src.getScale());
|
||||
@ -501,15 +506,6 @@ class Dispatcher
|
||||
|
||||
return col_res;
|
||||
}
|
||||
|
||||
public:
|
||||
static ColumnPtr apply(const IColumn * column, Scale scale_arg)
|
||||
{
|
||||
if constexpr (is_arithmetic_v<T>)
|
||||
return apply(checkAndGetColumn<ColumnVector<T>>(column), scale_arg);
|
||||
else if constexpr (IsDecimalNumber<T>)
|
||||
return apply(checkAndGetColumn<ColumnDecimal<T>>(column), scale_arg);
|
||||
}
|
||||
};
|
||||
|
||||
/** A template for functions that round the value of an input parameter of type
|
||||
|
@ -34,7 +34,7 @@ void writeSlice(const NumericArraySlice<T> & slice, NumericArraySink<T> & sink)
|
||||
template <typename T, typename U>
|
||||
void writeSlice(const NumericArraySlice<T> & slice, NumericArraySink<U> & sink)
|
||||
{
|
||||
using NativeU = typename NativeType<U>::Type;
|
||||
using NativeU = NativeType<U>;
|
||||
|
||||
sink.elements.resize(sink.current_offset + slice.size);
|
||||
for (size_t i = 0; i < slice.size; ++i)
|
||||
@ -42,9 +42,9 @@ void writeSlice(const NumericArraySlice<T> & slice, NumericArraySink<U> & sink)
|
||||
const auto & src = slice.data[i];
|
||||
auto & dst = sink.elements[sink.current_offset];
|
||||
|
||||
if constexpr (OverBigInt<T> || OverBigInt<U>)
|
||||
if constexpr (is_over_big_int<T> || is_over_big_int<U>)
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
dst = static_cast<NativeU>(src.value);
|
||||
else
|
||||
dst = static_cast<NativeU>(src);
|
||||
@ -99,7 +99,7 @@ inline ALWAYS_INLINE void writeSlice(const NumericArraySlice<T> & slice, Generic
|
||||
{
|
||||
for (size_t i = 0; i < slice.size; ++i)
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
{
|
||||
DecimalField field(T(slice.data[i]), 0); /// TODO: Decimal scale
|
||||
sink.elements.insert(field);
|
||||
@ -558,9 +558,9 @@ bool sliceEqualElements(const NumericArraySlice<T> & first [[maybe_unused]],
|
||||
size_t second_ind [[maybe_unused]])
|
||||
{
|
||||
/// TODO: Decimal scale
|
||||
if constexpr (IsDecimalNumber<T> && IsDecimalNumber<U>)
|
||||
if constexpr (is_decimal<T> && is_decimal<U>)
|
||||
return accurate::equalsOp(first.data[first_ind].value, second.data[second_ind].value);
|
||||
else if constexpr (IsDecimalNumber<T> || IsDecimalNumber<U>)
|
||||
else if constexpr (is_decimal<T> || is_decimal<U>)
|
||||
return false;
|
||||
else
|
||||
return accurate::equalsOp(first.data[first_ind], second.data[second_ind]);
|
||||
@ -588,7 +588,7 @@ bool insliceEqualElements(const NumericArraySlice<T> & first [[maybe_unused]],
|
||||
size_t first_ind [[maybe_unused]],
|
||||
size_t second_ind [[maybe_unused]])
|
||||
{
|
||||
if constexpr (IsDecimalNumber<T>)
|
||||
if constexpr (is_decimal<T>)
|
||||
return accurate::equalsOp(first.data[first_ind].value, first.data[second_ind].value);
|
||||
else
|
||||
return accurate::equalsOp(first.data[first_ind], first.data[second_ind]);
|
||||
|
@ -36,7 +36,7 @@ struct NullableValueSource;
|
||||
template <typename T>
|
||||
struct NumericArraySink : public ArraySinkImpl<NumericArraySink<T>>
|
||||
{
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<T>;
|
||||
using CompatibleArraySource = NumericArraySource<T>;
|
||||
using CompatibleValueSource = NumericValueSource<T>;
|
||||
|
||||
|
@ -39,7 +39,7 @@ template <typename ArraySink> struct NullableArraySink;
|
||||
template <typename T>
|
||||
struct NumericArraySource : public ArraySourceImpl<NumericArraySource<T>>
|
||||
{
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<T>;
|
||||
using Slice = NumericArraySlice<T>;
|
||||
using Column = ColumnArray;
|
||||
|
||||
@ -720,7 +720,7 @@ template <typename T>
|
||||
struct NumericValueSource : ValueSourceImpl<NumericValueSource<T>>
|
||||
{
|
||||
using Slice = NumericValueSlice<T>;
|
||||
using Column = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
||||
using Column = ColumnVectorOrDecimal<T>;
|
||||
|
||||
using SinkType = NumericArraySink<T>;
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct ArraySinkCreator<Type, Types...>
|
||||
{
|
||||
static std::unique_ptr<IArraySink> create(IColumn & values, ColumnArray::Offsets & offsets, size_t column_size)
|
||||
{
|
||||
using ColVecType = std::conditional_t<IsDecimalNumber<Type>, ColumnDecimal<Type>, ColumnVector<Type>>;
|
||||
using ColVecType = ColumnVectorOrDecimal<Type>;
|
||||
|
||||
IColumn * not_null_values = &values;
|
||||
bool is_nullable = false;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user