Skip to content

Commit

Permalink
chore: fix TinkerPop unit test (#2055)
Browse files Browse the repository at this point in the history
* chore: don't support persistence for memory backend
* chore: setup graph by first step graph when graph is null
* chore: apply relations optimize logic
* chore: don't support null properties
* fix: g.V().has(empty).count() and g.V().count().as('a').select('a')
* fix: specify the code generation directory for raft.proto (#2057)
* fix: tinkerpop unit schema no define
* fix the style & clean some outdated code

Co-authored-by: Simon Cheung <[email protected]>
Co-authored-by: imbajin <[email protected]>
  • Loading branch information
3 people authored Dec 26, 2022
1 parent fc27f2c commit 6c3170c
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ jobs:
distribution: 'zulu'

- name: Cache Maven packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Package
run: |
mvn clean package -DskipTests
mvn clean package -DskipTests -ntp
- name: Rename file
if: contains(env.TAG_NAME, "-")
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
distribution: 'zulu'

- name: Cache Maven packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down Expand Up @@ -68,18 +68,6 @@ jobs:
java-version: ${{ matrix.JAVA_VERSION }}
distribution: 'zulu'

# - name: Init MySQL Env
# if: ${{ env.BACKEND == 'mysql' }}
# uses: mirromutth/[email protected]
# with:
# host port: 3306 # Optional, default value is 3306. The port of host
# container port: 3306 # Optional, default value is 3306. The port of container
# character set server: 'utf8mb4' # Optional, default value is 'utf8mb4'. The '--character-set-server' option for mysqld
# collation server: 'utf8mb4_general_ci' # Optional, default value is 'utf8mb4_general_ci'. The '--collation-server' option for mysqld
# mysql version: '5.7' # Optional, default value is "latest". The version of the MySQL
# mysql database: 'test' # Optional, default value is "test". The specified database which will be create
# mysql root password: "******" # Required if "mysql user" is empty, default is empty. The root superuser password

- name: Run unit test
run: |
$TRAVIS_DIR/run-unit-test.sh $BACKEND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ public StandardHugeGraph(HugeConfig config) {

this.taskManager = TaskManager.instance();

this.features = new HugeFeatures(this, true);

this.name = config.get(CoreOptions.STORE);
this.started = false;
this.closed = false;
Expand All @@ -214,6 +212,8 @@ public StandardHugeGraph(HugeConfig config) {

try {
this.tx = new TinkerPopTransaction(this);
boolean supportsPersistence = this.backendStoreFeatures().supportsPersistence();
this.features = new HugeFeatures(this, supportsPersistence);

SnowflakeIdGenerator.init(this.params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.apache.hugegraph.util.NumericUtil;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

public final class ConditionQueryFlatten {

private static final Set<HugeKeys> SPECIAL_KEYS = ImmutableSet.of(
HugeKeys.LABEL
HugeKeys.LABEL
);

public static List<ConditionQuery> flatten(ConditionQuery query) {
Expand All @@ -51,7 +52,7 @@ public static List<ConditionQuery> flatten(ConditionQuery query) {
public static List<ConditionQuery> flatten(ConditionQuery query,
boolean supportIn) {
if (query.isFlattened() && !query.mayHasDupKeys(SPECIAL_KEYS)) {
return ImmutableList.of(query);
return flattenRelations(query);
}

List<ConditionQuery> queries = new ArrayList<>();
Expand Down Expand Up @@ -123,8 +124,8 @@ private static Condition flattenIn(Condition condition, boolean supportIn) {
return new Condition.Or(flattenIn(or.left(), supportIn),
flattenIn(or.right(), supportIn));
default:
throw new AssertionError(String.format(
"Wrong condition type: '%s'", condition.type()));
throw new AssertionError(String.format("Wrong condition type: '%s'",
condition.type()));
}
}

Expand All @@ -144,8 +145,7 @@ private static Condition convIn2Or(Relation relation, boolean supportIn) {
(key == HugeKeys.OWNER_VERTEX || key == HugeKeys.ID)) {
// TODO: Should not rely on HugeKeys here, improve key judgment
// Just mark flatten
return new Condition.FlattenSyspropRelation(
(SyspropRelation) relation);
return new Condition.FlattenSyspropRelation((SyspropRelation) relation);
}

// Do IN flatten, return null if values.size() == 0
Expand Down Expand Up @@ -214,8 +214,8 @@ private static Set<Relations> flattenAndOr(Condition condition) {
flattenAndOr(or.right()));
break;
default:
throw new AssertionError(String.format(
"Wrong condition type: '%s'", condition.type()));
throw new AssertionError(String.format("Wrong condition type: '%s'",
condition.type()));
}
return result;
}
Expand Down Expand Up @@ -251,6 +251,25 @@ private static ConditionQuery newQueryFromRelations(ConditionQuery query,
return cq;
}

private static List<ConditionQuery> flattenRelations(ConditionQuery query) {
Relations relations = new Relations();
List<Condition> nonRelations = new ArrayList<>();
for (Condition condition : query.conditions()) {
if (condition.isRelation()) {
relations.add((Relation) condition);
} else {
nonRelations.add(condition);
}
}
relations = optimizeRelations(relations);
if (relations != null) {
ConditionQuery cq = newQueryFromRelations(query, relations);
cq.query(nonRelations);
return ImmutableList.of(cq);
}
return ImmutableList.of(query);
}

private static Relations optimizeRelations(Relations relations) {
// Optimize and-relations in one query
// e.g. (age>1 and age>2) -> (age>2)
Expand Down Expand Up @@ -289,8 +308,9 @@ private static Relations optimizeRelations(Relations relations) {

/**
* Reduce and merge relations linked with 'AND' for same key
* @param relations linked with 'AND' having same key, may contains 'in',
* 'not in', '>', '<', '>=', '<=', '==', '!='
*
* @param relations linked with 'AND' having same key, may contain 'in', 'not in',
* '>', '<', '>=', '<=', '==', '!='
* @return merged relations
*/
private static Relations mergeRelations(Relations relations) {
Expand Down Expand Up @@ -410,8 +430,8 @@ private static boolean validRange(Relation low, Relation high) {
return true;
}
return compare(low, high) < 0 || compare(low, high) == 0 &&
low.relation() == Condition.RelationType.GTE &&
high.relation() == Condition.RelationType.LTE;
low.relation() == Condition.RelationType.GTE &&
high.relation() == Condition.RelationType.LTE;
}

private static boolean validEq(Relation eq, Relation low, Relation high) {
Expand Down Expand Up @@ -460,8 +480,7 @@ private static Relation lowRelation(Relation first, Relation second) {
return selectRelation(first, second, false);
}

private static Relation selectRelation(Relation first, Relation second,
boolean high) {
private static Relation selectRelation(Relation first, Relation second, boolean high) {
if (first == null) {
return second;
}
Expand Down Expand Up @@ -491,8 +510,8 @@ private static int compare(Relation first, Relation second) {
} else if (firstValue instanceof Date && secondValue instanceof Date) {
return ((Date) firstValue).compareTo((Date) secondValue);
} else {
throw new IllegalArgumentException(String.format(
"Can't compare between %s and %s", first, second));
throw new IllegalArgumentException(String.format("Can't compare between %s and %s",
first, second));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ public VertexProperty.Cardinality getCardinality(final String key) {
return VertexProperty.Cardinality.single;
}

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

public boolean supportsDefaultLabel() {
return true;
}
Expand All @@ -291,6 +296,11 @@ public class HugeEdgeFeatures extends HugeElementFeatures
public EdgePropertyFeatures properties() {
return this.edgePropertyFeatures;
}

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

public class HugeDataTypeFeatures implements DataTypeFeatures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void apply(Traversal.Admin<?, ?> traversal) {
graphStep.queryInfo().aggregate(Aggregate.AggregateFunc.COUNT, null);
HugeCountStep<?> countStep = new HugeCountStep<>(traversal, graphStep);
for (Step<?, ?> origin : originSteps) {
TraversalHelper.copyLabels(origin, countStep, false);
traversal.removeStep(origin);
}
traversal.addStep(0, countStep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public HugeGraphStep(final GraphStep<S, E> originGraphStep) {
}

protected long count() {
if (this.ids == null) {
return 0L;
}

if (this.returnsVertex()) {
return this.verticesCount();
} else {
Expand Down Expand Up @@ -144,14 +148,13 @@ private boolean hasIds() {
}

private Query makeQuery(HugeGraph graph, HugeType type) {
Query query = null;
Query query;
if (this.hasContainers.isEmpty()) {
// Query all
query = new Query(type);
} else {
ConditionQuery q = new ConditionQuery(type);
query = TraversalUtil.fillConditionQuery(q, this.hasContainers,
graph);
query = TraversalUtil.fillConditionQuery(q, this.hasContainers, graph);
}

query = this.injectQueryInfo(query);
Expand Down Expand Up @@ -198,6 +201,7 @@ public Iterator<?> lastTimeResults() {
return this.lastTimeResults;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof HugeGraphStep)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public void apply(Traversal.Admin<?, ?> traversal) {
List<GraphStep> steps = TraversalHelper.getStepsOfClass(
GraphStep.class, traversal);
for (GraphStep originStep : steps) {
TraversalUtil.trySetGraph(originStep,
TraversalUtil.tryGetGraph(steps.get(0)));

HugeGraphStep<?, ?> newStep = new HugeGraphStep<>(originStep);
TraversalHelper.replaceStep(originStep, newStep, traversal);

Expand Down
Loading

0 comments on commit 6c3170c

Please sign in to comment.