-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1987 from kuzudb/fix-agg-rel-bug
Fix aggregate rel bug
- Loading branch information
Showing
24 changed files
with
294 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "binder/expression/expression_util.h" | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
bool ExpressionUtil::isExpressionsWithDataType( | ||
const expression_vector& expressions, common::LogicalTypeID dataTypeID) { | ||
for (auto& expression : expressions) { | ||
if (expression->dataType.getLogicalTypeID() != dataTypeID) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
expression_vector ExpressionUtil::getExpressionsWithDataType( | ||
const expression_vector& expressions, common::LogicalTypeID dataTypeID) { | ||
expression_vector result; | ||
for (auto& expression : expressions) { | ||
if (expression->dataType.getLogicalTypeID() == dataTypeID) { | ||
result.push_back(expression); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
uint32_t ExpressionUtil::find(Expression* target, expression_vector expressions) { | ||
for (auto i = 0u; i < expressions.size(); ++i) { | ||
if (target->getUniqueName() == expressions[i]->getUniqueName()) { | ||
return i; | ||
} | ||
} | ||
return UINT32_MAX; | ||
} | ||
|
||
std::string ExpressionUtil::toString(const expression_vector& expressions) { | ||
if (expressions.empty()) { | ||
return std::string{}; | ||
} | ||
auto result = expressions[0]->toString(); | ||
for (auto i = 1u; i < expressions.size(); ++i) { | ||
result += "," + expressions[i]->toString(); | ||
} | ||
return result; | ||
} | ||
|
||
std::string ExpressionUtil::toString(const std::vector<expression_pair>& expressionPairs) { | ||
if (expressionPairs.empty()) { | ||
return std::string{}; | ||
} | ||
auto result = toString(expressionPairs[0]); | ||
for (auto i = 1u; i < expressionPairs.size(); ++i) { | ||
result += "," + toString(expressionPairs[i]); | ||
} | ||
return result; | ||
} | ||
|
||
std::string ExpressionUtil::toString(const expression_pair& expressionPair) { | ||
return expressionPair.first->toString() + "=" + expressionPair.second->toString(); | ||
} | ||
|
||
expression_vector ExpressionUtil::excludeExpressions( | ||
const expression_vector& expressions, const expression_vector& expressionsToExclude) { | ||
expression_set excludeSet; | ||
for (auto& expression : expressionsToExclude) { | ||
excludeSet.insert(expression); | ||
} | ||
expression_vector result; | ||
for (auto& expression : expressions) { | ||
if (!excludeSet.contains(expression)) { | ||
result.push_back(expression); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
std::vector<std::unique_ptr<common::LogicalType>> ExpressionUtil::getDataTypes( | ||
const kuzu::binder::expression_vector& expressions) { | ||
std::vector<std::unique_ptr<common::LogicalType>> result; | ||
result.reserve(expressions.size()); | ||
for (auto& expression : expressions) { | ||
result.push_back(expression->getDataType().copy()); | ||
} | ||
return result; | ||
} | ||
|
||
expression_vector ExpressionUtil::removeDuplication(const expression_vector& expressions) { | ||
expression_vector result; | ||
expression_set expressionSet; | ||
for (auto& expression : expressions) { | ||
if (expressionSet.contains(expression)) { | ||
continue; | ||
} | ||
result.push_back(expression); | ||
expressionSet.insert(expression); | ||
} | ||
return result; | ||
} | ||
|
||
} // namespace binder | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
add_subdirectory(aggregate) | ||
|
||
add_library(kuzu_function | ||
OBJECT | ||
aggregate_function.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_library(kuzu_function_aggregate | ||
OBJECT | ||
count.cpp) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_function_aggregate> | ||
PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "function/aggregate/count.h" | ||
|
||
#include "binder/expression/expression_util.h" | ||
#include "binder/expression/node_expression.h" | ||
#include "binder/expression/rel_expression.h" | ||
|
||
using namespace kuzu::common; | ||
using namespace kuzu::storage; | ||
using namespace kuzu::binder; | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
void CountFunction::updateAll( | ||
uint8_t* state_, ValueVector* input, uint64_t multiplicity, MemoryManager* memoryManager) { | ||
auto state = reinterpret_cast<CountState*>(state_); | ||
if (input->hasNoNullsGuarantee()) { | ||
for (auto i = 0u; i < input->state->selVector->selectedSize; ++i) { | ||
state->count += multiplicity; | ||
} | ||
} else { | ||
for (auto i = 0u; i < input->state->selVector->selectedSize; ++i) { | ||
auto pos = input->state->selVector->selectedPositions[i]; | ||
if (!input->isNull(pos)) { | ||
state->count += multiplicity; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void CountFunction::paramRewriteFunc(binder::expression_vector& arguments) { | ||
assert(arguments.size() == 1); | ||
if (ExpressionUtil::isNodeVariable(*arguments[0])) { | ||
auto node = (NodeExpression*)arguments[0].get(); | ||
arguments[0] = node->getInternalIDProperty(); | ||
} else if (ExpressionUtil::isRelVariable(*arguments[0])) { | ||
auto rel = (RelExpression*)arguments[0].get(); | ||
arguments[0] = rel->getInternalIDProperty(); | ||
} | ||
} | ||
|
||
} // namespace function | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.