-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refine AliasType deducing when planning (#4973)
* refine AliasType deducing when planning * refine * fix lint * fix tck * address comment * refine * refine code & add tck case * refine * fix compile * fix compile * fix compile * fix compile * fix compile * fix tck * fix tck Co-authored-by: Yee <[email protected]>
- Loading branch information
1 parent
4014c9b
commit c3ee460
Showing
11 changed files
with
419 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright (c) 2022 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include "graph/visitor/DeduceAliasTypeVisitor.h" | ||
|
||
#include <sstream> | ||
#include <unordered_map> | ||
|
||
#include "common/datatypes/DataSet.h" | ||
#include "common/datatypes/Edge.h" | ||
#include "common/datatypes/List.h" | ||
#include "common/datatypes/Map.h" | ||
#include "common/datatypes/Path.h" | ||
#include "common/datatypes/Set.h" | ||
#include "common/function/FunctionManager.h" | ||
#include "graph/context/QueryContext.h" | ||
#include "graph/context/QueryExpressionContext.h" | ||
#include "graph/context/ValidateContext.h" | ||
#include "graph/visitor/EvaluableExprVisitor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
DeduceAliasTypeVisitor::DeduceAliasTypeVisitor(QueryContext *qctx, | ||
ValidateContext *vctx, | ||
GraphSpaceID space, | ||
AliasType inputType) | ||
: qctx_(qctx), vctx_(vctx), space_(space), inputType_(inputType) {} | ||
|
||
void DeduceAliasTypeVisitor::visit(VertexExpression *expr) { | ||
UNUSED(expr); | ||
outputType_ = AliasType::kNode; | ||
} | ||
|
||
void DeduceAliasTypeVisitor::visit(EdgeExpression *expr) { | ||
UNUSED(expr); | ||
outputType_ = AliasType::kEdge; | ||
} | ||
|
||
void DeduceAliasTypeVisitor::visit(PathBuildExpression *expr) { | ||
UNUSED(expr); | ||
outputType_ = AliasType::kPath; | ||
} | ||
|
||
void DeduceAliasTypeVisitor::visit(FunctionCallExpression *expr) { | ||
std::string funName = expr->name(); | ||
std::transform(funName.begin(), funName.end(), funName.begin(), ::tolower); | ||
if (funName == "nodes") { | ||
outputType_ = AliasType::kNodeList; | ||
} else if (funName == "relationships") { | ||
outputType_ = AliasType::kEdgeList; | ||
} else if (funName == "reversepath") { | ||
outputType_ = AliasType::kPath; | ||
} else if (funName == "startnode" || funName == "endnode") { | ||
outputType_ = AliasType::kNode; | ||
} | ||
} | ||
|
||
void DeduceAliasTypeVisitor::visit(SubscriptExpression *expr) { | ||
Expression *leftExpr = expr->left(); | ||
DeduceAliasTypeVisitor childVisitor(qctx_, vctx_, space_, inputType_); | ||
leftExpr->accept(&childVisitor); | ||
if (!childVisitor.ok()) { | ||
status_ = std::move(childVisitor).status(); | ||
return; | ||
} | ||
inputType_ = childVisitor.outputType(); | ||
// This is not accurate, since there exist List of List...Edges/Nodes, | ||
// may have opportunities when analyze more detail of the expr. | ||
if (inputType_ == AliasType::kEdgeList) { | ||
outputType_ = AliasType::kEdge; | ||
} else if (inputType_ == AliasType::kNodeList) { | ||
outputType_ = AliasType::kNode; | ||
} else { | ||
outputType_ = inputType_; | ||
} | ||
} | ||
|
||
void DeduceAliasTypeVisitor::visit(SubscriptRangeExpression *expr) { | ||
Expression *leftExpr = expr->list(); | ||
DeduceAliasTypeVisitor childVisitor(qctx_, vctx_, space_, inputType_); | ||
leftExpr->accept(&childVisitor); | ||
if (!childVisitor.ok()) { | ||
status_ = std::move(childVisitor).status(); | ||
return; | ||
} | ||
inputType_ = childVisitor.outputType(); | ||
// This is not accurate, since there exist List of List...Edges/Nodes, | ||
// may have opportunities when analyze more detail of the expr. | ||
if (inputType_ == AliasType::kEdgeList) { | ||
outputType_ = AliasType::kEdgeList; | ||
} else if (inputType_ == AliasType::kNodeList) { | ||
outputType_ = AliasType::kNodeList; | ||
} else { | ||
outputType_ = inputType_; | ||
} | ||
} | ||
|
||
} // namespace graph | ||
} // namespace nebula |
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,100 @@ | ||
/* Copyright (c) 2022 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#ifndef NEBULA_GRAPH_DEDUCEALIASTYPEVISITOR_H | ||
#define NEBULA_GRAPH_DEDUCEALIASTYPEVISITOR_H | ||
|
||
#include "common/base/Status.h" | ||
#include "common/datatypes/Value.h" | ||
#include "common/expression/ExprVisitor.h" | ||
#include "graph/context/ValidateContext.h" | ||
#include "graph/context/ast/CypherAstContext.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
class QueryContext; | ||
|
||
// An expression visitor enable deducing AliasType when possible. | ||
class DeduceAliasTypeVisitor final : public ExprVisitor { | ||
public: | ||
DeduceAliasTypeVisitor(QueryContext *qctx, | ||
ValidateContext *vctx, | ||
GraphSpaceID space, | ||
AliasType inputType); | ||
|
||
~DeduceAliasTypeVisitor() = default; | ||
|
||
bool ok() const { | ||
return status_.ok(); | ||
} | ||
|
||
Status status() && { | ||
return std::move(status_); | ||
} | ||
|
||
AliasType outputType() const { | ||
return outputType_; | ||
} | ||
|
||
private: | ||
// Most expression cannot be used to deducing, | ||
// or deduced to primitive types, use the default kRuntime type | ||
void visit(ConstantExpression *) override {} | ||
void visit(UnaryExpression *) override {} | ||
void visit(TypeCastingExpression *) override {} | ||
void visit(LabelExpression *) override {} | ||
void visit(LabelAttributeExpression *) override {} | ||
void visit(ArithmeticExpression *) override {} | ||
void visit(RelationalExpression *) override {} | ||
void visit(AttributeExpression *) override {} | ||
void visit(LogicalExpression *) override {} | ||
void visit(AggregateExpression *) override {} | ||
void visit(UUIDExpression *) override {} | ||
void visit(VariableExpression *) override {} | ||
void visit(VersionedVariableExpression *) override {} | ||
void visit(ListExpression *) override {} | ||
void visit(SetExpression *) override {} | ||
void visit(MapExpression *) override {} | ||
void visit(LabelTagPropertyExpression *) override {} | ||
void visit(TagPropertyExpression *) override {} | ||
void visit(EdgePropertyExpression *) override {} | ||
void visit(InputPropertyExpression *) override {} | ||
void visit(VariablePropertyExpression *) override {} | ||
void visit(DestPropertyExpression *) override {} | ||
void visit(SourcePropertyExpression *) override {} | ||
void visit(EdgeSrcIdExpression *) override {} | ||
void visit(EdgeTypeExpression *) override {} | ||
void visit(EdgeRankExpression *) override {} | ||
void visit(EdgeDstIdExpression *) override {} | ||
void visit(CaseExpression *) override {} | ||
void visit(ColumnExpression *) override {} | ||
void visit(PredicateExpression *) override {} | ||
void visit(ListComprehensionExpression *) override {} | ||
void visit(ReduceExpression *) override {} | ||
void visit(MatchPathPatternExpression *) override {} | ||
|
||
// Expression may have deducing potential | ||
void visit(VertexExpression *expr) override; | ||
void visit(EdgeExpression *expr) override; | ||
void visit(PathBuildExpression *expr) override; | ||
void visit(FunctionCallExpression *expr) override; | ||
void visit(SubscriptExpression *expr) override; | ||
void visit(SubscriptRangeExpression *expr) override; | ||
|
||
private: | ||
QueryContext *qctx_{nullptr}; | ||
ValidateContext *vctx_{nullptr}; | ||
GraphSpaceID space_; | ||
Status status_; | ||
AliasType inputType_{AliasType::kRuntime}; | ||
// Default output type is Runtime | ||
AliasType outputType_{AliasType::kRuntime}; | ||
}; | ||
|
||
} // namespace graph | ||
} // namespace nebula | ||
|
||
#endif // NEBULA_GRAPH_DEDUCEALIASTYPEVISITOR_H |
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.