Skip to content

Commit

Permalink
rename to avoid duplicated class name
Browse files Browse the repository at this point in the history
  • Loading branch information
marin-ma committed Apr 10, 2024
1 parent 04a097d commit 3496962
Showing 1 changed file with 30 additions and 46 deletions.
76 changes: 30 additions & 46 deletions velox/functions/sparksql/Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,39 @@ struct HashTraits<XxHash64> {

template <
typename HashClass,
typename T,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
typename SeedType,
typename ReturnType,
typename T>
ReturnType hashOne(T input, SeedType seed) {
return HashClass::hashInt32(input, seed);
}

template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
template <typename HashClass, typename SeedType, typename ReturnType>
ReturnType hashOne(int64_t input, SeedType seed) {
return HashClass::hashInt64(input, seed);
}

template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
template <typename HashClass, typename SeedType, typename ReturnType>
ReturnType hashOne(float input, SeedType seed) {
return HashClass::hashFloat(input, seed);
}

template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
template <typename HashClass, typename SeedType, typename ReturnType>
ReturnType hashOne(double input, SeedType seed) {
return HashClass::hashDouble(input, seed);
}

template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
template <typename HashClass, typename SeedType, typename ReturnType>
ReturnType hashOne(int128_t input, SeedType seed) {
return HashClass::hashLongDecimal(input, seed);
}

template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
template <typename HashClass, typename SeedType, typename ReturnType>
ReturnType hashOne(Timestamp input, SeedType seed) {
return HashClass::hashTimestamp(input, seed);
}

template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
template <typename HashClass, typename SeedType, typename ReturnType>
ReturnType hashOne(StringView input, SeedType seed) {
return HashClass::hashBytes(input, seed);
}
Expand Down Expand Up @@ -130,7 +112,7 @@ template <
typename HashClass,
typename SeedType = typename HashTraits<HashClass>::SeedType,
typename ReturnType = typename HashTraits<HashClass>::ReturnType>
class VectorHasher {
class SparkVectorHasher {
public:
// Compute the hash value of input vector at index.
ReturnType hashAt(vector_size_t index, SeedType seed) {
Expand All @@ -142,22 +124,22 @@ class VectorHasher {

virtual ReturnType hashNotNull(vector_size_t index, SeedType seed) = 0;

VectorHasher(DecodedVector& decoded) : decoded_(decoded) {}
SparkVectorHasher(DecodedVector& decoded) : decoded_(decoded) {}

virtual ~VectorHasher() = default;
virtual ~SparkVectorHasher() = default;

protected:
const DecodedVector& decoded_;
};

template <typename HashClass, TypeKind kind>
std::shared_ptr<VectorHasher<HashClass>> createPrimitiveVectorHasher(
std::shared_ptr<SparkVectorHasher<HashClass>> createPrimitiveVectorHasher(
DecodedVector& decoded) {
return std::make_shared<PrimitiveVectorHasher<HashClass, kind>>(decoded);
}

template <typename HashClass>
std::shared_ptr<VectorHasher<HashClass>> createVectorHasher(
std::shared_ptr<SparkVectorHasher<HashClass>> createVectorHasher(
DecodedVector& decoded) {
auto baseType = decoded.base()->type();
if (baseType->isPrimitiveType()) {
Expand All @@ -178,24 +160,24 @@ template <
TypeKind kind,
typename SeedType,
typename ReturnType>
class PrimitiveVectorHasher
: public VectorHasher<HashClass, SeedType, ReturnType> {
class PrimitiveVectorHasher : public SparkVectorHasher<HashClass> {
public:
PrimitiveVectorHasher(DecodedVector& decoded)
: VectorHasher<HashClass, SeedType, ReturnType>(decoded) {}
: SparkVectorHasher<HashClass>(decoded) {}

ReturnType hashNotNull(vector_size_t index, SeedType seed) override {
return hashOne<HashClass>(
return hashOne<HashClass, SeedType, ReturnType>(
this->decoded_.template valueAt<typename TypeTraits<kind>::NativeType>(
index),
seed);
}
};

template <typename HashClass, typename SeedType, typename ReturnType>
class ArrayVectorHasher : public VectorHasher<HashClass> {
class ArrayVectorHasher : public SparkVectorHasher<HashClass> {
public:
ArrayVectorHasher(DecodedVector& decoded) : VectorHasher<HashClass>(decoded) {
ArrayVectorHasher(DecodedVector& decoded)
: SparkVectorHasher<HashClass>(decoded) {
base_ = decoded.base()->as<ArrayVector>();
indices_ = decoded.indices();

Expand All @@ -219,13 +201,14 @@ class ArrayVectorHasher : public VectorHasher<HashClass> {
const ArrayVector* base_;
const int32_t* indices_;
DecodedVector decodedElements_;
std::shared_ptr<VectorHasher<HashClass>> elementHasher_;
std::shared_ptr<SparkVectorHasher<HashClass>> elementHasher_;
};

template <typename HashClass, typename SeedType, typename ReturnType>
class MapVectorHasher : public VectorHasher<HashClass, SeedType, ReturnType> {
class MapVectorHasher : public SparkVectorHasher<HashClass> {
public:
MapVectorHasher(DecodedVector& decoded) : VectorHasher<HashClass>(decoded) {
MapVectorHasher(DecodedVector& decoded)
: SparkVectorHasher<HashClass>(decoded) {
base_ = decoded.base()->as<MapVector>();
indices_ = decoded.indices();

Expand Down Expand Up @@ -253,14 +236,15 @@ class MapVectorHasher : public VectorHasher<HashClass, SeedType, ReturnType> {
const int32_t* indices_;
DecodedVector decodedKeys_;
DecodedVector decodedValues_;
std::shared_ptr<VectorHasher<HashClass>> keyHasher_;
std::shared_ptr<VectorHasher<HashClass>> valueHasher_;
std::shared_ptr<SparkVectorHasher<HashClass>> keyHasher_;
std::shared_ptr<SparkVectorHasher<HashClass>> valueHasher_;
};

template <typename HashClass, typename SeedType, typename ReturnType>
class RowVectorHasher : public VectorHasher<HashClass, SeedType, ReturnType> {
class RowVectorHasher : public SparkVectorHasher<HashClass> {
public:
RowVectorHasher(DecodedVector& decoded) : VectorHasher<HashClass>(decoded) {
RowVectorHasher(DecodedVector& decoded)
: SparkVectorHasher<HashClass>(decoded) {
base_ = decoded.base()->as<RowVector>();
indices_ = decoded.indices();

Expand All @@ -285,7 +269,7 @@ class RowVectorHasher : public VectorHasher<HashClass, SeedType, ReturnType> {
const RowVector* base_;
const int32_t* indices_;
std::vector<DecodedVector> decodedChildren_;
std::vector<std::shared_ptr<VectorHasher<HashClass>>> hashers_;
std::vector<std::shared_ptr<SparkVectorHasher<HashClass>>> hashers_;
};

// ReturnType can be either int32_t or int64_t
Expand Down

0 comments on commit 3496962

Please sign in to comment.