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

Add union+identity test && Identity e2e Test #1

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public abstract class IrGremlinQueryTest extends AbstractGremlinProcessTest {

public abstract Traversal<Vertex, Map<Object, Object>> get_g_V_group_by_by_mean();

public abstract Traversal<Vertex, Object> get_g_V_identity_values();

public abstract Traversal<Vertex, Object> get_g_V_haslabel_as_identity_values();

public abstract Traversal<Vertex, Object> get_g_V_has_union_identity_out_values();

@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@Test
public void g_V_group_by_by_dedup_count_test() {
Expand Down Expand Up @@ -311,6 +317,61 @@ public void g_V_group_by_by_mean() {
Assert.assertEquals(4, result.size());
}

@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@Test
public void g_V_haslabel_identity() {
Traversal<Vertex, Object> traversal =
this.get_g_V_identity_values();
this.printTraversalForm(traversal);
int counter = 0;

List<String> expected = Arrays.asList("1", "2", "3", "4", "5", "6");

while (traversal.hasNext()) {
Object result = traversal.next();
Assert.assertTrue(expected.contains(result.toString()));
++counter;
System.out.println(result.toString());
}
}

@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@Test
public void g_V_haslabel_as_identity_values() {
Traversal<Vertex, Object> traversal =
this.get_g_V_haslabel_as_identity_values();
this.printTraversalForm(traversal);
int counter = 0;

List<String> expected = Arrays.asList("1", "2", "4", "6");

while (traversal.hasNext()) {
Object result = traversal.next();
Assert.assertTrue(expected.contains(result.toString()));
++counter;
System.out.println(result.toString());
}
}

@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@Test
public void g_V_haslabel_union_identity_out_values() {
Traversal<Vertex, Object> traversal =
this.get_g_V_has_union_identity_out_values();
this.printTraversalForm(traversal);
int counter = 0;

List<String> expected = Arrays.asList("1", "2", "3", "4");

while (traversal.hasNext()) {
Object result = traversal.next();
Assert.assertTrue(expected.contains(result.toString()));
++counter;
System.out.println(result.toString());
}

}

public static class Traversals extends IrGremlinQueryTest {

@Override
Expand Down Expand Up @@ -423,5 +484,20 @@ public Traversal<Vertex, Map<Object, Object>> get_g_V_group_by_by_min() {
public Traversal<Vertex, Map<Object, Object>> get_g_V_group_by_by_mean() {
return g.V().group().by().by(values("age").mean());
}

@Override
public Traversal<Vertex, Object> get_g_V_identity_values() {
return g.V().identity().values("id");
}

@Override
public Traversal<Vertex, Object> get_g_V_haslabel_as_identity_values() {
return g.V().hasLabel("person").as("a").identity().values("id");
}

@Override
public Traversal<Vertex, Object> get_g_V_has_union_identity_out_values() {
return g.V().has("name", "marko").union(identity(), out()).values("id");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public static GraphTraversal<?, Vertex> out(final String... edgeLabels) {
((IrCustomizedTraversal) start()).out(rangeTraversal, labels);
}

public static GraphTraversal<?, Vertex> bothV() {
return start().bothV();
}

public static GraphTraversal<?, Vertex> in(final String... edgeLabels) {
return start().in(edgeLabels);
}
Expand Down Expand Up @@ -118,4 +122,8 @@ public static <A, B> GraphTraversal<?, B> select(final String selectKey) {
public static <A> GraphTraversal<?, ?> has(final String propertyKey, final Object value) {
return start().has(propertyKey, value);
}

public static <A> GraphTraversal<?, ?> identity() {
return start().identity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.*;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.*;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SubgraphStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep;

import java.util.List;

Expand All @@ -40,7 +41,8 @@ public static GremlinResultParser analyze(Traversal traversal) {
|| Utils.equalClass(step, ExpandFusionStep.class)
|| Utils.equalClass(step, EdgeVertexStep.class)
|| Utils.equalClass(step, EdgeOtherVertexStep.class)
|| Utils.equalClass(step, PathExpandStep.class)) {
|| Utils.equalClass(step, PathExpandStep.class)
|| Utils.equalClass(step, IdentityStep.class)) {
parserType = GremlinResultParserFactory.GRAPH_ELEMENT;
} else if (Utils.equalClass(step, CountGlobalStep.class)
|| Utils.equalClass(step, SumGlobalStep.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,32 @@
package com.alibaba.graphscope.gremlin;



import com.alibaba.graphscope.common.IrPlan;
import com.alibaba.graphscope.common.ir.Utils;
import com.alibaba.graphscope.gremlin.transform.StepTransformFactory;
import com.alibaba.graphscope.common.intermediate.operator.AsNoneOp;
import com.alibaba.graphscope.common.intermediate.operator.UnionOp;
import com.alibaba.graphscope.gremlin.integration.suite.utils.__;
import com.alibaba.graphscope.gremlin.plugin.strategy.RemoveUselessStepStrategy;
import com.alibaba.graphscope.common.intermediate.InterOpCollection;

import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
import org.junit.Assert;
import org.junit.Test;
import java.util.Set;
import java.util.List;
import java.util.ArrayList;



public class IdentityStepTest {
Expand All @@ -48,4 +64,51 @@ public void g_E() {
AsNoneOp op = (AsNoneOp) StepTransformFactory.IDENTITY_STEP.apply(identityStep);
Assert.assertEquals(false, op.getAlias().isPresent());
}

@Test
public void g_V_union_identity_outE_test() {
// g.E().union(identity(), bothV())
Traversal getEdge = g.E();
Traversal identityTraversal = __.identity();
Traversal bothVTraversal = __.bothV();
// Traversal test = g.V().union(identity(), out());

//System.out.println(identityTraversal.asAdmin());
//System.out.println(bothVTraversal.asAdmin());

UnionStep unionStep = new UnionStep(getEdge.asAdmin(), identityTraversal.asAdmin(), bothVTraversal.asAdmin());

Traversal.Admin identityAdmin = (Traversal.Admin) unionStep.getGlobalChildren().get(0);
Traversal.Admin bothVAdmin = (Traversal.Admin) unionStep.getGlobalChildren().get(1);
identityAdmin.removeStep(1);
bothVAdmin.removeStep(1);

UnionOp op = (UnionOp) StepTransformFactory.UNION_STEP.apply(unionStep);
List<InterOpCollection> collection = (List<InterOpCollection>) op.getSubOpCollectionList().get().applyArg();
InterOpCollection identityCollection = (new InterOpCollectionBuilder(identityTraversal)).build();
InterOpCollection bothVCollection = (new InterOpCollectionBuilder(bothVTraversal)).build();

IrPlan identityUnionPlan = new IrPlan(Utils.schemaMeta, collection.get(0));
String identityUnionJson = identityUnionPlan.getPlanAsJson();

IrPlan identityPlan = new IrPlan(Utils.schemaMeta, identityCollection);
String identityJson = identityPlan.getPlanAsJson();

IrPlan bothVUnionPlan = new IrPlan(Utils.schemaMeta, collection.get(1));
String bothVUnionJson = bothVUnionPlan.getPlanAsJson();

IrPlan bothVPlan = new IrPlan(Utils.schemaMeta, bothVCollection);
String bothVJson = bothVPlan.getPlanAsJson();

Assert.assertEquals(identityUnionJson, identityJson);
Assert.assertEquals(bothVUnionJson, bothVJson);
}

@Test
public void g_V_as_identity_test() {
Traversal traversal = g.V().as("a").identity();
Step identityStep = traversal.asAdmin().getEndStep();
AsNoneOp op = (AsNoneOp) StepTransformFactory.IDENTITY_STEP.apply(identityStep);
Assert.assertEquals(false, op.getAlias().isPresent());
}
}
Loading