Skip to content

Commit

Permalink
Replace P.without(Collections.emptySet()) with Existence.NOTNULL
Browse files Browse the repository at this point in the history
Fix #321
  • Loading branch information
pieter committed Dec 9, 2018
1 parent ed51f62 commit 8e17cbf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ boolean removeNodesInvalidatedByHas() {
queue.add(this);
while (!queue.isEmpty()) {
SchemaTableTree current = queue.remove();
removeObsoleteHasContainers(current);
removeOrTransformHasContainers(current);
if (invalidateByHas(current)) {
removeNode(current);
} else {
Expand All @@ -2299,11 +2299,13 @@ boolean removeNodesInvalidatedByHas() {

/**
* remove "has" containers that are not valid anymore
* transform "has" containers that are equivalent to simpler statements.
*
* @param schemaTableTree the current table tree
*/
private void removeObsoleteHasContainers(final SchemaTableTree schemaTableTree) {
private void removeOrTransformHasContainers(final SchemaTableTree schemaTableTree) {
Set<HasContainer> toRemove = new HashSet<>();
Set<HasContainer> toAdd = new HashSet<>();
for (HasContainer hasContainer : schemaTableTree.hasContainers) {
if (hasContainer.getKey().equals(label.getAccessor())) {
toRemove.add(hasContainer);
Expand All @@ -2315,14 +2317,17 @@ private void removeObsoleteHasContainers(final SchemaTableTree schemaTableTree)
toRemove.add(hasContainer);
}
}
if (Contains.without.equals(hasContainer.getBiPredicate())){
Object o=hasContainer.getValue();
if (o instanceof Collection && ((Collection<?>)o).size()==0) {
toRemove.add(hasContainer);
}
if (Contains.without.equals(hasContainer.getBiPredicate())) {
Object o = hasContainer.getValue();
if (o instanceof Collection && ((Collection<?>) o).size() == 0) {
//P.without(Collections.emptySet()) translates to the sql IS NOT NULL
toRemove.add(hasContainer);
toAdd.add(new HasContainer(hasContainer.getKey(), new P<>(Existence.NOTNULL, null)));
}
}
}
schemaTableTree.hasContainers.removeAll(toRemove);
schemaTableTree.hasContainers.addAll(toAdd);
}

private SchemaTable getHasContainerSchemaTable(SchemaTableTree schemaTableTree, SchemaTable predicateSchemaTable) {
Expand Down
4 changes: 2 additions & 2 deletions sqlg-test/src/main/java/org/umlg/sqlg/AnyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.umlg.sqlg.test.gremlincompile.TestGremlinCompileChoose;
import org.umlg.sqlg.test.gremlincompile.TestGremlinCompileWithInOutV;

/**
* Date: 2014/07/16
* Time: 12:10 PM
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestGremlinCompileChoose.class
TestGremlinCompileWithInOutV.class
})
public class AnyTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
import org.umlg.sqlg.structure.SqlgGraph;
import org.umlg.sqlg.test.BaseTest;

import java.util.Collections;
import java.util.List;

/**
Expand All @@ -18,6 +20,33 @@
*/
public class TestGremlinCompileWithInOutV extends BaseTest {

/**
* P.without(Collections.emptySet()) translates to the sql where clause IS NOT NULL
*/
@Test
public void testWithoutEmptyCollection() {
Graph g = this.sqlgGraph;
Vertex v1 = g.addVertex(T.label, "A", "name", "a1");
Vertex v2 = g.addVertex(T.label, "A", "name", "a2", "prop", "p2");
Vertex v3 = g.addVertex(T.label, "A", "name", "a3", "prop", "p3");
Vertex v4 = g.addVertex(T.label, "A", "name", "a4", "prop", "");
Vertex v5 = g.addVertex(T.label, "A", "name", "a5");

v1.addEdge("e", v2);
v1.addEdge("e", v3);
v1.addEdge("e", v4);
v1.addEdge("e", v5);

g.tx().commit();

List<Vertex> result = g.traversal().V(v1).out("e").has("prop", P.without(Collections.emptySet())).toList();
Assert.assertEquals(3, result.size());
Assert.assertTrue(result.contains(v2));
Assert.assertTrue(result.contains(v3));
Assert.assertTrue(result.contains(v4));

}

@Test
public void testHasWithInMultipleHasContainers() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "1");
Expand Down

0 comments on commit 8e17cbf

Please sign in to comment.