From 38a42c5326bd5e0ef5c66ea21f0e3788b9906e70 Mon Sep 17 00:00:00 2001 From: codesigner Date: Mon, 5 Dec 2022 11:01:43 +0800 Subject: [PATCH] refine --- src/graph/validator/MatchValidator.cpp | 2 +- src/graph/visitor/DeduceAliasTypeVisitor.cpp | 10 ++++++- src/graph/visitor/DeduceAliasTypeVisitor.h | 5 +++- .../test/DeduceAliasTypeVisitorTest.cpp | 28 +++++++++---------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index ad059aa9f16..cbdd22f0271 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -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(col->expr())->accept(&visitor); if (!visitor.ok()) { return std::move(visitor).status(); diff --git a/src/graph/visitor/DeduceAliasTypeVisitor.cpp b/src/graph/visitor/DeduceAliasTypeVisitor.cpp index afb517aa649..0de60d7ef8f 100644 --- a/src/graph/visitor/DeduceAliasTypeVisitor.cpp +++ b/src/graph/visitor/DeduceAliasTypeVisitor.cpp @@ -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); diff --git a/src/graph/visitor/DeduceAliasTypeVisitor.h b/src/graph/visitor/DeduceAliasTypeVisitor.h index 28d6157075b..d20b03e54dc 100644 --- a/src/graph/visitor/DeduceAliasTypeVisitor.h +++ b/src/graph/visitor/DeduceAliasTypeVisitor.h @@ -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; diff --git a/src/graph/visitor/test/DeduceAliasTypeVisitorTest.cpp b/src/graph/visitor/test/DeduceAliasTypeVisitorTest.cpp index 3101f82ec89..1b75f4c6512 100644 --- a/src/graph/visitor/test/DeduceAliasTypeVisitorTest.cpp +++ b/src/graph/visitor/test/DeduceAliasTypeVisitorTest.cpp @@ -15,21 +15,21 @@ 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); @@ -37,35 +37,35 @@ TEST_F(DeduceAliasTypeVisitorTest, SubscriptExpr) { // 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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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);