Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
codesigner committed Dec 5, 2022
1 parent ef9123c commit 38a42c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ Status MatchValidator::validateWith(const WithClause *with,
return Status::SemanticError("Alias `%s` not defined", label.c_str());
}
AliasType inputType = withClauseCtx.yield->aliasesAvailable.at(label);
DeduceAliasTypeVisitor visitor(inputType);
DeduceAliasTypeVisitor visitor(qctx_, vctx_, space_.id, inputType);
const_cast<Expression *>(col->expr())->accept(&visitor);
if (!visitor.ok()) {
return std::move(visitor).status();
Expand Down
10 changes: 9 additions & 1 deletion src/graph/visitor/DeduceAliasTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
namespace nebula {
namespace graph {

DeduceAliasTypeVisitor::DeduceAliasTypeVisitor(AliasType inputType) : inputType_(inputType) {}
DeduceAliasTypeVisitor::DeduceAliasTypeVisitor(QueryContext *qctx,
ValidateContext *vctx,
GraphSpaceID space,
AliasType inputType)
: qctx_(qctx), vctx_(vctx), space_(space), inputType_(inputType) {
UNUSED(qctx_);
UNUSED(vctx_);
UNUSED(space_);
}

void DeduceAliasTypeVisitor::visit(VertexExpression *expr) {
UNUSED(expr);
Expand Down
5 changes: 4 additions & 1 deletion src/graph/visitor/DeduceAliasTypeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class QueryContext;
// An expression visitor enable deducing AliasType when possible.
class DeduceAliasTypeVisitor final : public ExprVisitor {
public:
explicit DeduceAliasTypeVisitor(AliasType inputType);
DeduceAliasTypeVisitor(QueryContext *qctx,
ValidateContext *vctx,
GraphSpaceID space,
AliasType inputType);

~DeduceAliasTypeVisitor() = default;

Expand Down
28 changes: 14 additions & 14 deletions src/graph/visitor/test/DeduceAliasTypeVisitorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,57 @@ class DeduceAliasTypeVisitorTest : public VisitorTestBase {};
TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
{
auto* expr = VertexExpression::make(pool);
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kNode);
}
{
auto* expr = EdgeExpression::make(pool);
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kEdge);
}
{
auto* expr = PathBuildExpression::make(pool);
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kPath);
}
// FunctionCallExpression
{
auto* expr = FunctionCallExpression::make(pool, "nodes");
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kNodeList);
}
{
auto* expr = FunctionCallExpression::make(pool, "relationships");
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kEdgeList);
}
{
auto* expr = FunctionCallExpression::make(pool, "reversepath");
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kPath);
}
{
auto* expr = FunctionCallExpression::make(pool, "startnode");
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kNode);
}
{
auto* expr = FunctionCallExpression::make(pool, "endnode");
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kNode);
Expand All @@ -76,7 +76,7 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
auto* items = ExpressionList::make(pool);
auto expr = SubscriptExpression::make(
pool, ListExpression::make(pool, items), ConstantExpression::make(pool, 1));
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kRuntime);
Expand All @@ -85,7 +85,7 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
auto* items = ExpressionList::make(pool);
auto expr = SubscriptExpression::make(
pool, ListExpression::make(pool, items), ConstantExpression::make(pool, 1));
DeduceAliasTypeVisitor visitor(AliasType::kEdgeList);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kEdgeList);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kEdge);
Expand All @@ -94,7 +94,7 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
auto* items = ExpressionList::make(pool);
auto expr = SubscriptExpression::make(
pool, ListExpression::make(pool, items), ConstantExpression::make(pool, 1));
DeduceAliasTypeVisitor visitor(AliasType::kNodeList);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kNodeList);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kNode);
Expand All @@ -105,7 +105,7 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
auto* items = ExpressionList::make(pool);
auto expr = SubscriptRangeExpression::make(
pool, ListExpression::make(pool, items), ConstantExpression::make(pool, 1));
DeduceAliasTypeVisitor visitor(AliasType::kRuntime);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kRuntime);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kRuntime);
Expand All @@ -114,7 +114,7 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
auto* items = ExpressionList::make(pool);
auto expr = SubscriptRangeExpression::make(
pool, ListExpression::make(pool, items), ConstantExpression::make(pool, 1));
DeduceAliasTypeVisitor visitor(AliasType::kEdgeList);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kEdgeList);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kEdgeList);
Expand All @@ -123,7 +123,7 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) {
auto* items = ExpressionList::make(pool);
auto expr = SubscriptRangeExpression::make(
pool, ListExpression::make(pool, items), ConstantExpression::make(pool, 1));
DeduceAliasTypeVisitor visitor(AliasType::kNodeList);
DeduceAliasTypeVisitor visitor(nullptr, nullptr, 0, AliasType::kNodeList);
expr->accept(&visitor);
EXPECT_TRUE(visitor.ok());
EXPECT_EQ(visitor.outputType(), AliasType::kNodeList);
Expand Down

0 comments on commit 38a42c5

Please sign in to comment.