From 335be4c8076a5d8f651cd0eab8dda446cd81f76d Mon Sep 17 00:00:00 2001 From: Memo Date: Mon, 18 Apr 2022 20:13:43 +0800 Subject: [PATCH] hex support Int128/Int256/UInt128/UInt256 --- src/Functions/FunctionsBinaryRepr.cpp | 25 +++++++++++-------- .../02285_hex_support_more_types.reference | 6 +++++ .../02285_hex_support_more_types.sql | 11 ++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 tests/queries/0_stateless/02285_hex_support_more_types.reference create mode 100644 tests/queries/0_stateless/02285_hex_support_more_types.sql diff --git a/src/Functions/FunctionsBinaryRepr.cpp b/src/Functions/FunctionsBinaryRepr.cpp index b8733cfc644..21370ba7bbb 100644 --- a/src/Functions/FunctionsBinaryRepr.cpp +++ b/src/Functions/FunctionsBinaryRepr.cpp @@ -43,7 +43,7 @@ struct HexImpl static constexpr size_t word_size = 2; template - static void executeOneUInt(T x, char *& out, bool skip_leading_zero = true, bool auto_close = true) + static void executeOneUIntOrInt(T x, char *& out, bool skip_leading_zero = true, bool auto_close = true) { bool was_nonzero = false; for (int offset = (sizeof(T) - 1) * 8; offset >= 0; offset -= 8) @@ -134,7 +134,7 @@ struct BinImpl static constexpr size_t word_size = 8; template - static void executeOneUInt(T x, char *& out, bool skip_leading_zero = true, bool auto_close = true) + static void executeOneUIntOrInt(T x, char *& out, bool skip_leading_zero = true, bool auto_close = true) { bool was_nonzero = false; for (int offset = (sizeof(T) - 1) * 8; offset >= 0; offset -= 8) @@ -280,6 +280,7 @@ public: !which.isDateTime() && !which.isDateTime64() && !which.isUInt() && + !which.isInt() && !which.isFloat() && !which.isDecimal() && !which.isUUID() && @@ -304,10 +305,14 @@ public: return res_column; } - if (tryExecuteUInt(column, res_column) || - tryExecuteUInt(column, res_column) || - tryExecuteUInt(column, res_column) || - tryExecuteUInt(column, res_column) || + if (tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || + tryExecuteUIntOrInt(column, res_column) || tryExecuteString(column, res_column) || tryExecuteFixedString(column, res_column) || tryExecuteFloat(column, res_column) || @@ -324,7 +329,7 @@ public: } template - bool tryExecuteUInt(const IColumn * col, ColumnPtr & col_res) const + bool tryExecuteUIntOrInt(const IColumn * col, ColumnPtr & col_res) const { const ColumnVector * col_vec = checkAndGetColumn>(col); @@ -351,7 +356,7 @@ public: char * begin = reinterpret_cast(&out_vec[pos]); char * end = begin; - Impl::executeOneUInt(in_vec[i], end); + Impl::executeOneUIntOrInt(in_vec[i], end); pos += end - begin; out_offsets[i] = pos; @@ -521,8 +526,8 @@ public: // use executeOnUInt instead of using executeOneString // because the latter one outputs the string in the memory order - Impl::executeOneUInt(uuid[i].toUnderType().items[0], end, false, false); - Impl::executeOneUInt(uuid[i].toUnderType().items[1], end, false, true); + Impl::executeOneUIntOrInt(uuid[i].toUnderType().items[0], end, false, false); + Impl::executeOneUIntOrInt(uuid[i].toUnderType().items[1], end, false, true); pos += end - begin; out_offsets[i] = pos; diff --git a/tests/queries/0_stateless/02285_hex_support_more_types.reference b/tests/queries/0_stateless/02285_hex_support_more_types.reference new file mode 100644 index 00000000000..2f5376381f3 --- /dev/null +++ b/tests/queries/0_stateless/02285_hex_support_more_types.reference @@ -0,0 +1,6 @@ +174876E800 +174876E800 +174876E800 +174876E800 +FFFFFFFFFFFFFFFFFFFFFFE8B7891800 +FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE8B7891800 diff --git a/tests/queries/0_stateless/02285_hex_support_more_types.sql b/tests/queries/0_stateless/02285_hex_support_more_types.sql new file mode 100644 index 00000000000..0f20ed84405 --- /dev/null +++ b/tests/queries/0_stateless/02285_hex_support_more_types.sql @@ -0,0 +1,11 @@ +SELECT hex(toUInt128(100000000000)) AS res; + +SELECT hex(toUInt256(100000000000)) AS res; + +SELECT hex(toInt128(100000000000)) AS res; + +SELECT hex(toInt256(100000000000)) AS res; + +SELECT hex(toInt128(-100000000000)) AS res; + +SELECT hex(toInt256(-100000000000)) AS res;