Skip to content

Commit

Permalink
Fix hashOne functions in HivePartitionFunction (#10079)
Browse files Browse the repository at this point in the history
Summary:
Pass by value to avoid strict aliasing issues for REAL and DOUBLE types.
We are seeing the HivePartitionFunctionTest failing with GCC12 here #9903

Pull Request resolved: #10079

Reviewed By: Yuhta

Differential Revision: D58294082

Pulled By: kevinwilfong

fbshipit-source-id: 765af472a35d1f8f2b619d5c58ee4399a8359ee2
  • Loading branch information
majetideepak authored and facebook-github-bot committed Jun 7, 2024
1 parent f9ab1f4 commit 1c0df40
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions velox/connectors/hive/HivePartitionFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,66 +46,65 @@ int32_t hashTimestamp(const Timestamp& ts) {
}

template <TypeKind kind>
inline uint32_t hashOne(
const typename TypeTraits<kind>::NativeType& /* value */) {
inline uint32_t hashOne(typename TypeTraits<kind>::NativeType /* value */) {
VELOX_UNSUPPORTED(
"Hive partitioning function doesn't support {} type",
TypeTraits<kind>::name);
return 0; // Make compiler happy.
}

template <>
inline uint32_t hashOne<TypeKind::BOOLEAN>(const bool& value) {
inline uint32_t hashOne<TypeKind::BOOLEAN>(bool value) {
return value ? 1 : 0;
}

template <>
inline uint32_t hashOne<TypeKind::TINYINT>(const int8_t& value) {
inline uint32_t hashOne<TypeKind::TINYINT>(int8_t value) {
return static_cast<uint32_t>(value);
}

template <>
inline uint32_t hashOne<TypeKind::SMALLINT>(const int16_t& value) {
inline uint32_t hashOne<TypeKind::SMALLINT>(int16_t value) {
return static_cast<uint32_t>(value);
}

template <>
inline uint32_t hashOne<TypeKind::INTEGER>(const int32_t& value) {
inline uint32_t hashOne<TypeKind::INTEGER>(int32_t value) {
return static_cast<uint32_t>(value);
}

template <>
inline uint32_t hashOne<TypeKind::REAL>(const float& value) {
inline uint32_t hashOne<TypeKind::REAL>(float value) {
return static_cast<uint32_t>(*reinterpret_cast<const int32_t*>(&value));
}

template <>
inline uint32_t hashOne<TypeKind::BIGINT>(const int64_t& value) {
inline uint32_t hashOne<TypeKind::BIGINT>(int64_t value) {
return hashInt64(value);
}

template <>
inline uint32_t hashOne<TypeKind::DOUBLE>(const double& value) {
inline uint32_t hashOne<TypeKind::DOUBLE>(double value) {
return hashInt64(*reinterpret_cast<const int64_t*>(&value));
}

template <>
inline uint32_t hashOne<TypeKind::VARCHAR>(const StringView& value) {
inline uint32_t hashOne<TypeKind::VARCHAR>(StringView value) {
return hashBytes(value, 0);
}

template <>
inline uint32_t hashOne<TypeKind::VARBINARY>(const StringView& value) {
inline uint32_t hashOne<TypeKind::VARBINARY>(StringView value) {
return hashBytes(value, 0);
}

template <>
inline uint32_t hashOne<TypeKind::TIMESTAMP>(const Timestamp& value) {
inline uint32_t hashOne<TypeKind::TIMESTAMP>(Timestamp value) {
return hashTimestamp(value);
}

template <>
inline uint32_t hashOne<TypeKind::UNKNOWN>(const UnknownValue& /*value*/) {
inline uint32_t hashOne<TypeKind::UNKNOWN>(UnknownValue /*value*/) {
VELOX_FAIL("Unknown values cannot be non-NULL");
}

Expand Down

0 comments on commit 1c0df40

Please sign in to comment.