github-actions[bot] commented on code in PR #18627:
URL: https://github.com/apache/doris/pull/18627#discussion_r1168389256
##########
be/test/vec/data_types/serde/data_type_serde_test.cpp:
##########
@@ -0,0 +1,172 @@
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#include "vec/columns/column_complex.h"
+#include "vec/columns/column_decimal.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/data_types/data_type_bitmap.h"
+#include "vec/data_types/data_type_decimal.h"
+#include "vec/data_types/data_type_hll.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/data_types/data_type_quantilestate.h"
+#include "vec/data_types/data_type_string.h"
+
+namespace doris::vectorized {
+
+void column_to_pb(const DataTypePtr data_type, const IColumn& col, PValues*
result) {
+ const DataTypeSerDeSPtr serde = data_type->get_serde();
+ serde->write_column_to_pb(col, *result, 0, col.size());
+}
+
+void pb_to_column(const DataTypePtr data_type, PValues& result, IColumn& col) {
+ auto serde = data_type->get_serde();
+ serde->read_column_from_pb(col, result);
+}
+
+void check_pb_col(const DataTypePtr data_type, const IColumn& col) {
+ PValues pv = PValues();
+ column_to_pb(data_type, col, &pv);
+ std::string s1 = pv.DebugString();
+
+ auto col1 = data_type->create_column();
+ pb_to_column(data_type, pv, *col1);
+ PValues as_pv = PValues();
+ column_to_pb(data_type, *col1, &as_pv);
+
+ std::string s2 = as_pv.DebugString();
+ EXPECT_EQ(s1, s2);
+}
+
+void serialize_and_deserialize_pb_test() {
+ // int
+ {
+ auto vec = vectorized::ColumnVector<Int32>::create();
+ auto& data = vec->get_data();
+ for (int i = 0; i < 1024; ++i) {
+ data.push_back(i);
+ }
+ vectorized::DataTypePtr
data_type(std::make_shared<vectorized::DataTypeInt32>());
+ check_pb_col(data_type, *vec.get());
+ }
+ // string
+ {
+ auto strcol = vectorized::ColumnString::create();
+ for (int i = 0; i < 1024; ++i) {
+ std::string is = std::to_string(i);
+ strcol->insert_data(is.c_str(), is.size());
+ }
+ vectorized::DataTypePtr
data_type(std::make_shared<vectorized::DataTypeString>());
+ check_pb_col(data_type, *strcol.get());
+ }
+ // decimal
+ {
+ vectorized::DataTypePtr
decimal_data_type(doris::vectorized::create_decimal(27, 9, true));
+ auto decimal_column = decimal_data_type->create_column();
+ auto& data =
((vectorized::ColumnDecimal<vectorized::Decimal<vectorized::Int128>>*)
+ decimal_column.get())
+ ->get_data();
+ for (int i = 0; i < 1024; ++i) {
+ __int128_t value = i * pow(10, 9) + i * pow(10, 8);
+ data.push_back(value);
+ }
+ check_pb_col(decimal_data_type, *decimal_column.get());
+ }
+ // bitmap
+ {
+ vectorized::DataTypePtr
bitmap_data_type(std::make_shared<vectorized::DataTypeBitMap>());
+ auto bitmap_column = bitmap_data_type->create_column();
+ std::vector<BitmapValue>& container =
+ ((vectorized::ColumnBitmap*)bitmap_column.get())->get_data();
+ for (int i = 0; i < 4; ++i) {
+ BitmapValue bv;
+ for (int j = 0; j <= i; ++j) {
+ bv.add(j);
+ }
+ container.push_back(bv);
+ }
+ check_pb_col(bitmap_data_type, *bitmap_column.get());
+ }
+ // hll
+ {
+ vectorized::DataTypePtr
hll_data_type(std::make_shared<vectorized::DataTypeHLL>());
+ auto hll_column = hll_data_type->create_column();
+ std::vector<HyperLogLog>& container =
+ ((vectorized::ColumnHLL*)hll_column.get())->get_data();
+ for (int i = 0; i < 4; ++i) {
+ HyperLogLog hll;
+ hll.update(i);
+ container.push_back(hll);
+ }
+ check_pb_col(hll_data_type, *hll_column.get());
+ }
+ // quantilestate
+ {
+ vectorized::DataTypePtr quantile_data_type(
+ std::make_shared<vectorized::DataTypeQuantileStateDouble>());
+ auto quantile_column = quantile_data_type->create_column();
+ std::vector<QuantileStateDouble>& container =
+
((vectorized::ColumnQuantileStateDouble*)quantile_column.get())->get_data();
+ const long max_rand = 1000000L;
+ double lower_bound = 0;
+ double upper_bound = 100;
+ srandom(time(NULL));
Review Comment:
warning: use nullptr [modernize-use-nullptr]
```suggestion
srandom(time(nullptr));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]