Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlg query with union and tree combination returns wrong vertices #359

Closed
dkarthikeyan88 opened this issue Aug 2, 2019 · 4 comments
Closed
Assignees
Labels

Comments

@dkarthikeyan88
Copy link

dkarthikeyan88 commented Aug 2, 2019

Sqlg query with union and tree combination returns incorrect vertices after upgrading to 2.0.2-SNAPSHOT. I've created the vertices for the below graph and associated the edges for all the vertices appropriately.

										 Test Cluster	
											|
											|
										 Test Service	
											|
											|  
										 Test DB			
									         /         \
									 /                      \
				        			 /                                  \
							/                                                  \
						 /	    				                        \
				   Test Schema1                    		            Test Schema2
				       /       \                                                            /       \
				     /           \                                                       /           \
				   /               \                		                           /               \ 
			  Table1             Table2                                     Table3               Table4
			  /    \                /    \                                             /    \                  /    \
			 /      \              /      \                                          /       \               /        \
			/        \            /        \                                      /           \           /            \
		Col1         Col2    Col3   Col4                                Col5   Col6      Col7        Col8

When I run the below query, I get incorrect vertices(some vertices are missing) with the latest master code.

g.traversal().V().has("public.Cluster","name","Test Cluster")
.out("has_Service").has("name","Test Service")
.out("has_Database").has("name","Test DB")
.union(
out("has_Schema").has("name",P.eq("Test Schema1")).out("has_Table").has("name",P.without("Table2")),
out("has_Schema").has("name",P.eq("Test Schema1")).out("has_Table").has("name",P.within("Table1")),
out("has_Schema").has("name",P.eq("Test Schema2")).out("has_Table").has("name",P.neq("Table4")))
.out("has_Column")
.range(0, 100).tree();

Expected result: "{Test Cluster={Test Service={Test DB={Test Schema1={Table1={Column1={}, Column2={}}}, Test Schema2={Table3={Column5={}, Column6={}}}}}}}";

Actual result: "{Test Cluster={Test Service={Test DB={Table3={Column5={}, Column6={}}, Table1={Column1={}, Column2={}}}}}}"

This works properly with 2.0.1 version though. I've added a simple test to validate the sqlg query at https://github.com/dkarthikeyan88/sqlg-version-testing/ for versions 2.0.2-SNAPSHOT and 2.0.1.

Please check if this is issue really an issue and let me know if any other information is required. Thank you!!

@pietermartin pietermartin self-assigned this Aug 4, 2019
@JPMoresmau
Copy link
Collaborator

A simpler test

@Test
    public void testUnionHasPath() {
    	Vertex a1 = this.sqlgGraph.addVertex(T.label, "A","name","A1");
        Vertex b1 = this.sqlgGraph.addVertex(T.label, "B","name","B1");
        Vertex b2 = this.sqlgGraph.addVertex(T.label, "B","name","B2");
        Vertex b3 = this.sqlgGraph.addVertex(T.label, "B","name","B3");
        Vertex c1 = this.sqlgGraph.addVertex(T.label, "C","name","C1");
        Vertex c2 = this.sqlgGraph.addVertex(T.label, "C","name","C2");
        Vertex c3 = this.sqlgGraph.addVertex(T.label, "C","name","C3");
        a1.addEdge("toB", b1);
        a1.addEdge("toB", b2);
        a1.addEdge("toB", b3);
        b1.addEdge("toC", c1);
        b2.addEdge("toC", c2);
        b3.addEdge("toC", c3);
        
        GraphTraversal<Vertex, Path> traversal = this.sqlgGraph.traversal().V().has("A","name","A1")
				   .union(
				        out("toB").has("name",P.eq("B1")).out("toC"),
				        out("toB").has("name",P.eq("B2")).out("toC"))
				   .path();
        
        Set<Object> objs=new HashSet<>();
        while (traversal.hasNext()) {
        	Path p=traversal.next();
        	assertEquals(3, p.size());
        	Object root0=p.get(0);
        	assertEquals(a1,root0);
        	Object child0=p.get(1);
        	assertEquals("B",((Vertex)child0).label());
        	Object child1=p.get(2);
        	assertEquals("C",((Vertex)child1).label());
        	objs.add(child0);
        	objs.add(child1);
        	
        	
        }
        assertEquals(4,objs.size());
        assertTrue(objs.contains(b1));
        assertTrue(objs.contains(b2));
        assertTrue(objs.contains(c1));
        assertTrue(objs.contains(c2));
        
    }

Looks like the VertexStep on B don't get labels, so we don't generate output for them...

@pietermartin
Copy link
Owner

Thanks, master branch is finally passing all TinkerPop tests again, so I'll get time to look at this one soon.

@pietermartin
Copy link
Owner

Ok started on this one. Sqlg does not currently optimize the UnionStep. When the UnionStep's traversals are optimized they do not realize that they are in fact part of a path query so no labels are added to them.
I am looking at optimizing the UnionStep now seeing as I am in the vicinity.

@pietermartin
Copy link
Owner

@dkarthikeyan88 I added your test in TestUnion. Your test still actually fails but just because the order of the map is slightly different.
@JPMoresmau your test is also added.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants