mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
New hex function release
Bugs and tests fixed
This commit is contained in:
parent
4f24512ba4
commit
bd29efdbbe
@ -946,9 +946,10 @@ public:
|
||||
{
|
||||
WhichDataType which(arguments[0]);
|
||||
|
||||
if (!which.isStringOrFixedString()
|
||||
&& !which.isDateOrDateTime()
|
||||
&& !which.isUInt() && !which.isFloat())
|
||||
if (!which.isStringOrFixedString() &&
|
||||
!which.isDateOrDateTime() &&
|
||||
!which.isUInt() &&
|
||||
!which.isFloat())
|
||||
throw Exception("Illegal type " + arguments[0]->getName() + " of argument of function " + getName(),
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
|
||||
@ -1026,7 +1027,7 @@ public:
|
||||
{
|
||||
const ColumnVector<T> * col_vec = checkAndGetColumn<ColumnVector<T>>(col);
|
||||
|
||||
static constexpr size_t MAX_FLOAT_HEX_LENGTH = sizeof(T) * 2 + 1; /// Including trailing zero byte.
|
||||
static constexpr size_t FLOAT_HEX_LENGTH = sizeof(T) * 2 + 1; /// Including trailing zero byte.
|
||||
|
||||
if (col_vec)
|
||||
{
|
||||
@ -1038,27 +1039,19 @@ public:
|
||||
|
||||
size_t size = in_vec.size();
|
||||
out_offsets.resize(size);
|
||||
out_vec.resize(size * 3 + MAX_FLOAT_HEX_LENGTH); /// 3 is length of one byte in hex plus zero byte.
|
||||
out_vec.resize(size * FLOAT_HEX_LENGTH);
|
||||
|
||||
size_t pos = 0;
|
||||
char * out = reinterpret_cast<char *>(&out_vec[0]);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
/// Manual exponential growth, so as not to rely on the linear amortized work time of `resize` (no one guarantees it).
|
||||
if (pos + MAX_FLOAT_HEX_LENGTH > out_vec.size())
|
||||
out_vec.resize(out_vec.size() * 2 + MAX_FLOAT_HEX_LENGTH);
|
||||
|
||||
char * begin = reinterpret_cast<char *>(&out_vec[pos]);
|
||||
char * end = begin;
|
||||
|
||||
const UInt8 * in_pos = reinterpret_cast<const UInt8 *>(&in_vec[i]);
|
||||
executeOneString(in_pos, in_pos + sizeof(in_vec[i]), end);
|
||||
executeOneString(in_pos, in_pos + sizeof(T), out);
|
||||
|
||||
pos += end - begin;
|
||||
pos += FLOAT_HEX_LENGTH;
|
||||
out_offsets[i] = pos;
|
||||
}
|
||||
|
||||
out_vec.resize(pos);
|
||||
|
||||
col_res = std::move(col_str);
|
||||
return true;
|
||||
}
|
||||
|
@ -4,4 +4,9 @@
|
||||
2342920CA19CC73B
|
||||
7DC39425AD49B254
|
||||
2C616D8C9DF0423F
|
||||
BA490C022BFF5EC0
|
||||
3BDF4F8D97FE5EC0
|
||||
0A57C742
|
||||
00004843
|
||||
00004943
|
||||
0000000000406940
|
||||
0000000000606940
|
||||
|
@ -4,4 +4,7 @@ SELECT hex(1e+18);
|
||||
SELECT hex(1e-20);
|
||||
SELECT hex(1e+100);
|
||||
SELECT hex(0.000578);
|
||||
SELECt hex(-123.987);
|
||||
SELECT hex(-123.978);
|
||||
SELECT hex(toFloat32(99.67));
|
||||
SELECT hex(toFloat32(number)) FROM numbers(200, 2);
|
||||
SELECT hex(toFloat64(number)) FROM numbers(202, 2);
|
||||
|
Loading…
Reference in New Issue
Block a user