public static String concat(String... ids) { return SplicingIdGenerator.concat(ids); }
/** * 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 SplicingIdGenerator instance() { if (instance == null) { synchronized (SplicingIdGenerator.class) { if (instance == null) { instance = new SplicingIdGenerator(); } } } return instance; }
@Override public String name() { E.checkState(this.label.idStrategy() == IdStrategy.PRIMARY_KEY, "Only primary key vertex has name, " + "but got '%s' with id strategy '%s'", this, this.label.idStrategy()); if (this.name == null) { if (this.id != null) { String[] parts = SplicingIdGenerator.parse(this.id); E.checkState(parts.length == 2, "Invalid primary key vertex id '%s'", this.id); this.name = parts[1]; } else { assert this.id == null; List<Object> propValues = this.primaryValues(); E.checkState(!propValues.isEmpty(), "Primary values must not be empty " + "(has properties %s)", hasProperties()); this.name = SplicingIdGenerator.concatValues(propValues); } } return this.name; }
@Override public String name() { if (this.name == null) { this.name = SplicingIdGenerator.concatValues(sortValues()); } return this.name; }
String[] parts = SplicingIdGenerator.parse(idObject); E.checkState(parts.length == 2, "Invalid secondary index id"); Id label = SchemaElement.schemaId(parts[0]);
@Override public String name() { assert this.label.idStrategy() == IdStrategy.PRIMARY_KEY; if (this.name == null) { if (this.id != null) { String[] parts = SplicingIdGenerator.parse(this.id); E.checkState(parts.length == 2, "Invalid vertex id '%s'", this.id); this.name = parts[1]; } else { assert this.id == null; List<Object> propValues = this.primaryValues(); E.checkState(!propValues.isEmpty(), "Primary values must not be empty " + "(has properties %s)", hasProperties()); this.name = SplicingIdGenerator.concatValues(propValues); } } return this.name; }
/** * This method is only used for secondary index scenario, * its relation must be EQ * @param fields the user property fields * @return the corresponding user property serial values of fields */ public String userpropValuesString(List<Id> fields) { List<Object> values = new ArrayList<>(fields.size()); for (Id field : fields) { boolean got = false; for (Relation r : this.userpropRelations()) { if (r.key().equals(field) && !r.isSysprop()) { E.checkState(r.relation == RelationType.EQ, "Method userpropValues(List<String>) only " + "used for secondary index, " + "relation must be EQ, but got %s", r.relation()); values.add(r.serialValue()); got = true; } } if (!got) { throw new BackendException( "No such userprop named '%s' in the query '%s'", field, this); } } return SplicingIdGenerator.concatValues(values); }
String[] parts = SplicingIdGenerator.parse(idObject); E.checkState(parts.length == 2, "Invalid secondary index id"); Id label = SchemaElement.schemaId(parts[0]);
private String formatSyspropName(String name) { return SplicingIdGenerator.concat(writeType(HugeType.SYS_PROPERTY), 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"))); }
value = SplicingIdGenerator.concatValues(prefixValues);
public static SplicingIdGenerator instance() { if (instance == null) { synchronized (SplicingIdGenerator.class) { if (instance == null) { instance = new SplicingIdGenerator(); } } } return instance; }
private String formatPropertyName(String key) { return SplicingIdGenerator.concat(writeType(HugeType.PROPERTY), key); }
@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"))); }
@Override public String name() { if (this.name == null) { this.name = SplicingIdGenerator.concatValues(sortValues()); } return this.name; }
@Override protected final String entryId(MysqlBackendEntry entry) { Double fieldValue = entry.<Double>column(HugeKeys.FIELD_VALUES); Integer labelId = entry.column(HugeKeys.INDEX_LABEL_ID); return SplicingIdGenerator.concat(labelId.toString(), fieldValue.toString()); } }
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(); } }