Skip to content
Permalink
Browse files

Support range sortKey feature

implement #271

Change-Id: Ib618c45bc6169a0fb7632dbbf0fb29b7ee0a08e3
  • Loading branch information...
javeme authored and zhoney committed Dec 21, 2018
1 parent af2df75 commit 7164a459ba1e665524aa9c5f44dc04b5421b7c8e
Showing with 1,214 additions and 416 deletions.
  1. +1 −1 hugegraph-api/pom.xml
  2. +1 −1 hugegraph-cassandra/pom.xml
  3. +2 −1 ...h-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraStoreProvider.java
  4. +3 −3 hugegraph-core/pom.xml
  5. +10 −0 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java
  6. +11 −15 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java
  7. +93 −0 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/IdPrefixQuery.java
  8. +104 −0 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/IdRangeQuery.java
  9. +4 −4 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/AbstractSerializer.java
  10. +1 −2 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java
  11. +172 −71 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java
  12. +4 −0 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java
  13. +1 −1 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java
  14. +60 −22 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java
  15. +73 −4 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java
  16. +52 −11 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java
  17. +4 −5 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java
  18. +2 −1 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBStoreProvider.java
  19. +30 −110 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTable.java
  20. +190 −0 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java
  21. +8 −7 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java
  22. +28 −6 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java
  23. +40 −28 hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
  24. +1 −5 hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeProperty.java
  25. +6 −0 hugegraph-core/src/main/java/com/baidu/hugegraph/util/StringEncoding.java
  26. +2 −1 hugegraph-core/src/main/java/com/baidu/hugegraph/version/CoreVersion.java
  27. +1 −1 hugegraph-dist/pom.xml
  28. +1 −1 hugegraph-example/pom.xml
  29. +4 −3 hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example1.java
  30. +1 −1 hugegraph-hbase/pom.xml
  31. +0 −27 hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSerializer.java
  32. +46 −0 hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java
  33. +2 −1 hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseStoreProvider.java
  34. +26 −4 hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseTable.java
  35. +24 −28 hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseTables.java
  36. +1 −1 hugegraph-mysql/pom.xml
  37. +2 −2 hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlSessions.java
  38. +2 −1 hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlStoreProvider.java
  39. +1 −1 hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlTable.java
  40. +1 −1 hugegraph-palo/pom.xml
  41. +2 −1 hugegraph-palo/src/main/java/com/baidu/hugegraph/backend/store/palo/PaloStoreProvider.java
  42. +1 −1 hugegraph-rocksdb/pom.xml
  43. +15 −33 hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStdSessions.java
  44. +2 −1 hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStoreProvider.java
  45. +37 −5 hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTable.java
  46. +14 −1 hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBTables.java
  47. +1 −1 hugegraph-scylladb/pom.xml
  48. +1 −1 hugegraph-test/pom.xml
  49. +79 −0 hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java
  50. +2 −0 hugegraph-test/src/main/java/com/baidu/hugegraph/unit/UnitTestSuite.java
  51. +44 −0 hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/VersionTest.java
  52. +1 −1 pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>hugegraph</artifactId>
<groupId>com.baidu.hugegraph</groupId>
<version>0.9.0</version>
<version>0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@@ -5,7 +5,7 @@
<parent>
<artifactId>hugegraph</artifactId>
<groupId>com.baidu.hugegraph</groupId>
<version>0.9.0</version>
<version>0.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@@ -51,7 +51,8 @@ public String version() {
* Versions history:
* [1.0] HugeGraph-1328: supports backend table version checking
* [1.1] HugeGraph-1322: add support for full-text search
* [1.2] #296: support range sortKey feature
*/
return "1.1";
return "1.2";
}
}
@@ -5,7 +5,7 @@
<parent>
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph</artifactId>
<version>0.9.0</version>
<version>0.9.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>hugegraph-core</artifactId>
@@ -19,7 +19,7 @@
<dependency>
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-common</artifactId>
<version>1.5.3</version>
<version>1.5.6</version>
</dependency>

<!-- tinkerpop -->
@@ -157,7 +157,7 @@
</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>0.9.0.0</Implementation-Version>
<Implementation-Version>0.9.1.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
@@ -204,6 +204,10 @@ public boolean isLogic() {
this.type() == ConditionType.OR;
}

public boolean isFlattened() {
return this.isRelation();
}

public static Condition and(Condition left, Condition right) {
return new And(left, right);
}
@@ -393,6 +397,12 @@ public boolean test(HugeElement element) {
public Condition copy() {
return new And(this.left().copy(), this.right().copy());
}

@Override
public boolean isFlattened() {
// If this is flattened, its sub-condition should not be nested
return this.left().isRelation() && this.right().isRelation();
}
}

public static class Or extends BinCondition {
@@ -142,7 +142,7 @@ public Object condition(Object key) {
for (Condition c : this.conditions) {
if (c.isRelation()) {
Condition.Relation r = (Condition.Relation) c;
if (r.key().equals(key)) {
if (r.key().equals(key) && r.relation() == RelationType.EQ) {
values.add(r.value());
}
}
@@ -277,11 +277,11 @@ public void resetUserpropConditions() {

/**
* This method is only used for secondary index scenario,
* relation must be EQ
* its relation must be EQ
* @param fields the user property fields
* @return the corresponding user property values of fileds
* @return the corresponding user property serial values of fields
*/
public List<Object> userpropValues(List<Id> fields) {
public String userpropValuesString(List<Id> fields) {
List<Object> values = new ArrayList<>(fields.size());
for (Id field : fields) {
boolean got = false;
@@ -290,9 +290,9 @@ public void resetUserpropConditions() {
E.checkState(r.relation == RelationType.EQ,
"Method userpropValues(List<String>) only " +
"used for secondary index, " +
"relation must be EQ, but got '%s'",
"relation must be EQ, but got %s",
r.relation());
values.add(r.value());
values.add(r.serialValue());
got = true;
}
}
@@ -302,18 +302,14 @@ public void resetUserpropConditions() {
field, this);
}
}
return values;
}

public String userpropValuesString(List<Id> fields) {
return SplicingIdGenerator.concatValues(this.userpropValues(fields));
return SplicingIdGenerator.concatValues(values);
}

public Set<Object> userpropValues(Id field) {
Set<Object> values = new HashSet<>();
for (Relation r : this.userpropRelations()) {
if (r.key().equals(field)) {
values.add(r.value());
values.add(r.serialValue());
}
}
return values;
@@ -325,8 +321,8 @@ public Object userpropValue(Id field) {
return null;
}
E.checkState(values.size() == 1,
"Expect one user-property value of field '%s', but got %s",
field, values.size());
"Expect one user-property value of field '%s', " +
"but got '%s'", field, values.size());
return values.iterator().next();
}

@@ -393,7 +389,7 @@ public boolean test(HugeElement element) {

public void checkFlattened() {
for (Condition condition : this.conditions) {
E.checkState(condition.isRelation(),
E.checkState(condition.isFlattened(),
"Condition Query has none-flatten condition '%s'",
condition);
}
@@ -0,0 +1,93 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.backend.query;

import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.structure.HugeElement;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.util.Bytes;
import com.baidu.hugegraph.util.E;

public class IdPrefixQuery extends Query {

private final Id start;
private final boolean inclusiveStart;
private final Id prefix;

public IdPrefixQuery(HugeType resultType, Id prefix) {
this(resultType, null, prefix, true, prefix);
}

public IdPrefixQuery(Query originQuery, Id prefix) {
this(originQuery.resultType(), originQuery, prefix, true, prefix);
}

public IdPrefixQuery(Query originQuery,
Id start, boolean inclusive, Id prefix) {
this(originQuery.resultType(), originQuery, start, inclusive, prefix);
}

public IdPrefixQuery(HugeType resultType, Query originQuery,
Id start, boolean inclusive, Id prefix) {
super(resultType, originQuery);
E.checkArgumentNotNull(start, "The start parameter can't be null");
this.start = start;
this.inclusiveStart = inclusive;
this.prefix = prefix;
}

public Id start() {
return this.start;
}

public boolean inclusiveStart() {
return this.inclusiveStart;
}

public Id prefix() {
return this.prefix;
}

@Override
public boolean empty() {
return false;
}

@Override
public boolean test(HugeElement element) {
byte[] elem = element.id().asBytes();
int cmp = Bytes.compare(elem, this.start.asBytes());
boolean matchedStart = this.inclusiveStart ? cmp >= 0 : cmp > 0;
boolean matchedPrefix = Bytes.prefixWith(elem, this.prefix.asBytes());
return matchedStart && matchedPrefix;
}

@Override
public IdPrefixQuery copy() {
return (IdPrefixQuery) super.copy();
}

@Override
public String toString() {
return String.format("%s where id prefix with %s and start with %s(%s)",
super.toString(), this.prefix, this.start,
this.inclusiveStart ? "inclusive" : "exclusive");
}
}
@@ -0,0 +1,104 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.backend.query;

import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.structure.HugeElement;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.util.Bytes;
import com.baidu.hugegraph.util.E;

public class IdRangeQuery extends Query {

private final Id start;
private final Id end;
private final boolean inclusiveStart;
private final boolean inclusiveEnd;

public IdRangeQuery(HugeType resultType, Id start, Id end) {
this(resultType, null, start, end);
}

public IdRangeQuery(HugeType resultType, Query originQuery,
Id start, Id end) {
this(resultType, originQuery, start, true, end, false);
}

public IdRangeQuery(Query originQuery,
Id start, boolean inclusiveStart,
Id end, boolean inclusiveEnd) {
this(originQuery.resultType(), originQuery,
start, inclusiveStart, end, inclusiveEnd);
}

public IdRangeQuery(HugeType resultType, Query originQuery,
Id start, boolean inclusiveStart,
Id end, boolean inclusiveEnd) {
super(resultType, originQuery);
E.checkArgumentNotNull(start, "The start parameter can't be null");
this.start = start;
this.end = end;
this.inclusiveStart = inclusiveStart;
this.inclusiveEnd = inclusiveEnd;
}

public Id start() {
return this.start;
}

public Id end() {
return this.end;
}

public boolean inclusiveStart() {
return this.inclusiveStart;
}

public boolean inclusiveEnd() {
return this.inclusiveEnd;
}

@Override
public boolean empty() {
return false;
}

@Override
public boolean test(HugeElement element) {
int cmp1 = Bytes.compare(element.id().asBytes(), this.start.asBytes());
int cmp2 = Bytes.compare(element.id().asBytes(), this.end.asBytes());
return (this.inclusiveStart ? cmp1 >= 0 : cmp1 > 0) &&
(this.inclusiveEnd ? cmp2 <= 0 : cmp2 < 0);
}

@Override
public IdRangeQuery copy() {
return (IdRangeQuery) super.copy();
}

@Override
public String toString() {
return String.format("%s where id in range %s%s,%s%s",
super.toString(),
this.inclusiveStart ? "[" : "(",
this.start, this.end,
this.inclusiveEnd ? "]" : ")");
}
}
@@ -38,7 +38,7 @@ protected BackendEntry convertEntry(BackendEntry entry) {

protected abstract Id writeQueryId(HugeType type, Id id);

protected abstract Id writeQueryEdgeCondition(Query query);
protected abstract Query writeQueryEdgeCondition(Query query);

protected abstract Query writeQueryCondition(Query query);

@@ -53,9 +53,9 @@ public Query writeQuery(Query query) {
"and by condition at the same time");
}

Id id = this.writeQueryEdgeCondition(query);
if (id != null) {
return new IdQuery(query, id);
Query result = this.writeQueryEdgeCondition(query);
if (result != null) {
return result;
}
}

@@ -31,7 +31,6 @@
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.util.Bytes;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.StringEncoding;

public class BinaryBackendEntry implements BackendEntry {

@@ -229,7 +228,7 @@ public boolean equals(Object other) {

@Override
public String toString() {
return StringEncoding.decode(this.bytes);
return "0x" + Bytes.toHex(this.bytes);
}
}
}

0 comments on commit 7164a45

Please sign in to comment.
You can’t perform that action at this time.