Skip to content
Permalink
Browse files
let getProperties() return Collection<HugeProperty> (#1624)
let getProperties() return Collection<HugeProperty> instead of Map<Id, HugeProperty>

Change-Id: I77c9cb86d2ae96f21660aa40993a4821ce64a2cf
  • Loading branch information
javeme committed Oct 28, 2021
1 parent d540040 commit 0b80d7700661cd73f3849898d4ae99aa582b416f
Showing 34 changed files with 132 additions and 98 deletions.
@@ -43,6 +43,7 @@
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.define.DataType;
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.InsertionOrderUtil;
import com.baidu.hugegraph.util.JsonUtil;
import com.google.common.collect.ImmutableMap;
@@ -126,7 +127,7 @@ protected void formatProperties(HugeElement element,
row.column(HugeKeys.PROPERTIES, ImmutableMap.of());
} else {
// Format properties
for (HugeProperty<?> prop : element.getProperties().values()) {
for (HugeProperty<?> prop : element.getProperties()) {
this.formatProperty(prop, row);
}
}
@@ -147,12 +148,16 @@ public BackendEntry writeOlapVertex(HugeVertex vertex) {
CassandraBackendEntry entry = newBackendEntry(HugeType.OLAP,
vertex.id());
entry.column(HugeKeys.ID, this.writeId(vertex.id()));
HugeProperty<?> prop = vertex.getProperties().values()
.iterator().next();
PropertyKey pk = prop.propertyKey();

Collection<HugeProperty<?>> properties = vertex.getProperties();
E.checkArgument(properties.size() == 1,
"Expect only 1 property for olap vertex, but got %s",
properties.size());
HugeProperty<?> property = properties.iterator().next();
PropertyKey pk = property.propertyKey();
entry.subId(pk.id());
entry.column(HugeKeys.PROPERTY_VALUE,
this.writeProperty(pk, prop.value()));
this.writeProperty(pk, property.value()));
entry.olap(true);
return entry;
}
@@ -37,7 +37,6 @@
import com.baidu.hugegraph.backend.store.BackendFeatures;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.backend.store.raft.RaftGroupManager;
import com.baidu.hugegraph.config.ConfigOption;
import com.baidu.hugegraph.config.TypedOption;
import com.baidu.hugegraph.rpc.RpcServiceConfig4Client;
import com.baidu.hugegraph.rpc.RpcServiceConfig4Server;
@@ -42,6 +42,8 @@

public class HugeProject extends Entity {

private static final long serialVersionUID = 8681323499069874520L;

private String name;
private Id adminGroupId;
private Id opGroupId;
@@ -579,7 +579,7 @@ private void ensureElement2IndexValueMap() {
}
}

public static String concatValues(List<Object> values) {
public static String concatValues(List<?> values) {
List<Object> newValues = new ArrayList<>(values.size());
for (Object v : values) {
newValues.add(convertNumberIfNeeded(v));
@@ -589,7 +589,7 @@ public static String concatValues(List<Object> values) {

public static String concatValues(Object value) {
if (value instanceof List) {
return concatValues((List<Object>)value);
return concatValues((List<?>) value);
}

if (needConvertNumber(value)) {
@@ -755,11 +755,11 @@ public LeftIndex(Set<Object> indexFieldValues, Id indexField) {
}

public Set<Object> indexFieldValues() {
return indexFieldValues;
return this.indexFieldValues;
}

public Id indexField() {
return indexField;
return this.indexField;
}
}
}
@@ -48,7 +48,7 @@ public BackendEntry writeVertex(HugeVertex vertex) {
entry.column(this.formatLabel(vertex));

// Write all properties of a Vertex
for (HugeProperty<?> prop : vertex.getProperties().values()) {
for (HugeProperty<?> prop : vertex.getProperties()) {
entry.column(this.formatProperty(prop));
}

@@ -62,9 +62,9 @@
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.type.define.IdStrategy;
import com.baidu.hugegraph.type.define.IndexType;
import com.baidu.hugegraph.type.define.WriteType;
import com.baidu.hugegraph.type.define.SchemaStatus;
import com.baidu.hugegraph.type.define.SerialEnum;
import com.baidu.hugegraph.type.define.WriteType;
import com.baidu.hugegraph.util.Bytes;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.JsonUtil;
@@ -231,14 +231,14 @@ protected byte[] formatEdgeName(HugeEdge edge) {
}

protected byte[] formatEdgeValue(HugeEdge edge) {
int propsCount = edge.getProperties().size();
int propsCount = edge.sizeOfProperties();
BytesBuffer buffer = BytesBuffer.allocate(4 + 16 * propsCount);

// Write edge id
//buffer.writeId(edge.id());

// Write edge properties
this.formatProperties(edge.getProperties().values(), buffer);
this.formatProperties(edge.getProperties(), buffer);

// Write edge expired time if needed
if (edge.hasTtl()) {
@@ -383,14 +383,14 @@ public BackendEntry writeVertex(HugeVertex vertex) {
return entry;
}

int propsCount = vertex.getProperties().size();
int propsCount = vertex.sizeOfProperties();
BytesBuffer buffer = BytesBuffer.allocate(8 + 16 * propsCount);

// Write vertex label
buffer.writeId(vertex.schemaLabel().id());

// Write all properties of the vertex
this.formatProperties(vertex.getProperties().values(), buffer);
this.formatProperties(vertex.getProperties(), buffer);

// Write vertex expired time if needed
if (vertex.hasTtl()) {
@@ -410,11 +410,14 @@ public BackendEntry writeOlapVertex(HugeVertex vertex) {
BinaryBackendEntry entry = newBackendEntry(HugeType.OLAP, vertex.id());
BytesBuffer buffer = BytesBuffer.allocate(8 + 16);

HugeProperty<?> hugeProperty = vertex.getProperties().values()
.iterator().next();
PropertyKey propertyKey = hugeProperty.propertyKey();
Collection<HugeProperty<?>> properties = vertex.getProperties();
E.checkArgument(properties.size() == 1,
"Expect only 1 property for olap vertex, but got %s",
properties.size());
HugeProperty<?> property = properties.iterator().next();
PropertyKey propertyKey = property.propertyKey();
buffer.writeVInt(SchemaElement.schemaId(propertyKey.id()));
buffer.writeProperty(propertyKey, hugeProperty.value());
buffer.writeProperty(propertyKey, property.value());

// Fill column
byte[] name = this.keyWithIdPrefix ? entry.id().asBytes() : EMPTY_BYTES;
@@ -24,7 +24,6 @@
import java.util.List;
import java.util.function.BiFunction;

import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.iterator.WrappedIterator;
import com.baidu.hugegraph.util.E;

@@ -86,7 +85,7 @@ protected final boolean fetch() {
continue;
}

if (merger.apply(next, element)) {
if (this.merger.apply(next, element)) {
Iterator<R> iter = this.iterators.get(i);
if (iter.hasNext()) {
this.headElements.set(i, iter.next());
@@ -65,8 +65,8 @@
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.type.define.IdStrategy;
import com.baidu.hugegraph.type.define.IndexType;
import com.baidu.hugegraph.type.define.WriteType;
import com.baidu.hugegraph.type.define.SchemaStatus;
import com.baidu.hugegraph.type.define.WriteType;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.JsonUtil;
import com.google.common.collect.ImmutableMap;
@@ -130,11 +130,11 @@ private String formatPropertyName() {
}

private String formatPropertyValues(HugeVertex vertex) {
int size = vertex.getProperties().size();
int size = vertex.sizeOfProperties();
StringBuilder sb = new StringBuilder(64 * size);
// Vertex properties
int i = 0;
for (HugeProperty<?> property : vertex.getProperties().values()) {
for (HugeProperty<?> property : vertex.getProperties()) {
sb.append(this.formatPropertyName(property));
sb.append(VALUE_SPLITOR);
sb.append(this.formatPropertyValue(property));
@@ -193,7 +193,7 @@ private String formatEdgeName(HugeEdge edge) {
}

private String formatEdgeValue(HugeEdge edge) {
StringBuilder sb = new StringBuilder(256 * edge.getProperties().size());
StringBuilder sb = new StringBuilder(256 * edge.sizeOfProperties());
// Edge id
sb.append(edge.id().asString());
// Write edge expired time
@@ -202,7 +202,7 @@ private String formatEdgeValue(HugeEdge edge) {
sb.append(VALUE_SPLITOR);
sb.append(edge.expiredTime());
// Edge properties
for (HugeProperty<?> property : edge.getProperties().values()) {
for (HugeProperty<?> property : edge.getProperties()) {
sb.append(VALUE_SPLITOR);
sb.append(this.formatPropertyName(property));
sb.append(VALUE_SPLITOR);
@@ -30,7 +30,6 @@
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.backend.store.raft.StoreSnapshotFile;
import com.baidu.hugegraph.config.CoreOptions;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.event.EventHub;
import com.baidu.hugegraph.event.EventListener;
import com.baidu.hugegraph.util.E;
@@ -178,7 +178,11 @@ public void updateEdgeIndex(HugeEdge edge, boolean removed) {
}

private void updateVertexOlapIndex(HugeVertex vertex, boolean removed) {
Id pkId = vertex.getProperties().keySet().iterator().next();
Set<Id> propKeys = vertex.getPropertyKeys();
E.checkArgument(propKeys.size() == 1,
"Expect only 1 property for olap vertex, but got %s",
propKeys.size());
Id pkId = propKeys.iterator().next();
List<IndexLabel> indexLabels = this.params().schemaTransaction()
.getIndexLabels();
for (IndexLabel il : indexLabels) {
@@ -262,8 +266,7 @@ protected void updateIndex(Id ilId, HugeElement element, boolean removed) {
* Property value is a collection
* we should create index for each item
*/
for (Object propValue :
(Collection<Object>) propValues.get(0)) {
for (Object propValue : (Collection<?>) propValues.get(0)) {
value = ConditionQuery.concatValues(propValue);
value = escapeIndexValueIfNeeded((String) value);
this.updateIndex(indexLabel, value, element.id(),
@@ -1458,8 +1461,7 @@ private static String propertyValueToString(Object value) {
* or else keep the origin value.
*/
return value instanceof Collection ?
StringUtils.join(((Collection<Object>) value).toArray(), " ") :
value.toString();
StringUtils.join(((Iterable<?>) value), " ") : value.toString();
}

private static String escapeIndexValueIfNeeded(String value) {
@@ -1562,6 +1564,7 @@ public MatchedIndex(SchemaLabel schemaLabel,
this.indexLabels = indexLabels;
}

@SuppressWarnings("unused")
public SchemaLabel schemaLabel() {
return this.schemaLabel;
}
@@ -1601,7 +1604,7 @@ public boolean containsSearchIndex() {

@Override
public int hashCode() {
return indexLabels.hashCode();
return this.indexLabels.hashCode();
}

@Override
@@ -1881,6 +1884,7 @@ private HugeElement constructErrorElem(
return errorElem;
}

@SuppressWarnings("unused")
private boolean deletedByError(ConditionQuery query,
HugeElement element) {
HugeElement elem = this.newestElement(element);
@@ -626,7 +626,7 @@ public HugeVertex constructVertex(boolean verifyVL, Object... keyValues) {
HugeVertex vertex = HugeVertex.create(this, id,
VertexLabel.OLAP_VL);
ElementHelper.attachProperties(vertex, keyValues);
Iterator<HugeProperty<?>> iterator = vertex.getProperties().values()
Iterator<HugeProperty<?>> iterator = vertex.getProperties()
.iterator();
assert iterator.hasNext();
if (iterator.next().propertyKey().olap()) {
@@ -1531,7 +1531,7 @@ private void checkAggregateProperty(HugeProperty<?> property) {
}

private void checkNonnullProperty(HugeVertex vertex) {
Set<Id> keys = vertex.getProperties().keySet();
Set<Id> keys = vertex.getPropertyKeys();
VertexLabel vertexLabel = vertex.schemaLabel();
// Check whether passed all non-null property
@SuppressWarnings("unchecked")
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
@@ -384,15 +385,15 @@ public void writeIdField(String fieldName, Id id,
}
}

public void writePropertiesField(Map<Id, HugeProperty<?>> properties,
public void writePropertiesField(Collection<HugeProperty<?>> properties,
JsonGenerator generator,
SerializerProvider provider)
throws IOException {
// Start write properties
generator.writeFieldName("properties");
generator.writeStartObject();

for (HugeProperty<?> property : properties.values()) {
for (HugeProperty<?> property : properties) {
String key = property.key();
Object val = property.value();
try {
@@ -270,7 +270,7 @@ public <V> Iterator<Property<V>> properties(String... keys) {
List<Property<V>> props = new ArrayList<>(propsCapacity);

if (keys.length == 0) {
for (HugeProperty<?> prop : this.getProperties().values()) {
for (HugeProperty<?> prop : this.getProperties()) {
assert prop instanceof Property;
props.add((Property<V>) prop);
}

0 comments on commit 0b80d77

Please sign in to comment.