Skip to content

Commit

Permalink
revert switch
Browse files Browse the repository at this point in the history
  • Loading branch information
marin-ma committed May 22, 2024
1 parent e2f4423 commit 6a270b3
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions velox/functions/sparksql/Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayVectorHasher<HashClass>*>(this)->hashValueAt(
index, seed);
case TypeKind::MAP:
return static_cast<MapVectorHasher<HashClass>*>(this)->hashValueAt(
index, seed);
case TypeKind::ROW:
return static_cast<RowVectorHasher<HashClass>*>(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 <TypeKind kind>
ReturnType hashPrimitive(vector_size_t index, SeedType seed) {
return static_cast<PrimitiveVectorHasher<HashClass, kind>*>(this)
->hashValueAt(index, seed);
}
};

template <typename HashClass, TypeKind kind>
Expand Down Expand Up @@ -171,7 +149,7 @@ class PrimitiveVectorHasher : public SparkVectorHasher<HashClass> {
PrimitiveVectorHasher(DecodedVector& decoded)
: SparkVectorHasher<HashClass>(decoded) {}

ReturnType hashValueAt(vector_size_t index, SeedType seed) {
ReturnType hashNotNullAt(vector_size_t index, SeedType seed) override {
return hashOne<HashClass>(
this->decoded_.template valueAt<typename TypeTraits<kind>::NativeType>(
index),
Expand All @@ -195,7 +173,7 @@ class ArrayVectorHasher : public SparkVectorHasher<HashClass> {
elementHasher_ = createVectorHasher<HashClass>(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]);

Expand Down Expand Up @@ -231,7 +209,7 @@ class MapVectorHasher : public SparkVectorHasher<HashClass> {
valueHasher_ = createVectorHasher<HashClass>(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]);

Expand Down Expand Up @@ -272,7 +250,7 @@ class RowVectorHasher : public SparkVectorHasher<HashClass> {
}
}

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);
Expand Down

0 comments on commit 6a270b3

Please sign in to comment.