diff --git a/velox/connectors/hive/FileHandleKey.h b/velox/connectors/hive/FileHandleKey.h index 24ce3b8fcb60a..f6f441cb1f7a0 100644 --- a/velox/connectors/hive/FileHandleKey.h +++ b/velox/connectors/hive/FileHandleKey.h @@ -58,23 +58,19 @@ class FileHandleKey { }; } // namespace facebook::velox -template -inline void hash_combine(std::size_t& seed, const T& v) { - std::hash hasher; - // See boost::hash_combine - // https://www.boost.org/doc/libs/1_55_0/doc/html/hash/reference.html#boost.hash_combine - seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); -} - namespace std { template <> struct hash { size_t operator()(const facebook::velox::FileHandleKey& key) const { - size_t seed = 0; - hash_combine(seed, key.getFilePath()); - hash_combine(seed, key.getFileSize()); - hash_combine(seed, key.getModificationTime()); - return seed; + auto hasher = folly::Hash{}; + uint64_t combinedHash = 0; + combinedHash = folly::hash::commutative_hash_combine_value_generic( + combinedHash, hasher, key.getFileSize()); + combinedHash = folly::hash::commutative_hash_combine_value_generic( + combinedHash, hasher, key.getModificationTime()); + combinedHash = folly::hash::commutative_hash_combine_value_generic( + combinedHash, hasher, key.getFilePath()); + return combinedHash; } }; } // namespace std diff --git a/velox/connectors/hive/tests/FileHandleTest.cpp b/velox/connectors/hive/tests/FileHandleTest.cpp index 9569d26f1be6f..3ebe76a26dab5 100644 --- a/velox/connectors/hive/tests/FileHandleTest.cpp +++ b/velox/connectors/hive/tests/FileHandleTest.cpp @@ -83,12 +83,6 @@ TEST(FileHandleTest, retrieveCachedLocalFile) { auto tempFile = exec::test::TempFilePath::create(); const auto& filename = tempFile->getPath(); - remove(filename.c_str()); - - { - LocalWriteFile writeFile(filename); - writeFile.append("foo"); - } FileHandleFactory factory( std::make_unique< @@ -104,14 +98,16 @@ TEST(FileHandleTest, retrieveCachedLocalFile) { factory.retrieveCached( {FileHandleKey( - tempFile->fileSize(), tempFile->fileModifiedTime(), filename), - FileHandleKey( - tempFile->fileSize() + 1, - tempFile->fileModifiedTime() + 1, - filename)}, + tempFile->fileSize(), tempFile->fileModifiedTime(), filename)}, &cached, &missing); - ASSERT_EQ(1, cached.size()); + ASSERT_EQ(0, missing.size()); + + factory.retrieveCached( + {FileHandleKey( + tempFile->fileSize() + 1, tempFile->fileModifiedTime(), filename)}, + &cached, + &missing); ASSERT_EQ(1, missing.size()); } \ No newline at end of file