Search in sources :

Example 11 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradeEdgeWithMultipleInOutLabelsAndAIndex.

@Test
public void testUpgradeEdgeWithMultipleInOutLabelsAndAIndex() throws Exception {
    VertexLabel aVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("A");
    VertexLabel bVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("B");
    VertexLabel cVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
    Map<String, PropertyType> properties = new HashMap<String, PropertyType>() {

        {
            put("name", PropertyType.STRING);
        }
    };
    @SuppressWarnings("UnusedAssignment") EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureEdgeLabelExist("edge", bVertexLabel, aVertexLabel, properties);
    edgeLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureEdgeLabelExist("edge", cVertexLabel, aVertexLabel, properties);
    edgeLabel.ensureIndexExists(IndexType.UNIQUE, new ArrayList<>(edgeLabel.getProperties().values()));
    this.sqlgGraph.tx().commit();
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
    b1.addEdge("edge", a1, "name", "b");
    c1.addEdge("edge", a1, "name", "c");
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(3, sqlgGraph1.traversal().V().count().next().intValue());
        Assert.assertEquals(2, sqlgGraph1.traversal().E().count().next().intValue());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) PropertyType(org.umlg.sqlg.structure.PropertyType) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 12 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class TestTraversalPerformance method testSpeedWithLargeSchemaFastQuery1.

@Test
public void testSpeedWithLargeSchemaFastQuery1() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Map<String, PropertyType> columns = new HashMap<>();
    for (int i = 0; i < 100; i++) {
        columns.put("property_" + i, PropertyType.STRING);
    }
    // Create a large schema, it slows the maps  down
    int NUMBER_OF_SCHEMA_ELEMENTS = 1_000;
    for (int i = 0; i < NUMBER_OF_SCHEMA_ELEMENTS; i++) {
        VertexLabel person = this.sqlgGraph.getTopology().ensureVertexLabelExist("Person_" + i, columns);
        VertexLabel dog = this.sqlgGraph.getTopology().ensureVertexLabelExist("Dog_" + i, columns);
        person.ensureEdgeLabelExist("pet_" + i, dog, columns);
        if (i % 100 == 0) {
            this.sqlgGraph.tx().commit();
        }
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("done creating schema time taken " + stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    Map<String, Object> columnValues = new HashMap<>();
    for (int i = 0; i < 100; i++) {
        columnValues.put("property_" + i, "asdasdasd");
    }
    for (int i = 0; i < NUMBER_OF_SCHEMA_ELEMENTS; i++) {
        SqlgVertex person = (SqlgVertex) this.sqlgGraph.addVertex("Person_" + i, columnValues);
        SqlgVertex dog = (SqlgVertex) this.sqlgGraph.addVertex("Dog_" + i, columnValues);
        person.addEdgeWithMap("pet_" + i, dog, columnValues);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("done inserting data time taken " + stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    for (int i = 0; i < 10_000; i++) {
        Assert.assertEquals(1, this.sqlgGraph.traversal().V().hasLabel("Person_0").out("pet_0").toList().size());
    }
    stopWatch.stop();
    System.out.println("total query time " + stopWatch.toString());
}
Also used : HashMap(java.util.HashMap) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) PropertyType(org.umlg.sqlg.structure.PropertyType) StopWatch(org.apache.commons.lang3.time.StopWatch) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 13 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class SchemaTableTree method getColumnNamePropertyName.

private Map<String, Pair<String, PropertyType>> getColumnNamePropertyName() {
    if (this.columnNamePropertyName == null) {
        this.columnNamePropertyName = new HashMap<>();
        for (Map.Entry<String, String> entry : getRoot().aliasMapHolder.getAliasColumnNameMap().entrySet()) {
            String alias = entry.getKey();
            String columnName = entry.getValue();
            // only load the labelled columns
            if (!columnName.endsWith(SchemaTableTree.ALIAS_SEPARATOR + Topology.ID) && (columnName.contains(BaseStrategy.PATH_LABEL_SUFFIX) || columnName.contains(BaseStrategy.EMIT_LABEL_SUFFIX))) {
                if (containsLabelledColumn(columnName)) {
                    String propertyName = propertyNameFromLabeledAlias(columnName);
                    PropertyType propertyType = this.sqlgGraph.getTopology().getTableFor(getSchemaTable()).get(propertyName);
                    this.columnNamePropertyName.put(alias, Pair.of(propertyName, propertyType));
                }
            }
        }
    }
    return this.columnNamePropertyName;
}
Also used : PropertyType(org.umlg.sqlg.structure.PropertyType)

Example 14 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class TestNotifyJson method testNotifyJson.

@Test
public void testNotifyJson() {
    Map<String, PropertyType> properties = new HashMap<>();
    properties.put("name", PropertyType.STRING);
    this.sqlgGraph.getTopology().ensureSchemaExist("A").ensureVertexLabelExist("A", properties);
    this.sqlgGraph.tx().commit();
    List<Vertex> logs = this.sqlgGraph.topology().V().hasLabel(Topology.SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_LOG).toList();
    assertEquals(1, logs.size());
    Vertex log = logs.get(0);
    JsonNode jsonLog = log.value(Topology.SQLG_SCHEMA_LOG_LOG);
    JsonNode schemas = jsonLog.get("uncommittedSchemas");
    assertNotNull("A", schemas);
    assertTrue(schemas instanceof ArrayNode);
    ArrayNode schemasArray = (ArrayNode) schemas;
    assertEquals(1, schemasArray.size());
    JsonNode aSchema = schemasArray.get(0);
    assertEquals("A", aSchema.get("name").asText());
    JsonNode uncommittedVertexLabels = aSchema.get("uncommittedVertexLabels");
    assertNotNull(uncommittedVertexLabels);
    assertTrue(uncommittedVertexLabels instanceof ArrayNode);
    ArrayNode uncommittedVertexLabelsArray = (ArrayNode) uncommittedVertexLabels;
    assertEquals(1, uncommittedVertexLabelsArray.size());
    JsonNode vertexLabel = uncommittedVertexLabels.get(0);
    assertEquals("A", vertexLabel.get("label").asText());
    JsonNode propertiesJson = vertexLabel.get("uncommittedProperties");
    assertNotNull(propertiesJson);
    assertTrue(propertiesJson instanceof ArrayNode);
    ArrayNode propertiesArray = (ArrayNode) propertiesJson;
    assertEquals(1, propertiesArray.size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) PropertyType(org.umlg.sqlg.structure.PropertyType) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 15 with PropertyType

use of org.umlg.sqlg.structure.PropertyType in project sqlg by pietermartin.

the class TestTopologyUpgrade method testCustomIndexIgnored.

// The asdasd index is for a property that foes not exist, it will be ignored when loading the topology.
@Test
public void testCustomIndexIgnored() throws Exception {
    // TODO one day for HSQLDB and the rest
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().isPostgresql());
    Map<String, PropertyType> properties = new HashMap<String, PropertyType>() {

        {
            put("name", PropertyType.STRING);
        }
    };
    Schema hour = this.sqlgGraph.getTopology().ensureSchemaExist("A");
    VertexLabel vertexLabel = hour.ensureVertexLabelExist("A", properties);
    PropertyColumn propertyColumn = vertexLabel.getProperty("name").get();
    vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, Collections.singletonList(propertyColumn));
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "aaaa");
    Connection conn = this.sqlgGraph.tx().getConnection();
    try (Statement statement = conn.createStatement()) {
        statement.execute("CREATE INDEX \"asdasd\" ON \"A\".\"V_A\" USING btree (left('name', 1)) ");
    }
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(1, sqlgGraph1.traversal().V().count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.getTopology().getSchema("A").get().getVertexLabel("A").get().getIndexes().size());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Statement(java.sql.Statement) Connection(java.sql.Connection) PropertyType(org.umlg.sqlg.structure.PropertyType) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

PropertyType (org.umlg.sqlg.structure.PropertyType)28 GeographyPoint (org.umlg.sqlg.gis.GeographyPoint)9 MultiMap (org.apache.tinkerpop.gremlin.util.tools.MultiMap)7 BaseTest (org.umlg.sqlg.test.BaseTest)7 Test (org.junit.Test)6 PGConnection (org.postgresql.PGConnection)5 SqlgGraph (org.umlg.sqlg.structure.SqlgGraph)4 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)4 SecureRandom (java.security.SecureRandom)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Array (java.lang.reflect.Array)2 java.sql (java.sql)2 HashMap (java.util.HashMap)2 Triple (org.apache.commons.lang3.tuple.Triple)2 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 JdbcArray (org.h2.jdbc.JdbcArray)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Preconditions (com.google.common.base.Preconditions)1