From 4a7f4b3ad67685678201c80557d69ad3d0ffb40c Mon Sep 17 00:00:00 2001 From: Shipeng Qi Date: Wed, 31 Jan 2024 10:01:14 +0800 Subject: [PATCH] fix #23: remove chinese characters in code comment (#402) * update copyright to 2024 * add deps * clean chinese characters in code comments * fix comments --- .../python/TuGraphClient/TuGraphClient.py | 5 ++- .../arithmetic/arithmetic_expression.cpp | 2 +- src/cypher/execution_plan/execution_plan.cpp | 34 +++++++++---------- .../execution_plan/execution_plan_maker.cpp | 4 +-- src/cypher/execution_plan/ops/op.h | 2 +- .../ops/op_all_node_scan_dynamic.h | 2 +- src/cypher/execution_plan/ops/op_apply.h | 4 +-- src/cypher/execution_plan/ops/op_filter.h | 6 ++-- .../execution_plan/ops/op_node_by_id_seek.h | 2 +- .../ops/op_node_by_label_scan_dynamic.h | 2 +- .../execution_plan/ops/op_node_index_seek.h | 2 +- src/cypher/execution_plan/ops/op_traversal.h | 2 +- .../locate_node_by_indexed_prop.h | 17 +++++----- .../optimization/locate_node_by_vid.h | 2 +- .../opt_rewrite_with_schema_inference.h | 11 +++--- .../optimization/parallel_traversal.h | 21 ++++++------ .../optimization/rewrite/schema_rewrite.cpp | 30 ++++++++-------- .../optimization/rewrite/schema_rewrite.h | 20 +++++------ src/cypher/filter/filter.h | 5 ++- src/cypher/parser/cypher_base_visitor.h | 2 +- 20 files changed, 85 insertions(+), 90 deletions(-) diff --git a/src/client/python/TuGraphClient/TuGraphClient.py b/src/client/python/TuGraphClient/TuGraphClient.py index 45e0ee8297..208417e5f4 100644 --- a/src/client/python/TuGraphClient/TuGraphClient.py +++ b/src/client/python/TuGraphClient/TuGraphClient.py @@ -16,7 +16,7 @@ # TODO: implement load balancing class AsyncTuGraphClient: - # 默认的客户端使用异步方式访问 + # client accesses server asynchronously by default def __init__(self, start_host_port, username, password, graph='default', use_https=False, load_balance=False, retry=3, retry_interval_s=1): @@ -319,8 +319,7 @@ async def get_server_info(self): class TuGraphClient(AsyncTuGraphClient): - # 还是暴露之前的TuGraphClient - # 将之前暴露的8个接口重新封装成可以直接同步方式调用 + # reserve legacy TuGraphClient for eight synchronous interface def list_graphs(self): return self._sync(partial(AsyncTuGraphClient.list_graphs, self)) diff --git a/src/cypher/arithmetic/arithmetic_expression.cpp b/src/cypher/arithmetic/arithmetic_expression.cpp index 3f235c8b0b..91f619455b 100644 --- a/src/cypher/arithmetic/arithmetic_expression.cpp +++ b/src/cypher/arithmetic/arithmetic_expression.cpp @@ -1273,7 +1273,7 @@ Entry ArithOpNode::Evaluate(RTContext *ctx, const Record &record) const { /* if !func, custom function */ std::string input, output; std::string name = func_name.substr(std::string(CUSTOM_FUNCTION_PREFIX).size()); - // 将children都分别进行evaluate操作,并且添加到input进行输出 + // evaluate every child and add to input for output for (int i = 1; i < (int)children.size(); i++) { auto v = children[i].Evaluate(ctx, record); input.append(v.ToString()); diff --git a/src/cypher/execution_plan/execution_plan.cpp b/src/cypher/execution_plan/execution_plan.cpp index d0d0596126..447a0673e0 100644 --- a/src/cypher/execution_plan/execution_plan.cpp +++ b/src/cypher/execution_plan/execution_plan.cpp @@ -325,7 +325,7 @@ void ExecutionPlan::_AddScanOp(const parser::QueryPart &part, const SymbolTable } } if (!has_arg) { - // 符号表中没有type为argument的 + // no argument type in symbol table if (pf.type == Property::VALUE || pf.type == Property::PARAMETER) { /* use index when possible. weak index lookup if label absent */ scan_op = new NodeIndexSeek(node, sym_tab); @@ -348,7 +348,7 @@ void ExecutionPlan::_AddScanOp(const parser::QueryPart &part, const SymbolTable } ops.emplace_back(scan_op); } else { - // 符号表有type为argument的 + // argument type exists in symbol table if (it->second.scope == SymbolNode::ARGUMENT) { if (skip_arg_op) return; scan_op = new Argument(sym_tab); @@ -551,7 +551,7 @@ void ExecutionPlan::_BuildExpandOps(const parser::QueryPart &part, PatternGraph auto &relp = pattern_graph.GetRelationship(std::get<1>(step)); auto &neighbor = pattern_graph.GetNode(std::get<2>(step)); if (relp.Empty() && neighbor.Empty()) { - // 邻居节点和关系都为空,证明是悬挂点 hanging为true + // neighbor and relationship are both empty, it's a hanging node /* Node doesn't have any incoming nor outgoing edges, * this is an hanging node "()", create a scan operation. */ CYPHER_THROW_ASSERT(stream.size() == 1); @@ -565,10 +565,10 @@ void ExecutionPlan::_BuildExpandOps(const parser::QueryPart &part, PatternGraph it->second.scope == SymbolNode::ARGUMENT) { // the previous argument op added skip_hanging_argument_op = - true; // 避免MATCH (a),(b) WITH a, b a,b会导致生成多个argument + true; // avoid `MATCH (a),(b) WITH a, b a,b` generates multiple arguments } } else if (relp.VarLen()) { - // 邻居不为空,进行expand + // expand when neighbor is not null OpBase *expand_op = new VarLenExpand(&pattern_graph, &start, &neighbor, &relp); expand_ops.emplace_back(expand_op); } else { @@ -606,7 +606,7 @@ void ExecutionPlan::_BuildExpandOps(const parser::QueryPart &part, PatternGraph /* Locates expand all operations which do not have a child operation, * And adds a scan operation as a new child. */ if (!hanging) { - // 如果不是悬挂点,就补一个scanop + // add a scan op when it is not a hanging node CYPHER_THROW_ASSERT(!stream.empty()); std::vector scan_ops; auto &start_node = pattern_graph.GetNode(std::get<0>(stream[0])); @@ -633,8 +633,9 @@ void ExecutionPlan::_BuildExpandOps(const parser::QueryPart &part, PatternGraph } } // end for streams if (!traversal_root) { - // 如果traversal_root为空,则判断stream里面是否是悬挂点,且为argument,如果是这种情况_AddScanOp就会跳过,不产生任何op - // 1. 判断符号表中是否有argument + // judge if nodes in stream are dangling and of type ARGUMENT when traversal_root is null + // _AddScanOp will be skipped in this case. No op will be generated + // 1. judge if ARGUMENT type exists in symbol table bool has_arg = false; for (auto &a : pattern_graph.symbol_table.symbols) { if (a.second.scope == SymbolNode::ARGUMENT) { @@ -643,23 +644,22 @@ void ExecutionPlan::_BuildExpandOps(const parser::QueryPart &part, PatternGraph } } if (!has_arg) CYPHER_TODO(); - // 2. 判断是否都是悬挂点 - // 所有stream都是悬挂点 + // 2. judge if all nodes are dangiling + // all streams are dangling nodes for (auto &stream : expand_streams) { if (stream.size() != 1 || !pattern_graph.GetRelationship(std::get<1>(stream[0])).Empty()) { CYPHER_TODO(); } } - // 没有argument 或 整个流不是悬挂点,就抛出异常 - // 符合条件的话,就在这里追加一个argument + // throw exception when argument or the stream is not dangling node + // add one more argument when condition is true traversal_root = new Argument(&pattern_graph.symbol_table); } - /* 调整树结构,使得笛卡尔积下的argument放到scan下 - * 删掉笛卡尔积,即children[1]作为根节点 - * 并且更改scan为dynamic - * 目前只处理CARTESIAN_PRODUCT下只有两个孩子的情况 - * 例如: + /* Restructure the tree to move the argument down + * 1. remove cartesian product and emplace children[1] as the root + * 2. update the scan op to the dynamic one + * Only works when there are only two children of CARTESIAN_PRODUCT. E.g, * before: * Cartesian Product Argument [c,f] diff --git a/src/cypher/execution_plan/execution_plan_maker.cpp b/src/cypher/execution_plan/execution_plan_maker.cpp index ed751b630f..11c52f8d97 100644 --- a/src/cypher/execution_plan/execution_plan_maker.cpp +++ b/src/cypher/execution_plan/execution_plan_maker.cpp @@ -192,7 +192,7 @@ void ExecutionPlanMaker::_AddScanOp(const SymbolTable* sym_tab, Node* node, } } if (!has_arg) { - // 符号表中没有type为argument的 + // no argument type in symbol table if (pf.type == Property::VALUE || pf.type == Property::PARAMETER) { /* use index when possible. weak index lookup if label absent */ scan_op = new NodeIndexSeek(node, sym_tab); @@ -217,7 +217,7 @@ void ExecutionPlanMaker::_AddScanOp(const SymbolTable* sym_tab, Node* node, } ops.emplace_back(scan_op); } else { - // 符号表有type为argument的 + // has argument type in symbol table if (it->second.scope == SymbolNode::ARGUMENT) { if (skip_arg_op) return; } else if (pf.type == Property::VALUE || pf.type == Property::PARAMETER) { diff --git a/src/cypher/execution_plan/ops/op.h b/src/cypher/execution_plan/ops/op.h index 2783c91877..5b230739d7 100644 --- a/src/cypher/execution_plan/ops/op.h +++ b/src/cypher/execution_plan/ops/op.h @@ -195,7 +195,7 @@ struct OpBase { bool IsDynamicScan() const { return type == OpType::NODE_INDEX_SEEK_DYNAMIC || type == OpType::ALL_NODE_SCAN_DYNAMIC || - type == OpType::NODE_BY_LABEL_SCAN_DYNAMIC; // 新增 + type == OpType::NODE_BY_LABEL_SCAN_DYNAMIC; } bool IsStreamRoot() const { diff --git a/src/cypher/execution_plan/ops/op_all_node_scan_dynamic.h b/src/cypher/execution_plan/ops/op_all_node_scan_dynamic.h index 37392b92be..e742ca490a 100644 --- a/src/cypher/execution_plan/ops/op_all_node_scan_dynamic.h +++ b/src/cypher/execution_plan/ops/op_all_node_scan_dynamic.h @@ -74,7 +74,7 @@ class AllNodeScanDynamic : public OpBase { auto child = children[0]; if (child->type != OpType::ARGUMENT) CYPHER_TODO(); if (!consuming_) { - // 第一次进来需要child->Consume + // call child->Consume first time if (child->Consume(ctx) != OP_OK) { return OP_DEPLETED; } diff --git a/src/cypher/execution_plan/ops/op_apply.h b/src/cypher/execution_plan/ops/op_apply.h index ddb56053a6..4774694ee2 100644 --- a/src/cypher/execution_plan/ops/op_apply.h +++ b/src/cypher/execution_plan/ops/op_apply.h @@ -98,14 +98,14 @@ class Apply : public OpBase { if (state == StreamDepleted) return OP_DEPLETED; if (state == StreamUnInitialized) { if (PullFromLhs(ctx) != OP_OK) { - // Apply的计算,是这里是先计算lhs的 + // starting with lhs first state = StreamDepleted; return OP_DEPLETED; } state = StreamConsuming; } auto res = rhs->Consume(ctx); - // 然后处理rhs + // then process rhs while (res != OP_OK) { if (PullFromLhs(ctx) != OP_OK) { state = StreamDepleted; diff --git a/src/cypher/execution_plan/ops/op_filter.h b/src/cypher/execution_plan/ops/op_filter.h index d144485760..07d3229933 100644 --- a/src/cypher/execution_plan/ops/op_filter.h +++ b/src/cypher/execution_plan/ops/op_filter.h @@ -69,7 +69,7 @@ class OpFilter : public OpBase { for (auto child : op->children) { allModified = true; if (child->type == cypher::OpType::ARGUMENT) { - // 判断ae_right的符号是否包含在argument中,全包含则containModifies为true + // containModifies is true when all ae_right symbols are included in arguments for (auto alias : tif->RhsAlias()) { if (std::find(child->modifies.begin(), child->modifies.end(), alias) == child->modifies.end()) { @@ -77,18 +77,16 @@ class OpFilter : public OpBase { break; } } - // 如果ARGUMENT符合条件,则直接返回true,无需再找;否则,继续查找孩子的孩子 if (allModified == true) { tif->SetProducerOp(child); return true; } else { - // 如果孩子树中找到了ARGUMENT,那么直接返回true,不继续迭代寻找 if (LocateAndSetProducer(child, tif) == true) { return true; } } } else { - // 如果孩子树中找到了ARGUMENT,那么直接返回true,不继续迭代寻找 + // return true when ARGUMENT found in the child tree if (LocateAndSetProducer(child, tif) == true) { return true; } diff --git a/src/cypher/execution_plan/ops/op_node_by_id_seek.h b/src/cypher/execution_plan/ops/op_node_by_id_seek.h index 87d75560dd..a0a657e5e4 100644 --- a/src/cypher/execution_plan/ops/op_node_by_id_seek.h +++ b/src/cypher/execution_plan/ops/op_node_by_id_seek.h @@ -66,7 +66,7 @@ class NodeByIdSeek : public OpBase { } OpResult RealConsume(RTContext *ctx) override { - // 记得每次都要设为-1!!!!! + // remember set vid to -1 every time node_->SetVid(-1); if (!it_ || !it_->IsValid()) return OP_DEPLETED; diff --git a/src/cypher/execution_plan/ops/op_node_by_label_scan_dynamic.h b/src/cypher/execution_plan/ops/op_node_by_label_scan_dynamic.h index af47cf9071..cc9aae5819 100644 --- a/src/cypher/execution_plan/ops/op_node_by_label_scan_dynamic.h +++ b/src/cypher/execution_plan/ops/op_node_by_label_scan_dynamic.h @@ -77,7 +77,7 @@ class NodeByLabelScanDynamic : public OpBase { auto child = children[0]; if (child->type != OpType::ARGUMENT) CYPHER_TODO(); if (!consuming_) { - // 第一次进来需要child->Consume + // call child->Consume first time if (child->Consume(ctx) != OP_OK) { return OP_DEPLETED; } diff --git a/src/cypher/execution_plan/ops/op_node_index_seek.h b/src/cypher/execution_plan/ops/op_node_index_seek.h index bfce83cdf3..ec018a0400 100644 --- a/src/cypher/execution_plan/ops/op_node_index_seek.h +++ b/src/cypher/execution_plan/ops/op_node_index_seek.h @@ -70,7 +70,7 @@ class NodeIndexSeek : public OpBase { record->SetParameter(ctx->param_tab_); auto &pf = node_->Prop(); - field_ = pf.type != Property::NUL ? pf.field : field_; // 优先用prop形式指定的field + field_ = pf.type != Property::NUL ? pf.field : field_; // use pf.field if applicable if (pf.type == Property::VALUE) { target_values_.emplace_back(pf.value); } else if (pf.type == Property::PARAMETER) { diff --git a/src/cypher/execution_plan/ops/op_traversal.h b/src/cypher/execution_plan/ops/op_traversal.h index 2650926cc9..3f18f3a735 100644 --- a/src/cypher/execution_plan/ops/op_traversal.h +++ b/src/cypher/execution_plan/ops/op_traversal.h @@ -229,7 +229,7 @@ class Traversal : public OpBase { for (auto &num : map_.lock_table()) { if (noneagg_property_.empty()) { result_buffer_.emplace_back(lgraph::FieldData(num.second)); - } else { // result_buffer_格式:[agg, key, agg, key, agg, key, ...] + } else { // result_buffer_ format:[agg, key, agg, key, agg, key, ...] result_buffer_.emplace_back(lgraph::FieldData(num.second)); result_buffer_.emplace_back(num.first); } diff --git a/src/cypher/execution_plan/optimization/locate_node_by_indexed_prop.h b/src/cypher/execution_plan/optimization/locate_node_by_indexed_prop.h index 60ee17a339..bff158d2a7 100644 --- a/src/cypher/execution_plan/optimization/locate_node_by_indexed_prop.h +++ b/src/cypher/execution_plan/optimization/locate_node_by_indexed_prop.h @@ -62,7 +62,7 @@ class LocateNodeByIndexedProp : public OptPass { Node *node; const SymbolTable *symtab; - // TODO(anyone) 2/9/22 gelincheng: 这里可以写的再优雅些嘛? + // TODO(anyone): rewrite this more elegantly if (op_filter->children[0]->type == OpType::ALL_NODE_SCAN) { node = dynamic_cast(op_filter->children[0])->GetNode(); symtab = dynamic_cast(op_filter->children[0])->sym_tab_; @@ -71,9 +71,9 @@ class LocateNodeByIndexedProp : public OptPass { symtab = dynamic_cast(op_filter->children[0])->sym_tab_; } - // try to reuse NodeIndexSeek - // 这里修改了NodeIndexSeek的实现,使其支持静态多值 - // 不选择直接构造一个unwind的原因:因为unwind需要增加一个符号,需要修改原先的symtab + // try to reuse NodeIndexSeek + // Here implemention of NodeIndexSeek is tweaked to support multiple static values + // Reason that not to build unwind:unwind needs one more symbol in symbol table if (target_value_datas.empty()) target_value_datas.emplace_back(value); auto op_node_index_seek = new NodeIndexSeek(node, symtab, field, target_value_datas); op_node_index_seek->parent = op_post; @@ -96,13 +96,13 @@ class LocateNodeByIndexedProp : public OptPass { range_filter->GetCompareOp() == lgraph::LBR_EQ && range_filter->GetAeRight().operand.type == ArithOperandNode::AR_OPERAND_CONSTANT) { if (field.empty()) { - // 右值可能会不是constant? 如果是para类型?需要处理嘛? + // right value may not be constant? need to process when it is para type. field = range_filter->GetAeLeft().operand.variadic.entity_prop; } if (field != range_filter->GetAeLeft().operand.variadic.entity_prop) { return false; } - // 这里默认是scalar,数组情况后续处理 + // assume the operand is scalar by default. Array will be supported later value = range_filter->GetAeRight().operand.constant.scalar; return true; } @@ -145,9 +145,9 @@ class LocateNodeByIndexedProp : public OptPass { std::vector &target_value_datas) { /** * @brief - * 检查Filter是不是符合属性值等值判断的filter + * Check if Filter is filters to filter prop values * - * 2/8 适用情况: where n.prop = value || OR || IN + * where n.prop = value || OR || IN */ auto filter = op_filter->Filter(); @@ -182,7 +182,6 @@ class LocateNodeByIndexedProp : public OptPass { } if (!getValueFromRangeFilter(filter->Left(), field, value)) return false; target_value_datas.emplace_back(value); - // 如果需要按照原来的输入顺序输出的话 std::reverse(target_value_datas.begin(), target_value_datas.end()); return true; } else if (filter->Type() == lgraph::Filter::GEAX_EXPR_FILTER) { diff --git a/src/cypher/execution_plan/optimization/locate_node_by_vid.h b/src/cypher/execution_plan/optimization/locate_node_by_vid.h index f0f34b5730..6dd43060db 100644 --- a/src/cypher/execution_plan/optimization/locate_node_by_vid.h +++ b/src/cypher/execution_plan/optimization/locate_node_by_vid.h @@ -79,7 +79,7 @@ class LocateNodeByVid : public OptPass { range_filter->GetAeLeft().op.func_name == "id" && range_filter->GetCompareOp() == lgraph::LBR_EQ) { if (!range_filter->GetAeRight().operand.constant.IsInteger()) { - return -1; // TODO(anyone): 右值可能不是integer,这里用-1做flag合适嘛? + return -1; // TODO(anyone): return -1 is not ok when AeRight is not an integer. } return range_filter->GetAeRight().operand.constant.scalar.integer(); } diff --git a/src/cypher/execution_plan/optimization/opt_rewrite_with_schema_inference.h b/src/cypher/execution_plan/optimization/opt_rewrite_with_schema_inference.h index 3e60cacbec..b2714b6334 100644 --- a/src/cypher/execution_plan/optimization/opt_rewrite_with_schema_inference.h +++ b/src/cypher/execution_plan/optimization/opt_rewrite_with_schema_inference.h @@ -76,7 +76,8 @@ class OptRewriteWithSchemaInference : public OptPass { return true; } - // match子句中的模式图可以分为多个极大连通子图,该函数提取每个极大连通子图的点和边,经过分析后加上标签信息 + // pattern graph in match clause can be divided to multiple maximal connected subgraphs + // this function extracts V and E of each subgraphs and labels them after analysis void _ExtractStreamAndAddLabels(OpBase *root, const lgraph::SchemaInfo *schema_info) { CYPHER_THROW_ASSERT(root->type == OpType::EXPAND_ALL); SchemaNodeMap schema_node_map; @@ -103,7 +104,7 @@ class OptRewriteWithSchemaInference : public OptPass { relp_map_value(start->ID(), neighbor->ID(), relp->Types(), relp->direction_); schema_relp_map[relp->ID()] = relp_map_value; } else if (op->type == OpType::VAR_LEN_EXPAND) { - // 含有可变长算子的情况暂不处理 + // currently do not process when var len ops exist return; } else if ((op->IsScan() || op->IsDynamicScan()) && op->type != OpType::ARGUMENT) { NodeID id; @@ -140,12 +141,12 @@ class OptRewriteWithSchemaInference : public OptPass { CYPHER_THROW_ASSERT(op->children.size() == 1); op = op->children[0]; } - // 调用schema函数 + // call schema function rewrite::SchemaRewrite schema_rewrite; std::vector schema_graph_maps; schema_graph_maps = schema_rewrite.GetEffectivePath(*schema_info, &schema_node_map, &schema_relp_map); - // 目前只对一条可行路径的情况进行重写 + // currently rewrite only when there is just one effective path if (schema_graph_maps.size() != 1) { return; } @@ -219,7 +220,7 @@ class OptRewriteWithSchemaInference : public OptPass { } void _RewriteWithSchemaInference(OpBase *root, const lgraph::SchemaInfo *schema_info) { - // 对单独的点和可变长不予优化 + // do not optimize on single node and var len if (root->type == OpType::EXPAND_ALL) { _ExtractStreamAndAddLabels(root, schema_info); } else { diff --git a/src/cypher/execution_plan/optimization/parallel_traversal.h b/src/cypher/execution_plan/optimization/parallel_traversal.h index ffe5e8006f..12fe91da2e 100644 --- a/src/cypher/execution_plan/optimization/parallel_traversal.h +++ b/src/cypher/execution_plan/optimization/parallel_traversal.h @@ -61,10 +61,10 @@ class ParallelTraversal : public OptPass { } bool _AdjustTraversal(OpBase *root) { - // 遍历查询计划,判断是否满足变换traversal条件 + // traverse the plan to see if the condition is satisfied. OpBase *leaf_op = root; while (!leaf_op->children.empty() && leaf_op->type != OpType::AGGREGATE) { - // 由于txn_.Abort(),无法传递以及处理其他需要txn的op + // can not pass or process other OPs that needs txn due to txn_.Abort() if (leaf_op->children.size() > 1 || (leaf_op->type != OpType::PRODUCE_RESULTS && leaf_op->type != OpType::SORT)) { return false; @@ -76,7 +76,7 @@ class ParallelTraversal : public OptPass { } Aggregate *aggregate = dynamic_cast(leaf_op); - // 目前仅处理单个聚合函数,且key的数量为0或1 + // only process single aggregation functions if (aggregate->GetAggregatedExpressions().size() != 1 || aggregate->GetNoneAggregatedExpressions().size() > 1) { return false; @@ -85,16 +85,17 @@ class ParallelTraversal : public OptPass { std::string start_alias; std::string end_alias; std::string start_label; + // has_filter is not used currently std::vector< std::tuple> - expands; // has_filter暂时不用 + expands; while (!leaf_op->children.empty()) { if (leaf_op->children.size() > 1) { return false; } leaf_op = leaf_op->children[0]; if (leaf_op->type == OpType::EXPAND_ALL) { - // 目前暂不考虑对expand进行filter + // do not filter on expand currently if (leaf_op->parent->type == OpType::FILTER) { return false; } @@ -117,13 +118,13 @@ class ParallelTraversal : public OptPass { if (leaf_op->parent->type == OpType::FILTER) { OpFilter *op_filter = dynamic_cast(leaf_op->parent); filter = op_filter->Filter(); - // 目前只处理RANGE_FILTER,可嵌套 + // only process RANGE_FILTER, it can be recursive if (!_JudgeRangeFilter(filter)) { return false; } } } else { - return false; // plan最后节点必须为node_by_label_scan + return false; // the leaf node must be a node_by_label_scan in the plan } if (start_alias.empty() || end_alias.empty()) { return false; @@ -131,16 +132,16 @@ class ParallelTraversal : public OptPass { ArithExprNode agg_expr; ArithExprNode noneagg_expr; - if (aggregate->GetNoneAggregatedExpressions().size() == 1) { // 有key + if (aggregate->GetNoneAggregatedExpressions().size() == 1) { // has key agg_expr = aggregate->GetAggregatedExpressions()[0]; noneagg_expr = aggregate->GetNoneAggregatedExpressions()[0]; if (noneagg_expr.operand.variadic.alias != end_alias || agg_expr.op.func_name != "count" || agg_expr.op.children[1].operand.variadic.alias != - start_alias) { // 判断是否为头+尾+count + start_alias) { // judge if head+end+count return false; } - } else { // 无key + } else { // has no key agg_expr = aggregate->GetAggregatedExpressions()[0]; if (agg_expr.op.func_name != "count" || agg_expr.op.children[1].operand.variadic.alias != start_alias) { diff --git a/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.cpp b/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.cpp index d49d4bce82..1d79bc3991 100644 --- a/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.cpp +++ b/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.cpp @@ -21,11 +21,11 @@ namespace cypher::rewrite { -// 根据schema信息和cypher信息获取有效路径 +// extract effective path based on schema and cypher information std::vector SchemaRewrite::GetEffectivePath( const lgraph::SchemaInfo& schema_info, cypher::SchemaNodeMap* schema_node_map, cypher::SchemaRelpMap* schema_relp_map) { - // 根据schema构建目标图 + // build the target graph based on schema m_schema_node_map = schema_node_map; m_schema_relp_map = schema_relp_map; label2idx.insert({"", -2}); @@ -56,7 +56,7 @@ std::vector SchemaRewrite::GetEffectivePath( label_num++; } - // cypher语句构建查询图 + // build query graph size_t cnt = 0; for (auto it = schema_node_map->begin(); it != schema_node_map->end(); it++) { vidx2pidx.insert({cnt, it->first}); @@ -86,7 +86,7 @@ std::vector SchemaRewrite::GetEffectivePath( e_cnt++; } - // 初始化相关参数 + // initialization target_size = target_graph.m_nodes.size(); query_size = query_graph.m_nodes.size(); edge_core.resize(query_graph.m_edges.size()); @@ -96,13 +96,13 @@ std::vector SchemaRewrite::GetEffectivePath( #ifdef DEBUG PrintLabel2Idx(); - LOG_DEBUG() << "目标图:"; + LOG_DEBUG() << "target graph:"; target_graph.PrintGraph(); - LOG_DEBUG() << "查询图:"; + LOG_DEBUG() << "query graph:"; query_graph.PrintGraph(); #endif - // 回溯 + // back track for (size_t i = 0; i < target_size; i++) { Reset(); if (CheckNodeLabel(0, i)) { @@ -115,7 +115,7 @@ std::vector SchemaRewrite::GetEffectivePath( return sgm; } -// 重置所有状态 +// reset all flags void SchemaRewrite::Reset() { for (size_t i = 0; i < query_size; i++) { core_2[i] = -1; @@ -211,14 +211,14 @@ std::vector SchemaRewrite::GenCandidateStateInfo() { return candidate_state_infos; } -// //回溯 +// //backtrack // void SchemaRewrite::Backtrack(size_t vid){ // map_cnt--; // visited[vid]=false; // core_2[vid]=-1; // } -// 检查目标图和查询图上当前点的label是否一致 +// Check if the labels are same on the target graph and query graph bool SchemaRewrite::CheckNodeLabel(size_t vid, size_t t_vid) { Node* query_node = &query_graph.m_nodes[vid]; Node* target_node = &target_graph.m_nodes[t_vid]; @@ -227,7 +227,7 @@ bool SchemaRewrite::CheckNodeLabel(size_t vid, size_t t_vid) { } return false; } -// 根据目标图上的边id集合获取点id集合 +// extract vid set using edge id set of target graph std::map> SchemaRewrite::GetNextTVidByEdgeId(std::set& edge_ids, size_t t_vid) { std::map> id2eidset; @@ -248,7 +248,7 @@ std::map> SchemaRewrite::GetNextTVidByEdgeId(std::set SchemaRewrite::GetNextEdgeIds(Edge* query_edge, size_t t_vid, size_t direction) { std::set edge_ids; Node& target_node = target_graph.m_nodes[t_vid]; @@ -290,7 +290,7 @@ std::set SchemaRewrite::GetNextEdgeIds(Edge* query_edge, size_t t_vid, s } return edge_ids; } -// 根据label获取其唯一的id +// get unique id using label int SchemaRewrite::GetLabelNum(std::string label) { auto it = label2idx.find(label); int label_num = -1; @@ -303,7 +303,7 @@ int SchemaRewrite::GetLabelNum(std::string label) { } return label_num; } -// 将匹配的路径加入到schema graph map中 +// add matched path to schema graph map void SchemaRewrite::AddMapping() { cypher::SchemaNodeMap snm(*m_schema_node_map); cypher::SchemaRelpMap srm(*m_schema_relp_map); @@ -341,7 +341,7 @@ void SchemaRewrite::AddMapping() { } sgm.push_back(std::make_pair(snm, srm)); } -// 打印当前匹配的路径 +// print matched path void SchemaRewrite::PrintMapping() { LOG_INFO() << "Node Mapping:"; for (size_t j = 0; j < query_size; j++) { diff --git a/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.h b/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.h index 6bfbcbb9e3..24749ddaae 100644 --- a/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.h +++ b/src/cypher/execution_plan/optimization/rewrite/schema_rewrite.h @@ -30,9 +30,7 @@ namespace cypher { -// key为pattern graph中的点id,value为label值 typedef std::map SchemaNodeMap; -// key为pattern graph中的边id,value为(源点id,终点id,边label值,边方向,最小跳数,最大跳数)的六元组 typedef std::map, parser::LinkDirection>> SchemaRelpMap; typedef std::pair SchemaGraphMap; @@ -41,15 +39,15 @@ namespace rewrite { class SchemaRewrite { public: - std::map label2idx; // 每个label对应一个id + std::map label2idx; // label to index int label_cnt = 0; - std::vector idx2label; // id到label的对应 + std::vector idx2label; // index to label - std::map vidx2pidx; // 顶点id到pattern graph中id对应 - std::map pidx2vidx; // pattern graph中id到顶点id对应 - std::map eidx2pidx; // 边id到pattern graph中id对应 + std::map vidx2pidx; // vertex id to pattern graph id + std::map pidx2vidx; // pattern graph id to vertex id + std::map eidx2pidx; // edge id to pattern graph id - std::vector> edge_core; // 保存查询图中边id到目标图中边id的对应关系 + std::vector> edge_core; // pattern graph edge id to dst graph edge id std::vector sgm; cypher::SchemaNodeMap* m_schema_node_map; cypher::SchemaRelpMap* m_schema_relp_map; @@ -59,11 +57,11 @@ class SchemaRewrite { Graph target_graph; Graph query_graph; - std::vector core_2; // 保存查询图中点id到目标图中点id的对应关系 + std::vector core_2; size_t query_size; size_t target_size; - size_t map_cnt = 0; // 查询图中点已经匹配的个数 - size_t depth = 0; // 遍历的深度 + size_t map_cnt = 0; // matched vertices count in graph + size_t depth = 0; // depth in traversal SchemaRewrite() {} ~SchemaRewrite() {} diff --git a/src/cypher/filter/filter.h b/src/cypher/filter/filter.h index 7f5e6f3e6d..6fcc4591d5 100644 --- a/src/cypher/filter/filter.h +++ b/src/cypher/filter/filter.h @@ -573,9 +573,8 @@ class TestInFilter : public Filter { // optimize with hash_set if (producer_op_ != nullptr) { - // producer_op_ != nullptr,说明可以使用set优化 + // producer_op_ != nullptr means it can be optimized with hash_set if (timestamp != producer_op_->stats.profileRecordCount) { - // 需要重置set right_set_.clear(); for (auto &r : *right.constant.array) { right_set_.emplace(r); @@ -593,7 +592,7 @@ class TestInFilter : public Filter { return true; } } else { - // 否则,就循环迭代,目前只处理argument这种情况 + // only process argument in a loop LOG_WARN() << "[" << __FILE__ << "] " << "do not use unordered_set"; for (auto &r : *right.constant.array) { diff --git a/src/cypher/parser/cypher_base_visitor.h b/src/cypher/parser/cypher_base_visitor.h index ed70e31942..ed75dd0606 100644 --- a/src/cypher/parser/cypher_base_visitor.h +++ b/src/cypher/parser/cypher_base_visitor.h @@ -113,7 +113,7 @@ class CypherBaseVisitor : public LcypherVisitor { public: CypherBaseVisitor() = default; - // TODO(anyone): 考虑在parser visit阶段之后,再处理yield items + // TODO(anyone): consider yield items after parser visit CypherBaseVisitor(cypher::RTContext *ctx, antlr4::tree::ParseTree *tree) : ctx_(ctx) { // The default implementation of visit() tree->accept(this);