MuhammadTahaNaveed commented on code in PR #2306:
URL: https://github.com/apache/age/pull/2306#discussion_r2702607654


##########
regress/expected/cypher_set.out:
##########
@@ -988,6 +988,224 @@ SELECT * FROM cypher('issue_1634', $$ MATCH (u) DELETE 
(u) $$) AS (u agtype);
 ---
 (0 rows)
 
+--
+-- Issue 1884: column reference is ambiguous when using same variable in
+--             SET expression and RETURN clause
+--
+-- These tests cover:
+-- 1. "column reference is ambiguous" error when variable is used in both
+--    SET expression RHS (e.g., SET n.prop = n) and RETURN clause
+-- 2. "Invalid AGT header value" error caused by incorrect offset calculation
+--    when nested VERTEX/EDGE/PATH values are serialized in properties
+--
+-- Tests use isolated data to keep output manageable and avoid cumulative 
nesting
+--
+SELECT * FROM create_graph('issue_1884');
+NOTICE:  graph "issue_1884" has been created
+ create_graph 
+--------------
+ 
+(1 row)
+
+-- ============================================================================
+-- Test Group A: Basic "column reference is ambiguous" fix (Issue 1884)
+-- ============================================================================
+-- Test A1: Core issue - SET n.prop = n with RETURN n (the original bug)
+SELECT * FROM cypher('issue_1884', $$
+    CREATE (n:TestA1 {name: 'A1'})
+    SET n.self = n
+    RETURN n
+$$) AS (result agtype);
+                                                                               
    result                                                                      
             
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 844424930131969, "label": "TestA1", "properties": {"name": "A1", 
"self": {"id": 844424930131969, "label": "TestA1", "properties": {"name": 
"A1"}}::vertex}}::vertex
+(1 row)
+
+-- Test A2: Multiple variables in SET and RETURN
+SELECT * FROM cypher('issue_1884', $$
+    CREATE (a:TestA2 {name: 'A'})-[e:LINK {w: 1}]->(b:TestA2 {name: 'B'})
+    SET a.edge = e, b.edge = e
+    RETURN a, e, b
+$$) AS (a agtype, e agtype, b agtype);
+                                                                               
                               a                                                
                                                              |                 
                                                e                               
                                  |                                             
                                                                 b              
                                                                                
                
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 1125899906842625, "label": "TestA2", "properties": {"edge": {"id": 
1407374883553281, "label": "LINK", "end_id": 1125899906842626, "start_id": 
1125899906842625, "properties": {"w": 1}}::edge, "name": "A"}}::vertex | {"id": 
1407374883553281, "label": "LINK", "end_id": 1125899906842626, "start_id": 
1125899906842625, "properties": {"w": 1}}::edge | {"id": 1125899906842626, 
"label": "TestA2", "properties": {"edge": {"id": 1407374883553281, "label": 
"LINK", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": 
{"w": 1}}::edge, "name": "B"}}::vertex
+(1 row)
+
+-- Test A3: SET edge property to node reference
+SELECT * FROM cypher('issue_1884', $$
+    CREATE (a:TestA3 {name: 'X'})-[e:REL]->(b:TestA3 {name: 'Y'})
+    SET e.src = a, e.dst = b
+    RETURN e
+$$) AS (e agtype);
+                                                                               
                                                                      e         
                                                                                
                                                             
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 1970324836974593, "label": "REL", "end_id": 1688849860263938, 
"start_id": 1688849860263937, "properties": {"dst": {"id": 1688849860263938, 
"label": "TestA3", "properties": {"name": "Y"}}::vertex, "src": {"id": 
1688849860263937, "label": "TestA3", "properties": {"name": 
"X"}}::vertex}}::edge
+(1 row)
+
+-- ============================================================================
+-- Test Group B: Nested VERTEX/EDGE/PATH serialization (offset error fix)
+-- ============================================================================
+-- Test B1: Vertex nested in vertex property (tests VERTEX serialization)
+SELECT * FROM cypher('issue_1884', $$
+    CREATE (n:TestB1 {val: 1})
+    SET n.copy = n
+    RETURN n
+$$) AS (result agtype);
+                                                                               
 result                                                                         
       
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 2251799813685249, "label": "TestB1", "properties": {"val": 1, "copy": 
{"id": 2251799813685249, "label": "TestB1", "properties": {"val": 
1}}::vertex}}::vertex
+(1 row)
+
+-- Verify nested vertex can be read back
+SELECT * FROM cypher('issue_1884', $$
+    MATCH (n:TestB1)
+    RETURN n.copy
+$$) AS (copy agtype);
+                                     copy                                      
+-------------------------------------------------------------------------------
+ {"id": 2251799813685249, "label": "TestB1", "properties": {"val": 1}}::vertex
+(1 row)
+
+-- Test B2: Edge nested in node property (tests EDGE serialization)
+SELECT * FROM cypher('issue_1884', $$
+    CREATE (a:TestB2 {name: 'start'})-[e:B2REL {x: 100}]->(b:TestB2 {name: 
'end'})
+    SET a.myEdge = e
+    RETURN a
+$$) AS (a agtype);
+                                                                               
                                   a                                            
                                                                       
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 2533274790395905, "label": "TestB2", "properties": {"name": "start", 
"myEdge": {"id": 2814749767106561, "label": "B2REL", "end_id": 
2533274790395906, "start_id": 2533274790395905, "properties": {"x": 
100}}::edge}}::vertex
+(1 row)
+
+-- Verify nested edge can be read back
+SELECT * FROM cypher('issue_1884', $$
+    MATCH (n:TestB2 {name: 'start'})
+    RETURN n.myEdge
+$$) AS (edge agtype);
+                                                                 edge          
                                                       
+--------------------------------------------------------------------------------------------------------------------------------------
+ {"id": 2814749767106561, "label": "B2REL", "end_id": 2533274790395906, 
"start_id": 2533274790395905, "properties": {"x": 100}}::edge
+(1 row)
+
+-- Test B3: Path nested in node property (tests PATH serialization)
+SELECT * FROM cypher('issue_1884', $$
+    CREATE (a:TestB3)-[e:B3REL]->(b:TestB3)
+    WITH a, e, b
+    MATCH p = (a)-[e]->(b)
+    SET a.myPath = p
+    RETURN a
+$$) AS (a agtype);
+ a 
+---
+(0 rows)

Review Comment:
   This is a bug, unrelated to this PR. A seperate issue has been created to 
track it https://github.com/apache/age/issues/2308



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to