fix hash functions for IPv4

This commit is contained in:
Yakov Olkhovskiy 2023-01-08 20:58:09 +00:00
parent 0eaf05a2dd
commit 6ec1592a9f
3 changed files with 10 additions and 1 deletions

View File

@ -37,6 +37,9 @@ public:
bool shouldAlignRightInPrettyFormats() const override { return false; }
bool textCanContainOnlyValidUTF8() const override { return true; }
bool isComparable() const override { return true; }
bool isValueRepresentedByNumber() const override { return true; }
bool isValueRepresentedByInteger() const override { return true; }
bool isValueRepresentedByUnsignedInteger() const override { return true; }
bool isValueUnambiguouslyRepresentedInContiguousMemoryRegion() const override { return true; }
bool isValueUnambiguouslyRepresentedInFixedSizeContiguousMemoryRegion() const override { return true; }
bool haveMaximumSizeOfValue() const override { return true; }

View File

@ -6,6 +6,7 @@
#include <Functions/FunctionHelpers.h>
#include <Functions/IFunction.h>
#include <Common/typeid_cast.h>
#include <base/IPv4andIPv6.h>
#include <Interpreters/Context_fwd.h>
@ -43,7 +44,7 @@ public:
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (!isInteger(arguments[0]))
if (!isInteger(arguments[0]) && !isIPv4(arguments[0]))
throw Exception("Illegal type " + arguments[0]->getName() + " of the first argument of function " + getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
@ -132,6 +133,8 @@ private:
executeType<Int32>(hash_col, num_buckets, res_col.get());
else if (which.isInt64())
executeType<Int64>(hash_col, num_buckets, res_col.get());
else if (which.isIPv4())
executeType<IPv4>(hash_col, num_buckets, res_col.get());
else
throw Exception("Illegal type " + hash_type->getName() + " of the first argument of function " + getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

View File

@ -52,6 +52,7 @@
#include <Functions/FunctionHelpers.h>
#include <Functions/PerformanceAdaptors.h>
#include <Common/TargetSpecific.h>
#include <base/IPv4andIPv6.h>
#include <base/range.h>
#include <base/bit_cast.h>
@ -838,6 +839,8 @@ public:
return executeType<Decimal32>(arguments);
else if (which.isDecimal64())
return executeType<Decimal64>(arguments);
else if (which.isIPv4())
return executeType<IPv4>(arguments);
else
throw Exception("Illegal type " + arguments[0].type->getName() + " of argument of function " + getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);