summaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/bitTest.cpp
diff options
context:
space:
mode:
authorvitalyisaev <[email protected]>2023-11-14 09:58:56 +0300
committervitalyisaev <[email protected]>2023-11-14 10:20:20 +0300
commitc2b2dfd9827a400a8495e172a56343462e3ceb82 (patch)
treecd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/bitTest.cpp
parentd4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff)
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/bitTest.cpp')
-rw-r--r--contrib/clickhouse/src/Functions/bitTest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/bitTest.cpp b/contrib/clickhouse/src/Functions/bitTest.cpp
new file mode 100644
index 00000000000..4c9c6aa2dfb
--- /dev/null
+++ b/contrib/clickhouse/src/Functions/bitTest.cpp
@@ -0,0 +1,47 @@
+#include <Functions/FunctionFactory.h>
+#include <Functions/FunctionBinaryArithmetic.h>
+#include <Core/Defines.h>
+
+
+namespace DB
+{
+namespace ErrorCodes
+{
+ extern const int NOT_IMPLEMENTED;
+}
+
+namespace
+{
+
+template <typename A, typename B>
+struct BitTestImpl
+{
+ using ResultType = UInt8;
+ static const constexpr bool allow_fixed_string = false;
+ static const constexpr bool allow_string_integer = false;
+
+ template <typename Result = ResultType>
+ NO_SANITIZE_UNDEFINED static inline Result apply(A a [[maybe_unused]], B b [[maybe_unused]])
+ {
+ if constexpr (is_big_int_v<A> || is_big_int_v<B>)
+ throw Exception(ErrorCodes::NOT_IMPLEMENTED, "bitTest is not implemented for big integers as second argument");
+ else
+ return (typename NumberTraits::ToInteger<A>::Type(a) >> typename NumberTraits::ToInteger<B>::Type(b)) & 1;
+ }
+
+#if USE_EMBEDDED_COMPILER
+ static constexpr bool compilable = false; /// TODO
+#endif
+};
+
+struct NameBitTest { static constexpr auto name = "bitTest"; };
+using FunctionBitTest = BinaryArithmeticOverloadResolver<BitTestImpl, NameBitTest, true, false>;
+
+}
+
+REGISTER_FUNCTION(BitTest)
+{
+ factory.registerFunction<FunctionBitTest>();
+}
+
+}