From bdb6cb2177a43a3a06c8601f40a830cca5172d15 Mon Sep 17 00:00:00 2001 From: Jacob Khaliqi Date: Tue, 10 Dec 2024 13:14:53 -0800 Subject: [PATCH] [native] Change C-style casts to C++-style --- .../presto_cpp/main/PeriodicTaskManager.cpp | 8 ++++---- .../presto_cpp/main/PrestoExchangeSource.cpp | 3 ++- presto-native-execution/presto_cpp/main/common/Utils.cpp | 3 ++- .../presto_cpp/main/http/HttpServer.cpp | 4 ++-- .../presto_cpp/main/operators/tests/BroadcastTest.cpp | 4 +++- .../main/runtime-metrics/PrometheusStatsReporter.cpp | 4 ++-- .../presto_cpp/main/tests/QueryContextCacheTest.cpp | 2 +- .../presto_cpp/main/tests/TaskManagerTest.cpp | 4 +++- .../presto_cpp/main/thrift/ProtocolToThrift.cpp | 4 ++-- .../presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp | 5 +++-- .../presto_cpp/presto_protocol/Base64Util.cpp | 2 +- .../tests/VariableReferenceExpressionTest.cpp | 4 +++- 12 files changed, 28 insertions(+), 19 deletions(-) diff --git a/presto-native-execution/presto_cpp/main/PeriodicTaskManager.cpp b/presto-native-execution/presto_cpp/main/PeriodicTaskManager.cpp index c27cb5f44f8ae..00b78e2b70321 100644 --- a/presto-native-execution/presto_cpp/main/PeriodicTaskManager.cpp +++ b/presto-native-execution/presto_cpp/main/PeriodicTaskManager.cpp @@ -428,15 +428,15 @@ void PeriodicTaskManager::updateOperatingSystemStats() { getrusage(RUSAGE_SELF, &usage); const int64_t userCpuTimeUs{ - (int64_t)usage.ru_utime.tv_sec * 1'000'000 + - (int64_t)usage.ru_utime.tv_usec}; + static_cast(usage.ru_utime.tv_sec) * 1'000'000 + + static_cast(usage.ru_utime.tv_usec)}; RECORD_METRIC_VALUE( kCounterOsUserCpuTimeMicros, userCpuTimeUs - lastUserCpuTimeUs_); lastUserCpuTimeUs_ = userCpuTimeUs; const int64_t systemCpuTimeUs{ - (int64_t)usage.ru_stime.tv_sec * 1'000'000 + - (int64_t)usage.ru_stime.tv_usec}; + static_cast(usage.ru_stime.tv_sec) * 1'000'000 + + static_cast(usage.ru_stime.tv_usec)}; RECORD_METRIC_VALUE( kCounterOsSystemCpuTimeMicros, systemCpuTimeUs - lastSystemCpuTimeUs_); lastSystemCpuTimeUs_ = systemCpuTimeUs; diff --git a/presto-native-execution/presto_cpp/main/PrestoExchangeSource.cpp b/presto-native-execution/presto_cpp/main/PrestoExchangeSource.cpp index aa7c1a798586c..11b8781053640 100644 --- a/presto-native-execution/presto_cpp/main/PrestoExchangeSource.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoExchangeSource.cpp @@ -58,7 +58,8 @@ std::string bodyAsString( std::ostringstream oss; auto iobufs = response.consumeBody(); for (auto& body : iobufs) { - oss << std::string((const char*)body->data(), body->length()); + oss << std::string( + reinterpret_cast(body->data()), body->length()); if (pool != nullptr) { pool->free(body->writableData(), body->capacity()); } diff --git a/presto-native-execution/presto_cpp/main/common/Utils.cpp b/presto-native-execution/presto_cpp/main/common/Utils.cpp index 9c9f77d253949..bc4b9ce63a925 100644 --- a/presto-native-execution/presto_cpp/main/common/Utils.cpp +++ b/presto-native-execution/presto_cpp/main/common/Utils.cpp @@ -69,7 +69,8 @@ std::string extractMessageBody( // TODO Avoid copy std::ostringstream oss; for (auto& buf : body) { - oss << std::string((const char*)buf->data(), buf->length()); + oss << std::string( + reinterpret_cast(buf->data()), buf->length()); } return oss.str(); } diff --git a/presto-native-execution/presto_cpp/main/http/HttpServer.cpp b/presto-native-execution/presto_cpp/main/http/HttpServer.cpp index 04bc6288e25d4..64bb555b157cb 100644 --- a/presto-native-execution/presto_cpp/main/http/HttpServer.cpp +++ b/presto-native-execution/presto_cpp/main/http/HttpServer.cpp @@ -276,8 +276,8 @@ void HttpServer::start( options.handlerFactories = handlerFactories.build(); // Increase the default flow control to 1MB/10MB - options.initialReceiveWindow = uint32_t(1 << 20); - options.receiveStreamWindowSize = uint32_t(1 << 20); + options.initialReceiveWindow = static_cast(1 << 20); + options.receiveStreamWindowSize = static_cast(1 << 20); options.receiveSessionWindowSize = 10 * (1 << 20); options.h2cEnabled = true; diff --git a/presto-native-execution/presto_cpp/main/operators/tests/BroadcastTest.cpp b/presto-native-execution/presto_cpp/main/operators/tests/BroadcastTest.cpp index 0973a8359c0b2..6b54b58f02024 100644 --- a/presto-native-execution/presto_cpp/main/operators/tests/BroadcastTest.cpp +++ b/presto-native-execution/presto_cpp/main/operators/tests/BroadcastTest.cpp @@ -206,7 +206,9 @@ class BroadcastTest : public exec::test::OperatorTestBase { std::vector ranges; for (const auto& range : *ioBuf) { ranges.emplace_back(ByteRange{ - const_cast(range.data()), (int32_t)range.size(), 0}); + const_cast(range.data()), + static_cast(range.size()), + 0}); } auto byteStream = std::make_unique(std::move(ranges)); diff --git a/presto-native-execution/presto_cpp/main/runtime-metrics/PrometheusStatsReporter.cpp b/presto-native-execution/presto_cpp/main/runtime-metrics/PrometheusStatsReporter.cpp index 30e361a6bc4d4..6ed3ea7c39594 100644 --- a/presto-native-execution/presto_cpp/main/runtime-metrics/PrometheusStatsReporter.cpp +++ b/presto-native-execution/presto_cpp/main/runtime-metrics/PrometheusStatsReporter.cpp @@ -133,8 +133,8 @@ void PrometheusStatsReporter::registerHistogramMetricExportType( .Register(*impl_->registry); ::prometheus::Summary::Quantiles quantiles; for (auto pct : pcts) { - quantiles.push_back( - ::prometheus::detail::CKMSQuantiles::Quantile(pct / (double)100, 0)); + quantiles.push_back(::prometheus::detail::CKMSQuantiles::Quantile( + pct / static_cast(100), 0)); } auto& summaryMetric = summaryFamily.Add({impl_->labels}, quantiles); registeredMetricsMap_.emplace( diff --git a/presto-native-execution/presto_cpp/main/tests/QueryContextCacheTest.cpp b/presto-native-execution/presto_cpp/main/tests/QueryContextCacheTest.cpp index 2d0821e8568ce..f45d6d4f8e38d 100644 --- a/presto-native-execution/presto_cpp/main/tests/QueryContextCacheTest.cpp +++ b/presto-native-execution/presto_cpp/main/tests/QueryContextCacheTest.cpp @@ -55,7 +55,7 @@ TEST_F(QueryContextCacheTest, basic) { for (int i = 0; i < 16; ++i) { auto queryId = fmt::format("query-{}", i); auto queryCtx = core::QueryCtx::create( - (folly::Executor*)nullptr, core::QueryConfig({})); + static_cast(nullptr), core::QueryConfig({})); queryCtxs[queryId] = queryCtx; queryContextCache.insert(queryId, queryCtx); } diff --git a/presto-native-execution/presto_cpp/main/tests/TaskManagerTest.cpp b/presto-native-execution/presto_cpp/main/tests/TaskManagerTest.cpp index 43190f2e5c039..46c17378d888f 100644 --- a/presto-native-execution/presto_cpp/main/tests/TaskManagerTest.cpp +++ b/presto-native-execution/presto_cpp/main/tests/TaskManagerTest.cpp @@ -156,7 +156,9 @@ class Cursor { std::vector byteRanges; for (auto& range : *buffer) { byteRanges.emplace_back(ByteRange{ - const_cast(range.data()), (int32_t)range.size(), 0}); + const_cast(range.data()), + static_cast(range.size()), + 0}); } const auto input = diff --git a/presto-native-execution/presto_cpp/main/thrift/ProtocolToThrift.cpp b/presto-native-execution/presto_cpp/main/thrift/ProtocolToThrift.cpp index 6875d2fb20324..8a08fe121677b 100644 --- a/presto-native-execution/presto_cpp/main/thrift/ProtocolToThrift.cpp +++ b/presto-native-execution/presto_cpp/main/thrift/ProtocolToThrift.cpp @@ -65,10 +65,10 @@ void toThrift(const std::vector

& p, std::vector& t) { } void toThrift(const protocol::TaskState& proto, thrift::TaskState& thrift) { - thrift = (thrift::TaskState)((int)proto); + thrift = static_cast(static_cast(proto)); } void toThrift(const protocol::ErrorType& proto, thrift::ErrorType& thrift) { - thrift = (thrift::ErrorType)((int)proto); + thrift = static_cast(static_cast(proto)); } void toThrift(const protocol::Lifespan& proto, thrift::Lifespan& thrift) { toThrift(proto.isgroup, *thrift.grouped_ref()); diff --git a/presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp b/presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp index ce4e2fb322807..71f2bffb27b8f 100644 --- a/presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp +++ b/presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp @@ -79,7 +79,7 @@ RowTypePtr toRowType( template std::string toJsonString(const T& value) { - return ((json)value).dump(); + return (static_cast(value)).dump(); } std::shared_ptr toColumnHandle( @@ -1736,7 +1736,8 @@ core::ExecutionStrategy toStrategy(protocol::StageExecutionStrategy strategy) { "RECOVERABLE_GROUPED_EXECUTION " "Stage Execution Strategy is not supported"); } - VELOX_UNSUPPORTED("Unknown Stage Execution Strategy type {}", (int)strategy); + VELOX_UNSUPPORTED( + "Unknown Stage Execution Strategy type {}", static_cast(strategy)); } // Presto doesn't have PartitionedOutputNode and assigns its source node's plan diff --git a/presto-native-execution/presto_cpp/presto_protocol/Base64Util.cpp b/presto-native-execution/presto_cpp/presto_protocol/Base64Util.cpp index 4dbaa20d3ec23..27bcd50573362 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/Base64Util.cpp +++ b/presto-native-execution/presto_cpp/presto_protocol/Base64Util.cpp @@ -22,7 +22,7 @@ namespace { std::unique_ptr toByteStream(const std::string& input) { ByteRange byteRange{ reinterpret_cast(const_cast(input.data())), - (int32_t)input.length(), + static_cast(input.length()), 0}; return std::make_unique(std::vector{byteRange}); } diff --git a/presto-native-execution/presto_cpp/presto_protocol/tests/VariableReferenceExpressionTest.cpp b/presto-native-execution/presto_cpp/presto_protocol/tests/VariableReferenceExpressionTest.cpp index cf8232c0273bd..3a78bc0880b89 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/tests/VariableReferenceExpressionTest.cpp +++ b/presto-native-execution/presto_cpp/presto_protocol/tests/VariableReferenceExpressionTest.cpp @@ -38,6 +38,8 @@ TEST_F(VariableReferenceExpressionTest, basic) { testJsonRoundtrip(j, p); ASSERT_EQ(json_map_key(p), "segment") << "... json_map_key"; - ASSERT_EQ((json)VariableReferenceExpression("segment"), (json)p) + ASSERT_EQ( + static_cast(VariableReferenceExpression("segment")), + static_cast(p)) << "... string constructor"; }