tugraph-analytics icon indicating copy to clipboard operation
tugraph-analytics copied to clipboard

feat: support shard predicate

Open kitalkuyo-gita opened this issue 3 months ago • 2 comments

What changes were proposed in this pull request?

Related to issue-368

How was this PR tested?

  • [ ] Tests have Added for the changes
  • [ ] Production environment verified

kitalkuyo-gita avatar Sep 02 '25 06:09 kitalkuyo-gita

The SAME predicate is primarily used to assert whether entities in a path are same. Is the EXISTS syntax implemented in this pr?

Here is a syntax definition for reference. <same predicate> ::= SAME <left paren> <element variable reference> <comma> <element variable reference> [ { <comma> <element variable reference> }... ] <right paren>

  • EXISTS Syntax - Fully Implemented Feature

Usage: Check if a match exists for a certain path

Grammar Format: EXISTS PathPattern

Actual SQL Example:

-- 检查b节点是否有出边连接到c节点
MATCH (a:person WHERE id = 1)-[e]->(b)
WHERE EXISTS (b) -> (c)
RETURN a, e, b

-- 检查b节点是否有入边连接
MATCH (a:person WHERE id = 1)-[e]->(b)  
WHERE EXISTS (b) <- (c:person where id != 1)
RETURN a, e, b

-- 否定存在性检查
MATCH (a:person WHERE id = 1)-[e]->(b)
WHERE NOT EXISTS (b) -> (c)
RETURN a, e, b

Test Case Proof : The project already has a complete EXISTS test case

  • gql_subquery_005.sql
  • gql_subquery_006.sql
  • gql_subquery_007.sql
  • gql_subquery_009.sql
  1. SAME predicate - New features implemented in this PR

Purpose : Share the same conditions among multiple path patterns

Grammar Format: MATCH path1 | path2 WHERE SAME(condition)

Actual SQL Example:

-- 基本用法:两个路径都要求a.age > 25
MATCH (a:person) -> (b) | (a:person) -> (c) WHERE SAME(a.age > 25)
RETURN a.id as a_id, a.age as a_age, b.id as b_id, c.id as c_id

-- 支持DISTINCT语义
MATCH (a:person) -> (b) | (a:person) -> (c) WHERE SAME(a.age > 25) DISTINCT
RETURN a.id as a_id, a.age as a_age, b.id as b_id, c.id as c_id

-- 支持多个路径模式
MATCH (a:person) -> (b) | (a:person) -> (c) | (a:person) -> (d) WHERE SAME(a.age > 25)
RETURN a.id as a_id, a.age as a_age, b.id as b_id, c.id as c_id, d.id as d_id

-- 复杂条件:涉及多个变量的条件
MATCH (a:person) -> (b) | (a:person) -> (c) WHERE SAME(a.age > 25 AND b.id != c.id)
RETURN a.id as a_id, a.age as a_age, b.id as b_id, c.id as c_id

kitalkuyo-gita avatar Sep 05 '25 06:09 kitalkuyo-gita

The SAME predicate is primarily used to assert whether entities in a path are same. Is the EXISTS syntax implemented in this pr?

Here is a syntax definition for reference. <same predicate> ::= SAME <left paren> <element variable reference> <comma> <element variable reference> [ { <comma> <element variable reference> }... ] <right paren>

I personally think what you said makes some sense. But this is rarely needed in practice because the entities in the path are usually different You can see the following two examples

Expected SAME (Entity Comparison) by yours:

--Check if a, b, and c are the same entity
MATCH (a:person) -> (b) | (a:person) -> (c) WHERE SAME(a, b, c)
--This is rarely needed in practice because the entities in the path are usually different

Actual implementation of SAME (Conditional Sharing):

--Find people over 25 years old who are connected to both b and c at the same time
MATCH (a:person) -> (b) | (a:person) -> (c) WHERE SAME(a.age > 25)
--This is very useful in practice, ensuring that multiple paths meet the same conditions

Exits (path existence):

--Find people with friends
MATCH (a:person) WHERE EXISTS (a) -> (b:person)
--Find people without friends
MATCH (a:person) WHERE NOT EXISTS (a) -> (b:person)

kitalkuyo-gita avatar Sep 05 '25 06:09 kitalkuyo-gita