Skip to content

implement exist#604

Merged
jiazhenjiang merged 68 commits intoTuGraph-family:masterfrom
jiazhenjiang:exist_path
Jul 29, 2024
Merged

implement exist#604
jiazhenjiang merged 68 commits intoTuGraph-family:masterfrom
jiazhenjiang:exist_path

Conversation

@jiazhenjiang
Copy link
Contributor

No description provided.

[{"content":"Rachel Kempson","n":{"identity":0,"label":"Person","properties":{"birthyear":1910,"name":"Rachel Kempson"}}},{"content":"Michael Redgrave","n":{"identity":1,"label":"Person","properties":{"birthyear":1908,"name":"Michael Redgrave"}}},{"content":"Vanessa Redgrave","n":{"identity":2,"label":"Person","properties":{"birthyear":1937,"name":"Vanessa Redgrave"}}},{"content":"Corin Redgrave","n":{"identity":3,"label":"Person","properties":{"birthyear":1939,"name":"Corin Redgrave"}}},{"content":"Liam Neeson","n":{"identity":4,"label":"Person","properties":{"birthyear":1952,"name":"Liam Neeson"}}},{"content":"Natasha Richardson","n":{"identity":5,"label":"Person","properties":{"birthyear":1963,"name":"Natasha Richardson"}}},{"content":"Richard Harris","n":{"identity":6,"label":"Person","properties":{"birthyear":1930,"name":"Richard Harris"}}},{"content":"Dennis Quaid","n":{"identity":7,"label":"Person","properties":{"birthyear":1954,"name":"Dennis Quaid"}}},{"content":"Lindsay Lohan","n":{"identity":8,"label":"Person","properties":{"birthyear":1986,"name":"Lindsay Lohan"}}},{"content":"Jemma Redgrave","n":{"identity":9,"label":"Person","properties":{"birthyear":1965,"name":"Jemma Redgrave"}}},{"content":"Roy Redgrave","n":{"identity":10,"label":"Person","properties":{"birthyear":1873,"name":"Roy Redgrave"}}},{"content":"John Williams","n":{"identity":11,"label":"Person","properties":{"birthyear":1932,"name":"John Williams"}}},{"content":"Christopher Nolan","n":{"identity":12,"label":"Person","properties":{"birthyear":1970,"name":"Christopher Nolan"}}},{"content":"New York","n":{"identity":13,"label":"City","properties":{"name":"New York"}}},{"content":"London","n":{"identity":14,"label":"City","properties":{"name":"London"}}},{"content":"Houston","n":{"identity":15,"label":"City","properties":{"name":"Houston"}}},{"content":"Goodbye, Mr. Chips","n":{"identity":16,"label":"Film","properties":{"title":"Goodbye, Mr. Chips"}}},{"content":"Batman Begins","n":{"identity":17,"label":"Film","properties":{"title":"Batman Begins"}}},{"content":"Harry Potter and the Sorcerer's Stone","n":{"identity":18,"label":"Film","properties":{"title":"Harry Potter and the Sorcerer's Stone"}}},{"content":"The Parent Trap","n":{"identity":19,"label":"Film","properties":{"title":"The Parent Trap"}}},{"content":"Camelot","n":{"identity":20,"label":"Film","properties":{"title":"Camelot"}}}]
MATCH (n {name:'Rachel Kempson'}) RETURN exists((n)-[]->()) /*true*/;
[{"{EXISTS(NestedPattern(n,@ANON_N1))}":true}]
[{"exists((n)-[]->())":true}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where 中的exists 例子在哪,通过了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists中最后一条就是where的例子,已经通过了

[{"exists((n)-[]->())":true}]
MATCH (n {name:'Rachel Kempson'}) RETURN exists((n)-[]->(:Person)) /*true*/;
[{"{EXISTS(NestedPattern(n,@ANON_N1))}":true}]
[{"exists((n)-[]->(:Person))":true}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match (a),(b) where not (a)-->(b) return a,b 这种支持吗(不带exists)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前还不支持,Geax里path并不是个表达式,不能直接放入filter中,要支持这个语句,可以在构造Geax AstNode的时候手动补个Exists,或者扩展Geax AstNode支持path类型的表达式,这个要做的话可以加一下

*/
bool Next();

bool Goto(lgraph::VertexId vid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一一下 bool Goto(VertexId vid);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经处理

++filter_level_;
}
std::reverse(expand_ops.begin(), expand_ops.end());
if (ClauseGuard::InClause(geax::frontend::AstNodeType::kExists, cur_types_)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段逻辑处理的是什么子句,举个cypher语句例子

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段逻辑是在处理 exists部分,用limit和optional算子模拟semiapply。类似下面的查询
MATCH (n {name:'Rachel Kempson'}),(m:City) RETURN exists((n)-[:HAS_CHILD]->()-[:BORN_IN]->(m)) /1 true/;
MATCH (n:Person)-[:BORN_IN]->(c) WHERE exists((n)-[:HAS_CHILD]->()-[:BORN_IN]->(c)) RETURN n,c;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在注释里加上个例子,语句 以及 对应的plan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cypher :
MATCH (n {name:'Rachel Kempson'}) RETURN exists((n)-[:MARRIED]->()-[:BORN_IN]->())
plan:
Produce Results
Project [exists((n)-[:MARRIED]->()-[:BORN_IN]->())]
Apply
Limit [1]
Optional
Expand(All) [@ANON_N1 --> @ANON_N3 ]
Expand(All) [n --> @ANON_N1 ]
Argument [n]
Node Index Seek [n] IN []
cypher:
MATCH (n {name:'Rachel Kempson'}),(m:City) RETURN exists((n)-[:HAS_CHILD]->()-[:BORN_IN]->(m))
plan:
Produce Results
Project [exists((n)-[:HAS_CHILD]->()-[:BORN_IN]->(m))]
Apply
Limit [1]
Optional
Expand(Into) [@ANON_N1 --> m ]
Expand(All) [n --> @ANON_N1 ]
Argument [n,m]
Cartesian Product
Node Index Seek [n] IN []
Node By Label Scan [m:City]
cypher :
MATCH (n:Person)-[:BORN_IN]->(c) WHERE exists((n)-[:HAS_CHILD]->()-[:BORN_IN]->(c)) RETURN n,c;
plan:
Expand(All) [n --> c ]
Node By Label Scan [n:Person]
Produce Results
Project [n,c]
Filter [Exists]
Expand(Into) [@ANON_N2 --> c ]
Expand(All) [n --> @ANON_N2 ]
Argument [n,c]

}
}

bool Entry::GetEntityEfficient(RTContext *ctx) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entry::GetEntityEfficient这个方法在做什么?作用?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法是在判断某个record是点或者边,它是不是有效的,有没有保存一个正常的vid或者euid,作用是在exists表达式中判断表达式的结果

@spasserby spasserby self-requested a review July 23, 2024 07:59
field_, value, value);
} else {
// Weak index iterator
// Weak index iterator]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无用的符号

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理

eit_->FreeIter();
neighbor_->PushVid(-1);
if (!expand_into_)
neighbor_->PushVid(-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!expand_into_) neighbor_->PushVid(-1);
或者
if (!expand_into_) {
neighbor_->PushVid(-1);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改为第一种方式

}
}

bool Entry::GetEntityEfficient(RTContext *ctx) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个命名再斟酌一下:
这个是一个校验某个Entity的是否“有效”,不是获取一个Entity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改为CheckEntityEfficient

std::string s = "Execution Plan Before Connect: \n";
if (lgraph_log::LoggerManager::GetInstance().GetLevel()
== lgraph_log::severity_level::DEBUG) {
if (lgraph_log::LoggerManager::GetInstance().GetLevel() == lgraph_log::severity_level::DEBUG) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不太合适:log level不是debug导致 _DumpPlanBeforeConnect 返回结果不同

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经去除if条件

@ljcui ljcui self-requested a review July 25, 2024 03:04
Copy link
Collaborator

@ljcui ljcui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本周先不要合入。

@jiazhenjiang jiazhenjiang enabled auto-merge (squash) July 29, 2024 01:46
@jiazhenjiang jiazhenjiang merged commit d5cda17 into TuGraph-family:master Jul 29, 2024
@jiazhenjiang jiazhenjiang deleted the exist_path branch July 29, 2024 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants