Skip to content

Commit

Permalink
Fix test and change HASH type to UINT64
Browse files Browse the repository at this point in the history
  • Loading branch information
manh9203 committed Apr 4, 2024
1 parent c7f62df commit 3e3846e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/function/vector_hash_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static void computeStructVecHash(ValueVector* operand, ValueVector* result) {
case LogicalTypeID::STRUCT: {
VectorHashFunction::computeHash(
StructVector::getFieldVector(operand, 0 /* idx */).get(), result);
auto tmpHashVector = std::make_unique<ValueVector>(LogicalTypeID::INT64);
auto tmpHashVector = std::make_unique<ValueVector>(LogicalTypeID::UINT64);
for (auto i = 1u; i < StructType::getNumFields(&operand->dataType); i++) {
auto fieldVector = StructVector::getFieldVector(operand, i);
VectorHashFunction::computeHash(fieldVector.get(), tmpHashVector.get());
Expand All @@ -129,7 +129,7 @@ static void computeStructVecHash(ValueVector* operand, ValueVector* result) {

void VectorHashFunction::computeHash(ValueVector* operand, ValueVector* result) {
result->state = operand->state;
KU_ASSERT(result->dataType.getLogicalTypeID() == LogicalTypeID::INT64);
KU_ASSERT(result->dataType.getLogicalTypeID() == LogicalTypeID::UINT64);
switch (operand->dataType.getPhysicalType()) {
case PhysicalTypeID::INTERNAL_ID: {
UnaryHashFunctionExecutor::execute<internalID_t, hash_t>(*operand, *result);
Expand Down Expand Up @@ -191,7 +191,7 @@ void VectorHashFunction::computeHash(ValueVector* operand, ValueVector* result)
}

void VectorHashFunction::combineHash(ValueVector* left, ValueVector* right, ValueVector* result) {
KU_ASSERT(left->dataType.getLogicalTypeID() == LogicalTypeID::INT64);
KU_ASSERT(left->dataType.getLogicalTypeID() == LogicalTypeID::UINT64);
KU_ASSERT(left->dataType.getLogicalTypeID() == right->dataType.getLogicalTypeID());
KU_ASSERT(left->dataType.getLogicalTypeID() == result->dataType.getLogicalTypeID());
// TODO(Xiyang/Guodong): we should resolve result state of hash vector at compile time.
Expand Down Expand Up @@ -227,7 +227,7 @@ function_set HashFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::ANY},
LogicalTypeID::INT64, HashExecFunc, false /* isVarLength */));
LogicalTypeID::UINT64, HashExecFunc, false /* isVarLength */));
return functionSet;
}

Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class LogicalType {
return std::make_unique<LogicalType>(LogicalTypeID::BOOL);
}
static std::unique_ptr<LogicalType> HASH() {
return std::make_unique<LogicalType>(LogicalTypeID::INT64);
return std::make_unique<LogicalType>(LogicalTypeID::UINT64);
}
static std::unique_ptr<LogicalType> INT64() {
return std::make_unique<LogicalType>(LogicalTypeID::INT64);
Expand Down
4 changes: 2 additions & 2 deletions src/processor/operator/aggregate/aggregate_hash_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ bool AggregateHashTable::isAggregateValueDistinctForGroupByKeys(
VectorHashFunction::computeHash(groupByFlatKeyVectors[0], hashVector.get());
computeAndCombineVecHash(groupByFlatKeyVectors, 1 /* startVecIdx */);
auto tmpHashResultVector =
std::make_unique<ValueVector>(LogicalTypeID::INT64, &memoryManager);
std::make_unique<ValueVector>(LogicalTypeID::UINT64, &memoryManager);
auto tmpHashCombineResultVector =
std::make_unique<ValueVector>(LogicalTypeID::INT64, &memoryManager);
std::make_unique<ValueVector>(LogicalTypeID::UINT64, &memoryManager);
VectorHashFunction::computeHash(aggregateVector, tmpHashResultVector.get());
VectorHashFunction::combineHash(
hashVector.get(), tmpHashResultVector.get(), tmpHashCombineResultVector.get());
Expand Down
2 changes: 1 addition & 1 deletion src/processor/operator/hash_join/hash_join_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void HashJoinProbe::initLocalStateInternal(ResultSet* resultSet, ExecutionContex
LogicalTypeID::INT64, context->clientContext->getMemoryManager());
if (keyVectors.size() > 1) {
tmpHashVector = std::make_unique<ValueVector>(
LogicalTypeID::INT64, context->clientContext->getMemoryManager());
LogicalTypeID::UINT64, context->clientContext->getMemoryManager());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/processor/result/base_hash_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void BaseHashTable::computeAndCombineVecHash(
for (; startVecIdx < unFlatKeyVectors.size(); startVecIdx++) {
auto keyVector = unFlatKeyVectors[startVecIdx];
auto tmpHashResultVector =
std::make_unique<ValueVector>(LogicalTypeID::INT64, &memoryManager);
std::make_unique<ValueVector>(LogicalTypeID::UINT64, &memoryManager);
auto tmpHashCombineResultVector =
std::make_unique<ValueVector>(LogicalTypeID::INT64, &memoryManager);
std::make_unique<ValueVector>(LogicalTypeID::UINT64, &memoryManager);
VectorHashFunction::computeHash(keyVector, tmpHashResultVector.get());
VectorHashFunction::combineHash(
hashVector.get(), tmpHashResultVector.get(), tmpHashCombineResultVector.get());
Expand Down
6 changes: 3 additions & 3 deletions test/test_files/function/hash/hash.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
# String
-STATEMENT RETURN hash('hello');
---- 1
-2347141879292577852
16099602194416973764

# Interval
-STATEMENT RETURN hash(interval("1 years 2 months 3 hours"));
---- 1
-5050076354121952078
13396667719587599538

# Struct
-STATEMENT RETURN hash({name: 'Alice', age: 20});
---- 1
-4980099835463142906
13466644238246408710

# List
-STATEMENT RETURN hash(list_creation(1,2,3,4,5,56,2));
Expand Down

0 comments on commit 3e3846e

Please sign in to comment.