mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
clickhouse: added bitwise and and or functions [#CONV-6318].
This commit is contained in:
parent
57fccc9387
commit
1383bfd005
@ -240,6 +240,90 @@ struct ModuloImpl
|
||||
}
|
||||
};
|
||||
|
||||
template<typename A, typename B>
|
||||
struct BitwiseAndImpl
|
||||
{
|
||||
typedef typename NumberTraits::ResultOfBitwise<A, B>::Type ResultType;
|
||||
|
||||
static void vector_vector(const std::vector<A> & a, const std::vector<B> & b, std::vector<ResultType> & c)
|
||||
{
|
||||
size_t size = a.size();
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
c[i] = static_cast<ResultType>(a[i])
|
||||
& static_cast<ResultType>(b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void vector_constant(const std::vector<A> & a, B b, std::vector<ResultType> & c)
|
||||
{
|
||||
size_t size = a.size();
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
c[i] = static_cast<ResultType>(a[i])
|
||||
& static_cast<ResultType>(b);
|
||||
}
|
||||
}
|
||||
|
||||
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
|
||||
{
|
||||
size_t size = b.size();
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
c[i] = static_cast<ResultType>(a)
|
||||
& static_cast<ResultType>(b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void constant_constant(A a, B b, ResultType & c)
|
||||
{
|
||||
c = static_cast<ResultType>(a)
|
||||
& static_cast<ResultType>(b);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename A, typename B>
|
||||
struct BitwiseOrImpl
|
||||
{
|
||||
typedef typename NumberTraits::ResultOfBitwise<A, B>::Type ResultType;
|
||||
|
||||
static void vector_vector(const std::vector<A> & a, const std::vector<B> & b, std::vector<ResultType> & c)
|
||||
{
|
||||
size_t size = a.size();
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
c[i] = static_cast<ResultType>(a[i])
|
||||
| static_cast<ResultType>(b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void vector_constant(const std::vector<A> & a, B b, std::vector<ResultType> & c)
|
||||
{
|
||||
size_t size = a.size();
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
c[i] = static_cast<ResultType>(a[i])
|
||||
| static_cast<ResultType>(b);
|
||||
}
|
||||
}
|
||||
|
||||
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
|
||||
{
|
||||
size_t size = b.size();
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
c[i] = static_cast<ResultType>(a)
|
||||
| static_cast<ResultType>(b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void constant_constant(A a, B b, ResultType & c)
|
||||
{
|
||||
c = static_cast<ResultType>(a)
|
||||
| static_cast<ResultType>(b);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename A>
|
||||
struct NegateImpl
|
||||
{
|
||||
@ -567,6 +651,8 @@ struct NameMultiply { static const char * get() { return "multiply"; } };
|
||||
struct NameDivideFloating { static const char * get() { return "divide"; } };
|
||||
struct NameDivideIntegral { static const char * get() { return "intDiv"; } };
|
||||
struct NameModulo { static const char * get() { return "modulo"; } };
|
||||
struct NameBitwiseAnd { static const char * get() { return "bitwiseAnd"; } };
|
||||
struct NameBitwiseOr { static const char * get() { return "bitwiseOr"; } };
|
||||
struct NameNegate { static const char * get() { return "negate"; } };
|
||||
|
||||
typedef FunctionBinaryArithmetic<PlusImpl, NamePlus> FunctionPlus;
|
||||
@ -575,6 +661,8 @@ typedef FunctionBinaryArithmetic<MultiplyImpl, NameMultiply> FunctionMultip
|
||||
typedef FunctionBinaryArithmetic<DivideFloatingImpl, NameDivideFloating> FunctionDivideFloating;
|
||||
typedef FunctionBinaryArithmetic<DivideIntegralImpl, NameDivideIntegral> FunctionDivideIntegral;
|
||||
typedef FunctionBinaryArithmetic<ModuloImpl, NameModulo> FunctionModulo;
|
||||
typedef FunctionBinaryArithmetic<BitwiseAndImpl, NameBitwiseAnd> FunctionBitwiseAnd;
|
||||
typedef FunctionBinaryArithmetic<BitwiseOrImpl, NameBitwiseOr> FunctionBitwiseOr;
|
||||
typedef FunctionUnaryArithmetic<NegateImpl, NameNegate> FunctionNegate;
|
||||
|
||||
|
||||
|
@ -146,7 +146,25 @@ namespace NumberTraits
|
||||
typename Traits<A>::Bits>::Type Type;
|
||||
};
|
||||
|
||||
/** Перед применением оператора %, операнды приводятся к целым числам. */
|
||||
/** При побитовых операциях получается целое число, битность которого равна максимальной из битностей аргументов.
|
||||
*/
|
||||
template <typename A, typename B> struct ResultOfBitwise
|
||||
{
|
||||
typedef typename Construct<
|
||||
typename boost::mpl::or_<typename Traits<A>::Sign, typename Traits<B>::Sign>::type,
|
||||
Integer,
|
||||
typename boost::mpl::max<
|
||||
typename boost::mpl::if_<
|
||||
typename Traits<A>::Floatness,
|
||||
Bits64,
|
||||
typename Traits<A>::Bits>::type,
|
||||
typename boost::mpl::if_<
|
||||
typename Traits<B>::Floatness,
|
||||
Bits64,
|
||||
typename Traits<B>::Bits>::type>::type>::Type Type;
|
||||
};
|
||||
|
||||
/** Перед применением оператора % и побитовых операций, операнды приводятся к целым числам. */
|
||||
template <typename A> struct ToInteger
|
||||
{
|
||||
typedef typename Construct<
|
||||
|
@ -34,6 +34,8 @@ FunctionPtr FunctionFactory::get(
|
||||
else if (name == "divide") return new FunctionDivideFloating;
|
||||
else if (name == "intDiv") return new FunctionDivideIntegral;
|
||||
else if (name == "modulo") return new FunctionModulo;
|
||||
else if (name == "bitwiseAnd") return new FunctionBitwiseAnd;
|
||||
else if (name == "bitwiseOr") return new FunctionBitwiseOr;
|
||||
else if (name == "negate") return new FunctionNegate;
|
||||
|
||||
else if (name == "equals") return new FunctionEquals;
|
||||
|
Loading…
Reference in New Issue
Block a user