Skip to content

Commit

Permalink
Revert "Revert "Fix aggregate default value (vesoft-inc#477)" (vesoft…
Browse files Browse the repository at this point in the history
…-inc#478)"

This reverts commit a8d0723.
  • Loading branch information
czpmango committed Apr 1, 2021
1 parent a8d0723 commit 225855d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/common/expression/AggregateExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class AggregateExpression final : public Expression {

const Value& eval(ExpressionContext& ctx) override;

void apply(AggData* aggData, const Value& val);

bool operator==(const Expression& rhs) const override;

std::string toString() const override;
Expand Down Expand Up @@ -78,8 +80,6 @@ class AggregateExpression final : public Expression {


private:
void apply(AggData* aggData, const Value& val);

void writeTo(Encoder& encoder) const override;
void resetFrom(Decoder& decoder) override;

Expand Down
4 changes: 2 additions & 2 deletions src/common/expression/test/ExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4327,8 +4327,8 @@ TEST_F(ExpressionTest, AggregateExpression) {
TEST_AGG(COUNT, true, isConst, vals5_, expected2);
TEST_AGG(COUNT, false, abs, vals9_, expected5);
TEST_AGG(COUNT, true, abs, vals9_, expected5);
TEST_AGG(SUM, false, isConst, vals5_, expected1);
TEST_AGG(SUM, true, isConst, vals5_, expected1);
TEST_AGG(SUM, false, isConst, vals5_, expected2);
TEST_AGG(SUM, true, isConst, vals5_, expected2);
TEST_AGG(SUM, false, isConst, vals9_, expected5);
TEST_AGG(SUM, true, isConst, vals9_, expected5);
TEST_AGG(AVG, false, isConst, vals5_, expected1);
Expand Down
3 changes: 3 additions & 0 deletions src/common/function/AggFunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ AggFunctionManager::AggFunctionManager() {
if (res.isBadNull()) {
return;
}
if (res.isNull()) {
res = 0;
}
if (UNLIKELY(val.isBadNull() || (!val.isNull() && !val.empty() && !val.isNumeric()))) {
res = Value::kNullBadType;
return;
Expand Down
40 changes: 38 additions & 2 deletions src/common/function/test/AggFunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common/function/AggFunctionManager.h"
#include "common/datatypes/Set.h"
#include "common/time/TimeUtils.h"
#include "common/datatypes/List.h"

namespace nebula {

Expand Down Expand Up @@ -56,8 +57,8 @@ TEST_F(AggFunctionManagerTest, aggFunc) {
TEST_FUNCTION(count, testData_["mixed"], 2);
}
{
TEST_FUNCTION(sum, testData_["empty"], Value::kNullValue);
TEST_FUNCTION(sum, testData_["null"], Value::kNullValue);
TEST_FUNCTION(sum, testData_["empty"], 0);
TEST_FUNCTION(sum, testData_["null"], 0);
TEST_FUNCTION(sum, testData_["int"], 6);
TEST_FUNCTION(sum, testData_["float"], 6.6);
TEST_FUNCTION(sum, testData_["mixed"], 3.0);
Expand Down Expand Up @@ -90,6 +91,41 @@ TEST_F(AggFunctionManagerTest, aggFunc) {
TEST_FUNCTION(std, testData_["float"], 0.8981462390204984);
TEST_FUNCTION(std, testData_["mixed"], 0.5);
}
{
TEST_FUNCTION(bit_and, testData_["empty"], Value::kNullValue);
TEST_FUNCTION(bit_and, testData_["null"], Value::kNullValue);
TEST_FUNCTION(bit_and, testData_["int"], 0);
TEST_FUNCTION(bit_and, testData_["float"], Value::kNullValue);
TEST_FUNCTION(bit_and, testData_["mixed"], Value::kNullValue);
}
{
TEST_FUNCTION(bit_or, testData_["empty"], Value::kNullValue);
TEST_FUNCTION(bit_or, testData_["null"], Value::kNullValue);
TEST_FUNCTION(bit_or, testData_["int"], 3);
TEST_FUNCTION(bit_or, testData_["float"], Value::kNullValue);
TEST_FUNCTION(bit_or, testData_["mixed"], Value::kNullValue);
}
{
TEST_FUNCTION(bit_xor, testData_["empty"], Value::kNullValue);
TEST_FUNCTION(bit_xor, testData_["null"], Value::kNullValue);
TEST_FUNCTION(bit_xor, testData_["int"], 0);
TEST_FUNCTION(bit_xor, testData_["float"], Value::kNullValue);
TEST_FUNCTION(bit_xor, testData_["mixed"], Value::kNullValue);
}
{
TEST_FUNCTION(collect, testData_["empty"], List());
TEST_FUNCTION(collect, testData_["null"], List());
TEST_FUNCTION(collect, testData_["int"], List({1, 2, 3}));
TEST_FUNCTION(collect, testData_["float"], List({1.1, 2.2, 3.3}));
TEST_FUNCTION(collect, testData_["mixed"], List({1, 2.0}));
}
{
TEST_FUNCTION(collect_set, testData_["empty"], Set());
TEST_FUNCTION(collect_set, testData_["null"], Set());
TEST_FUNCTION(collect_set, testData_["int"], Set({1, 2, 3}));
TEST_FUNCTION(collect_set, testData_["float"], Set({1.1, 2.2, 3.3}));
TEST_FUNCTION(collect_set, testData_["mixed"], Set({1, 2.0}));
}
}

} // namespace nebula
Expand Down

0 comments on commit 225855d

Please sign in to comment.