This is an automated email from the ASF dual-hosted git repository.
zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new f25e0c098c5 [Enhancement](check) Add compile check for some files
(#55582)
f25e0c098c5 is described below
commit f25e0c098c58e41520342255ef07e58972b613f0
Author: zclllyybb <[email protected]>
AuthorDate: Wed Sep 3 19:40:29 2025 +0800
[Enhancement](check) Add compile check for some files (#55582)
---
be/src/util/cpu_info.cpp | 31 +++++++++++++++++++------------
be/src/util/cpu_info.h | 2 +-
be/src/util/date_func.cpp | 30 ++++++++++++++++++------------
be/src/util/date_func.h | 2 +-
be/src/util/mysql_row_buffer.cpp | 12 +++++-------
be/src/util/time_lut.cpp | 32 ++++++++++++++++++++------------
be/src/util/time_lut.h | 13 ++++++-------
be/src/vec/runtime/vdatetime_value.h | 2 +-
8 files changed, 71 insertions(+), 53 deletions(-)
diff --git a/be/src/util/cpu_info.cpp b/be/src/util/cpu_info.cpp
index b438dbb083b..c5ed4562f64 100644
--- a/be/src/util/cpu_info.cpp
+++ b/be/src/util/cpu_info.cpp
@@ -73,21 +73,21 @@ DEFINE_int32(num_cores, 0,
" according to /proc/cpuinfo.");
namespace doris {
+#include "common/compile_check_begin.h"
// Helper function to warn if a given file does not contain an expected string
as its
// first line. If the file cannot be opened, no error is reported.
void WarnIfFileNotEqual(const std::string& filename, const std::string&
expected,
const std::string& warning_text) {
std::ifstream file(filename);
- if (!file) return;
+ if (!file) {
+ return;
+ }
std::string line;
getline(file, line);
if (line != expected) {
LOG(ERROR) << "Expected " << expected << ", actual " << line <<
std::endl << warning_text;
}
}
-} // namespace doris
-
-namespace doris {
bool CpuInfo::initialized_ = false;
int64_t CpuInfo::hardware_flags_ = 0;
@@ -105,8 +105,9 @@ static struct {
std::string name;
int64_t flag;
} flag_mappings[] = {
- {"ssse3", CpuInfo::SSSE3}, {"sse4_1", CpuInfo::SSE4_1}, {"sse4_2",
CpuInfo::SSE4_2},
- {"popcnt", CpuInfo::POPCNT}, {"avx", CpuInfo::AVX}, {"avx2",
CpuInfo::AVX2},
+ {.name = "ssse3", .flag = CpuInfo::SSSE3}, {.name = "sse4_1", .flag
= CpuInfo::SSE4_1},
+ {.name = "sse4_2", .flag = CpuInfo::SSE4_2}, {.name = "popcnt", .flag
= CpuInfo::POPCNT},
+ {.name = "avx", .flag = CpuInfo::AVX}, {.name = "avx2", .flag =
CpuInfo::AVX2},
};
// Helper function to parse for hardware flags.
@@ -124,7 +125,9 @@ int64_t ParseCPUFlags(const std::string& values) {
}
void CpuInfo::init() {
- if (initialized_) return;
+ if (initialized_) {
+ return;
+ }
std::string line;
std::string name;
std::string value;
@@ -150,7 +153,7 @@ void CpuInfo::init() {
// that when impala is running, the core will not be in a
lower power state.
// TODO: is there a more robust way to do this, such as
// Window's QueryPerformanceFrequency()
- float mhz = atof(value.c_str());
+ float mhz = std::stof(value);
max_mhz = max(mhz, max_mhz);
} else if (name == "processor") {
++physical_num_cores;
@@ -224,7 +227,9 @@ void CpuInfo::_init_numa() {
max_num_numa_nodes_ = 0;
for (; dir_it != fs::directory_iterator(); ++dir_it) {
const std::string filename = dir_it->path().filename().string();
- if (filename.find("node") == 0) ++max_num_numa_nodes_;
+ if (filename.starts_with("node")) {
+ ++max_num_numa_nodes_;
+ }
}
if (max_num_numa_nodes_ == 0) {
LOG(WARNING) << "Could not find nodes in /sys/devices/system/node";
@@ -268,7 +273,7 @@ void CpuInfo::_init_numa_node_to_cores() {
numa_node_core_idx_.resize(max_num_cores_);
for (int core = 0; core < max_num_cores_; ++core) {
std::vector<int>* cores_of_node =
&numa_node_to_cores_[core_to_numa_node_[core]];
- numa_node_core_idx_[core] = cores_of_node->size();
+ numa_node_core_idx_[core] = static_cast<int>(cores_of_node->size());
cores_of_node->push_back(core);
}
}
@@ -319,7 +324,9 @@ int CpuInfo::get_current_core() {
// so that we can build and run with degraded perf.
#ifdef HAVE_SCHED_GETCPU
int cpu = sched_getcpu();
- if (cpu < 0) return 0;
+ if (cpu < 0) {
+ return 0;
+ }
if (cpu >= max_num_cores_) {
LOG_FIRST_N(WARNING, 5) << "sched_getcpu() return value " << cpu
<< ", which is greater than get_nprocs_conf()
retrun value "
@@ -413,5 +420,5 @@ std::string CpuInfo::debug_string() {
stream << std::endl;
return stream.str();
}
-
+#include "common/compile_check_end.h"
} // namespace doris
diff --git a/be/src/util/cpu_info.h b/be/src/util/cpu_info.h
index 0e03ad3928a..19548ecc964 100644
--- a/be/src/util/cpu_info.h
+++ b/be/src/util/cpu_info.h
@@ -21,8 +21,8 @@
#pragma once
#include <glog/logging.h>
-#include <stdint.h>
+#include <cstdint>
#include <memory>
#include <string>
#include <vector>
diff --git a/be/src/util/date_func.cpp b/be/src/util/date_func.cpp
index 7719bfa6384..f2cd5c823f6 100644
--- a/be/src/util/date_func.cpp
+++ b/be/src/util/date_func.cpp
@@ -24,11 +24,13 @@
#include <cstring>
#include <ctime>
+#include "common/cast_set.h"
+#include "vec/common/int_exp.h"
#include "vec/runtime/time_value.h"
#include "vec/runtime/vdatetime_value.h"
namespace doris {
-
+#include "common/compile_check_begin.h"
VecDateTimeValue timestamp_from_datetime(const std::string& datetime_str) {
tm time_tm;
char* res = strptime(datetime_str.c_str(), "%Y-%m-%d %H:%M:%S", &time_tm);
@@ -87,16 +89,15 @@ DateV2Value<DateTimeV2ValueType>
timestamp_from_datetime_v2(const std::string& d
}
//FIXME: try to remove or refactor all those time input/output functions.
-int32_t timev2_to_buffer_from_double(double time, char* buffer, int scale) {
- static int pow10[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
-
+uint8_t timev2_to_buffer_from_double(double time, char* buffer, int scale) {
char* begin = buffer;
if (time < 0) {
time = -time;
*buffer++ = '-';
}
- auto m_time = (int64_t)TimeValue::limit_with_bound(time);
- int64_t hour = m_time / ((int64_t)3600 * 1000 * 1000);
+ auto m_time = (uint64_t)TimeValue::limit_with_bound(time);
+
+ auto hour = static_cast<uint16_t>(m_time / (3600ULL * 1000 * 1000));
if (hour >= 100) {
buffer = fmt::format_to(buffer, FMT_COMPILE("{}"), hour);
} else {
@@ -104,31 +105,35 @@ int32_t timev2_to_buffer_from_double(double time, char*
buffer, int scale) {
*buffer++ = (char)('0' + (hour % 10));
}
*buffer++ = ':';
- m_time %= (int64_t)3600 * 1000 * 1000;
- int64_t minute = m_time / (60 * 1000 * 1000);
+ m_time %= 3600ULL * 1000 * 1000;
+
+ auto minute = static_cast<uint8_t>(m_time / (60 * 1000 * 1000));
*buffer++ = (char)('0' + (minute / 10));
*buffer++ = (char)('0' + (minute % 10));
*buffer++ = ':';
m_time %= 60 * 1000 * 1000;
- int32_t second = m_time / (1000 * 1000);
+
+ auto second = static_cast<uint8_t>(m_time / (1000 * 1000));
*buffer++ = (char)('0' + (second / 10));
*buffer++ = (char)('0' + (second % 10));
m_time %= 1000 * 1000;
if (scale == 0) {
- return buffer - begin;
+ return static_cast<uint8_t>(buffer - begin);
}
+
*buffer++ = '.';
memset(buffer, '0', scale);
buffer += scale;
int32_t micosecond = m_time % (1000 * 1000);
- micosecond /= pow10[6 - scale];
+ micosecond /= common::exp10_i32(6 - scale);
auto* it = buffer - 1;
while (micosecond) {
*it = (char)('0' + (micosecond % 10));
micosecond /= 10;
it--;
}
- return buffer - begin;
+ DCHECK_LT(scale, 10);
+ return static_cast<uint8_t>(buffer - begin);
}
std::string timev2_to_buffer_from_double(double time, int scale) {
@@ -180,4 +185,5 @@ std::string timev2_to_buffer_from_double(double time, int
scale) {
return fmt::to_string(buffer);
}
+#include "common/compile_check_end.h"
} // namespace doris
diff --git a/be/src/util/date_func.h b/be/src/util/date_func.h
index 0b97eaaba04..adab78e1a32 100644
--- a/be/src/util/date_func.h
+++ b/be/src/util/date_func.h
@@ -32,7 +32,7 @@ class VecDateTimeValue;
VecDateTimeValue timestamp_from_datetime(const std::string& datetime_str);
VecDateTimeValue timestamp_from_date(const std::string& date_str);
-int32_t timev2_to_buffer_from_double(double time, char* buffer, int scale);
+uint8_t timev2_to_buffer_from_double(double time, char* buffer, int scale);
DateV2Value<DateV2ValueType> timestamp_from_date_v2(const std::string&
date_str);
DateV2Value<DateTimeV2ValueType> timestamp_from_datetime_v2(const std::string&
date_str);
std::string timev2_to_buffer_from_double(double time, int scale);
diff --git a/be/src/util/mysql_row_buffer.cpp b/be/src/util/mysql_row_buffer.cpp
index 6f3e7f265b5..9ee00a398db 100644
--- a/be/src/util/mysql_row_buffer.cpp
+++ b/be/src/util/mysql_row_buffer.cpp
@@ -25,7 +25,6 @@
#include <algorithm>
#include <new>
-#include <ostream>
#include <string>
#include "common/logging.h"
@@ -188,12 +187,13 @@ char* add_float(T data, char* pos, bool dynamic_mode) {
}
static char* add_timev2(double data, char* pos, bool dynamic_mode, int scale) {
- int length = timev2_to_buffer_from_double(data, pos + !dynamic_mode,
scale);
+ uint8_t length = timev2_to_buffer_from_double(data, pos + !dynamic_mode,
scale);
if (!dynamic_mode) {
int1store(pos++, length);
}
return pos + length;
}
+
template <typename DateType>
static char* add_datetime(const DateType& data, char* pos, bool dynamic_mode) {
int length = data.to_buffer(pos + !dynamic_mode);
@@ -366,10 +366,8 @@ static int encode_binary_timev2(char* buff, double time,
int scale) {
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
- if (total_microseconds > MAX_TIME_MICROSECONDS) {
- total_microseconds = MAX_TIME_MICROSECONDS; // Cap at max time
- }
+ auto total_microseconds = static_cast<int64_t>(abs_time); // Total
microseconds
+ total_microseconds = std::min(total_microseconds, MAX_TIME_MICROSECONDS);
// Adjust microseconds precision based on scale
total_microseconds /= static_cast<int64_t>(std::pow(10, 6 - scale)); //
Scale adjustment
@@ -535,7 +533,7 @@ int MysqlRowBuffer<is_binary_format>::push_null() {
uint offset = (_field_pos + 2) / 8 + 1;
uint bit = (1 << ((_field_pos + 2) & 7));
/* Room for this as it's allocated start_binary_row*/
- char* to = (char*)_buf + offset;
+ char* to = _buf + offset;
*to = (char)((uchar)*to | (uchar)bit);
_field_pos++;
return 0;
diff --git a/be/src/util/time_lut.cpp b/be/src/util/time_lut.cpp
index 9864dd9923b..45c8b696794 100644
--- a/be/src/util/time_lut.cpp
+++ b/be/src/util/time_lut.cpp
@@ -18,23 +18,30 @@
#include "util/time_lut.h"
+#include <cstdint>
+
+#include "common/cast_set.h"
#include "vec/runtime/vdatetime_value.h"
namespace doris {
+#include "common/compile_check_begin.h"
TimeLUTImpl::TimeLUTImpl() {
init_time_lut();
}
void TimeLUTImpl::init_time_lut() {
- for (uint32_t y = LUT_START_YEAR; y < LUT_END_YEAR; y++) {
+ for (uint16_t y = LUT_START_YEAR; y < LUT_END_YEAR; y++) {
uint16_t tmp_year = 0;
for (uint8_t m = 0; m < NUM_MONTHS; m++) {
for (uint8_t i = 0; i < NUM_DAYS; i++) {
- week_table[y - LUT_START_YEAR][m][i] =
- calc_week(y, m + 1, i + 1, false, false, true,
&tmp_year);
- week_of_year_table[y - LUT_START_YEAR][m][i] =
- calc_week(y, m + 1, i + 1, true, true, false,
&tmp_year);
- year_week_table[y - LUT_START_YEAR][m][i] = year_week(y, m +
1, i + 1);
+ if (!VecDateTimeValue::check_date(y, m + 1, i + 1)) {
+ // valid date
+ week_table[y - LUT_START_YEAR][m][i] =
+ calc_week(y, m + 1, i + 1, false, false, true,
&tmp_year);
+ week_of_year_table[y - LUT_START_YEAR][m][i] =
+ calc_week(y, m + 1, i + 1, true, true, false,
&tmp_year);
+ year_week_table[y - LUT_START_YEAR][m][i] = year_week(y, m
+ 1, i + 1);
+ }
}
}
}
@@ -46,7 +53,7 @@ uint8_t calc_week(uint16_t year, uint8_t month, uint8_t day,
bool monday_first,
uint64_t daynr_first_day = calc_daynr(year, 1, 1);
uint8_t weekday_first_day = calc_weekday(daynr_first_day, !monday_first);
- int days = 0;
+ uint16_t days = 0; // days in year
*to_year = year;
// Check weather the first days of this year belongs to last year
@@ -62,12 +69,13 @@ uint8_t calc_week(uint16_t year, uint8_t month, uint8_t
day, bool monday_first,
}
// How many days since first week
+ DCHECK_LE(day_nr - daynr_first_day, 373);
if ((first_weekday && weekday_first_day != 0) || (!first_weekday &&
weekday_first_day > 3)) {
// days in new year belongs to last year.
- days = day_nr - (daynr_first_day + (7 - weekday_first_day));
+ days = static_cast<uint16_t>(day_nr - daynr_first_day - (7 -
weekday_first_day));
} else {
// days in new year belongs to this year.
- days = day_nr - (daynr_first_day - weekday_first_day);
+ days = static_cast<uint16_t>(day_nr - daynr_first_day +
weekday_first_day);
}
if (week_year && days >= 52 * 7) {
@@ -80,10 +88,10 @@ uint8_t calc_week(uint16_t year, uint8_t month, uint8_t
day, bool monday_first,
}
}
- return days / 7 + 1;
+ return static_cast<uint8_t>(days / 7 + 1);
}
-uint32_t calc_days_in_year(uint32_t year) {
+uint16_t calc_days_in_year(uint32_t year) {
return is_leap(year) ? 366 : 365;
}
@@ -98,5 +106,5 @@ uint32_t year_week(uint16_t yy, uint8_t month, uint8_t day) {
uint8_t week = calc_week(yy, month, day, false, true, true, &to_year);
return to_year * 100 + week;
}
-
+#include "common/compile_check_end.h"
} // namespace doris
diff --git a/be/src/util/time_lut.h b/be/src/util/time_lut.h
index 4764cf00220..5e2990d8240 100644
--- a/be/src/util/time_lut.h
+++ b/be/src/util/time_lut.h
@@ -18,17 +18,16 @@
#pragma once
-#include <stdint.h>
-
#include <atomic>
+#include <cstdint>
namespace doris {
-constexpr uint32_t LUT_START_YEAR = 1950;
-constexpr uint32_t LUT_END_YEAR = 2030;
+constexpr uint16_t LUT_START_YEAR = 1950;
+constexpr uint16_t LUT_END_YEAR = 2030;
-constexpr uint32_t NUM_MONTHS = 12;
-constexpr uint32_t NUM_DAYS = 31;
+constexpr uint8_t NUM_MONTHS = 12;
+constexpr uint8_t NUM_DAYS = 31;
uint32_t year_week(uint16_t yy, uint8_t month, uint8_t day);
@@ -38,7 +37,7 @@ inline bool is_leap(uint32_t year) {
return ((year % 4) == 0) && ((year % 100 != 0) || ((year % 400) == 0 &&
year));
}
-uint32_t calc_days_in_year(uint32_t year);
+uint16_t calc_days_in_year(uint32_t year);
uint8_t calc_week(uint16_t yy, uint8_t month, uint8_t day, bool monday_first,
bool week_year,
bool first_weekday, uint16_t* to_year);
diff --git a/be/src/vec/runtime/vdatetime_value.h
b/be/src/vec/runtime/vdatetime_value.h
index b4bda18ddc7..0e6bb620377 100644
--- a/be/src/vec/runtime/vdatetime_value.h
+++ b/be/src/vec/runtime/vdatetime_value.h
@@ -174,7 +174,7 @@ constexpr int64_t SECOND_PER_HOUR = 3600;
constexpr int64_t SECOND_PER_MINUTE = 60;
constexpr int64_t MS_PER_SECOND = 1000 * 1000;
-inline constexpr int S_DAYS_IN_MONTH[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31};
+inline constexpr uint8_t S_DAYS_IN_MONTH[13] = {0, 31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31};
constexpr size_t const_length(const char* str) {
return (str == nullptr || *str == 0) ? 0 : const_length(str + 1) + 1;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]