yiguolei commented on code in PR #19501:
URL: https://github.com/apache/doris/pull/19501#discussion_r1189587279


##########
be/test/vec/core/field_uint64_test.cpp:
##########
@@ -0,0 +1,232 @@
+#include "vec/common/uint128.h"
+#include "vec/core/field.h"
+
+#include "gutil/integral_types.h"
+
+#include <gen_cpp/segment_v2.pb.h>
+#include <gtest/gtest-message.h>
+#include <gtest/gtest-test-part.h>
+#include <climits>
+#include <cstdint>
+
+#include "common/config.h"
+#include "gen_cpp/data.pb.h"
+#include "gtest/gtest_pred_impl.h"
+#include "vec/core/types.h"
+
+namespace doris::vectorized {
+
+// Null
+TEST(FieldTest, Test_Field_Null) {
+    Field field_Null;
+    EXPECT_EQ("Null", field_Null.get_type_name());
+}
+
+// UInt64
+TEST(FieldTest, Test_Field_UInt64) {
+    constexpr UInt64 a = -114514;
+    
+    Field field_UInt64(a);
+    auto b = get<UInt64>(field_UInt64);
+    
+    EXPECT_EQ("UInt64", field_UInt64.get_type_name());
+    EXPECT_EQ(a, b);
+}
+
+// UInt128
+TEST(FieldTest, Test_Field_UInt128) {
+    constexpr unsigned __int128 a = -114514;
+
+    UInt128 val((uint64_t)a, (uint64_t)(a >> 64));
+
+    Field field_UInt128(val);
+    auto b = get<UInt128>(field_UInt128);
+    
+    auto U128_to_string=[](unsigned __int128 rhs) -> String {
+        std::stringstream ss;
+        ss << std::setw(16) << std::setfill('0') << std::hex << (uint64_t)(rhs 
>> 64) << (uint64_t)rhs;
+        return String(ss.str());
+    };
+
+    EXPECT_EQ("UInt128", field_UInt128.get_type_name());
+    EXPECT_EQ(U128_to_string(a), b.to_hex_string());
+    EXPECT_EQ(val, b);
+}
+
+// Int64
+TEST(FieldTest, Test_Field_Int64) {
+    constexpr Int64 a = LLONG_MAX - 114514;
+    
+    Field field_Int64(a);
+    auto b = get<Int64>(field_Int64);
+    
+    EXPECT_EQ("Int64", field_Int64.get_type_name());
+    EXPECT_EQ(a, b);
+}
+
+// Int128
+TEST(FieldTest, Test_Field_Int128) {
+    Int128 a = (1ULL << 63);
+    a = a * a + 114514;
+    
+    Field field_Int128(a);
+    auto b = get<Int128>(field_Int128);
+    
+    EXPECT_EQ("Int128", field_Int128.get_type_name());
+    EXPECT_EQ(a, b);
+}
+
+// Float64
+TEST(FieldTest, Test_Field_Float64) {
+    constexpr Float64 a = 1.2e154;
+    
+    Field field_Float64(a);
+    auto b = get<Float64>(field_Float64);
+
+    EXPECT_EQ("Float64", field_Float64.get_type_name());
+    EXPECT_EQ(a, b);
+}
+
+// String
+TEST(FieldTest, Test_Field_String) {
+    const String a(("114514"));
+    
+    Field field_String(a);
+    auto b = get<String>(field_String);
+
+    EXPECT_EQ("String", field_String.get_type_name());
+    EXPECT_EQ(a, b);
+}
+
+// Decimal32
+TEST(FieldTest, Test_Field_Decimal32) {
+    constexpr Int32 val1 = 114514, val2 = 554514;
+    DecimalField<Decimal32> a(val1, UInt32(3));
+    DecimalField<Decimal32> aa(val2, UInt32(3));
+    
+    Field field_Decimal32(a);
+    auto b = get<DecimalField<Decimal32>>(field_Decimal32);
+
+    EXPECT_EQ("Decimal32", field_Decimal32.get_type_name());
+    EXPECT_EQ(Int32(114514), a.get_value());
+    EXPECT_EQ(UInt32(3), a.get_scale());
+    EXPECT_EQ(a, b);
+    EXPECT_LE(a, aa);
+}
+
+/*
+需要补位,所以会导致溢出
+非法case,需要保证scale相同才能比较大小关系
+*/
+// Decimal64
+TEST(FieldTest, Test_Field_Decimal64) {
+    constexpr Int64 val1 = 114514e12, val2 = 554514e12;

Review Comment:
   check the string value of decimal<type> and datetype



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to