Copilot commented on code in PR #62179:
URL: https://github.com/apache/doris/pull/62179#discussion_r3061898638
##########
be/test/exprs/function/cast/cast_to_string_api_test.cpp:
##########
@@ -159,4 +159,16 @@ TEST(CastToStringTest, test) {
}
}
-} // namespace doris
\ No newline at end of file
+TEST(CastToStringTest, from_int128_overloads) {
+
EXPECT_EQ(CastToString::from_int128(static_cast<int128_t>(-1234567890123456789LL)),
+ "-1234567890123456789");
+
EXPECT_EQ(CastToString::from_uint128(static_cast<uint128_t>(12345678901234567890ULL)),
+ "12345678901234567890");
+
+ UInt128 value;
+ value.items[0] = 0x0123456789ABCDEFULL;
+ value.items[1] = 0x0FEDCBA987654321ULL;
+ EXPECT_EQ(CastToString::from_uint128(value),
"0123456789abcdeffedcba987654321");
Review Comment:
The expected hex string here depends on `wide::integer<>::to_hex_string()`
formatting details (it currently prints `items[0]` then `items[1]` and does not
zero-pad each 64-bit chunk consistently). This makes the test fragile if the
underlying hex formatter is corrected or its ordering changes. Consider either
asserting against a stable, documented hex format (e.g. fixed-width 32 hex
chars, high->low order) or choose a test value that avoids leading zeros in the
upper word so padding behavior isn't part of the expectation.
##########
be/test/core/data_type_serde/data_type_serde_number_test.cpp:
##########
@@ -336,4 +338,38 @@ TEST_F(DataTypeNumberSerDeTest, ArrowMemNotAligned) {
EXPECT_TRUE(st.ok());
}
+TEST_F(DataTypeNumberSerDeTest, ArrowStringToUnsignedDateLikeTypes) {
+ std::vector<std::string> strings = {"20240102", "20240102112233"};
+ std::vector<int32_t> offsets = {0};
+ int32_t total_length = 0;
+ for (const auto& str : strings) {
+ total_length += static_cast<int32_t>(str.length());
+ offsets.push_back(total_length);
+ }
+
+ std::string value_bytes;
+ value_bytes.reserve(total_length);
+ for (const auto& str : strings) {
+ value_bytes.append(str);
+ }
+
+ auto value_buffer = arrow::Buffer::Wrap(value_bytes.data(),
value_bytes.size());
+ auto offset_buffer = arrow::Buffer::Wrap(offsets);
+ auto arr = std::make_shared<arrow::StringArray>(strings.size(),
offset_buffer, value_buffer);
+
+ auto datev2_column = ColumnVector<TYPE_DATEV2>::create();
+ auto datetimev2_column = ColumnVector<TYPE_DATETIMEV2>::create();
+ cctz::time_zone tz;
+
+ auto st = serde_datev2_num->read_column_from_arrow(*datev2_column,
arr.get(), 0, 1, tz);
+ ASSERT_TRUE(st.ok());
+ ASSERT_EQ(1, datev2_column->size());
+ EXPECT_EQ(20240102U, datev2_column->get_data()[0].to_date_int_val());
+
+ st = serde_datetimev2_num->read_column_from_arrow(*datetimev2_column,
arr.get(), 1, 2, tz);
+ ASSERT_TRUE(st.ok());
+ ASSERT_EQ(1, datetimev2_column->size());
+ EXPECT_EQ(20240102112233ULL,
datetimev2_column->get_data()[0].to_date_int_val());
+}
Review Comment:
This test uses string values like "20240102" / "20240102112233" and asserts
`to_date_int_val()` equals those decimal digits.
`DateV2Value::to_date_int_val()` is the packed internal representation
(bitfields), so treating YYYYMMDD(…)/YYYYMMDDhhmmss(…) as the internal value
will produce an invalid date/datetime payload even though the integer matches.
To make this test meaningful, either (a) parse the strings via the
date/datetime cast/parsers and assert the resulting `to_string()`/components,
or (b) if the Arrow STRING encoding is intended to carry the packed integer,
use expected packed values (not human-formatted digits) and name the test
accordingly.
##########
be/test/exec/column_type_convert_test.cpp:
##########
@@ -1282,9 +1283,11 @@ TEST_F(ColumnTypeConverterTest,
TestStringToIntegerTypes) {
ASSERT_TRUE(st.ok());
ASSERT_EQ(4, nested_col.size());
- EXPECT_EQ("123456789012345678901234567890",
int128_to_string(nested_col.get_data()[0]));
+ EXPECT_EQ("123456789012345678901234567890",
+ CastToString::from_uint128(nested_col.get_data()[0]));
- EXPECT_EQ("-123456789012345678901234567890",
int128_to_string(nested_col.get_data()[1]));
+ EXPECT_EQ("-123456789012345678901234567890",
+ CastToString::from_int128(nested_col.get_data()[1]));
Review Comment:
`nested_col` here is a `ColumnInt128` (signed LARGEINT), but the positive
case is formatted via `CastToString::from_uint128(...)`. This works for the
current value but is type-mismatched and can become confusing (or wrong for
values with the sign bit set). Prefer using `from_int128` consistently for
signed LARGEINT values, or cast explicitly with a comment if the intent is to
treat the value as unsigned.
--
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]