Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
Signed-off-by: Zhigao Tong <[email protected]>
  • Loading branch information
solotzg committed Oct 18, 2023
1 parent 3fee901 commit 0f3ebb5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
37 changes: 25 additions & 12 deletions dbms/src/Functions/FunctionsCoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,16 @@ class FunctionIPv4NumToString : public IFunction

DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (!checkDataType<DataTypeUInt32>(&*arguments[0]) && !checkDataType<DataTypeInt32>(&*arguments[0]))
/*
UInt64/Int64 or other types are NOT allowed by now. MySQL will return default value and warning if failed to cast into 4B integer.
Warning 1411: Incorrect integer value: '`?`.`?`.`?`' for function inet_ntoa
*/
if (!checkDataType<DataTypeUInt32>(&*arguments[0]) && !checkDataType<DataTypeInt32>(&*arguments[0])
&& !checkDataType<DataTypeUInt16>(&*arguments[0]) && !checkDataType<DataTypeInt16>(&*arguments[0])
&& !checkDataType<DataTypeUInt8>(&*arguments[0]) && !checkDataType<DataTypeInt8>(&*arguments[0]))
throw Exception(
fmt::format(
"Illegal type {} of argument of function {}, expected UInt32/Int32",
"Illegal type {} of argument of function {}, expected UInt32/Int32/UInt16/Int16/UInt8/Int8",
arguments[0]->getName(),
getName()),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
Expand Down Expand Up @@ -850,23 +856,30 @@ class FunctionIPv4NumToString : public IFunction
{
const ColumnPtr & column = block.getByPosition(arguments[0]).column;

if (const auto * col = typeid_cast<const ColumnUInt32 *>(column.get()))
{
const typename ColumnUInt32::Container & vec_in = col->getData();
executeImplColumnInteger(block, vec_in, result);
}
else if (const auto * col = typeid_cast<const ColumnInt32 *>(column.get()))
{
const typename ColumnInt32::Container & vec_in = col->getData();
executeImplColumnInteger(block, vec_in, result);
}
#define DISPATCH(ColType) \
else if (const auto * col = typeid_cast<const ColType *>(column.get())) \
{ \
const typename ColType::Container & vec_in = col->getData(); \
executeImplColumnInteger(block, vec_in, result); \
}

if (false) {} // NOLINT
DISPATCH(ColumnUInt32)
DISPATCH(ColumnInt32)
DISPATCH(ColumnUInt16)
DISPATCH(ColumnInt16)
DISPATCH(ColumnUInt8)
DISPATCH(ColumnInt8)
else
{
throw Exception(
fmt::format(
"Illegal column {} of argument of function {}",
block.getByPosition(arguments[0]).column->getName(),
getName()),
ErrorCodes::ILLEGAL_COLUMN);
}
#undef DISPATCH
}
};

Expand Down
8 changes: 8 additions & 0 deletions dbms/src/Functions/tests/gtest_inet_aton_ntoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ void testInetNtoaImpl(TestInetAtonNtoa & tester)
createColumn<Nullable<IntegerType>>({16909060, 65537, 16711935, 66051, 0, 16777472, 1862276364})));
}

TEST_F(TestInetAtonNtoa, InetNtoa)
try
{
testInetNtoaImpl<UInt32>(*this);
testInetNtoaImpl<Int32>(*this);
}
CATCH

TEST_F(TestInetAtonNtoa, InetNtoaReversible)
try
{
Expand Down

0 comments on commit 0f3ebb5

Please sign in to comment.