diff --git a/velox/functions/sparksql/Hash.cpp b/velox/functions/sparksql/Hash.cpp index a7ec95e2aa96..d20cf5d4c8b5 100644 --- a/velox/functions/sparksql/Hash.cpp +++ b/velox/functions/sparksql/Hash.cpp @@ -109,32 +109,10 @@ class SparkVectorHasher { } // Compute the hash value of input vector at index for non-null values. - ReturnType hashNotNullAt(vector_size_t index, SeedType seed) { - switch (decoded_.base()->typeKind()) { - case TypeKind::ARRAY: - return static_cast*>(this)->hashValueAt( - index, seed); - case TypeKind::MAP: - return static_cast*>(this)->hashValueAt( - index, seed); - case TypeKind::ROW: - return static_cast*>(this)->hashValueAt( - index, seed); - default: - return VELOX_DYNAMIC_SCALAR_TYPE_DISPATCH( - hashPrimitive, decoded_.base()->typeKind(), index, seed); - } - } + virtual ReturnType hashNotNullAt(vector_size_t index, SeedType seed) = 0; protected: const DecodedVector& decoded_; - - private: - template - ReturnType hashPrimitive(vector_size_t index, SeedType seed) { - return static_cast*>(this) - ->hashValueAt(index, seed); - } }; template @@ -171,7 +149,7 @@ class PrimitiveVectorHasher : public SparkVectorHasher { PrimitiveVectorHasher(DecodedVector& decoded) : SparkVectorHasher(decoded) {} - ReturnType hashValueAt(vector_size_t index, SeedType seed) { + ReturnType hashNotNullAt(vector_size_t index, SeedType seed) override { return hashOne( this->decoded_.template valueAt::NativeType>( index), @@ -195,7 +173,7 @@ class ArrayVectorHasher : public SparkVectorHasher { elementHasher_ = createVectorHasher(decodedElements_); } - ReturnType hashValueAt(vector_size_t index, SeedType seed) { + ReturnType hashNotNullAt(vector_size_t index, SeedType seed) override { auto size = base_->sizeAt(indices_[index]); auto offset = base_->offsetAt(indices_[index]); @@ -231,7 +209,7 @@ class MapVectorHasher : public SparkVectorHasher { valueHasher_ = createVectorHasher(decodedValues_); } - ReturnType hashValueAt(vector_size_t index, SeedType seed) { + ReturnType hashNotNullAt(vector_size_t index, SeedType seed) override { auto size = base_->sizeAt(indices_[index]); auto offset = base_->offsetAt(indices_[index]); @@ -272,7 +250,7 @@ class RowVectorHasher : public SparkVectorHasher { } } - ReturnType hashValueAt(vector_size_t index, SeedType seed) { + ReturnType hashNotNullAt(vector_size_t index, SeedType seed) override { ReturnType result = seed; for (auto i = 0; i < base_->childrenSize(); ++i) { result = hashers_[i]->hashAt(indices_[index], result);