From 650a330b3582c6799e0dbaa76e79ad201c010711 Mon Sep 17 00:00:00 2001 From: Rui Mo Date: Mon, 16 Mar 2026 20:24:58 +0000 Subject: [PATCH] fix: Caps the count metric at int64_t's max value --- presto-native-execution/presto_cpp/main/PrestoTask.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/presto-native-execution/presto_cpp/main/PrestoTask.cpp b/presto-native-execution/presto_cpp/main/PrestoTask.cpp index 7e616f5266938..29879af2e4523 100644 --- a/presto-native-execution/presto_cpp/main/PrestoTask.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoTask.cpp @@ -998,11 +998,17 @@ folly::dynamic PrestoTask::toJson() const { protocol::RuntimeMetric toRuntimeMetric( const std::string& name, const RuntimeMetric& metric) { + // Presto's RuntimeMetric uses int64_t for count, but Velox's RuntimeMetric + // uses uint64_t. To avoid overflow, we cap the count at int64_t's max value. + static const uint64_t maxCount = + static_cast(std::numeric_limits::max()); + const auto count = static_cast( + std::min(static_cast(metric.count), maxCount)); return protocol::RuntimeMetric{ name, toPrestoRuntimeUnit(metric.unit), metric.sum, - metric.count, + count, metric.max, metric.min}; }