/** * Generate a string id of HugeVertex from Vertex name */ @Override public Id generate(HugeVertex vertex) { /* * Hash for row-key which will be evenly distributed. * We can also use LongEncoding.encode() to encode the int/long hash * if needed. * id = String.format("%s%s%s", HashUtil.hash(id), ID_SPLITOR, id); */ // TODO: use binary Id with binary fields instead of string id return splicing(vertex.schemaLabel().id().asString(), vertex.name()); }
@Test public void testQueryByLabel() { HugeGraph graph = graph(); init10Vertices(); // Query by vertex label List<Vertex> vertexes = graph.traversal().V().hasLabel("book") .toList(); String bookId = graph.vertexLabel("book").id().asString(); Assert.assertEquals(5, vertexes.size()); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-1"))); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-2"))); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-3"))); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-4"))); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-5"))); }
@Test public void testSplicingId() { HugeGraph graph = graph(); init10Vertices(); List<Vertex> vertexes = graph.traversal().V().toList(); String bookId = graph.vertexLabel("book").id().asString(); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-1"))); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-3"))); Assert.assertTrue(Utils.containsId(vertexes, SplicingIdGenerator.splicing(bookId, "java-5"))); }
public static Id formatIndexId(HugeType type, Id indexLabel, Object fieldValues) { if (type.isStringIndex()) { String value = fieldValues == null ? "" : fieldValues.toString(); /* * Modify order between index label and field-values to put the * index label in front(hugegraph-1317) */ return SplicingIdGenerator.splicing(indexLabel.asString(), value); } else { assert type.isRangeIndex(); BytesBuffer buffer = BytesBuffer.allocate(16); buffer.writeInt((int) indexLabel.asLong()); if (fieldValues != null) { E.checkState(fieldValues instanceof Number, "Field value of range index must be number: %s", fieldValues.getClass().getSimpleName()); byte[] value = number2bytes((Number) fieldValues); buffer.write(value); } return buffer.asId(); } }
@Test public void testQueryByIdNotFound() { HugeGraph graph = graph(); init10Vertices(); // Query vertex by id which not exists Id id = SplicingIdGenerator.splicing("author", "not-exists-id"); Assert.assertTrue(graph.traversal().V(id).toList().isEmpty()); Assert.assertThrows(NoSuchElementException.class, () -> { graph.traversal().V(id).next(); }); }
@Test public void testQueryById() { HugeGraph graph = graph(); init10Vertices(); String authorId = graph.vertexLabel("author").id().asString(); // Query vertex by id Id id = SplicingIdGenerator.splicing(authorId, "1"); List<Vertex> vertexes = graph.traversal().V(id).toList(); Assert.assertEquals(1, vertexes.size()); assertContains(vertexes, T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); }
@Test public void testQueryWithTxNotCommittedById() { HugeGraph graph = graph(); graph.addVertex(T.label, "person", "name", "marko", "age", 18, "city", "Beijing"); List<Vertex> vertices; String personId = graph.vertexLabel("person").id().asString(); String vid = SplicingIdGenerator.splicing(personId, "marko").asString(); vertices = graph.traversal().V(vid).toList(); Assert.assertEquals(1, vertices.size()); Assert.assertEquals(vid, vertices.get(0).id().toString()); graph.tx().rollback(); vertices = graph.traversal().V(personId + ":marko").toList(); Assert.assertEquals(0, vertices.size()); }
Id id = SplicingIdGenerator.splicing(indexLabelId, fieldValue); IdQuery q = new IdQuery(query, id); q.offset(query.offset());
LOG.debug("Query vertices by primaryKeys: {}", query); Id id = SplicingIdGenerator.splicing(label.asString(), primaryValues);
/** * Generate a string id of HugeVertex from Vertex name */ @Override public Id generate(HugeVertex vertex) { /* * Hash for row-key which will be evenly distributed. * We can also use LongEncoding.encode() to encode the int/long hash * if needed. * id = String.format("%s%s%s", HashUtil.hash(id), ID_SPLITOR, id); */ // TODO: use binary Id with binary fields instead of string id return splicing(vertex.schemaLabel().id().asString(), vertex.name()); }
public static Id formatIndexId(HugeType type, Id indexLabel, Object fieldValues) { if (type.isStringIndex()) { String value = fieldValues == null ? "" : fieldValues.toString(); /* * Modify order between index label and field-values to put the * index label in front(hugegraph-1317) */ return SplicingIdGenerator.splicing(indexLabel.asString(), value); } else { assert type.isRangeIndex(); BytesBuffer buffer = BytesBuffer.allocate(16); buffer.writeInt((int) indexLabel.asLong()); if (fieldValues != null) { E.checkState(fieldValues instanceof Number, "Field value of range index must be number: %s", fieldValues.getClass().getSimpleName()); byte[] value = number2bytes((Number) fieldValues); buffer.write(value); } return buffer.asId(); } }
Id id = SplicingIdGenerator.splicing(indexLabelId, fieldValue); IdQuery q = new IdQuery(query, id); q.offset(query.offset());
LOG.debug("Query vertices by primaryKeys: {}", query); Id id = SplicingIdGenerator.splicing( vertexLabel.id().asString(), primaryValues);