From 4353a4e0f998e9d9ad719d303159972f40598a08 Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Fri, 7 Jun 2024 12:45:34 -0700 Subject: [PATCH] Fix hashOne functions in HivePartitionFunction (#10079) Summary: Pass by value to avoid strict aliasing issues for REAL and DOUBLE types. We are seeing the HivePartitionFunctionTest failing with GCC12 here https://github.com/facebookincubator/velox/pull/9903 Pull Request resolved: https://github.com/facebookincubator/velox/pull/10079 Reviewed By: Yuhta Differential Revision: D58294082 Pulled By: kevinwilfong fbshipit-source-id: 765af472a35d1f8f2b619d5c58ee4399a8359ee2 --- .../connectors/hive/HivePartitionFunction.cpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/velox/connectors/hive/HivePartitionFunction.cpp b/velox/connectors/hive/HivePartitionFunction.cpp index ad787455abc6..8f583164c1a6 100644 --- a/velox/connectors/hive/HivePartitionFunction.cpp +++ b/velox/connectors/hive/HivePartitionFunction.cpp @@ -46,8 +46,7 @@ int32_t hashTimestamp(const Timestamp& ts) { } template -inline uint32_t hashOne( - const typename TypeTraits::NativeType& /* value */) { +inline uint32_t hashOne(typename TypeTraits::NativeType /* value */) { VELOX_UNSUPPORTED( "Hive partitioning function doesn't support {} type", TypeTraits::name); @@ -55,57 +54,57 @@ inline uint32_t hashOne( } template <> -inline uint32_t hashOne(const bool& value) { +inline uint32_t hashOne(bool value) { return value ? 1 : 0; } template <> -inline uint32_t hashOne(const int8_t& value) { +inline uint32_t hashOne(int8_t value) { return static_cast(value); } template <> -inline uint32_t hashOne(const int16_t& value) { +inline uint32_t hashOne(int16_t value) { return static_cast(value); } template <> -inline uint32_t hashOne(const int32_t& value) { +inline uint32_t hashOne(int32_t value) { return static_cast(value); } template <> -inline uint32_t hashOne(const float& value) { +inline uint32_t hashOne(float value) { return static_cast(*reinterpret_cast(&value)); } template <> -inline uint32_t hashOne(const int64_t& value) { +inline uint32_t hashOne(int64_t value) { return hashInt64(value); } template <> -inline uint32_t hashOne(const double& value) { +inline uint32_t hashOne(double value) { return hashInt64(*reinterpret_cast(&value)); } template <> -inline uint32_t hashOne(const StringView& value) { +inline uint32_t hashOne(StringView value) { return hashBytes(value, 0); } template <> -inline uint32_t hashOne(const StringView& value) { +inline uint32_t hashOne(StringView value) { return hashBytes(value, 0); } template <> -inline uint32_t hashOne(const Timestamp& value) { +inline uint32_t hashOne(Timestamp value) { return hashTimestamp(value); } template <> -inline uint32_t hashOne(const UnknownValue& /*value*/) { +inline uint32_t hashOne(UnknownValue /*value*/) { VELOX_FAIL("Unknown values cannot be non-NULL"); }