Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aggregate expression type deduce #4706

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/graph/validator/test/YieldValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,11 @@ TEST_F(YieldValidatorTest, TypeCastTest) {
}
{
std::string query = "YIELD (int)\"123abc\"";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: `(INT)\"123abc\"' is not a valid expression ");
EXPECT_TRUE(checkResult(query));
}
{
std::string query = "YIELD (int)\"abc123\"";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: `(INT)\"abc123\"' is not a valid expression ");
EXPECT_TRUE(checkResult(query));
}
{
std::string query = "YIELD (doublE)\"123\"";
Expand All @@ -182,9 +178,7 @@ TEST_F(YieldValidatorTest, TypeCastTest) {
}
{
std::string query = "YIELD (doublE)\".a123\"";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: `(FLOAT)\".a123\"' is not a valid expression ");
EXPECT_TRUE(checkResult(query));
}
{
std::string query = "YIELD (STRING)1.23";
Expand All @@ -200,15 +194,15 @@ TEST_F(YieldValidatorTest, TypeCastTest) {
}
{
std::string query = "YIELD (BOOL)123";
EXPECT_FALSE(checkResult(query, expected_));
EXPECT_TRUE(checkResult(query, expected_));
}
{
std::string query = "YIELD (BOOL)0";
EXPECT_FALSE(checkResult(query, expected_));
EXPECT_TRUE(checkResult(query, expected_));
}
{
std::string query = "YIELD (BOOL)\"12\"";
EXPECT_FALSE(checkResult(query, expected_));
EXPECT_TRUE(checkResult(query, expected_));
}
{
std::string query = "YIELD (MAP)(\"12\")";
Expand Down
24 changes: 16 additions & 8 deletions src/graph/visitor/DeduceTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,7 @@ void DeduceTypeVisitor::visit(TypeCastingExpression *expr) {
status_ = Status::SemanticError(out.str());
return;
}
QueryExpressionContext ctx(nullptr);
auto val = expr->eval(ctx(nullptr));
if (val.isNull()) {
status_ = Status::SemanticError("`%s' is not a valid expression ", expr->toString().c_str());
return;
}
type_ = val.type();
type_ = expr->type();
status_ = Status::OK();
}

Expand Down Expand Up @@ -486,7 +480,21 @@ void DeduceTypeVisitor::visit(FunctionCallExpression *expr) {
void DeduceTypeVisitor::visit(AggregateExpression *expr) {
expr->arg()->accept(this);
if (!ok()) return;
type_ = Value::Type::__EMPTY__;
auto func = expr->name();
std::transform(func.begin(), func.end(), func.begin(), ::toupper);
if ("COUNT" == func) {
type_ = Value::Type::INT;
} else if ("COLLECT" == func) {
type_ = Value::Type::LIST;
} else if ("COLLECT_SET" == func) {
type_ = Value::Type::SET;
} else if ("AVG" == func || "SUM" == func) {
type_ = Value::Type::FLOAT;
} else if ("MAX" == func || "MIN" == func) {
// Keep same with arg's type
} else {
type_ = Value::Type::__EMPTY__;
}
}

void DeduceTypeVisitor::visit(UUIDExpression *) {
Expand Down
10 changes: 10 additions & 0 deletions tests/tck/features/go/GO.feature
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ Feature: Go Sentence
| "Spurs" |
| "Hornets" |
| "Trail Blazers" |
When executing query:
"""
GO FROM "Tim Duncan" OVER like WHERE like._rank<10 YIELD like._src AS src, like._dst AS dst, like._rank AS rank
| YIELD $-.src AS src, $-.dst AS dst, max($-.rank) AS maxRank
| FETCH PROP ON like $-.src -> $-.dst@$-.maxRank YIELD edge AS e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] |
| [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] |

Scenario: In expression
When executing query:
Expand Down