mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
hex support Int128/Int256/UInt128/UInt256
This commit is contained in:
parent
89deaf0af1
commit
335be4c807
@ -43,7 +43,7 @@ struct HexImpl
|
||||
static constexpr size_t word_size = 2;
|
||||
|
||||
template <typename T>
|
||||
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 <typename T>
|
||||
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<UInt8>(column, res_column) ||
|
||||
tryExecuteUInt<UInt16>(column, res_column) ||
|
||||
tryExecuteUInt<UInt32>(column, res_column) ||
|
||||
tryExecuteUInt<UInt64>(column, res_column) ||
|
||||
if (tryExecuteUIntOrInt<UInt8>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<UInt16>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<UInt32>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<UInt64>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<UInt128>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<UInt256>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<Int128>(column, res_column) ||
|
||||
tryExecuteUIntOrInt<Int256>(column, res_column) ||
|
||||
tryExecuteString(column, res_column) ||
|
||||
tryExecuteFixedString(column, res_column) ||
|
||||
tryExecuteFloat<Float32>(column, res_column) ||
|
||||
@ -324,7 +329,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool tryExecuteUInt(const IColumn * col, ColumnPtr & col_res) const
|
||||
bool tryExecuteUIntOrInt(const IColumn * col, ColumnPtr & col_res) const
|
||||
{
|
||||
const ColumnVector<T> * col_vec = checkAndGetColumn<ColumnVector<T>>(col);
|
||||
|
||||
@ -351,7 +356,7 @@ public:
|
||||
|
||||
char * begin = reinterpret_cast<char *>(&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;
|
||||
|
@ -0,0 +1,6 @@
|
||||
174876E800
|
||||
174876E800
|
||||
174876E800
|
||||
174876E800
|
||||
FFFFFFFFFFFFFFFFFFFFFFE8B7891800
|
||||
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE8B7891800
|
11
tests/queries/0_stateless/02285_hex_support_more_types.sql
Normal file
11
tests/queries/0_stateless/02285_hex_support_more_types.sql
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user