Skip to content

Commit

Permalink
fix compiler error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Aug 30, 2021
1 parent 0dcd59c commit 056c32a
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 55 deletions.
5 changes: 4 additions & 1 deletion src/graph/context/ast/QueryAstContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ struct SubgraphContext final : public AstContext {

struct FetchVerticesContext final : public AstContext {
Starts from;
bool distince{false};
bool distinct{false};
YieldColumns* yieldExpr{nullptr};
ExpressionProps exprProps;
std::vector<std::string> colNames;

// store the result of the previous sentence
std::string inputVarName;
};

} // namespace graph
Expand Down
11 changes: 8 additions & 3 deletions src/graph/planner/ngql/FetchVerticesPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ std::unique_ptr<FetchVerticesPlanner::VertexProps> FetchVerticesPlanner::buildVe
StatusOr<SubPlan> FetchVerticesPlanner::transform(AstContext* astCtx) {
fetchCtx_ = static_cast<FetchVerticesContext*>(astCtx);
auto qctx = fetchCtx_->qctx;
auto space = fetchCtx_->space;
auto& starts = fetchCtx_->from;

std::string vidsVar;
if (starts.vids.empty() && starts.originalSrc == nullptr) {
if (!starts.vids.empty() && starts.originalSrc == nullptr) {
PlannerUtil::buildConstantInput(qctx, starts, vidsVar);
} else {
starts.src = starts.originalSrc;
vidsVar = starts.userDefinedVarName;
if (starts.fromType == kVariable) {
vidsVar = starts.userDefinedVarName;
} else {
vidsVar = fetchCtx_->inputVarName;
}
}

SubPlan subPlan;
Expand All @@ -59,7 +64,7 @@ StatusOr<SubPlan> FetchVerticesPlanner::transform(AstContext* astCtx) {

subPlan.root = Project::make(qctx, getVertices, fetchCtx_->yieldExpr);
if (fetchCtx_->distinct) {
subPlan.root = Dedup::make(qctx, subPlan.root)
subPlan.root = Dedup::make(qctx, subPlan.root);
}
subPlan.tail = getVertices;
return subPlan;
Expand Down
2 changes: 2 additions & 0 deletions src/graph/planner/ngql/FetchVerticesPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ class FetchVerticesPlanner final : public Planner {
};
} // namespace graph
} // namespace nebula

#endif // GRAPH_PLANNER_NGQL_FETCH_VERTICES_PLANNER_H
2 changes: 1 addition & 1 deletion src/graph/planner/ngql/GoPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ StatusOr<SubPlan> GoPlanner::transform(AstContext* astCtx) {
goCtx_->joinInput = goCtx_->from.fromType != FromType::kInstantExpr;
goCtx_->joinDst = !goCtx_->exprProps.dstTagProps().empty();

SubPlan startPlan = Planner::buildStart(qctx, goCtx_->from, goCtx_->vidsVar);
SubPlan startPlan = PlannerUtil::buildStart(qctx, goCtx_->from, goCtx_->vidsVar);

auto& steps = goCtx_->steps;
if (steps.isMToN()) {
Expand Down
4 changes: 2 additions & 2 deletions src/graph/util/ValidateUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "graph/context/ast/QueryAstContext.h"
#include "graph/planner/Planner.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtil.h"
#include "graph/util/ExpressionUtils.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -74,7 +74,7 @@ Status ValidateUtil::validateOver(QueryContext* qctx, const OverClause* clause,
return Status::OK();
}

Status ValidateUtil::invalidLabelIdentifiers(const Expression* expr) const {
Status ValidateUtil::invalidLabelIdentifiers(const Expression* expr) {
auto labelExprs = ExpressionUtils::collectAll(expr, {Expression::Kind::kLabel});
if (!labelExprs.empty()) {
std::stringstream ss;
Expand Down
6 changes: 5 additions & 1 deletion src/graph/util/ValidateUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
#ifndef GRAPH_UTIL_VALIDATE_UTIL_H_
#define GRAPH_UTIL_VALIDATE_UTIL_H_
#include "common/base/Base.h"
#include "common/base/StatusOr.h"
#include "common/expression/Expression.h"
#include "parser/Clauses.h"

namespace nebula {
namespace graph {
class QueryContext;
class PlanNode;
struct Over;

class ValidateUtil final {
public:
Expand All @@ -21,7 +25,7 @@ class ValidateUtil final {

static Status validateOver(QueryContext* qctx, const OverClause* clause, Over& over);

static Status invalidLabelIdentifiers(const Expression* expr) const;
static Status invalidLabelIdentifiers(const Expression* expr);
};

} // namespace graph
Expand Down
3 changes: 2 additions & 1 deletion src/graph/validator/FetchEdgesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/SchemaUtil.h"
#include "graph/util/ValidateUtil.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -184,7 +185,7 @@ Status FetchEdgesValidator::preparePropertiesWithYield(const YieldClause *yield)
dedup_ = newYield_->isDistinct();
for (auto col : newYield_->columns()) {
col->setExpr(ExpressionUtils::rewriteLabelAttr2EdgeProp(col->expr()));
NG_RETURN_IF_ERROR(invalidLabelIdentifiers(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));
const auto *invalidExpr = findInvalidYieldExpression(col->expr());
if (invalidExpr != nullptr) {
return Status::SemanticError("Invalid newYield_ expression `%s'.",
Expand Down
50 changes: 30 additions & 20 deletions src/graph/validator/FetchVerticesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/SchemaUtil.h"
#include "graph/util/ValidateUtils.h"
#include "graph/util/ValidateUtil.h"
#include "graph/visitor/DeducePropsVisitor.h"

namespace nebula {
Expand All @@ -18,13 +18,16 @@ static constexpr char VertexID[] = "VertexID";

Status FetchVerticesValidator::validateImpl() {
auto *fSentence = static_cast<FetchVerticesSentence *>(sentence_);
fetchCtx_ = getContext<FetchVerticesContext>();
fetchCtx_->inputVarName = inputVarName_;

NG_RETURN_IF_ERROR(validateTag(fSentence->tags()));
NG_RETURN_IF_ERROR(validateStart(fSentence->vertices(), fetchCtx_->from));
NG_RETURN_IF_ERROR(validateStarts(fSentence->vertices(), fetchCtx_->from));
NG_RETURN_IF_ERROR(validateYield(fSentence->yieldClause()));
return Status::OK();
}

Status FetchVerticesValidator::validateTag(NameLabelList *nameLabels) {
Status FetchVerticesValidator::validateTag(const NameLabelList *nameLabels) {
if (nameLabels == nullptr) {
// all tag
const auto &tagStatus = qctx_->schemaMng()->getAllLatestVerTagSchema(space_.id);
Expand All @@ -34,14 +37,14 @@ Status FetchVerticesValidator::validateTag(NameLabelList *nameLabels) {
}
} else {
auto labels = nameLabels->labels();
auto &schemaMng = qctx_->schemaMng();
auto *schemaMng = qctx_->schemaMng();
for (const auto &label : labels) {
auto tagStatus = schemaMng->toTagID(space_.id, *label);
NG_RETURN_IF_ERROR(tagStatus);
auto tagID = tagStatus.value();
auto tagSchema = schemaMng->getTagSchema(space_.id, tagID);
if (tagSchema == nullptr) {
return Status::SemanticError("No schema found for `%s'", nameLabel->c_str());
return Status::SemanticError("No schema found for `%s'", label->c_str());
}
tagsSchema_.emplace(tagID, tagSchema);
}
Expand All @@ -51,22 +54,29 @@ Status FetchVerticesValidator::validateTag(NameLabelList *nameLabels) {

Status FetchVerticesValidator::validateYield(YieldClause *yield) {
auto pool = qctx_->objPool();
if (yield == nullptr) {
// version 3.0: return Status::SemanticError("No YIELD Clause");
auto *yieldColumns = new YieldColumns();
auto *vertex = new YieldColumn(VertexExpression::make(pool));
yieldColumns->addColumn(vertex);
yield = pool->add(new YieldClause(yieldColumns));
}
fetchCtx_->distinct = yield->isDistinct();

auto size = yield->columns()->size();
outputs_.reverse(size + 1); // VertexID
auto size = yield->columns().size();
outputs_.reserve(size + 1); // VertexID
outputs_.emplace_back(VertexID, vidType_);

auto &exprProps = fetctCtx_->exprProps;
auto &exprProps = fetchCtx_->exprProps;
for (auto col : yield->columns()) {
// yield vertex or id(vertex)
auto colExpr = col->expr();
col->setExpr(ExpressionUtils::rewriteLabelAttr2TagProp(colExpr));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(colExpr));
col->setExpr(ExpressionUtils::rewriteLabelAttr2TagProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));

auto colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
NG_RETURN_IF_ERROR(typeStatus);
ouputs_.emplace_back(col->name(), typeStatus.value());
outputs_.emplace_back(col->name(), typeStatus.value());

NG_RETURN_IF_ERROR(deduceProps(colExpr, exprProps));
}
Expand All @@ -78,17 +88,17 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) {
return Status::SemanticError("Unsupported src/dst property expression in yield.");
}

for (const auto &tag : exprProps.tagNameIds()) {
if (tagsSchema_.find(tag.first) == tagsSchema_.end()) {
return Status::SemanticError("Mismatched tag `%s'", tag);
}
}
// for (const auto &tag : exprProps.tagNameIds()) {
// if (tagsSchema_.find(tag.first) == tagsSchema_.end()) {
// return Status::SemanticError("Mismatched tag `%s'", tag);
// }
// }
auto *newCols = pool->add(new YieldColumns());
// TODO (will be deleted in version 3.0)
auto *col = new YieldColumn(InputPropertyExpression::make(pool, nebula::kVid), VertexID);
newCols->addColumn(col);
auto *vidCol = new YieldColumn(InputPropertyExpression::make(pool, nebula::kVid), VertexID);
newCols->addColumn(vidCol);
for (const auto &col : yield->columns()) {
newCols->addColumn(col->clone()->release());
newCols->addColumn(col->clone().release());
}
fetchCtx_->yieldExpr = newCols;
auto colNames = getOutColNames();
Expand Down
5 changes: 3 additions & 2 deletions src/graph/validator/FetchVerticesValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#ifndef _VALIDATOR_FETCH_VERTICES_VALIDATOR_H_
#define _VALIDATOR_FETCH_VERTICES_VALIDATOR_H_

#include "graph/context/ast/QueryAstContext.h"
#include "graph/validator/Validator.h"
#include "parser/TraverseSentence.h"
#include "parser/TraverseSentences.h"

namespace nebula {
namespace graph {
Expand All @@ -21,7 +22,7 @@ class FetchVerticesValidator final : public Validator {
private:
Status validateImpl() override;

Status validateTag(NameLabelList* nameLables);
Status validateTag(const NameLabelList* nameLables);

Status validateYield(YieldClause* yield);

Expand Down
3 changes: 2 additions & 1 deletion src/graph/validator/FindPathValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common/expression/VariableExpression.h"
#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ValidateUtil.h"

namespace nebula {
namespace graph {
Expand All @@ -22,7 +23,7 @@ Status FindPathValidator::validateImpl() {

NG_RETURN_IF_ERROR(validateStarts(fpSentence->from(), pathCtx_->from));
NG_RETURN_IF_ERROR(validateStarts(fpSentence->to(), pathCtx_->to));
NG_RETURN_IF_ERROR(validateOver(fpSentence->over(), pathCtx_->over));
NG_RETURN_IF_ERROR(ValidateUtil::validateOver(qctx_, fpSentence->over(), pathCtx_->over));
NG_RETURN_IF_ERROR(validateWhere(fpSentence->where()));
NG_RETURN_IF_ERROR(ValidateUtil::validateStep(fpSentence->step(), pathCtx_->steps));

Expand Down
7 changes: 3 additions & 4 deletions src/graph/validator/FindPathValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

#include "common/base/Base.h"
#include "graph/context/ast/QueryAstContext.h"
#include "graph/validator/TraversalValidator.h"
#include "graph/validator/Validator.h"

namespace nebula {
namespace graph {

class FindPathValidator final : public TraversalValidator {
class FindPathValidator final : public Validator {
public:
FindPathValidator(Sentence* sentence, QueryContext* context)
: TraversalValidator(sentence, context) {}
FindPathValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {}

private:
Status validateImpl() override;
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "graph/context/QueryExpressionContext.h"
#include "graph/planner/plan/Logic.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ValidateUtil.h"
#include "parser/TraverseSentences.h"

namespace nebula {
Expand Down
7 changes: 3 additions & 4 deletions src/graph/validator/GetSubgraphValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#define GRAPH_VALIDATOR_GETSUBGRAPHVALIDATOR_H_

#include "graph/context/ast/QueryAstContext.h"
#include "graph/validator/TraversalValidator.h"
#include "graph/validator/Validator.h"
#include "parser/Clauses.h"

namespace nebula {
namespace graph {
class GetSubgraphValidator final : public TraversalValidator {
class GetSubgraphValidator final : public Validator {
public:
GetSubgraphValidator(Sentence* sentence, QueryContext* context)
: TraversalValidator(sentence, context) {}
GetSubgraphValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {}

private:
Status validateImpl() override;
Expand Down
3 changes: 2 additions & 1 deletion src/graph/validator/GoValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common/expression/VariableExpression.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/ValidateUtil.h"
#include "graph/visitor/ExtractPropExprVisitor.h"
#include "parser/TraverseSentences.h"

Expand All @@ -22,7 +23,7 @@ Status GoValidator::validateImpl() {

NG_RETURN_IF_ERROR(ValidateUtil::validateStep(goSentence->stepClause(), goCtx_->steps));
NG_RETURN_IF_ERROR(validateStarts(goSentence->fromClause(), goCtx_->from));
NG_RETURN_IF_ERROR(validateOver(goSentence->overClause(), goCtx_->over));
NG_RETURN_IF_ERROR(ValidateUtil::validateOver(qctx_, goSentence->overClause(), goCtx_->over));
NG_RETURN_IF_ERROR(validateWhere(goSentence->whereClause()));
NG_RETURN_IF_ERROR(validateYield(goSentence->yieldClause()));
NG_RETURN_IF_ERROR(validateTruncate(goSentence->truncateClause()));
Expand Down
6 changes: 3 additions & 3 deletions src/graph/validator/GoValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

#include "graph/context/ast/QueryAstContext.h"
#include "graph/planner/plan/Query.h"
#include "graph/validator/TraversalValidator.h"
#include "graph/validator/Validator.h"

namespace nebula {
namespace graph {
class GoValidator final : public TraversalValidator {
class GoValidator final : public Validator {
public:
using VertexProp = nebula::storage::cpp2::VertexProp;
using EdgeProp = nebula::storage::cpp2::EdgeProp;

GoValidator(Sentence* sentence, QueryContext* context) : TraversalValidator(sentence, context) {}
GoValidator(Sentence* sentence, QueryContext* context) : Validator(sentence, context) {}

private:
Status validateImpl() override;
Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace nebula {
namespace graph {
MatchValidator::MatchValidator(Sentence *sentence, QueryContext *context)
: TraversalValidator(sentence, context) {
: Validator(sentence, context) {
matchCtx_ = getContext<MatchAstContext>();
}

Expand Down
4 changes: 2 additions & 2 deletions src/graph/validator/MatchValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include "graph/context/ast/CypherAstContext.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/AnonVarGenerator.h"
#include "graph/validator/TraversalValidator.h"
#include "graph/validator/Validator.h"

namespace nebula {

class MatchStepRange;
class ObjectPool;
namespace graph {
class MatchValidator final : public TraversalValidator {
class MatchValidator final : public Validator {
public:
MatchValidator(Sentence *sentence, QueryContext *context);

Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "graph/validator/Validator.h"

#include <thrift/lib/cpp/util/EnumUtils.h>

#include "common/function/FunctionManager.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"
Expand Down
Loading

0 comments on commit 056c32a

Please sign in to comment.