Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix core-backend checkstyle issue #1852

Merged
merged 19 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
public class EdgeId implements Id {

public static final HugeKeys[] KEYS = new HugeKeys[] {
HugeKeys.OWNER_VERTEX,
HugeKeys.DIRECTION,
HugeKeys.LABEL,
HugeKeys.SORT_VALUES,
HugeKeys.OTHER_VERTEX
HugeKeys.OWNER_VERTEX,
HugeKeys.DIRECTION,
HugeKeys.LABEL,
HugeKeys.SORT_VALUES,
HugeKeys.OTHER_VERTEX
};

private final Id ownerVertexId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,56 +54,83 @@ public enum ConditionType {

public enum RelationType implements BiPredicate<Object, Object> {

EQ("==", (v1, v2) -> {return equals(v1, v2); }),
GT(">", (v1, v2) -> { return compare(v1, v2) > 0; }),
GTE(">=", (v1, v2) -> { return compare(v1, v2) >= 0; }),
LT("<", (v1, v2) -> { return compare(v1, v2) < 0; }),
LTE("<=", (v1, v2) -> { return compare(v1, v2) <= 0; }),
NEQ("!=", (v1, v2) -> { return compare(v1, v2) != 0; }),
EQ("==", (v1, v2) -> {
return equals(v1, v2);
}),

GT(">", (v1, v2) -> {
return compare(v1, v2) > 0;
}),

GTE(">=", (v1, v2) -> {
return compare(v1, v2) >= 0;
}),

LT("<", (v1, v2) -> {
return compare(v1, v2) < 0;
}),

LTE("<=", (v1, v2) -> {
return compare(v1, v2) <= 0;
}),

NEQ("!=", (v1, v2) -> {
return compare(v1, v2) != 0;
}),

IN("in", null, Collection.class, (v1, v2) -> {
assert v2 != null;
return ((Collection<?>) v2).contains(v1);
}),

NOT_IN("notin", null, Collection.class, (v1, v2) -> {
assert v2 != null;
return !((Collection<?>) v2).contains(v1);
}),

PREFIX("prefix", Id.class, Id.class, (v1, v2) -> {
assert v2 != null;
return v1 != null && Bytes.prefixWith(((Id) v2).asBytes(),
((Id) v1).asBytes());
}),

TEXT_CONTAINS("textcontains", String.class, String.class, (v1, v2) -> {
// TODO: support collection-property textcontains
return v1 != null && ((String) v1).contains((String) v2);
}),
TEXT_CONTAINS_ANY("textcontainsany", String.class, Collection.class,
(v1, v2) -> {

TEXT_CONTAINS_ANY("textcontainsany", String.class, Collection.class, (v1, v2) -> {
assert v2 != null;
if (v1 == null) {
return false;
}

@SuppressWarnings("unchecked")
Collection<String> words = (Collection<String>) v2;

for (String word : words) {
if (((String) v1).contains(word)) {
return true;
}
}
return false;
}),

CONTAINS("contains", Collection.class, null, (v1, v2) -> {
assert v2 != null;
return v1 != null && ((Collection<?>) v1).contains(v2);
}),

CONTAINS_VALUE("containsv", Map.class, null, (v1, v2) -> {
assert v2 != null;
return v1 != null && ((Map<?, ?>) v1).containsValue(v2);
}),

CONTAINS_KEY("containsk", Map.class, null, (v1, v2) -> {
assert v2 != null;
return v1 != null && ((Map<?, ?>) v1).containsKey(v2);
}),

SCAN("scan", (v1, v2) -> {
assert v2 != null;
/*
Expand All @@ -118,12 +145,12 @@ public enum RelationType implements BiPredicate<Object, Object> {
private final Class<?> v1Class;
private final Class<?> v2Class;

private RelationType(String op,
RelationType(String op,
BiFunction<Object, Object, Boolean> tester) {
this(op, null, null, tester);
}

private RelationType(String op, Class<?> v1Class, Class<?> v2Class,
RelationType(String op, Class<?> v1Class, Class<?> v2Class,
BiFunction<Object, Object, Boolean> tester) {
this.operator = op;
this.tester = tester;
Expand Down Expand Up @@ -390,7 +417,7 @@ public static Condition contains(Id key, Object value) {
/**
* Condition defines
*/
public static abstract class BinCondition extends Condition {
public abstract static class BinCondition extends Condition {

private Condition left;
private Condition right;
Expand Down Expand Up @@ -741,11 +768,15 @@ public RangeConditions(List<? extends Condition> conditions) {
break;
case GTE:
this.keyMinEq = true;
this.keyMin = r.value();
break;
case GT:
this.keyMin = r.value();
break;
case LTE:
this.keyMaxEq = true;
this.keyMax = r.value();
break;
case LT:
this.keyMax = r.value();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public List<Condition.Relation> relations() {
return relations;
}

public Relation relation(Id key){
public Relation relation(Id key) {
for (Relation r : this.relations()) {
if (r.key().equals(key)) {
return r;
Expand Down Expand Up @@ -831,7 +831,7 @@ public boolean checkRangeIndex(HugeElement element, Condition cond) {
}

private static boolean removeFieldValue(Set<Object> values,
Object value){
Object value) {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved
for (Object elem : values) {
if (numberEquals(elem, value)) {
values.remove(elem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private static Condition convTextContainsAny2Or(Relation relation) {
assert relation.relation() == Condition.RelationType.TEXT_CONTAINS_ANY;
@SuppressWarnings("unchecked")
Collection<String> words = (Collection<String>) relation.value();
Condition cond, conds = null;
Condition cond = null;
Condition conds = null;
for (String word : words) {
assert relation.key() instanceof Id;
cond = Condition.textContains((Id) relation.key(), word);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ public IdRangeQuery copy() {

@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
assert sb.length() > 0;
sb.deleteCharAt(sb.length() - 1); // Remove the last "`"
sb.append(" id in range ")
.append(this.inclusiveStart ? "[" : "(")
.append(this.start)
.append(", ")
.append(this.end)
.append(this.inclusiveEnd ? "]" : ")")
.append("`");
return sb.toString();
StringBuilder builder = new StringBuilder(super.toString());
assert builder.length() > 0;
builder.deleteCharAt(builder.length() - 1); // Remove the last "`"
builder.append(" id in range ")
.append(this.inclusiveStart ? "[" : "(")
.append(this.start)
.append(", ")
.append(this.end)
.append(this.inclusiveEnd ? "]" : ")")
.append("`");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Query implements Cloneable {
public static final long NO_CAPACITY = -1L;
public static final long DEFAULT_CAPACITY = 800000L; // HugeGraph-777

private static final ThreadLocal<Long> capacityContext = new ThreadLocal<>();
private static final ThreadLocal<Long> CAPACITY_CONTEXT = new ThreadLocal<>();

protected static final Query NONE = new Query(HugeType.UNKNOWN);

Expand Down Expand Up @@ -558,17 +558,17 @@ public String toString() {
}

public static long defaultCapacity(long capacity) {
Long old = capacityContext.get();
capacityContext.set(capacity);
Long old = CAPACITY_CONTEXT.get();
CAPACITY_CONTEXT.set(capacity);
return old != null ? old : DEFAULT_CAPACITY;
}

public static long defaultCapacity() {
Long capacity = capacityContext.get();
Long capacity = CAPACITY_CONTEXT.get();
return capacity != null ? capacity : DEFAULT_CAPACITY;
}

public final static void checkForceCapacity(long count)
public static final void checkForceCapacity(long count)
throws LimitExceedException {
if (count > Query.DEFAULT_CAPACITY) {
throw new LimitExceedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void removeLastRecord() {
((BinaryBackendEntry) this.current).removeColumn(lastOne);
}

public final static long sizeOfEntry(BackendEntry entry) {
public static final long sizeOfEntry(BackendEntry entry) {
/*
* 3 cases:
* 1) one vertex per entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ protected void parseEdge(BackendColumn col, HugeVertex vertex,
}
}


protected void parseVertex(byte[] value, HugeVertex vertex) {
BytesBuffer buffer = BytesBuffer.wrap(value);

Expand Down Expand Up @@ -871,9 +870,9 @@ public BackendEntry parse(BackendEntry originEntry) {
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
buffer.write(parsedEntry.id().asBytes());
buffer.write(bytes);
parsedEntry = new BinaryBackendEntry(originEntry.type(),
new BinaryId(buffer.bytes(),
BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
parsedEntry = new BinaryBackendEntry(originEntry.type(), new BinaryId(buffer.bytes(),
BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

for (BackendEntry.BackendColumn col : originEntry.columns()) {
parsedEntry.column(buffer.bytes(), col.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@

public interface GraphSerializer {

public BackendEntry writeVertex(HugeVertex vertex);
public BackendEntry writeOlapVertex(HugeVertex vertex);
public BackendEntry writeVertexProperty(HugeVertexProperty<?> prop);
public HugeVertex readVertex(HugeGraph graph, BackendEntry entry);
BackendEntry writeVertex(HugeVertex vertex);

public BackendEntry writeEdge(HugeEdge edge);
public BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop);
public HugeEdge readEdge(HugeGraph graph, BackendEntry entry);
BackendEntry writeOlapVertex(HugeVertex vertex);

public BackendEntry writeIndex(HugeIndex index);
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query,
BackendEntry entry);
BackendEntry writeVertexProperty(HugeVertexProperty<?> prop);

public BackendEntry writeId(HugeType type, Id id);
public Query writeQuery(Query query);
HugeVertex readVertex(HugeGraph graph, BackendEntry entry);

BackendEntry writeEdge(HugeEdge edge);

BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop);

HugeEdge readEdge(HugeGraph graph, BackendEntry entry);

BackendEntry writeIndex(HugeIndex index);

HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry entry);

BackendEntry writeId(HugeType type, Id id);

Query writeQuery(Query query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@

public interface SchemaSerializer {

public BackendEntry writeVertexLabel(VertexLabel vertexLabel);
public VertexLabel readVertexLabel(HugeGraph graph, BackendEntry entry);
BackendEntry writeVertexLabel(VertexLabel vertexLabel);

public BackendEntry writeEdgeLabel(EdgeLabel edgeLabel);
public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry entry);
VertexLabel readVertexLabel(HugeGraph graph, BackendEntry entry);

public BackendEntry writePropertyKey(PropertyKey propertyKey);
public PropertyKey readPropertyKey(HugeGraph graph, BackendEntry entry);
BackendEntry writeEdgeLabel(EdgeLabel edgeLabel);

public BackendEntry writeIndexLabel(IndexLabel indexLabel);
public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry entry);
EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry entry);

BackendEntry writePropertyKey(PropertyKey propertyKey);

PropertyKey readPropertyKey(HugeGraph graph, BackendEntry entry);

BackendEntry writeIndexLabel(IndexLabel indexLabel);

IndexLabel readIndexLabel(HugeGraph graph, BackendEntry entry);
}
Loading