csun5285 commented on code in PR #47389: URL: https://github.com/apache/doris/pull/47389#discussion_r1942626208
########## be/src/util/mysql_row_buffer.cpp: ########## @@ -361,13 +361,76 @@ int MysqlRowBuffer<is_binary_format>::push_double(double data) { return 0; } +// Refer to https://dev.mysql.com/doc/refman/5.7/en/time.html +// Encode time into MySQL binary protocol format with support for scale (microsecond precision) +// Time value is limited between '-838:59:59' and '838:59:59' +static int encode_binary_timev2(char* buff, double time, int scale) { + // Check if scale is valid (0 to 6) + if (scale < 0 || scale > 6) { + return -1; // Return error for invalid scale + } + + int pos = 0; // Current position in the buffer + bool is_negative = time < 0; // Determine if the time is negative + double abs_time = std::abs(time); // Convert time to absolute value + + // Maximum time in microseconds: 838 hours, 59 minutes, 59 seconds + const int64_t MAX_TIME_MICROSECONDS = (838 * 3600 + 59 * 60 + 59) * 1000000LL; + + // Convert time into microseconds and enforce range limit + int64_t total_microseconds = static_cast<int64_t>(abs_time); // Total microseconds Review Comment: The precision of the double is lost ########## be/test/util/mysql_row_buffer_test.cpp: ########## @@ -115,4 +115,20 @@ TEST(MysqlRowBufferTest, dynamic_mode) { EXPECT_EQ(0, strncmp(buf + 43, "test", 4)); } +TEST(MysqlRowBufferTest, TestBinaryTimeCompressedEncoding) { + MysqlRowBuffer<true> buffer; + + // case1 : all 0, should only send 1 byte + buffer.push_timev2(0.0, 6); Review Comment: check the contents of a buffer -- 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