3131#include "compression/algorithms/float_utils.h"
3232#include "compression/algorithms/gorilla.h"
3333#include "compression/algorithms/null.h"
34+ #include "compression/algorithms/simple8b_rle.h"
3435#include "compression/arrow_c_data_interface.h"
3536#include "compression/batch_metadata_builder_minmax.h"
3637
@@ -1009,6 +1010,65 @@ test_null()
10091010 }
10101011}
10111012
1013+ static void
1014+ test_simple8b_rle_compressed_size (uint64 * elements , int num_elements )
1015+ {
1016+ Simple8bRleCompressor compressor ;
1017+ simple8brle_compressor_init (& compressor );
1018+
1019+ for (int i = 0 ; i < num_elements ; i ++ )
1020+ {
1021+ simple8brle_compressor_append (& compressor , elements [i ]);
1022+ }
1023+
1024+ size_t compressed_size = simple8brle_compressor_compressed_const_size (& compressor );
1025+ if (num_elements == 0 )
1026+ {
1027+ TestAssertInt64Eq (compressed_size , 0 );
1028+ return ;
1029+ }
1030+
1031+ Simple8bRleSerialized * serialized = simple8brle_compressor_finish (& compressor );
1032+ size_t serialized_size = simple8brle_serialized_total_size (serialized );
1033+ TestAssertInt64Eq (compressed_size , serialized_size );
1034+
1035+ /* Check the const size function after the compressor is finished,
1036+ * this may happen accidentally, not on purpose.
1037+ */
1038+ compressed_size = simple8brle_compressor_compressed_const_size (& compressor );
1039+ TestAssertInt64Eq (compressed_size , serialized_size );
1040+
1041+ pfree (serialized );
1042+ }
1043+
1044+ static void
1045+ test_simple8b_rle ()
1046+ {
1047+ /* clang-format off */
1048+ /* clang would place all the elements on a single line otherwise */
1049+ uint64 elements [] = {
1050+ 1 , 2 , 4 , 8 , 16 , 7 , 3 , 32 , 64 , 63 , 31 , 15 , 7 , 3 , 1 , 0 ,
1051+ 128 , 127 , 63 , 31 , 15 , 7 , 3 , 1 , 0 , 256 , 255 , 127 , 63 , 31 , 15 , 7 ,
1052+ 3 , 1 , 0 , 512 , 511 , 126 , 63 , 31 , 15 , 7 , 3 , 1 , 0 , 1024 , 1023 , 511 ,
1053+ 255 , 127 , 63 , 31 , 15 , 7 , 3 , 1 , 0 , 2048 , 2047 , 1023 , 511 , 255 , 127 ,
1054+ 63 , 31 , 15 , 7 , 3 , 1 , 0 , 4096 , 4095 , 2047 , 1023 , 511 , 255 , 127 , 63 ,
1055+ 31 , 15 , 7 , 3 , 1 , 0 , 8192 , 8191 , 4095 , 2047 , 1023 , 511 , 255 , 127 ,
1056+ 63 , 31 , 15 , 7 , 3 , 1 , 0 , 16384 , 16383 , 8191 , 4095 , 2047 , 1023 , 511 ,
1057+ 255 , 127 , 63 , 31 , 15 , 7 , 3 , 1 , 0 , 32768 , 32767 , 16383 , 8191 , 4095 ,
1058+ 2047 , 1023 , 511 , 255 , 127 , 63 , 31 , 15 , 7 , 3 , 1 , 0 , 65536 , 65535 ,
1059+ 32767 , 16383 , 8191 , 4095 , 2047 , 1023 , 511 , 255 , 127 , 63 , 31 , 15 ,
1060+ 131072 , 131071 , 65535 , 16777216 , 16777211 , 16777215 , 4294967296ULL ,
1061+ 12884901888ULL
1062+ };
1063+ /* clang-format on */
1064+
1065+ int n = sizeof (elements ) / sizeof (* elements );
1066+ for (int i = 0 ; i < n ; i ++ )
1067+ {
1068+ test_simple8b_rle_compressed_size (elements , i );
1069+ }
1070+ }
1071+
10121072Datum
10131073ts_test_compression (PG_FUNCTION_ARGS )
10141074{
@@ -1030,6 +1090,7 @@ ts_test_compression(PG_FUNCTION_ARGS)
10301090 test_delta3 (/* have_nulls = */ true, /* have_random = */ true);
10311091 test_bool ();
10321092 test_null ();
1093+ test_simple8b_rle ();
10331094
10341095 /* Some tests for zig-zag encoding overflowing the original element width. */
10351096 test_delta4 (test_delta4_case1 , sizeof (test_delta4_case1 ) / sizeof (* test_delta4_case1 ));
0 commit comments