From 36100b09f65bb2419008512fecbb652f1021cdd7 Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:12:28 +0800 Subject: [PATCH] Add more comments --- src/graph/util/ExpressionUtils.h | 3 +-- src/graph/util/IdGenerator.h | 2 +- src/graph/util/IndexUtil.h | 5 +++++ src/graph/util/ParserUtil.cpp | 6 ------ src/graph/util/ParserUtil.h | 10 +++++++++- src/graph/util/PlannerUtil.h | 8 +++++++- src/graph/util/SchemaUtil.h | 23 +++++++++++++++++------ src/graph/util/ToJson.h | 4 ++++ src/graph/util/Utils.h | 2 ++ src/graph/util/ValidateUtil.cpp | 4 ++-- src/graph/util/ValidateUtil.h | 5 +++++ src/graph/util/ZoneUtil.h | 1 + src/graph/validator/Validator.cpp | 1 + 13 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/graph/util/ExpressionUtils.h b/src/graph/util/ExpressionUtils.h index 741238849d7..83ca54aa145 100644 --- a/src/graph/util/ExpressionUtils.h +++ b/src/graph/util/ExpressionUtils.h @@ -174,10 +174,9 @@ class ExpressionUtils { Expression** filterPicked, Expression** filterUnpicked); + // TODO(Aiee) These functions are unused. Remove when refactor. static Expression* expandExpr(ObjectPool* pool, const Expression* expr); - static Expression* expandImplAnd(ObjectPool* pool, const Expression* expr); - static std::vector expandImplOr(const Expression* expr); // Check if the aggExpr is valid in yield clause diff --git a/src/graph/util/IdGenerator.h b/src/graph/util/IdGenerator.h index e0578c4248c..b99cb1f4f20 100644 --- a/src/graph/util/IdGenerator.h +++ b/src/graph/util/IdGenerator.h @@ -10,7 +10,7 @@ namespace nebula { namespace graph { -// TODO(Aiee) Remove class and use snowflake id generater +// TODO(Aiee) Remove class and use snowflake id generater instead class IdGenerator { public: explicit IdGenerator(int64_t init = 0) : counter_(init) {} diff --git a/src/graph/util/IndexUtil.h b/src/graph/util/IndexUtil.h index 70161a37222..2bbcc51021e 100644 --- a/src/graph/util/IndexUtil.h +++ b/src/graph/util/IndexUtil.h @@ -16,11 +16,16 @@ class IndexUtil final { public: IndexUtil() = delete; + // Checks wether the parameter in the geo s2 index is valid static Status validateIndexParams(const std::vector ¶ms, meta::cpp2::IndexParams &indexParams); + // TODO(Aiee) no status will be returned. Change the interface + // Extracts the field and type from the indexItem and returns a Dataset to depscribe the index static StatusOr toDescIndex(const meta::cpp2::IndexItem &indexItem); + // TODO(Aiee) no status will be returned. Change the interface + // Returns the infomation of the given index static StatusOr toShowCreateIndex(bool isTagIndex, const std::string &indexName, const meta::cpp2::IndexItem &indexItem); diff --git a/src/graph/util/ParserUtil.cpp b/src/graph/util/ParserUtil.cpp index 56679d9d668..de0e8c0132a 100644 --- a/src/graph/util/ParserUtil.cpp +++ b/src/graph/util/ParserUtil.cpp @@ -10,12 +10,6 @@ namespace nebula { namespace graph { -// static -bool ParserUtil::isLabel(const Expression *expr) { - return expr->kind() == Expression::Kind::kLabel || - expr->kind() == Expression::Kind::kLabelAttribute; -} - // static void ParserUtil::rewriteLC(QueryContext *qctx, ListComprehensionExpression *lc, diff --git a/src/graph/util/ParserUtil.h b/src/graph/util/ParserUtil.h index ab4f2d310b3..e9f843aaa1a 100644 --- a/src/graph/util/ParserUtil.h +++ b/src/graph/util/ParserUtil.h @@ -17,15 +17,23 @@ class ParserUtil final { public: ParserUtil() = delete; - static bool isLabel(const Expression *expr); + // Rewrites the list comprehension expression so that the innerVar_ will be replaced by a newly + // generated variable. + // This is to prevent duplicate variable names existing both inside and outside the expression. static void rewriteLC(QueryContext *qctx, ListComprehensionExpression *lc, const std::string &oldVarName); + // Rewrites the predicate comprehension expression so that the innerVar_ will be replaced by a + // newly generated variable. This is to prevent duplicate variable names existing both inside and + // outside the expression. static void rewritePred(QueryContext *qctx, PredicateExpression *pred, const std::string &oldVarName); + // Rewrites the list reduce expression so that the innerVar_ and the accumulator_ will be replaced + // by newly generated variables. This is to prevent duplicate variable names existing both inside + // and outside the expression. static void rewriteReduce(QueryContext *qctx, ReduceExpression *reduce, const std::string &oldAccName, diff --git a/src/graph/util/PlannerUtil.h b/src/graph/util/PlannerUtil.h index 017494be55c..bdba5e642a8 100644 --- a/src/graph/util/PlannerUtil.h +++ b/src/graph/util/PlannerUtil.h @@ -15,13 +15,19 @@ class PlanNode; class PlannerUtil final { public: PlannerUtil() = delete; - + // Generates a dataset where each row is a vid from starts.vids, and saves the dataset in variable + // vidsVar static void buildConstantInput(QueryContext* qctx, Starts& starts, std::string& vidsVar); + // Builds a starts subplan when in the runtime static SubPlan buildRuntimeInput(QueryContext* qctx, Starts& starts); + // Builds a starts subplan from the Starts object. + // If starts.vids is not empty and the starts.originalSrc is null, call buildConstantInput(), + // otherwise build a runtime input static SubPlan buildStart(QueryContext* qctx, Starts& starts, std::string& vidsVar); + // Deduplicates the dst in the getNeighbor plan node and outputs the result to variable output static PlanNode* extractDstFromGN(QueryContext* qctx, PlanNode* gn, const std::string& output); }; diff --git a/src/graph/util/SchemaUtil.h b/src/graph/util/SchemaUtil.h index b6faddcf768..424cca2daec 100644 --- a/src/graph/util/SchemaUtil.h +++ b/src/graph/util/SchemaUtil.h @@ -24,24 +24,35 @@ class SchemaUtil final { SchemaUtil() = delete; public: + // Iterates schemaProps and sets the each shchemaProp into schema. + // Returns Status error when when failed to set. static Status validateProps(const std::vector& schemaProps, meta::cpp2::Schema& schema); + // Generates a NebulaSchemaProvider that contains schema info from the schema. static std::shared_ptr generateSchemaProvider( const SchemaVer ver, const meta::cpp2::Schema& schema); + // Sets TTLDuration from shcemaProp into shcema. static Status setTTLDuration(SchemaPropItem* schemaProp, meta::cpp2::Schema& schema); + // Sets TTLCol from shcemaProp into shcema. static Status setTTLCol(SchemaPropItem* schemaProp, meta::cpp2::Schema& schema); + // Sets Comment from shcemaProp into shcema. static Status setComment(SchemaPropItem* schemaProp, meta::cpp2::Schema& schema); + // Calculates the vid value from expr. + // If the result value type mismatches vidType, returns Status error. static StatusOr toVertexID(Expression* expr, Value::Type vidType); + // Iterate exprs and calculate each element's value and return them as a vector. static StatusOr> toValueVec(std::vector exprs); + // Returns the "Field", "Type", "Null", "Default", "Comment" of the schema as a dataset static StatusOr toDescSchema(const meta::cpp2::Schema& schema); + // Returns the schema info of the given tag/edge as a dataset. static StatusOr toShowCreateSchema(bool isTag, const std::string& name, const meta::cpp2::Schema& schema); @@ -49,22 +60,22 @@ class SchemaUtil final { static std::string typeToString(const meta::cpp2::ColumnTypeDef& col); static std::string typeToString(const meta::cpp2::ColumnDef& col); + // Returns the coresponding Value type of the given PropertyType. static Value::Type propTypeToValueType(nebula::cpp2::PropertyType propType); + // Validates wether the value type matches the ColumnTypeDef. static bool isValidVid(const Value& value, const meta::cpp2::ColumnTypeDef& type); - static bool isValidVid(const Value& value, nebula::cpp2::PropertyType type); - static bool isValidVid(const Value& value); - // Fetch all tags in the space and retrieve props from tags - // only take _tag when withProp is false + // Fetches all tags in the space and retrieve props from tags. + // Only take _tag when withProp is false. static StatusOr>> getAllVertexProp(QueryContext* qctx, GraphSpaceID spaceId, bool withProp); - // retrieve prop from specific edgetypes - // only take _src _dst _type _rank when withProp is false + // Retrieves prop from specific edgetypes. + // Only takes _src _dst _type _rank when withProp is false. static StatusOr>> getEdgeProps( QueryContext* qctx, const SpaceInfo& space, diff --git a/src/graph/util/ToJson.h b/src/graph/util/ToJson.h index 4c03abf9989..67c34326ae3 100644 --- a/src/graph/util/ToJson.h +++ b/src/graph/util/ToJson.h @@ -50,6 +50,7 @@ struct Variable; } // namespace graph namespace util { +// Converts all elements in arr to JSON objects, returns a dynamic::array template folly::dynamic toJson(const std::vector &arr); @@ -64,6 +65,8 @@ std::string toJson(const List &list); std::string toJson(const Value &value); std::string toJson(const EdgeKeyRef *ref); std::string toJson(const Expression *expr); + +// Concerts the given object to a dynamic object folly::dynamic toJson(const meta::cpp2::SpaceDesc &desc); folly::dynamic toJson(const meta::cpp2::ColumnDef &column); folly::dynamic toJson(const meta::cpp2::Schema &schema); @@ -84,6 +87,7 @@ folly::dynamic toJson(const storage::cpp2::IndexQueryContext &iqc); folly::dynamic toJson(const storage::cpp2::IndexColumnHint &hints); folly::dynamic toJson(const graph::Variable *var); +// Converts std::pair p into a dynamic object where the key is p.first and value if p.second template folly::dynamic toJson(const std::pair &p) { return folly::dynamic::object(toJson(p.first), toJson(p.second)); diff --git a/src/graph/util/Utils.h b/src/graph/util/Utils.h index 1a1db5c54a7..5c729a720df 100644 --- a/src/graph/util/Utils.h +++ b/src/graph/util/Utils.h @@ -13,6 +13,8 @@ namespace nebula::graph::util { +// Iterates the container and for each element, apply the function fn(). Joins the results of the +// fn() with the delimiter template std::string join(const Container& container, Fn fn, const std::string& delimiter = ",") { std::vector strs; diff --git a/src/graph/util/ValidateUtil.cpp b/src/graph/util/ValidateUtil.cpp index c71bc7279b5..87095cf27f0 100644 --- a/src/graph/util/ValidateUtil.cpp +++ b/src/graph/util/ValidateUtil.cpp @@ -46,7 +46,7 @@ Status ValidateUtil::validateOver(QueryContext* qctx, const OverClause* clause, if (edges.empty()) { return Status::SemanticError("No edge type found in space `%s'", space.name.c_str()); } - for (auto edge : edges) { + for (const auto& edge : edges) { auto edgeType = schemaMng->toEdgeType(space.id, edge); if (!edgeType.ok()) { return Status::SemanticError( @@ -56,7 +56,7 @@ Status ValidateUtil::validateOver(QueryContext* qctx, const OverClause* clause, } over.allEdges = std::move(edges); over.isOverAll = true; - } else { + } else { // Over specific edges auto edges = clause->edges(); for (auto* edge : edges) { auto edgeName = *edge->edge(); diff --git a/src/graph/util/ValidateUtil.h b/src/graph/util/ValidateUtil.h index 66621cd7bd1..330ee417448 100644 --- a/src/graph/util/ValidateUtil.h +++ b/src/graph/util/ValidateUtil.h @@ -18,10 +18,15 @@ class ValidateUtil final { public: ValidateUtil() = delete; + // Checks the upper bound steps of clause is greater than its lower bound. + // TODO(Aiee) Seems this method not only checks the clause but also set the clause into step which + // is in the context. Consider seprate it. static Status validateStep(const StepClause* clause, StepClause& step); + // Retrives edges from schema manager and validate the over clause. static Status validateOver(QueryContext* qctx, const OverClause* clause, Over& over); + // Returns a status error if the expr contains any labelExpression. static Status invalidLabelIdentifiers(const Expression* expr); }; diff --git a/src/graph/util/ZoneUtil.h b/src/graph/util/ZoneUtil.h index 9a08919f236..c44a12a3b8f 100644 --- a/src/graph/util/ZoneUtil.h +++ b/src/graph/util/ZoneUtil.h @@ -11,6 +11,7 @@ namespace nebula { namespace graph { +// TODO(Aiee) Remove unused class class ZoneUtil final { public: ZoneUtil() = delete; diff --git a/src/graph/validator/Validator.cpp b/src/graph/validator/Validator.cpp index 03f8d48867d..ceef1627b86 100644 --- a/src/graph/validator/Validator.cpp +++ b/src/graph/validator/Validator.cpp @@ -419,6 +419,7 @@ Status Validator::checkDuplicateColName() { return Status::OK(); } +// TODO(Aiee) Move to validateUtil Status Validator::validateStarts(const VerticesClause* clause, Starts& starts) { if (clause == nullptr) { return Status::SemanticError("From clause nullptr.");