Merge pull request #71871 from ClickHouse/revert-bitshift-backport-for-24.3

Revert "Merge pull request #71861 from pamarcos/fix-bitshift-test"
This commit is contained in:
Pablo Marcos 2024-11-13 16:35:33 +01:00 committed by GitHub
commit 9c47782273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 62 additions and 68 deletions

View File

@ -24,10 +24,6 @@ struct BitShiftLeftImpl
{
if constexpr (is_big_int_v<B>)
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "BitShiftLeft is not implemented for big integers as second argument");
else if (b < 0)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "The number of shift positions needs to be a non-negative value");
else if (static_cast<UInt256>(b) > 8 * sizeof(A))
return static_cast<Result>(0);
else if constexpr (is_big_int_v<A>)
return static_cast<Result>(a) << static_cast<UInt32>(b);
else
@ -41,13 +37,9 @@ struct BitShiftLeftImpl
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "BitShiftLeft is not implemented for big integers as second argument");
else
{
const UInt8 word_size = 8 * sizeof(*pos);
size_t n = end - pos;
const UInt128 bit_limit = static_cast<UInt128>(word_size) * n;
if (b < 0)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "The number of shift positions needs to be a non-negative value");
if (b == bit_limit || static_cast<decltype(bit_limit)>(b) > bit_limit)
UInt8 word_size = 8;
/// To prevent overflow
if (static_cast<double>(b) >= (static_cast<double>(end - pos) * word_size) || b < 0)
{
// insert default value
out_vec.push_back(0);
@ -110,13 +102,10 @@ struct BitShiftLeftImpl
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "BitShiftLeft is not implemented for big integers as second argument");
else
{
const UInt8 word_size = 8;
UInt8 word_size = 8;
size_t n = end - pos;
const UInt128 bit_limit = static_cast<UInt128>(word_size) * n;
if (b < 0)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "The number of shift positions needs to be a non-negative value");
if (b == bit_limit || static_cast<decltype(bit_limit)>(b) > bit_limit)
/// To prevent overflow
if (static_cast<double>(b) >= (static_cast<double>(n) * word_size) || b < 0)
{
// insert default value
out_vec.resize_fill(out_vec.size() + n);

View File

@ -25,10 +25,6 @@ struct BitShiftRightImpl
{
if constexpr (is_big_int_v<B>)
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "BitShiftRight is not implemented for big integers as second argument");
else if (b < 0)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "The number of shift positions needs to be a non-negative value");
else if (static_cast<UInt256>(b) > 8 * sizeof(A))
return static_cast<Result>(0);
else if constexpr (is_big_int_v<A>)
return static_cast<Result>(a) >> static_cast<UInt32>(b);
else
@ -57,13 +53,9 @@ struct BitShiftRightImpl
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "BitShiftRight is not implemented for big integers as second argument");
else
{
const UInt8 word_size = 8;
size_t n = end - pos;
const UInt128 bit_limit = static_cast<UInt128>(word_size) * n;
if (b < 0)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "The number of shift positions needs to be a non-negative value");
if (b == bit_limit || static_cast<decltype(bit_limit)>(b) > bit_limit)
UInt8 word_size = 8;
/// To prevent overflow
if (static_cast<double>(b) >= (static_cast<double>(end - pos) * word_size) || b < 0)
{
/// insert default value
out_vec.push_back(0);
@ -98,13 +90,10 @@ struct BitShiftRightImpl
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "BitShiftRight is not implemented for big integers as second argument");
else
{
const UInt8 word_size = 8;
UInt8 word_size = 8;
size_t n = end - pos;
const UInt128 bit_limit = static_cast<UInt128>(word_size) * n;
if (b < 0)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "The number of shift positions needs to be a non-negative value");
if (b == bit_limit || static_cast<decltype(bit_limit)>(b) > bit_limit)
/// To prevent overflow
if (static_cast<double>(b) >= (static_cast<double>(n) * word_size) || b < 0)
{
// insert default value
out_vec.resize_fill(out_vec.size() + n);

View File

@ -41,6 +41,8 @@ String ConstConst
38 Hello 00010010000110010101101100011011000110111100000000000000000000000000000000000000
39 Hello 00100100001100101011011000110110001101111000000000000000000000000000000000000000
40 Hello
41 Hello
42 Hello
FixedString ConstConst
1
0 Hello\0\0\0\0\0 01001000011001010110110001101100011011110000000000000000000000000000000000000000
@ -90,8 +92,10 @@ FixedString ConstConst
78 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
79 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
80 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
81 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
String VectorVector
-1 Hello
0 Hello 0100100001100101011011000110110001101111
1 Hello 000000001001000011001010110110001101100011011110
7 Hello 001001000011001010110110001101100011011110000000
@ -108,6 +112,8 @@ String VectorVector
33 Hello 00000000100100001100101011011000110110001101111000000000000000000000000000000000
39 Hello 00100100001100101011011000110110001101111000000000000000000000000000000000000000
40 Hello
41 Hello
42 Hello
7 Hel 00100100001100101011011000000000
8 Hel 01001000011001010110110000000000
9 Hel 0000000010010000110010101101100000000000
@ -119,6 +125,7 @@ String VectorVector
9 Hel 0000000010010000110010101101100000000000
FixedString VectorVector
-1 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
0 Hello\0\0\0\0\0 01001000011001010110110001101100011011110000000000000000000000000000000000000000
1 Hello\0\0\0\0\0 10010000110010101101100011011000110111100000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
@ -135,6 +142,8 @@ FixedString VectorVector
33 Hello\0\0\0\0\0 11011110000000000000000000000000000000000000000000000000000000000000000000000000
39 Hello\0\0\0\0\0 10000000000000000000000000000000000000000000000000000000000000000000000000000000
40 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
41 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
42 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
7 Hel\0\0\0\0\0\0\0 00110010101101100000000000000000000000000000000000000000000000000000000000000000
8 Hel\0\0\0\0\0\0\0 01100101011011000000000000000000000000000000000000000000000000000000000000000000
9 Hel\0\0\0\0\0\0\0 11001010110110000000000000000000000000000000000000000000000000000000000000000000
@ -162,6 +171,9 @@ String VectorConst
7 Hello 001001000011001010110110001101100011011110000000
7 Hello 001001000011001010110110001101100011011110000000
7 Hello 001001000011001010110110001101100011011110000000
7 Hello 001001000011001010110110001101100011011110000000
7 Hello 001001000011001010110110001101100011011110000000
7 Hello 001001000011001010110110001101100011011110000000
7 Hel 00100100001100101011011000000000
7 Hel 00100100001100101011011000000000
7 Hel 00100100001100101011011000000000
@ -181,6 +193,9 @@ String VectorConst
8 Hello 010010000110010101101100011011000110111100000000
8 Hello 010010000110010101101100011011000110111100000000
8 Hello 010010000110010101101100011011000110111100000000
8 Hello 010010000110010101101100011011000110111100000000
8 Hello 010010000110010101101100011011000110111100000000
8 Hello 010010000110010101101100011011000110111100000000
8 Hel 01001000011001010110110000000000
8 Hel 01001000011001010110110000000000
8 Hel 01001000011001010110110000000000
@ -202,6 +217,9 @@ FixedString VectorConst
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
7 Hel\0\0\0\0\0\0\0 00110010101101100000000000000000000000000000000000000000000000000000000000000000
7 Hel\0\0\0\0\0\0\0 00110010101101100000000000000000000000000000000000000000000000000000000000000000
7 Hel\0\0\0\0\0\0\0 00110010101101100000000000000000000000000000000000000000000000000000000000000000
@ -221,11 +239,15 @@ FixedString VectorConst
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
8 Hel\0\0\0\0\0\0\0 01100101011011000000000000000000000000000000000000000000000000000000000000000000
8 Hel\0\0\0\0\0\0\0 01100101011011000000000000000000000000000000000000000000000000000000000000000000
8 Hel\0\0\0\0\0\0\0 01100101011011000000000000000000000000000000000000000000000000000000000000000000
String ConstVector
-1 Hello
0 Hello 0100100001100101011011000110110001101111
1 Hello 000000001001000011001010110110001101100011011110
7 Hello 001001000011001010110110001101100011011110000000
@ -242,9 +264,12 @@ String ConstVector
33 Hello 00000000100100001100101011011000110110001101111000000000000000000000000000000000
39 Hello 00100100001100101011011000110110001101111000000000000000000000000000000000000000
40 Hello
41 Hello
42 Hello
7 Hello 001001000011001010110110001101100011011110000000
8 Hello 010010000110010101101100011011000110111100000000
9 Hello 00000000100100001100101011011000110110001101111000000000
-1 Hel
0 Hel 010010000110010101101100
1 Hel 00000000100100001100101011011000
7 Hel 00100100001100101011011000000000
@ -255,11 +280,20 @@ String ConstVector
17 Hel 000000001001000011001010110110000000000000000000
23 Hel 001001000011001010110110000000000000000000000000
24 Hel
25 Hel
31 Hel
32 Hel
33 Hel
39 Hel
40 Hel
41 Hel
42 Hel
7 Hel 00100100001100101011011000000000
8 Hel 01001000011001010110110000000000
9 Hel 0000000010010000110010101101100000000000
FixedString ConstVector
-1 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
0 Hello\0\0\0\0\0 01001000011001010110110001101100011011110000000000000000000000000000000000000000
1 Hello\0\0\0\0\0 10010000110010101101100011011000110111100000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
@ -276,9 +310,12 @@ FixedString ConstVector
33 Hello\0\0\0\0\0 11011110000000000000000000000000000000000000000000000000000000000000000000000000
39 Hello\0\0\0\0\0 10000000000000000000000000000000000000000000000000000000000000000000000000000000
40 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
41 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
42 Hello\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
7 Hello\0\0\0\0\0 00110010101101100011011000110111100000000000000000000000000000000000000000000000
8 Hello\0\0\0\0\0 01100101011011000110110001101111000000000000000000000000000000000000000000000000
9 Hello\0\0\0\0\0 11001010110110001101100011011110000000000000000000000000000000000000000000000000
-1 Hel\0\0\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
0 Hel\0\0\0\0\0\0\0 01001000011001010110110000000000000000000000000000000000000000000000000000000000
1 Hel\0\0\0\0\0\0\0 10010000110010101101100000000000000000000000000000000000000000000000000000000000
7 Hel\0\0\0\0\0\0\0 00110010101101100000000000000000000000000000000000000000000000000000000000000000
@ -295,6 +332,8 @@ FixedString ConstVector
33 Hel\0\0\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
39 Hel\0\0\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
40 Hel\0\0\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
41 Hel\0\0\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
42 Hel\0\0\0\0\0\0\0 00000000000000000000000000000000000000000000000000000000000000000000000000000000
7 Hel\0\0\0\0\0\0\0 00110010101101100000000000000000000000000000000000000000000000000000000000000000
8 Hel\0\0\0\0\0\0\0 01100101011011000000000000000000000000000000000000000000000000000000000000000000
9 Hel\0\0\0\0\0\0\0 11001010110110000000000000000000000000000000000000000000000000000000000000000000

View File

@ -41,6 +41,8 @@ SELECT 37,'Hello',bin(bitShiftLeft('Hello', 37));
SELECT 38,'Hello',bin(bitShiftLeft('Hello', 38));
SELECT 39,'Hello',bin(bitShiftLeft('Hello', 39));
SELECT 40,'Hello',bin(bitShiftLeft('Hello', 40));
SELECT 41,'Hello',bin(bitShiftLeft('Hello', 41));
SELECT 42,'Hello',bin(bitShiftLeft('Hello', 42));
SELECT 'FixedString ConstConst';
SELECT bin(toFixedString('Hello', 10)) == bin(bitShiftLeft(toFixedString('Hello', 10), 0));
@ -91,39 +93,40 @@ SELECT 77,toFixedString('Hello', 10), bin(bitShiftLeft(toFixedString('Hello', 10
SELECT 78,toFixedString('Hello', 10), bin(bitShiftLeft(toFixedString('Hello', 10), 78));
SELECT 79,toFixedString('Hello', 10), bin(bitShiftLeft(toFixedString('Hello', 10), 79));
SELECT 80,toFixedString('Hello', 10), bin(bitShiftLeft(toFixedString('Hello', 10), 80));
SELECT 81,toFixedString('Hello', 10), bin(bitShiftLeft(toFixedString('Hello', 10), 81));
DROP TABLE IF EXISTS test_bit_shift_left_string_integer;
CREATE TABLE test_bit_shift_left_string_integer (str String, fixedStr FixedString(10), id Int64) engine=Log;
INSERT INTO test_bit_shift_left_string_integer VALUES('Hello','Hello',0),('Hello','Hello',1),('Hello','Hello',7),('Hello','Hello',8),('Hello','Hello',9),('Hello','Hello',15),('Hello','Hello',16),('Hello','Hello',17),('Hello','Hello',23),('Hello','Hello',24),('Hello','Hello',25),('Hello','Hello',31),('Hello','Hello',32),('Hello','Hello',33),('Hello','Hello',39),('Hello','Hello',40),('Hel','Hel',7),('Hel','Hel',8),('Hel','Hel',9);
INSERT INTO test_bit_shift_left_string_integer VALUES('Hello','Hello',-1)('Hello','Hello',0),('Hello','Hello',1),('Hello','Hello',7),('Hello','Hello',8),('Hello','Hello',9),('Hello','Hello',15),('Hello','Hello',16),('Hello','Hello',17),('Hello','Hello',23),('Hello','Hello',24),('Hello','Hello',25),('Hello','Hello',31),('Hello','Hello',32),('Hello','Hello',33),('Hello','Hello',39),('Hello','Hello',40),('Hello','Hello',41),('Hello','Hello',42),('Hel','Hel',7),('Hel','Hel',8),('Hel','Hel',9);
SELECT bin(bitShiftLeft('Hello', 40)); --A blank line
SELECT bin(bitShiftLeft('Hello', 42)); --A blank line
SELECT 'String VectorVector';
SELECT id as shift_right_bit,str as arg,bin(bitShiftLeft(str, id)) as string_res FROM test_bit_shift_left_string_integer;
SELECT id as shift_right_bit,str as arg,bin(bitShiftLeft(str, id)) as string_res FROM test_bit_shift_left_string_integer WHERE (str='Hello' AND (id=23 OR id=24 OR id=25)) OR (str='Hel' AND (id=7 OR id=8 OR id=9));
SELECT bin(bitShiftLeft('Hello', 40));
SELECT bin(bitShiftLeft('Hello', 42));
SELECT 'FixedString VectorVector';
SELECT id as shift_right_bit,fixedStr as arg,bin(bitShiftLeft(fixedStr, id)) as fixed_string_res FROM test_bit_shift_left_string_integer;
SELECT id as shift_right_bit,fixedStr as arg,bin(bitShiftLeft(fixedStr, id)) as fixed_string_res FROM test_bit_shift_left_string_integer WHERE (str='Hello' AND (id=23 OR id=24 OR id=25)) OR (str='Hel' AND (id=7 OR id=8 OR id=9));
SELECT bin(bitShiftLeft('Hello', 40)); --A blank line
SELECT bin(bitShiftLeft('Hello', 42)); --A blank line
SELECT 'String VectorConst';
SELECT 7 as shift_right_bit,str as arg,bin(bitShiftLeft(str, 7)) as string_res FROM test_bit_shift_left_string_integer;
SELECT 8 as shift_right_bit,str as arg,bin(bitShiftLeft(str, 8)) as string_res FROM test_bit_shift_left_string_integer;
SELECT bin(bitShiftLeft('Hello', 40)); --A blank line
SELECT bin(bitShiftLeft('Hello', 42)); --A blank line
SELECT 'FixedString VectorConst';
SELECT 7 as shift_right_bit,fixedStr as arg,bin(bitShiftLeft(fixedStr, 7)) as fixed_string_res FROM test_bit_shift_left_string_integer;
SELECT 8 as shift_right_bit,fixedStr as arg,bin(bitShiftLeft(fixedStr, 8)) as fixed_string_res FROM test_bit_shift_left_string_integer;
SELECT bin(bitShiftLeft('Hello', 40)); --A blank line
SELECT bin(bitShiftLeft('Hello', 42)); --A blank line
SELECT 'String ConstVector';
SELECT id as shift_right_bit,'Hello' as arg,bin(bitShiftLeft('Hello', id)) as string_res FROM test_bit_shift_left_string_integer;
SELECT id as shift_right_bit,'Hel' as arg,bin(bitShiftLeft('Hel', id)) as string_res FROM test_bit_shift_left_string_integer WHERE id <= 8 * 3;
SELECT id as shift_right_bit,'Hel' as arg,bin(bitShiftLeft('Hel', id)) as string_res FROM test_bit_shift_left_string_integer;
SELECT bin(bitShiftLeft('Hello', 40)); --A blank line
SELECT bin(bitShiftLeft('Hello', 42)); --A blank line
SELECT 'FixedString ConstVector';
SELECT id as shift_right_bit,toFixedString('Hello', 10) as arg,bin(bitShiftLeft(toFixedString('Hello', 10), id)) as fixed_string_res FROM test_bit_shift_left_string_integer;
SELECT id as shift_right_bit,toFixedString('Hel', 10) as arg,bin(bitShiftLeft(toFixedString('Hel', 10), id)) as fixed_string_res FROM test_bit_shift_left_string_integer;

View File

@ -1,9 +0,0 @@
-- bitShiftRight
0
\0\0\0\0\0\0\0\0
-- bitShiftLeft
0
\0\0\0\0\0\0\0\0
OK

View File

@ -1,17 +0,0 @@
SELECT '-- bitShiftRight';
SELECT bitShiftRight(1, -1); -- { serverError ARGUMENT_OUT_OF_BOUND }
SELECT bitShiftRight(toUInt8(1), 8 + 1);
SELECT bitShiftRight('hola', -1); -- { serverError ARGUMENT_OUT_OF_BOUND }
SELECT bitShiftRight('hola', 4 * 8 + 1);
SELECT bitShiftRight(toFixedString('hola', 8), -1); -- { serverError ARGUMENT_OUT_OF_BOUND }
SELECT bitShiftRight(toFixedString('hola', 8), 8 * 8 + 1);
SELECT '-- bitShiftLeft';
SELECT bitShiftLeft(1, -1); -- { serverError ARGUMENT_OUT_OF_BOUND }
SELECT bitShiftLeft(toUInt8(1), 8 + 1);
SELECT bitShiftLeft('hola', -1); -- { serverError ARGUMENT_OUT_OF_BOUND }
SELECT bitShiftLeft('hola', 4 * 8 + 1);
SELECT bitShiftLeft(toFixedString('hola', 8), -1); -- { serverError ARGUMENT_OUT_OF_BOUND }
SELECT bitShiftLeft(toFixedString('hola', 8), 8 * 8 + 1);
SELECT 'OK';