Search in sources :

Example 1 with EdgeLabel

use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.

the class SchemaTableTree method hasOnlyOneInOutEdgeLabel.

private boolean hasOnlyOneInOutEdgeLabel(SchemaTable schemaTable) {
    Optional<Schema> schemaOptional = sqlgGraph.getTopology().getSchema(schemaTable.getSchema());
    Preconditions.checkState(schemaOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.getSchema());
    Schema schema = schemaOptional.get();
    boolean result = true;
    if (schemaTable.isVertexTable()) {
        // Need to delete any in/out edges.
        Optional<VertexLabel> vertexLabelOptional = schema.getVertexLabel(schemaTable.withOutPrefix().getTable());
        Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.withOutPrefix().getTable());
        VertexLabel vertexLabel = vertexLabelOptional.get();
        Collection<EdgeLabel> outEdgeLabels = vertexLabel.getOutEdgeLabels().values();
        for (EdgeLabel edgeLabel : outEdgeLabels) {
            result = edgeLabel.getOutVertexLabels().size() == 1;
            if (!result) {
                break;
            }
        }
        if (result) {
            Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values();
            for (EdgeLabel edgeLabel : inEdgeLabels) {
                result = edgeLabel.getInVertexLabels().size() == 1;
                if (!result) {
                    break;
                }
            }
        }
    }
    return result;
}
Also used : VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) Schema(org.umlg.sqlg.structure.topology.Schema) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel)

Example 2 with EdgeLabel

use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.

the class TestTopologyDeleteSpecific method testRemoveAndAddInSameTransaction.

/**
 * @see <a href="https://github.com/pietermartin/sqlg/issues/212">https://github.com/pietermartin/sqlg/issues/212</a>
 */
@Test
public void testRemoveAndAddInSameTransaction() {
    // remove it, it does not exist but duplicating work logic.
    Optional<EdgeLabel> aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
    if (aaEdgeLabelOpt.isPresent()) {
        aaEdgeLabelOpt.get().remove(false);
    }
    Optional<VertexLabel> aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    if (aVertexLabelOpt.isPresent()) {
        aVertexLabelOpt.get().remove(false);
    }
    VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
    aVertexLabel.ensureEdgeLabelExist("aa", aVertexLabel);
    this.sqlgGraph.tx().commit();
    aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
    if (aaEdgeLabelOpt.isPresent()) {
        aaEdgeLabelOpt.get().remove(false);
    }
    aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    if (aVertexLabelOpt.isPresent()) {
        aVertexLabelOpt.get().remove(false);
    }
    aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
    aVertexLabel.ensureEdgeLabelExist("aa", aVertexLabel);
    this.sqlgGraph.tx().commit();
    aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
    assertTrue(aaEdgeLabelOpt.isPresent());
    aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    assertTrue(aVertexLabelOpt.isPresent());
}
Also used : VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 3 with EdgeLabel

use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.

the class TestSchemaEagerCreation method testEdgeLabelsProperties.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testEdgeLabelsProperties() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    a.addEdge("ab", b);
    this.sqlgGraph.tx().commit();
    Optional<VertexLabel> vertexLabelAOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A");
    assertTrue(vertexLabelAOptional.isPresent());
    Optional<VertexLabel> vertexLabelBOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("B");
    assertTrue(vertexLabelBOptional.isPresent());
    Optional<EdgeLabel> edgeLabelOptional = vertexLabelAOptional.get().getOutEdgeLabel("ab");
    assertTrue(edgeLabelOptional.isPresent());
    Map<String, PropertyType> properties = new HashMap<>();
    properties.put("name", PropertyType.STRING);
    properties.put("age", PropertyType.INTEGER);
    EdgeLabel edgeLabel = edgeLabelOptional.get();
    edgeLabel.ensurePropertiesExist(properties);
    this.sqlgGraph.tx().rollback();
    edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
    assertTrue(edgeLabel.getProperties().isEmpty());
    edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
    edgeLabel.ensurePropertiesExist(properties);
    this.sqlgGraph.tx().commit();
    edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
    assertEquals(2, edgeLabel.getProperties().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 4 with EdgeLabel

use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.

the class TestSchemaEagerCreation method testEdgeLabelAddVertexLabels.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testEdgeLabelAddVertexLabels() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    a.addEdge("ab", b);
    this.sqlgGraph.tx().commit();
    Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getPublicSchema().getEdgeLabel("ab");
    assertTrue(edgeLabelOptional.isPresent());
    EdgeLabel edgeLabel = edgeLabelOptional.get();
    VertexLabel inVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.IN, inVertexLabel);
    this.sqlgGraph.tx().rollback();
    edgeLabelOptional = this.sqlgGraph.getTopology().getPublicSchema().getEdgeLabel("ab");
    assertTrue(edgeLabelOptional.isPresent());
    edgeLabel = edgeLabelOptional.get();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(1, edgeLabel.getInVertexLabels().size());
    inVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.IN, inVertexLabel);
    this.sqlgGraph.tx().commit();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    VertexLabel outVertexLabel = this.sqlgGraph.getTopology().ensureSchemaExist("D").ensureVertexLabelExist("D");
    try {
        edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
        fail("Should fail as the out vertex is in a different schema to the edgeLabel");
    } catch (IllegalStateException e) {
    // swallow
    }
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    this.sqlgGraph.tx().rollback();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    outVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("D");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
    assertEquals(2, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    this.sqlgGraph.tx().rollback();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    outVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("D");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
    assertEquals(2, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    this.sqlgGraph.tx().commit();
    assertEquals(2, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 5 with EdgeLabel

use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.

the class TestSchemaEagerCreation method testAddEdgeLabelViaOutVertexLabel.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testAddEdgeLabelViaOutVertexLabel() {
    VertexLabel a = this.sqlgGraph.getTopology().ensureSchemaExist("A").ensureVertexLabelExist("A");
    Optional<Schema> schemaOptional = this.sqlgGraph.getTopology().getSchema("A");
    assertTrue(schemaOptional.isPresent());
    VertexLabel b = schemaOptional.get().ensureVertexLabelExist("B");
    a.ensureEdgeLabelExist("ab", b);
    this.sqlgGraph.tx().commit();
    Optional<EdgeLabel> edgeLabel = this.sqlgGraph.getTopology().getSchema("A").get().getEdgeLabel("ab");
    assertTrue(edgeLabel.isPresent());
    assertEquals("ab", edgeLabel.get().getLabel());
}
Also used : VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) Schema(org.umlg.sqlg.structure.topology.Schema) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

EdgeLabel (org.umlg.sqlg.structure.topology.EdgeLabel)10 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)10 Test (org.junit.Test)5 BaseTest (org.umlg.sqlg.test.BaseTest)5 Schema (org.umlg.sqlg.structure.topology.Schema)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 SqlgSqlExecutor (org.umlg.sqlg.strategy.SqlgSqlExecutor)2 PropertyColumn (org.umlg.sqlg.structure.topology.PropertyColumn)2 Preconditions (com.google.common.base.Preconditions)1 java.util (java.util)1 HashMap (java.util.HashMap)1 MultiValuedMap (org.apache.commons.collections4.MultiValuedMap)1 HashSetValuedHashMap (org.apache.commons.collections4.multimap.HashSetValuedHashMap)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Triple (org.apache.commons.lang3.tuple.Triple)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 Traverser (org.apache.tinkerpop.gremlin.process.traversal.Traverser)1 Mutating (org.apache.tinkerpop.gremlin.process.traversal.step.Mutating)1 CallbackRegistry (org.apache.tinkerpop.gremlin.process.traversal.step.util.event.CallbackRegistry)1 Event (org.apache.tinkerpop.gremlin.process.traversal.step.util.event.Event)1