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());
}
}
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());
}
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;
}
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());
}
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());
}
}
Aggregations