Skip to content

Commit

Permalink
Merge pull request #75 from JPMoresmau/master
Browse files Browse the repository at this point in the history
check if given label contain schema, fixes #73
  • Loading branch information
pietermartin authored Sep 28, 2016
2 parents 305661c + b88083a commit a4a83dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1777,15 +1777,22 @@ boolean removeNodesInvalidatedByHas() {
}
}

/**
* remove "has" containers that are not valid anymore
* @param schemaTableTree the current table tree
*/
private void removeObsoleteHasContainers(final SchemaTableTree schemaTableTree) {
Set<HasContainer> toRemove = new HashSet<>();
for (HasContainer hasContainer : schemaTableTree.hasContainers) {
if (hasContainer.getKey().equals(label.getAccessor()) && hasContainer.getBiPredicate().equals(Compare.eq)) {
SchemaTable hasContainerLabelSchemaTable;
// we may have been given a type in a schema
SchemaTable predicateSchemaTable=SchemaTable.from(sqlgGraph, hasContainer.getValue().toString(), this.sqlgGraph.getSqlDialect().getPublicSchema());
//Check if we are on a vertex or edge
if (schemaTableTree.getSchemaTable().getTable().startsWith(SchemaManager.VERTEX_PREFIX)) {
hasContainerLabelSchemaTable = SchemaTable.from(this.sqlgGraph, SchemaManager.VERTEX_PREFIX + hasContainer.getValue().toString(), this.sqlgGraph.getSqlDialect().getPublicSchema());
hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), SchemaManager.VERTEX_PREFIX +predicateSchemaTable.getTable() );
} else {
hasContainerLabelSchemaTable = SchemaTable.from(this.sqlgGraph, SchemaManager.EDGE_PREFIX + hasContainer.getValue().toString(), this.sqlgGraph.getSqlDialect().getPublicSchema());
hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), SchemaManager.EDGE_PREFIX +predicateSchemaTable.getTable() );
}
if (hasContainerLabelSchemaTable.toString().equals(schemaTableTree.getSchemaTable().toString())) {
toRemove.add(hasContainer);
Expand All @@ -1795,16 +1802,23 @@ private void removeObsoleteHasContainers(final SchemaTableTree schemaTableTree)
schemaTableTree.hasContainers.removeAll(toRemove);
}

/**
* verify the "has" containers we have are valid with the schema table tree given
* @param schemaTableTree
* @return true if any has container does NOT match, false if everything is fine
*/
private boolean invalidateByHas(SchemaTableTree schemaTableTree) {
for (HasContainer hasContainer : schemaTableTree.hasContainers) {
if (!hasContainer.getKey().equals(TopologyStrategy.TOPOLOGY_SELECTION_WITHOUT) && !hasContainer.getKey().equals(TopologyStrategy.TOPOLOGY_SELECTION_FROM)) {
if (hasContainer.getKey().equals(label.getAccessor())) {
//Check if we are on a vertex or edge
SchemaTable hasContainerLabelSchemaTable;
// we may have been given a type in a schema
SchemaTable predicateSchemaTable=SchemaTable.from(sqlgGraph, hasContainer.getValue().toString(), this.sqlgGraph.getSqlDialect().getPublicSchema());
//Check if we are on a vertex or edge
if (schemaTableTree.getSchemaTable().getTable().startsWith(SchemaManager.VERTEX_PREFIX)) {
hasContainerLabelSchemaTable = SchemaTable.from(this.sqlgGraph, SchemaManager.VERTEX_PREFIX + hasContainer.getValue().toString(), this.sqlgGraph.getSqlDialect().getPublicSchema());
hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), SchemaManager.VERTEX_PREFIX +predicateSchemaTable.getTable() );
} else {
hasContainerLabelSchemaTable = SchemaTable.from(this.sqlgGraph, SchemaManager.EDGE_PREFIX + hasContainer.getValue().toString(), this.sqlgGraph.getSqlDialect().getPublicSchema());
hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), SchemaManager.EDGE_PREFIX +predicateSchemaTable.getTable() );
}
if (hasContainer.getBiPredicate().equals(Compare.eq) && !hasContainerLabelSchemaTable.toString().equals(schemaTableTree.getSchemaTable().toString())) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ public void testVertexHasLabel() {
Assert.assertEquals(1,vertexTraversal(marko).out("drives").has(T.label, "Car").has("name", "bmw").count().next(), 0);
Assert.assertEquals(0, vertexTraversal(marko).out("drives").has(T.label, "Person").has("name", "vw").count().next(), 0);
}

/**
* we reference labels that have schemas
*/
@Test
public void testVertexHasLabelInSchema() {
Vertex marko = this.sqlgGraph.addVertex(T.label, "TestSchema.Person", "name", "marko");
Vertex bmw = this.sqlgGraph.addVertex(T.label, "TestSchema.Car", "name", "bmw");
Vertex vw = this.sqlgGraph.addVertex(T.label, "TestSchema.Car", "name", "vw");
marko.addEdge("drives", bmw);
marko.addEdge("drives", vw);
this.sqlgGraph.tx().commit();
Assert.assertEquals(1,vertexTraversal(marko).out("drives").has(T.label, "TestSchema.Car").has("name", "bmw").count().next(), 0);
Assert.assertEquals(0, vertexTraversal(marko).out("drives").has(T.label, "TestSchema.Person").has("name", "vw").count().next(), 0);
}

@Test
public void testHasWithPercentageInIt() {
Expand Down

0 comments on commit a4a83dd

Please sign in to comment.