From 1c062b8947d423ceeaae5e2ce7088711b8d6bb58 Mon Sep 17 00:00:00 2001 From: Linary Date: Thu, 12 Sep 2019 19:04:30 +0800 Subject: [PATCH] Upgrade tinkerpop version to 3.4.3 (#648) Change-Id: I5443b6a05eea74205a373f093dad27536e04f0be --- hugegraph-api/pom.xml | 2 +- .../traversers/CustomizedCrosspointsAPI.java | 4 +- .../api/traversers/CustomizedPathsAPI.java | 4 +- .../hugegraph/auth/ContextGremlinServer.java | 36 +--- .../hugegraph/auth/HugeGraphAuthProxy.java | 2 +- .../hugegraph/auth/StandardAuthenticator.java | 3 +- hugegraph-cassandra/pom.xml | 6 +- hugegraph-core/pom.xml | 2 +- .../backend/page/PageEntryIterator.java | 2 +- .../hugegraph/backend/page/QueryList.java | 5 +- .../backend/query/ConditionQueryFlatten.java | 2 +- .../hugegraph/backend/query/QueryResults.java | 198 ++++++++++++++++++ .../backend/serializer/BinarySerializer.java | 6 +- .../backend/serializer/TableSerializer.java | 6 +- .../backend/serializer/TextSerializer.java | 6 +- .../backend/store/memory/InMemoryDBTable.java | 4 +- .../store/memory/InMemoryDBTables.java | 5 +- .../backend/tx/AbstractTransaction.java | 146 +------------ .../backend/tx/GraphTransaction.java | 7 +- .../backend/tx/SchemaIndexTransaction.java | 1 + .../hugegraph/io/HugeGraphSONModule.java | 20 +- .../plugin/HugeGraphGremlinPlugin.java | 57 +++-- .../security/HugeSecurityManager.java | 11 +- .../baidu/hugegraph/structure/HugeEdge.java | 84 +++----- .../hugegraph/structure/HugeFeatures.java | 5 - .../baidu/hugegraph/structure/HugeVertex.java | 6 +- .../algorithm/ShortestPathTraverser.java | 3 +- .../traversal/optimize/HugeGraphStep.java | 7 +- .../traversal/optimize/HugeVertexStep.java | 2 +- .../traversal/optimize/TraversalUtil.java | 18 +- .../com/baidu/hugegraph/util/DateUtil.java | 4 + .../baidu/hugegraph/version/CoreVersion.java | 4 +- hugegraph-dist/pom.xml | 2 +- .../assembly/static/conf/gremlin-server.yaml | 48 +++-- .../baidu/hugegraph/dist/HugeGraphServer.java | 5 + hugegraph-example/pom.xml | 2 +- .../com/baidu/hugegraph/example/Example2.java | 18 +- hugegraph-hbase/pom.xml | 2 +- hugegraph-mysql/pom.xml | 2 +- hugegraph-palo/pom.xml | 2 +- hugegraph-postgresql/pom.xml | 2 +- hugegraph-rocksdb/pom.xml | 2 +- hugegraph-scylladb/pom.xml | 2 +- hugegraph-test/pom.xml | 32 +-- .../baidu/hugegraph/core/EdgeCoreTest.java | 47 ++++- .../baidu/hugegraph/core/VertexCoreTest.java | 47 ++++- .../tinkerpop/ProcessBasicSuite.java | 36 ++-- .../tinkerpop/ProcessPerformanceSuite.java | 83 -------- .../tinkerpop/ProcessPerformanceTest.java | 31 --- .../tinkerpop/StructurePerformanceSuite.java | 85 -------- .../tinkerpop/StructurePerformanceTest.java | 30 --- .../baidu/hugegraph/tinkerpop/TestGraph.java | 118 +++++++++-- .../tinkerpop/TestGraphProvider.java | 19 ++ .../src/main/resources/fast-methods.filter | 22 ++ .../src/main/resources/methods.filter | 22 ++ pom.xml | 48 +---- 56 files changed, 658 insertions(+), 717 deletions(-) create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceSuite.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceTest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceSuite.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceTest.java diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml index 487d8ff82..51536b53c 100644 --- a/hugegraph-api/pom.xml +++ b/hugegraph-api/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java index 76b33a385..e73448598 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPI.java @@ -25,7 +25,6 @@ import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATH import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -47,6 +46,7 @@ import org.slf4j.Logger; import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.api.API; import com.baidu.hugegraph.backend.id.Id; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.core.GraphManager; import com.baidu.hugegraph.schema.EdgeLabel; import com.baidu.hugegraph.server.RestServer; @@ -97,7 +97,7 @@ public class CustomizedCrosspointsAPI extends API { CustomizedCrosspointsTraverser.CrosspointsPaths paths; paths = traverser.crosspointsPaths(sources, patterns, request.capacity, request.limit); - Iterator iter = Collections.emptyIterator(); + Iterator iter = QueryResults.emptyIterator(); if (!request.withVertex) { return manager.serializer(g).writeCrosspoints(paths, iter, request.withPath); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java index 8b9c58a83..7c5f9b4f6 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedPathsAPI.java @@ -27,7 +27,6 @@ import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_WEIG import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -49,6 +48,7 @@ import org.slf4j.Logger; import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.api.API; import com.baidu.hugegraph.backend.id.Id; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.core.GraphManager; import com.baidu.hugegraph.schema.EdgeLabel; import com.baidu.hugegraph.schema.PropertyKey; @@ -114,7 +114,7 @@ public class CustomizedPathsAPI extends API { for (HugeTraverser.Path p : paths) { ids.addAll(p.vertices()); } - Iterator iter = Collections.emptyIterator(); + Iterator iter = QueryResults.emptyIterator(); if (!ids.isEmpty()) { iter = g.vertices(ids.toArray()); } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/ContextGremlinServer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/ContextGremlinServer.java index bdba2ad0a..cde0f8c92 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/ContextGremlinServer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/ContextGremlinServer.java @@ -23,13 +23,11 @@ import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; -import org.apache.commons.lang3.SystemUtils; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.server.GraphManager; import org.apache.tinkerpop.gremlin.server.GremlinServer; import org.apache.tinkerpop.gremlin.server.Settings; import org.apache.tinkerpop.gremlin.server.util.MetricManager; -import org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor; import org.apache.tinkerpop.gremlin.server.util.ThreadFactoryUtil; import org.apache.tinkerpop.gremlin.structure.Graph; import org.slf4j.Logger; @@ -40,10 +38,6 @@ import com.baidu.hugegraph.auth.HugeGraphAuthProxy.Context; import com.baidu.hugegraph.auth.HugeGraphAuthProxy.ContextThreadPoolExecutor; import com.baidu.hugegraph.util.Log; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.epoll.EpollEventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; - /** * GremlinServer with custom ServerGremlinExecutor, which can pass Context */ @@ -51,17 +45,11 @@ public class ContextGremlinServer extends GremlinServer { private static final Logger LOG = Log.logger(ContextGremlinServer.class); - @SuppressWarnings("deprecation") public ContextGremlinServer(final Settings settings) { /* - * TODO: use GremlinServer(Settings, ExecutorService) * which can be obtained from https://github.com/apache/tinkerpop/pull/813 - * - * NOTE: should call GremlinServer::configureMetrics() but it's private - * settings.optionalMetrics().ifPresent(GremlinServer::configureMetrics) */ - super(create(settings)); - settings.optionalMetrics().ifPresent(this::configureMetrics); + super(settings, newGremlinExecutorService(settings)); } public void injectAuthGraph() { @@ -92,28 +80,10 @@ public class ContextGremlinServer extends GremlinServer { } } - static ServerGremlinExecutor create(Settings settings) { + static ExecutorService newGremlinExecutorService(Settings settings) { if (settings.gremlinPool == 0) { settings.gremlinPool = Runtime.getRuntime().availableProcessors(); } - - ExecutorService service = newGremlinExecutorService(settings); - - EventLoopGroup group; - boolean isEpollEnabled = settings.useEpollEventLoop && - SystemUtils.IS_OS_LINUX; - ThreadFactory factory = ThreadFactoryUtil.create("worker-%d"); - if (isEpollEnabled) { - group = new EpollEventLoopGroup(settings.threadPoolWorker, factory); - } else { - group = new NioEventLoopGroup(settings.threadPoolWorker, factory); - } - - return new ServerGremlinExecutor<>(settings, service, - group, EventLoopGroup.class); - } - - static ExecutorService newGremlinExecutorService(Settings settings) { int size = settings.gremlinPool; ThreadFactory factory = ThreadFactoryUtil.create("exec-%d"); return new ContextThreadPoolExecutor(size, size, factory); @@ -146,7 +116,7 @@ public class ContextGremlinServer extends GremlinServer { if (config.enabled) { try { metrics.addGangliaReporter(config.host, config.port, - config.optionalAddressingMode(), + config.addressingMode, config.ttl, config.protocol31, config.hostUUID, config.spoof, config.interval); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java index b7afbe2bf..e7ca91ffc 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java @@ -256,7 +256,7 @@ public class HugeGraphAuthProxy implements GremlinGraph { public ContextThreadPoolExecutor(int corePoolSize, int maxPoolSize, ThreadFactory threadFactory) { super(corePoolSize, maxPoolSize, 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue(), threadFactory); + new LinkedBlockingQueue<>(), threadFactory); } @Override diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java index 89e40f6f7..469c40d1e 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java @@ -19,6 +19,7 @@ package com.baidu.hugegraph.auth; +import java.net.InetAddress; import java.util.HashMap; import java.util.Map; @@ -112,7 +113,7 @@ public class StandardAuthenticator implements HugeAuthenticator { } @Override - public SaslNegotiator newSaslNegotiator() { + public SaslNegotiator newSaslNegotiator(InetAddress remoteAddress) { throw new NotImplementedException("SaslNegotiator is unsupported"); } diff --git a/hugegraph-cassandra/pom.xml b/hugegraph-cassandra/pom.xml index d60148945..3ded5ec78 100644 --- a/hugegraph-cassandra/pom.xml +++ b/hugegraph-cassandra/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 @@ -15,7 +15,7 @@ io.netty netty-all - 4.0.44.Final + 4.1.36.Final com.baidu.hugegraph @@ -59,7 +59,7 @@ io.netty netty-transport-native-epoll - 4.0.44.Final + 4.1.36.Final linux-x86_64 diff --git a/hugegraph-core/pom.xml b/hugegraph-core/pom.xml index 700459509..00edc7862 100644 --- a/hugegraph-core/pom.xml +++ b/hugegraph-core/pom.xml @@ -5,7 +5,7 @@ com.baidu.hugegraph hugegraph - 0.10.3 + 0.10.4 ../pom.xml hugegraph-core diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/PageEntryIterator.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/PageEntryIterator.java index 222c5b484..e9c78d14f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/PageEntryIterator.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/PageEntryIterator.java @@ -23,8 +23,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.store.BackendEntry; -import com.baidu.hugegraph.backend.tx.AbstractTransaction.QueryResults; import com.baidu.hugegraph.exception.NotSupportException; import com.baidu.hugegraph.iterator.Metadatable; import com.baidu.hugegraph.util.E; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java index dd5631ce8..63399cfea 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java @@ -20,7 +20,6 @@ package com.baidu.hugegraph.backend.page; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -30,8 +29,8 @@ import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.backend.id.Id; import com.baidu.hugegraph.backend.query.IdQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.store.BackendEntry; -import com.baidu.hugegraph.backend.tx.AbstractTransaction.QueryResults; import com.baidu.hugegraph.config.CoreOptions; import com.baidu.hugegraph.util.Bytes; import com.baidu.hugegraph.util.CollectionUtil; @@ -267,7 +266,7 @@ public final class QueryList { public static class PageIterator { public static final PageIterator EMPTY = new PageIterator( - Collections.emptyIterator(), + QueryResults.emptyIterator(), ImmutableList.of(Query.NONE), PageState.EMPTY); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java index 6d261596e..e5b3798a6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java @@ -144,7 +144,7 @@ public final class ConditionQueryFlatten { assert relation.relation() == Condition.RelationType.NOT_IN; Object key = relation.key(); @SuppressWarnings("unchecked") - List values = (List) relation.value(); + List values = (List) relation.value(); Condition cond; Condition conds = null; for (Object value : values) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java new file mode 100644 index 000000000..85f412a23 --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/QueryResults.java @@ -0,0 +1,198 @@ +/* + * 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 java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.function.Function; + +import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; + +import com.baidu.hugegraph.backend.id.Id; +import com.baidu.hugegraph.backend.store.BackendEntry; +import com.baidu.hugegraph.iterator.FlatMapperIterator; +import com.baidu.hugegraph.iterator.MapperIterator; +import com.baidu.hugegraph.iterator.Metadatable; +import com.baidu.hugegraph.type.Idfiable; +import com.baidu.hugegraph.util.E; +import com.baidu.hugegraph.util.InsertionOrderUtil; + +public class QueryResults { + + private static final Iterator EMPTY_ITERATOR = new EmptyIterator<>(); + + private static final QueryResults EMPTY = new QueryResults(emptyIterator(), + Query.NONE); + + private final Iterator results; + private final List queries; + + public QueryResults(Iterator results, Query query) { + this(results); + this.addQuery(query); + } + + public QueryResults(Iterator results) { + this.results = results; + this.queries = InsertionOrderUtil.newList(); + } + + public void setQuery(Query query) { + if (this.queries.size() > 0) { + this.queries.clear(); + } + this.addQuery(query); + } + + private void addQuery(Query query) { + E.checkNotNull(query, "query"); + this.queries.add(query); + } + + private void addQueries(List queries) { + for (Query query : queries) { + this.addQuery(query); + } + } + + public Iterator iterator() { + return this.results; + } + + public List list() { + return IteratorUtils.list(this.results); + } + + public List queries() { + return Collections.unmodifiableList(this.queries); + } + + public Iterator keepInputOrderIfNeeded( + Iterator origin) { + if (!origin.hasNext()) { + // None result found + return origin; + } + Set ids; + if (this.paging() || !this.mustSortByInputIds() || + (ids = this.queryIds()).size() <= 1) { + /* + * Return the original iterator if it's paging query or if the + * query input is less than one id, or don't have to do sort. + */ + return origin; + } + + // Fill map with all elements + Map results = new HashMap<>(); + fillMap(origin, results); + + return new MapperIterator<>(ids.iterator(), id -> { + return results.get(id); + }); + } + + private boolean mustSortByInputIds() { + if (this.queries.size() == 1) { + Query query = this.queries.get(0); + if (query instanceof IdQuery) { + return ((IdQuery) query).mustSortByInput(); + } + } + return true; + } + + private boolean paging() { + for (Query query : this.queries) { + Query origin = query.originQuery(); + if (query.paging() || origin != null && origin.paging()) { + return true; + } + } + return false; + } + + private Set queryIds() { + if (this.queries.size() == 1) { + return this.queries.get(0).ids(); + } + + Set ids = InsertionOrderUtil.newSet(); + for (Query query : this.queries) { + ids.addAll(query.ids()); + } + return ids; + } + + public static void fillMap(Iterator iterator, + Map map) { + while (iterator.hasNext()) { + T result = iterator.next(); + assert result.id() != null; + map.put(result.id(), result); + } + } + + public static QueryResults flatMap(Iterator iterator, + Function func) { + QueryResults[] qr = new QueryResults[1]; + qr[0] = new QueryResults(new FlatMapperIterator<>(iterator, i -> { + QueryResults results = func.apply(i); + if (results == null) { + return null; + } + qr[0].addQueries(results.queries()); + return results.iterator(); + })); + return qr[0]; + } + + public static QueryResults empty() { + return EMPTY; + } + + @SuppressWarnings("unchecked") + public static Iterator emptyIterator() { + return (Iterator) EMPTY_ITERATOR; + } + + private static class EmptyIterator implements Iterator, + Metadatable { + @Override + public Object metadata(String meta, Object... args) { + return null; + } + + @Override + public boolean hasNext() { + return false; + } + + @Override + public E next() { + throw new NoSuchElementException(); + } + } +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java index e1d6e488f..8edf697e2 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java @@ -276,15 +276,13 @@ public class BinarySerializer extends AbstractSerializer { HugeEdge edge = new HugeEdge(graph, null, edgeLabel); edge.name(sk); + edge.vertices(isOutEdge, vertex, otherVertex); + edge.assignId(); if (isOutEdge) { - edge.vertices(vertex, vertex, otherVertex); - edge.assignId(); vertex.addOutEdge(edge); otherVertex.addInEdge(edge.switchOwner()); } else { - edge.vertices(vertex, otherVertex, vertex); - edge.assignId(); vertex.addInEdge(edge); otherVertex.addOutEdge(edge.switchOwner()); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java index 7822abe82..d86fbe8da 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java @@ -167,15 +167,13 @@ public abstract class TableSerializer extends AbstractSerializer { HugeEdge edge = new HugeEdge(graph, null, edgeLabel); edge.name(sortValues); + edge.vertices(isOutEdge, vertex, otherVertex); + edge.assignId(); if (isOutEdge) { - edge.vertices(vertex, vertex, otherVertex); - edge.assignId(); vertex.addOutEdge(edge); otherVertex.addInEdge(edge.switchOwner()); } else { - edge.vertices(vertex, otherVertex, vertex); - edge.assignId(); vertex.addInEdge(edge); otherVertex.addOutEdge(edge.switchOwner()); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java index 520e8f966..beb6a5a85 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java @@ -187,15 +187,13 @@ public class TextSerializer extends AbstractSerializer { HugeEdge edge = new HugeEdge(graph, null, label); edge.name(colParts[2]); + edge.vertices(isOutEdge, vertex, otherVertex); + edge.assignId(); if (isOutEdge) { - edge.vertices(vertex, vertex, otherVertex); - edge.assignId(); vertex.addOutEdge(edge); otherVertex.addInEdge(edge.switchOwner()); } else { - edge.vertices(vertex, otherVertex, vertex); - edge.assignId(); vertex.addInEdge(edge); otherVertex.addOutEdge(edge.switchOwner()); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTable.java index ec3a4a97f..1810da6ed 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTable.java @@ -20,7 +20,6 @@ package com.baidu.hugegraph.backend.store.memory; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -34,6 +33,7 @@ import com.baidu.hugegraph.backend.query.Condition; import com.baidu.hugegraph.backend.query.IdPrefixQuery; import com.baidu.hugegraph.backend.query.IdRangeQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.serializer.TextBackendEntry; import com.baidu.hugegraph.backend.store.BackendEntry; import com.baidu.hugegraph.backend.store.BackendSession; @@ -143,7 +143,7 @@ public class InMemoryDBTable extends BackendTable iterator = rs.values().iterator(); if (query.offset() >= rs.size()) { - return Collections.emptyIterator(); + return QueryResults.emptyIterator(); } iterator = this.skipOffset(iterator, query.offset()); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java index acfa6dc22..4351ed811 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java @@ -40,6 +40,7 @@ import com.baidu.hugegraph.backend.query.Condition.RangeConditions; import com.baidu.hugegraph.backend.query.ConditionQuery; import com.baidu.hugegraph.backend.query.IdQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.serializer.TextBackendEntry; import com.baidu.hugegraph.backend.store.BackendEntry; import com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn; @@ -289,7 +290,7 @@ public class InMemoryDBTables { if (count == offset) { return iter; } else if (count < offset) { - return Collections.emptyIterator(); + return QueryResults.emptyIterator(); } // Collect edges that are over-skipped @@ -496,7 +497,7 @@ public class InMemoryDBTables { max = keyMaxEq ? rs.floorKey(max) : rs.lowerKey(max); if (max == null) { - return Collections.emptyIterator(); + return QueryResults.emptyIterator(); } Map results = InsertionOrderUtil.newMap(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/AbstractTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/AbstractTransaction.java index 20a95bb28..2a0b32309 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/AbstractTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/AbstractTransaction.java @@ -19,15 +19,8 @@ package com.baidu.hugegraph.backend.tx; -import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; import org.slf4j.Logger; import com.baidu.hugegraph.HugeGraph; @@ -36,19 +29,16 @@ import com.baidu.hugegraph.backend.Transaction; import com.baidu.hugegraph.backend.id.Id; import com.baidu.hugegraph.backend.query.IdQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.serializer.AbstractSerializer; import com.baidu.hugegraph.backend.store.BackendEntry; import com.baidu.hugegraph.backend.store.BackendMutation; import com.baidu.hugegraph.backend.store.BackendStore; import com.baidu.hugegraph.exception.NotFoundException; -import com.baidu.hugegraph.iterator.FlatMapperIterator; -import com.baidu.hugegraph.iterator.MapperIterator; import com.baidu.hugegraph.perf.PerfUtil.Watched; import com.baidu.hugegraph.type.HugeType; -import com.baidu.hugegraph.type.Idfiable; import com.baidu.hugegraph.type.define.Action; import com.baidu.hugegraph.util.E; -import com.baidu.hugegraph.util.InsertionOrderUtil; import com.baidu.hugegraph.util.Log; import com.google.common.util.concurrent.RateLimiter; @@ -344,138 +334,4 @@ public abstract class AbstractTransaction implements Transaction { E.checkNotNull(entry, "entry"); this.mutation.add(entry, action); } - - public static class QueryResults { - - private static final QueryResults EMPTY = new QueryResults( - Collections.emptyIterator(), - Query.NONE); - - private final Iterator results; - private final List queries; - - public QueryResults(Iterator results, Query query) { - this(results); - this.addQuery(query); - } - - public QueryResults(Iterator results) { - this.results = results; - this.queries = InsertionOrderUtil.newList(); - } - - public void setQuery(Query query) { - if (this.queries.size() > 0) { - this.queries.clear(); - } - this.addQuery(query); - } - - private void addQuery(Query query) { - E.checkNotNull(query, "query"); - this.queries.add(query); - } - - private void addQueries(List queries) { - for (Query query : queries) { - this.addQuery(query); - } - } - - public Iterator iterator() { - return this.results; - } - - public List list() { - return IteratorUtils.list(this.results); - } - - public List queries() { - return Collections.unmodifiableList(this.queries); - } - - protected Iterator keepInputOrderIfNeeded( - Iterator origin) { - if (!origin.hasNext()) { - // None result found - return origin; - } - Set ids; - if (this.paging() || !this.mustSortByInputIds() || - (ids = this.queryIds()).size() <= 1) { - /* - * Return the original iterator if it's paging query or if the - * query input is less than one id, or don't have to do sort. - */ - return origin; - } - - // Fill map with all elements - Map results = new HashMap<>(); - fillMap(origin, results); - - return new MapperIterator<>(ids.iterator(), id -> { - return results.get(id); - }); - } - - private boolean mustSortByInputIds() { - if (this.queries.size() == 1) { - Query query = this.queries.get(0); - if (query instanceof IdQuery) { - return ((IdQuery) query).mustSortByInput(); - } - } - return true; - } - - private boolean paging() { - for (Query query : this.queries) { - Query origin = query.originQuery(); - if (query.paging() || origin != null && origin.paging()) { - return true; - } - } - return false; - } - - private Set queryIds() { - if (this.queries.size() == 1) { - return this.queries.get(0).ids(); - } - - Set ids = InsertionOrderUtil.newSet(); - for (Query query : this.queries) { - ids.addAll(query.ids()); - } - return ids; - } - - public static void fillMap(Iterator iterator, - Map map) { - while (iterator.hasNext()) { - T result = iterator.next(); - assert result.id() != null; - map.put(result.id(), result); - } - } - - public static QueryResults empty() { - return EMPTY; - } - - public static QueryResults flatMap(Iterator iterator, - Function func) { - QueryResults[] qr = new QueryResults[1]; - qr[0] = new QueryResults(new FlatMapperIterator<>(iterator, i -> { - QueryResults results = func.apply(i); - if (results == null) { - return null; - } - qr[0].addQueries(results.queries()); - return results.iterator(); - })); - return qr[0]; - } - } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java index 0022324c4..a3d66bb76 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java @@ -22,7 +22,6 @@ package com.baidu.hugegraph.backend.tx; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -54,6 +53,7 @@ import com.baidu.hugegraph.backend.query.ConditionQuery; import com.baidu.hugegraph.backend.query.ConditionQueryFlatten; import com.baidu.hugegraph.backend.query.IdQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.store.BackendEntry; import com.baidu.hugegraph.backend.store.BackendMutation; import com.baidu.hugegraph.backend.store.BackendStore; @@ -386,8 +386,7 @@ public class GraphTransaction extends IndexableTransaction { return super.query(query); } - QueryList queries = new QueryList(this.graph(), query, - q -> super.query(q)); + QueryList queries = new QueryList(this.graph(), query, super::query); for (ConditionQuery cq: ConditionQueryFlatten.flatten( (ConditionQuery) query)) { Query q = this.optimizeQuery(cq); @@ -489,7 +488,7 @@ public class GraphTransaction extends IndexableTransaction { public Iterator queryAdjacentVertices(Iterator edges) { if (!edges.hasNext()) { - return Collections.emptyIterator(); + return QueryResults.emptyIterator(); } List vertexIds = new ArrayList<>(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java index e9debbedc..1430a3701 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java @@ -25,6 +25,7 @@ import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.backend.query.ConditionQuery; import com.baidu.hugegraph.backend.query.IdQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.backend.store.BackendEntry; import com.baidu.hugegraph.backend.store.BackendStore; import com.baidu.hugegraph.perf.PerfUtil.Watched; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphSONModule.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphSONModule.java index 371106d17..a22dde388 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphSONModule.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/io/HugeGraphSONModule.java @@ -60,6 +60,8 @@ public class HugeGraphSONModule extends TinkerPopJacksonModule { private static final long serialVersionUID = 6480426922914059122L; + public static boolean OPTIMIZE_SERIALIZE = true; + private static final String TYPE_NAMESPACE = "hugegraph"; @SuppressWarnings("rawtypes") @@ -127,15 +129,15 @@ public class HugeGraphSONModule extends TinkerPopJacksonModule { addSerializer(EdgeLabel.class, new EdgeLabelSerializer()); addSerializer(IndexLabel.class, new IndexLabelSerializer()); - addSerializer(HugeVertex.class, new HugeVertexSerializer()); - /* - * Use customized edge serializer need to be compatible with V1 and V2 - * Graphson, and seems need to implement edge deserializer,it is - * a little complicated. - * Honestly, I don't know why there is no problem with vertex serializer - */ - // addSerializer(HugeEdge.class, new HugeEdgeSerializer()); - + if (OPTIMIZE_SERIALIZE) { + /* + * Use customized serializer need to be compatible with V1 and V2 + * Graphson, and seems need to implement edge deserializer,it is + * a little complicated. + */ + addSerializer(HugeVertex.class, new HugeVertexSerializer()); + addSerializer(HugeEdge.class, new HugeEdgeSerializer()); + } addSerializer(Shard.class, new ShardSerializer()); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphGremlinPlugin.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphGremlinPlugin.java index c15d2650e..c1219a973 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphGremlinPlugin.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphGremlinPlugin.java @@ -19,38 +19,51 @@ package com.baidu.hugegraph.plugin; +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; import java.util.Set; -import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin; -import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor; +import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin; +import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer; +import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer; +import org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin; -import com.baidu.hugegraph.io.HugeGraphIoRegistry; -import com.baidu.hugegraph.traversal.optimize.Text; -import com.google.common.collect.ImmutableSet; +import com.baidu.hugegraph.HugeException; +import com.baidu.hugegraph.util.ReflectionUtil; +import com.google.common.reflect.ClassPath; -@SuppressWarnings("deprecation") // TODO: use new Plugin API -public class HugeGraphGremlinPlugin implements GremlinPlugin { +public class HugeGraphGremlinPlugin extends AbstractGremlinPlugin { - private static final String IMPORT = "import "; - private static final String DOT_STAR = ".*"; + private static final String PACKAGE = "com.baidu.hugegraph"; + private static final String NAME = "com.baidu.hugegraph"; - private static final Set IMPORTS = ImmutableSet.of( - IMPORT + "com.baidu.hugegraph" + DOT_STAR, - IMPORT + HugeGraphIoRegistry.class.getName(), - IMPORT + Text.class.getName()); + private static final HugeGraphGremlinPlugin instance; + private static final ImportCustomizer imports; - @Override - public String getName() { - return "com.baidu.hugegraph"; + static { + instance = new HugeGraphGremlinPlugin(); + + Iterator classInfos; + try { + classInfos = ReflectionUtil.classes(PACKAGE); + } catch (IOException e) { + throw new HugeException("Failed to scan classes under package %s", + PACKAGE); + } + + Set classes = new HashSet<>(); + classInfos.forEachRemaining(classInfo -> classes.add(classInfo.load())); + imports = DefaultImportCustomizer.build() + .addClassImports(classes) + .create(); } - @Override - public void pluginTo(final PluginAcceptor pluginAcceptor) { - pluginAcceptor.addImports(IMPORTS); + public HugeGraphGremlinPlugin() { + super(NAME, imports); } - @Override - public boolean requireRestart() { - return true; + public static HugeGraphGremlinPlugin instance() { + return instance; } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java index 61578724f..b81204469 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java @@ -45,6 +45,10 @@ public class HugeSecurityManager extends SecurityManager { "org.codehaus.groovy.runtime.callsite.CallSiteClassLoader" ); + private static final Set CAFFEINE_CLASSES = ImmutableSet.of( + "com.github.benmanes.caffeine.cache.BoundedLocalCache" + ); + private static final Set WHITE_SYSTEM_PROPERTYS = ImmutableSet.of( "line.separator", "file.separator" @@ -132,7 +136,7 @@ public class HugeSecurityManager extends SecurityManager { @Override public void checkRead(String file) { - if (callFromGremlin()) { + if (callFromGremlin() && !callFromCaffeine()) { throw new SecurityException("Not allowed to read file via Gremlin"); } super.checkRead(file); @@ -314,9 +318,7 @@ public class HugeSecurityManager extends SecurityManager { } private static boolean callFromCaffeine() { - String clazz = "com.github.benmanes.caffeine.cache.BoundedLocalCache"; - String method = "scheduleDrainBuffers"; - return callFromMethod(clazz, method); + return callFromWorkerWithClass(CAFFEINE_CLASSES); } private static boolean callFromWorkerWithClass(Set classes) { @@ -334,6 +336,7 @@ public class HugeSecurityManager extends SecurityManager { return false; } + @SuppressWarnings("unused") private static boolean callFromMethod(String clazz, String method) { Thread curThread = Thread.currentThread(); StackTraceElement[] elements = curThread.getStackTrace(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdge.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdge.java index 6a944f804..1ae07ead1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdge.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdge.java @@ -52,15 +52,16 @@ public class HugeEdge extends HugeElement implements Edge, Cloneable { protected EdgeLabel label; protected String name; - // The Vertex who owned me - protected HugeVertex ownerVertex; protected HugeVertex sourceVertex; protected HugeVertex targetVertex; + protected boolean isOutEdge; - public HugeEdge(final HugeVertex owner, Id id, EdgeLabel label) { - this(owner.graph(), id, label); - - this.ownerVertex = owner; + public HugeEdge(HugeVertex sourceVertex, Id id, EdgeLabel label, + HugeVertex targetVertex) { + this(sourceVertex.graph(), id, label); + this.sourceVertex = sourceVertex; + this.targetVertex = targetVertex; + this.isOutEdge = true; this.fresh = true; } @@ -71,17 +72,15 @@ public class HugeEdge extends HugeElement implements Edge, Cloneable { this.label = label; this.name = null; - this.ownerVertex = null; this.sourceVertex = null; this.targetVertex = null; + this.isOutEdge = true; } @Override public HugeType type() { // NOTE: we optimize the edge type that let it include direction - return this.ownerVertex == this.sourceVertex ? - HugeType.EDGE_OUT : - HugeType.EDGE_IN; + return this.isOutEdge ? HugeType.EDGE_OUT : HugeType.EDGE_IN; } @Override @@ -119,30 +118,25 @@ public class HugeEdge extends HugeElement implements Edge, Cloneable { return this.label.name(); } + public boolean selfLoop() { + return this.sourceVertex != null && + this.sourceVertex == this.targetVertex; + } + public Directions direction() { - if (this.ownerVertex == this.sourceVertex) { - return Directions.OUT; - } else { - assert this.ownerVertex == this.targetVertex; - return Directions.IN; - } + return this.isOutEdge ? Directions.OUT : Directions.IN; } public boolean matchDirection(Directions direction) { - if (direction == Directions.BOTH) { + if (direction == Directions.BOTH || this.selfLoop()) { return true; } return this.isDirection(direction); } public boolean isDirection(Directions direction) { - // NOTE: self-loop edge will match both OUT and IN - if (direction == Directions.OUT) { - return this.ownerVertex == this.sourceVertex; - } else if (direction == Directions.IN) { - return this.ownerVertex == this.targetVertex; - } - return false; + return this.isOutEdge && direction == Directions.OUT || + !this.isOutEdge && direction == Directions.IN; } @Watched(prefix = "edge") @@ -329,30 +323,22 @@ public class HugeEdge extends HugeElement implements Edge, Cloneable { return this.targetVertex; } - public void vertices(HugeVertex source, HugeVertex target) { - // The default owner is the source vertex - this.ownerVertex = source; - - this.sourceVertex = source; - this.targetVertex = target; - } - - public void vertices(HugeVertex owner, - HugeVertex source, - HugeVertex target) { - this.ownerVertex = owner; - this.sourceVertex = source; - this.targetVertex = target; + public void vertices(boolean isOutEdge, + HugeVertex owner, + HugeVertex other) { + this.isOutEdge = isOutEdge; + if (isOutEdge) { + this.sourceVertex = owner; + this.targetVertex = other; + } else { + this.sourceVertex = other; + this.targetVertex = owner; + } } public HugeEdge switchOwner() { HugeEdge edge = this.clone(); - if (edge.ownerVertex == edge.sourceVertex) { - edge.ownerVertex = edge.targetVertex; - } else { - assert edge.ownerVertex == this.targetVertex; - edge.ownerVertex = edge.sourceVertex; - } + edge.isOutEdge = !edge.isOutEdge; edge.assignId(); return edge; } @@ -365,13 +351,7 @@ public class HugeEdge extends HugeElement implements Edge, Cloneable { } public HugeVertex ownerVertex() { - return this.ownerVertex; - } - - public void ownerVertex(HugeVertex owner) { - E.checkState(owner == this.sourceVertex || owner == this.targetVertex, - "The owner vertex must be sourceVertex or targetVertex"); - this.ownerVertex = owner; + return this.isOutEdge ? this.sourceVertex : this.targetVertex; } public HugeVertex sourceVertex() { @@ -421,7 +401,7 @@ public class HugeEdge extends HugeElement implements Edge, Cloneable { } public HugeVertex otherVertex() { - return this.otherVertex(this.ownerVertex); + return this.isOutEdge ? this.targetVertex : this.sourceVertex; } /** diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeFeatures.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeFeatures.java index 3ca3cfe39..de4cc67f0 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeFeatures.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeFeatures.java @@ -169,11 +169,6 @@ public class HugeFeatures implements Graph.Features { public class HugeVertexPropertyFeatures extends HugeDataTypeFeatures implements VertexPropertyFeatures { - @Override - public boolean supportsAddProperty() { - return true; - } - @Override public boolean supportsRemoveProperty() { return true; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java index b38d05541..25ed7d30c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java @@ -287,9 +287,7 @@ public class HugeVertex extends HugeElement implements Vertex, Cloneable { this.graph().mapPkId2Name(missed)); } - HugeEdge edge = new HugeEdge(this, id, edgeLabel); - - edge.vertices(this, targetVertex); + HugeEdge edge = new HugeEdge(this, id, edgeLabel, targetVertex); // Set properties ElementHelper.attachProperties(edge, keyValues); @@ -313,7 +311,6 @@ public class HugeVertex extends HugeElement implements Vertex, Cloneable { public void addOutEdge(HugeEdge edge) { if (edge.ownerVertex() == null) { edge.sourceVertex(this); - edge.ownerVertex(this); } E.checkState(edge.isDirection(Directions.OUT), "The owner vertex('%s') of OUT edge '%s' should be '%s'", @@ -328,7 +325,6 @@ public class HugeVertex extends HugeElement implements Vertex, Cloneable { public void addInEdge(HugeEdge edge) { if (edge.ownerVertex() == null) { edge.targetVertex(this); - edge.ownerVertex(this); } E.checkState(edge.isDirection(Directions.IN), "The owner vertex('%s') of IN edge '%s' should be '%s'", diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java index 8bc692c1e..190d70e3d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/ShortestPathTraverser.java @@ -30,6 +30,7 @@ import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.backend.id.Id; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.structure.HugeEdge; import com.baidu.hugegraph.type.define.Directions; import com.baidu.hugegraph.util.E; @@ -219,7 +220,7 @@ public class ShortestPathTraverser extends HugeTraverser { edgeList.add(edges.next()); } if (i >= this.skipDegree) { - return Collections.emptyIterator(); + return QueryResults.emptyIterator(); } } return edgeList.iterator(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java index 465c98d0a..8c53f8dab 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.backend.query.ConditionQuery; import com.baidu.hugegraph.backend.query.Query; +import com.baidu.hugegraph.backend.query.QueryResults; import com.baidu.hugegraph.type.HugeType; import com.baidu.hugegraph.util.Log; @@ -73,7 +74,11 @@ public final class HugeGraphStep LOG.debug("HugeGraphStep.vertices(): {}", this); HugeGraph graph = (HugeGraph) this.getTraversal().getGraph().get(); - if (this.ids != null && this.ids.length > 0) { + // g.V().hasId(EMPTY_LIST) will set ids to null + if (this.ids == null) { + return QueryResults.emptyIterator(); + } + if (this.ids.length > 0) { return TraversalUtil.filterResult(this.hasContainers, graph.vertices(this.ids)); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java index 6adf66f41..662679a63 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java @@ -51,7 +51,7 @@ public final class HugeVertexStep private static final Logger LOG = Log.logger(HugeVertexStep.class); - private final List hasContainers = new ArrayList<>();; + private final List hasContainers = new ArrayList<>(); // Store limit/order-by private final Query queryInfo = new Query(null); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java index b56164198..925fa740d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/TraversalUtil.java @@ -20,6 +20,7 @@ package com.baidu.hugegraph.traversal.optimize; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.function.BiPredicate; @@ -362,7 +363,7 @@ public final class TraversalUtil { HasContainer has) { BiPredicate bp = has.getPredicate().getBiPredicate(); assert bp instanceof Contains; - List values = (List) has.getValue(); + Collection values = (Collection) has.getValue(); String originKey = has.getKey(); if (values.size() > 1) { @@ -379,24 +380,25 @@ public final class TraversalUtil { // Ignore } + List valueList; if (hugeKey != null) { - values = convSysListValueIfNeeded(graph, type, hugeKey, values); - + valueList = convSysListValueIfNeeded(graph, type, hugeKey, values); switch ((Contains) bp) { case within: - return Condition.in(hugeKey, values); + return Condition.in(hugeKey, valueList); case without: - return Condition.nin(hugeKey, values); + return Condition.nin(hugeKey, valueList); } } else { + valueList = new ArrayList<>(values); String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); switch ((Contains) bp) { case within: - return Condition.in(pkey.id(), values); + return Condition.in(pkey.id(), valueList); case without: - return Condition.nin(pkey.id(), values); + return Condition.nin(pkey.id(), valueList); } } @@ -539,7 +541,7 @@ public final class TraversalUtil { private static List convSysListValueIfNeeded(HugeGraph graph, HugeType type, HugeKeys key, - List values) { + Collection values) { List newValues = new ArrayList<>(values.size()); for (Object value : values) { newValues.add(convSysValueIfNeeded(graph, type, key, value)); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/DateUtil.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/DateUtil.java index bd9214bb8..f1d8ada37 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/DateUtil.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/DateUtil.java @@ -65,6 +65,10 @@ public final class DateUtil { return dateFormat.parse(value); } + public static Date now() { + return new Date(); + } + private static SafeDateFormat getDateFormat(String df) { SafeDateFormat dateFormat = DATE_FORMATS.get(df); if (dateFormat == null) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/version/CoreVersion.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/version/CoreVersion.java index 168d31fdd..fb2789fee 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/version/CoreVersion.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/version/CoreVersion.java @@ -33,9 +33,9 @@ public class CoreVersion { // The second parameter of Version.of() is for IDE running without JAR public static final Version VERSION = Version.of(CoreVersion.class, - "0.10.3"); + "0.10.4"); - public static final String GREMLIN_VERSION = "3.2.5"; + public static final String GREMLIN_VERSION = "3.4.3"; public static void check() { // Check version of hugegraph-common diff --git a/hugegraph-dist/pom.xml b/hugegraph-dist/pom.xml index e3bf2412c..73a91dc7f 100644 --- a/hugegraph-dist/pom.xml +++ b/hugegraph-dist/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 hugegraph-dist diff --git a/hugegraph-dist/src/assembly/static/conf/gremlin-server.yaml b/hugegraph-dist/src/assembly/static/conf/gremlin-server.yaml index e9229531e..4bdfe39c7 100644 --- a/hugegraph-dist/src/assembly/static/conf/gremlin-server.yaml +++ b/hugegraph-dist/src/assembly/static/conf/gremlin-server.yaml @@ -5,13 +5,19 @@ channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer graphs: { hugegraph: conf/hugegraph.properties } -plugins: - - com.baidu.hugegraph scriptEngines: { gremlin-groovy: { - imports: [java.lang.Math], - staticImports: [java.lang.Math.PI], - scripts: [scripts/empty-sample.groovy] + plugins: { + com.baidu.hugegraph.plugin.HugeGraphGremlinPlugin: {}, + org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, + org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: { + classImports: [java.lang.Math, com.baidu.hugegraph.util.DateUtil], + methodImports: [java.lang.Math#*] + }, + org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: { + files: [scripts/empty-sample.groovy] + } + } } } serializers: @@ -20,31 +26,31 @@ serializers: serializeResultToString: false, ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] } - } - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, - config: { - serializeResultToString: true, - ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] - } - } - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, + } + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, config: { serializeResultToString: false, ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] } - } - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, - config: { - serializeResultToString: false, - ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] - } - } + } - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: false, ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] } - } + } + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, + config: { + serializeResultToString: false, + ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] + } + } + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, + config: { + serializeResultToString: false, + ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] + } + } metrics: { consoleReporter: {enabled: false, interval: 180000}, csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv}, diff --git a/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java b/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java index 7c83649e5..5d94a608d 100644 --- a/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java +++ b/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java @@ -36,6 +36,9 @@ public class HugeGraphServer { public HugeGraphServer(String gremlinServerConf, String restServerConf) throws Exception { + // Only switch on security manager after HugeGremlinServer started + SecurityManager securityManager = System.getSecurityManager(); + System.setSecurityManager(null); try { // Start GremlinServer this.gremlinServer = HugeGremlinServer.start(gremlinServerConf); @@ -43,6 +46,8 @@ public class HugeGraphServer { LOG.error("HugeGremlinServer start error: ", e); HugeGraph.shutdown(30L); throw e; + } finally { + System.setSecurityManager(securityManager); } try { diff --git a/hugegraph-example/pom.xml b/hugegraph-example/pom.xml index b43f5ee97..edeca3951 100644 --- a/hugegraph-example/pom.xml +++ b/hugegraph-example/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example2.java b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example2.java index aa2a95809..d45334e7e 100644 --- a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example2.java +++ b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example2.java @@ -39,7 +39,7 @@ public class Example2 { private static final Logger LOG = Log.logger(Example2.class); - public static void main(String[] args) throws InterruptedException { + public static void main(String[] args) { LOG.info("Example2 start!"); HugeGraph graph = ExampleUtil.loadGraph(); @@ -147,7 +147,7 @@ public class Example2 { schema.propertyKey("city").asText().ifNotExist().create(); schema.propertyKey("weight").asDouble().ifNotExist().create(); schema.propertyKey("lang").asText().ifNotExist().create(); - schema.propertyKey("date").asText().ifNotExist().create(); + schema.propertyKey("date").asDate().ifNotExist().create(); schema.propertyKey("price").asInt().ifNotExist().create(); schema.vertexLabel("person") @@ -205,7 +205,7 @@ public class Example2 { schema.indexLabel("createdByDate") .onE("created") .by("date") - .secondary() + .range() .ifNotExist() .create(); @@ -238,12 +238,12 @@ public class Example2 { Vertex peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city", "Shanghai"); - marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5); - marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0); - marko.addEdge("created", lop, "date", "20171210", "weight", 0.4); - josh.addEdge("created", lop, "date", "20091111", "weight", 0.4); - josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0); - peter.addEdge("created", lop, "date", "20170324", "weight", 0.2); + marko.addEdge("knows", vadas, "date", "2016-01-10", "weight", 0.5); + marko.addEdge("knows", josh, "date", "2013-02-20", "weight", 1.0); + marko.addEdge("created", lop, "date", "2017-12-10", "weight", 0.4); + josh.addEdge("created", lop, "date", "2009-11-11", "weight", 0.4); + josh.addEdge("created", ripple, "date", "2017-12-10", "weight", 1.0); + peter.addEdge("created", lop, "date", "2017-03-24", "weight", 0.2); graph.tx().commit(); } diff --git a/hugegraph-hbase/pom.xml b/hugegraph-hbase/pom.xml index ef7bb106d..cb5501a5b 100644 --- a/hugegraph-hbase/pom.xml +++ b/hugegraph-hbase/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-mysql/pom.xml b/hugegraph-mysql/pom.xml index 47579c308..d56a0028d 100644 --- a/hugegraph-mysql/pom.xml +++ b/hugegraph-mysql/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-palo/pom.xml b/hugegraph-palo/pom.xml index 69b90ef5d..891d51d16 100644 --- a/hugegraph-palo/pom.xml +++ b/hugegraph-palo/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-postgresql/pom.xml b/hugegraph-postgresql/pom.xml index d1f88560a..d275f2936 100644 --- a/hugegraph-postgresql/pom.xml +++ b/hugegraph-postgresql/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-rocksdb/pom.xml b/hugegraph-rocksdb/pom.xml index b459dde29..b109af819 100644 --- a/hugegraph-rocksdb/pom.xml +++ b/hugegraph-rocksdb/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-scylladb/pom.xml b/hugegraph-scylladb/pom.xml index c7fb4cbd3..534a5dc7c 100644 --- a/hugegraph-scylladb/pom.xml +++ b/hugegraph-scylladb/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 diff --git a/hugegraph-test/pom.xml b/hugegraph-test/pom.xml index 39f9464dc..182bf50eb 100644 --- a/hugegraph-test/pom.xml +++ b/hugegraph-test/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.3 + 0.10.4 4.0.0 @@ -66,7 +66,7 @@ org.apache.tinkerpop gremlin-groovy-test - ${tinkerpop.version} + 3.2.11 @@ -133,6 +133,8 @@ tinkerpop-process-test + + -Dbuild.dir=${project.build.directory} ${basedir}/src/main/java/ ${basedir}/target/classes/ @@ -142,30 +144,6 @@ - - tinkerpop-structure-perf-test - - ${basedir}/src/main/java/ - - ${basedir}/target/classes/ - - - **/StructurePerformanceTest.java - - - - - tinkerpop-process-perf-test - - ${basedir}/src/main/java/ - - ${basedir}/target/classes/ - - - **/ProcessPerformanceTest.java - - - @@ -192,7 +170,7 @@ org.jacoco jacoco-maven-plugin - 0.8.3 + 0.8.4 com/baidu/hugegraph/traversal/algorithm/*.class diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java index 01bad9a70..f69da5bef 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java @@ -19,6 +19,7 @@ package com.baidu.hugegraph.core; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -753,21 +754,28 @@ public class EdgeCoreTest extends BaseCoreTest { .range(1, 6) .range(4, 8) .toList(); - // [4, 6) - Assert.assertEquals(2, edges.size()); + // [5, 6) + Assert.assertEquals(1, edges.size()); edges = graph.traversal().E() .range(1, -1) .range(6, 8) .toList(); - // [6, 8) + // [7, 9) Assert.assertEquals(2, edges.size()); edges = graph.traversal().E() .range(1, 6) .range(6, 8) .toList(); - // [6, 6) + // [7, 6) will be converted to NoneStep by EarlyLimitStrategy + Assert.assertEquals(0, edges.size()); + + edges = graph.traversal().E() + .range(1, 6) + .range(7, 8) + .toList(); + // [8, 6) will be converted to NoneStep by EarlyLimitStrategy Assert.assertEquals(0, edges.size()); } @@ -791,11 +799,6 @@ public class EdgeCoreTest extends BaseCoreTest { Assert.assertThrows(IllegalArgumentException.class, () -> { graph.traversal().E().range(-4, -2).toList(); }); - - Assert.assertThrows(IllegalArgumentException.class, () -> { - // [7, 6) - graph.traversal().E().range(1, 6).range(7, 8).toList(); - }); } @Test @@ -3869,6 +3872,32 @@ public class EdgeCoreTest extends BaseCoreTest { }); } + @Test + public void testQueryByHasIdEmptyList() { + HugeGraph graph = graph(); + GraphTraversalSource g = graph.traversal(); + + List edges = g.E().hasId(Collections.EMPTY_LIST).toList(); + Assert.assertEquals(0, edges.size()); + } + + @Test + public void testQueryByHasIdEmptyListInPage() { + Assume.assumeTrue("Not support paging", + storeFeatures().supportsQueryByPage()); + + HugeGraph graph = graph(); + GraphTraversalSource g = graph.traversal(); + + GraphTraversal iter = g.E() + .hasId(Collections.EMPTY_LIST) + .has("~page", "").limit(1); + Assert.assertEquals(0, IteratorUtils.count(iter)); + + String page = TraversalUtil.page(iter); + Assert.assertNull(page); + } + private void init18Edges() { this.init18Edges(true); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java index 971539105..eb7a037bd 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java @@ -20,6 +20,7 @@ package com.baidu.hugegraph.core; import java.math.BigDecimal; +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -996,21 +997,28 @@ public class VertexCoreTest extends BaseCoreTest { .range(1, 6) .range(4, 8) .toList(); - // [4, 6) - Assert.assertEquals(2, vertices.size()); + // [5, 6) + Assert.assertEquals(1, vertices.size()); vertices = graph.traversal().V() .range(1, -1) .range(6, 8) .toList(); - // [6, 8) + // [7, 9) Assert.assertEquals(2, vertices.size()); vertices = graph.traversal().V() .range(1, 6) .range(6, 8) .toList(); - // [6, 6) + // [7, 6) will be converted to NoneStep by EarlyLimitStrategy + Assert.assertEquals(0, vertices.size()); + + vertices = graph.traversal().V() + .range(1, 6) + .range(7, 8) + .toList(); + // [8, 6) will be converted to NoneStep by EarlyLimitStrategy Assert.assertEquals(0, vertices.size()); } @@ -1034,11 +1042,6 @@ public class VertexCoreTest extends BaseCoreTest { Assert.assertThrows(IllegalArgumentException.class, () -> { graph.traversal().V().range(-4, -2).toList(); }); - - Assert.assertThrows(IllegalArgumentException.class, () -> { - // [7, 6) - graph.traversal().V().range(1, 6).range(7, 8).toList(); - }); } @Test @@ -5549,6 +5552,32 @@ public class VertexCoreTest extends BaseCoreTest { Assert.assertEquals(0, vertices.size()); } + @Test + public void testQueryByHasIdEmptyList() { + HugeGraph graph = graph(); + GraphTraversalSource g = graph.traversal(); + + List vertices = g.V().hasId(Collections.EMPTY_LIST).toList(); + Assert.assertEquals(0, vertices.size()); + } + + @Test + public void testQueryByHasIdEmptyListInPage() { + Assume.assumeTrue("Not support paging", + storeFeatures().supportsQueryByPage()); + + HugeGraph graph = graph(); + GraphTraversalSource g = graph.traversal(); + + GraphTraversal iter = g.V() + .hasId(Collections.EMPTY_LIST) + .has("~page", "").limit(1); + Assert.assertEquals(0, IteratorUtils.count(iter)); + + String page = TraversalUtil.page(iter); + Assert.assertNull(page); + } + private void init10Vertices() { HugeGraph graph = graph(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java index aa09a293d..fa98bf595 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java @@ -19,7 +19,6 @@ package com.baidu.hugegraph.tinkerpop; -import org.apache.commons.configuration.ConfigurationException; import org.apache.tinkerpop.gremlin.AbstractGremlinSuite; import org.apache.tinkerpop.gremlin.GraphManager; import org.apache.tinkerpop.gremlin.GraphProvider; @@ -55,11 +54,11 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.FoldTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphTest; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.IndexTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.LoopsTest; -import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapKeysTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapTest; -import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapValuesTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.MathTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.MinTest; @@ -68,16 +67,17 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.PathTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProfileTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProjectTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesTest; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.UnfoldTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.ValueMapTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexTest; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.WriteTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ExplainTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GroupCountTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GroupTest; -import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GroupTestV3d0; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.InjectTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SackTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectCapTest; @@ -90,6 +90,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventS import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategyProcessTest; import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategyProcessTest; import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategyProcessTest; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.EarlyLimitStrategyProcessTest; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.IncidentToAdjacentStrategyProcessTest; import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategyProcessTest; import org.junit.runners.model.InitializationError; import org.junit.runners.model.RunnerBuilder; @@ -102,7 +104,6 @@ import com.baidu.hugegraph.dist.RegisterUtil; * * @author Stephen Mallette (http://stephen.genoprime.com) */ -@SuppressWarnings("deprecation") public class ProcessBasicSuite extends AbstractGremlinSuite { /** * This list of tests in the suite that will be executed @@ -143,11 +144,11 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { FoldTest.Traversals.class, GraphTest.Traversals.class, LoopsTest.Traversals.class, + IndexTest.Traversals.class, MapTest.Traversals.class, - MapKeysTest.Traversals.class, - MapValuesTest.Traversals.class, MatchTest.CountMatchTraversals.class, MatchTest.GreedyMatchTraversals.class, + MathTest.Traversals.class, MaxTest.Traversals.class, MeanTest.Traversals.class, MinTest.Traversals.class, @@ -157,16 +158,17 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { ProfileTest.Traversals.class, ProjectTest.Traversals.class, PropertiesTest.Traversals.class, + ReadTest.Traversals.class, SelectTest.Traversals.class, VertexTest.Traversals.class, UnfoldTest.Traversals.class, ValueMapTest.Traversals.class, + WriteTest.Traversals.class, // sideEffect AggregateTest.Traversals.class, ExplainTest.Traversals.class, GroupTest.Traversals.class, - GroupTestV3d0.Traversals.class, GroupCountTest.Traversals.class, InjectTest.Traversals.class, SackTest.Traversals.class, @@ -189,7 +191,11 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { EventStrategyProcessTest.class, ReadOnlyStrategyProcessTest.class, PartitionStrategyProcessTest.class, - SubgraphStrategyProcessTest.class + SubgraphStrategyProcessTest.class, + + // optimizations + IncidentToAdjacentStrategyProcessTest.class, + EarlyLimitStrategyProcessTest.class }; /** @@ -230,10 +236,10 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { FlatMapTest.class, FoldTest.class, LoopsTest.class, + IndexTest.class, MapTest.class, - MapKeysTest.class, - MapValuesTest.class, MatchTest.class, + MathTest.class, MaxTest.class, MeanTest.class, MinTest.class, @@ -258,13 +264,12 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { SideEffectTest.class, StoreTest.class, SubgraphTest.class, - TreeTest.class, + TreeTest.class }; public ProcessBasicSuite(final Class klass, final RunnerBuilder builder) - throws InitializationError, - ConfigurationException { + throws InitializationError { super(klass, builder, allTests, testsToEnforce, true, TraversalEngine.Type.STANDARD); RegisterUtil.registerBackends(); @@ -273,8 +278,7 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { public ProcessBasicSuite(final Class klass, final RunnerBuilder builder, final Class[] testsToExecute) - throws InitializationError, - ConfigurationException { + throws InitializationError { super(klass, builder, testsToExecute, testsToEnforce, true, TraversalEngine.Type.STANDARD); RegisterUtil.registerBackends(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceSuite.java deleted file mode 100644 index a1433bb4a..000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceSuite.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.tinkerpop; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.tinkerpop.gremlin.AbstractGremlinSuite; -import org.apache.tinkerpop.gremlin.GraphManager; -import org.apache.tinkerpop.gremlin.GraphProvider; -import org.apache.tinkerpop.gremlin.process.TraversalPerformanceTest; -import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.RunnerBuilder; -import org.junit.runners.model.Statement; - -import com.baidu.hugegraph.dist.RegisterUtil; - -/** - * The {@code ProcessPerformanceSuite} is a JUnit test runner that executes the - * Gremlin Test Suite over a Graph implementation. This suite contains - * "long-run" tests that produce reports on the traversal execution - * performance of a vendor implementation {@link Graph}. Its usage is optional - * to providers as the tests are somewhat redundant to those found elsewhere - * in other required test suites. - * For more information on the usage of this suite, - * please see {@link StructureStandardSuite}. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.0-incubating, replaced by gremlin-benchmark. - */ -@Deprecated -public class ProcessPerformanceSuite extends AbstractGremlinSuite { - - /** - * This list of tests in the suite that will be executed. - * Gremlin developers should add to this list - * as needed to enforce tests upon implementations. - */ - private static final Class[] allTests = new Class[]{ - TraversalPerformanceTest.class - }; - - public ProcessPerformanceSuite(final Class klass, - final RunnerBuilder builder) - throws InitializationError, - ConfigurationException { - super(klass, builder, allTests, null, true, - TraversalEngine.Type.STANDARD); - RegisterUtil.registerBackends(); - } - - @Override - protected Statement withAfterClasses(final Statement statement) { - Statement wrappedStatement = new Statement() { - @Override - public void evaluate() throws Throwable { - statement.evaluate(); - GraphProvider gp = GraphManager.setGraphProvider(null); - ((TestGraphProvider) gp).clear(); - GraphManager.setGraphProvider(gp); - } - }; - return super.withAfterClasses(wrappedStatement); - } -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceTest.java deleted file mode 100644 index 291f44cc0..000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessPerformanceTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.tinkerpop; - -import org.apache.tinkerpop.gremlin.GraphProviderClass; -import org.junit.runner.RunWith; - -@RunWith(ProcessPerformanceSuite.class) -@GraphProviderClass(provider = ProcessTestGraphProvider.class, - graph = TestGraph.class) -@SuppressWarnings("deprecation") -public class ProcessPerformanceTest { -} - diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceSuite.java deleted file mode 100644 index 2cafd5618..000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceSuite.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.tinkerpop; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.tinkerpop.gremlin.AbstractGremlinSuite; -import org.apache.tinkerpop.gremlin.GraphManager; -import org.apache.tinkerpop.gremlin.GraphProvider; -import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.GraphReadPerformanceTest; -import org.apache.tinkerpop.gremlin.structure.GraphWritePerformanceTest; -import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.RunnerBuilder; -import org.junit.runners.model.Statement; - -import com.baidu.hugegraph.dist.RegisterUtil; - -/** - * The {@code StructurePerformanceSuite} is a JUnit test runner that executes - * the Gremlin Test Suite over a {@link Graph} implementation. This suite - * contains "long-run" tests that produce reports on the read/write - * performance of a providers implementation {@link Graph}. Its usage is - * optional to providers as the tests are somewhat redundant to those found - * elsewhere in other required test suites. - * For more information on the usage of this suite, - * please see {@link StructureStandardSuite}. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.1, replaced by gremlin-benchmark. - */ -@Deprecated -public class StructurePerformanceSuite extends AbstractGremlinSuite { - - /** - * This list of tests in the suite that will be executed. - * Gremlin developers should add to this list - * as needed to enforce tests upon implementations. - */ - private static final Class[] allTests = new Class[]{ - GraphWritePerformanceTest.class, - GraphReadPerformanceTest.class - }; - - public StructurePerformanceSuite(final Class klass, - final RunnerBuilder builder) - throws InitializationError, - ConfigurationException { - super(klass, builder, allTests, null, true, - TraversalEngine.Type.STANDARD); - RegisterUtil.registerBackends(); - } - - @Override - protected Statement withAfterClasses(final Statement statement) { - Statement wrappedStatement = new Statement() { - @Override - public void evaluate() throws Throwable { - statement.evaluate(); - GraphProvider gp = GraphManager.setGraphProvider(null); - ((TestGraphProvider) gp).clear(); - GraphManager.setGraphProvider(gp); - } - }; - return super.withAfterClasses(wrappedStatement); - } -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceTest.java deleted file mode 100644 index 7f3bebb58..000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructurePerformanceTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.tinkerpop; - -import org.apache.tinkerpop.gremlin.GraphProviderClass; -import org.junit.runner.RunWith; - -@RunWith(StructurePerformanceSuite.class) -@GraphProviderClass(provider = StructureTestGraphProvider.class, - graph = TestGraph.class) -@SuppressWarnings("deprecation") -public class StructurePerformanceTest { -} \ No newline at end of file diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java index d2ba44634..3d1535c36 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java @@ -36,6 +36,7 @@ import org.apache.tinkerpop.gremlin.structure.io.Io; import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.io.HugeGraphIoRegistry; +import com.baidu.hugegraph.io.HugeGraphSONModule; import com.baidu.hugegraph.perf.PerfUtil.Watched; import com.baidu.hugegraph.schema.PropertyKey; import com.baidu.hugegraph.schema.SchemaManager; @@ -231,6 +232,7 @@ public class TestGraph implements Graph { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public I io(final Io.Builder builder) { + HugeGraphSONModule.OPTIMIZE_SERIALIZE = false; return (I) builder.graph(this).onMapper(mapper -> mapper.addRegistry(HugeGraphIoRegistry.instance()) ).create(); @@ -322,6 +324,10 @@ public class TestGraph implements Graph { case "String": schema.propertyKey(key).ifNotExist().create(); break; + case "BooleanArray": + schema.propertyKey(key).asBoolean().valueList() + .ifNotExist().create(); + break; case "IntegerArray": schema.propertyKey(key).asInt().valueList() .ifNotExist().create(); @@ -352,7 +358,6 @@ public class TestGraph implements Graph { throw new RuntimeException( String.format("Wrong type %s for %s", type, key)); } - } @Watched @@ -430,12 +435,15 @@ public class TestGraph implements Graph { schema.propertyKey("marko").ifNotExist().create(); schema.propertyKey("ripple").ifNotExist().create(); schema.propertyKey("lop").ifNotExist().create(); + schema.propertyKey("test").ifNotExist().create(); switch (idStrategy) { case AUTOMATIC: + schema.vertexLabel("name") + .ifNotExist().create(); schema.vertexLabel("person") - .properties("name", "age") - .nullableKeys("name", "age") + .properties("name", "age", "test") + .nullableKeys("name", "age", "test") .ifNotExist().create(); schema.vertexLabel("software") .properties("name", "lang", "temp") @@ -567,6 +575,8 @@ public class TestGraph implements Graph { .nullableKeys("weight") .ifNotExist().create(); + schema.indexLabel("vertexByName").onV("vertex").by("name").secondary() + .ifNotExist().create(); schema.indexLabel("vertexByAge").onV("vertex").by("age").range() .ifNotExist().create(); } @@ -597,6 +607,12 @@ public class TestGraph implements Graph { schema.propertyKey("double").asDouble().ifNotExist().create(); schema.propertyKey("string").ifNotExist().create(); schema.propertyKey("integer").asInt().ifNotExist().create(); + /* + * The method shouldHaveStandardStringRepresentationForEdgeProperty() + * in PropertyTest$BasicPropertyTest need 'short' property with + * datatype String + */ + schema.propertyKey("short").asText().ifNotExist().create(); schema.propertyKey("long").asLong().ifNotExist().create(); schema.propertyKey("x").asInt().ifNotExist().create(); schema.propertyKey("y").asInt().ifNotExist().create(); @@ -651,6 +667,7 @@ public class TestGraph implements Graph { private void initBasicVertexLabelV(IdStrategy idStrategy, String defaultVL) { SchemaManager schema = this.graph.schema(); + switch (idStrategy) { case CUSTOMIZE_STRING: this.isLastIdCustomized = true; @@ -718,21 +735,29 @@ public class TestGraph implements Graph { SchemaManager schema = this.graph.schema(); schema.vertexLabel("person") - .properties("name") - .nullableKeys("name") + .properties("name", "age") + .nullableKeys("name", "age") + .ifNotExist().create(); + schema.vertexLabel("software") + .properties("name", "lang") + .nullableKeys("name", "lang") .ifNotExist().create(); schema.vertexLabel("thing") .properties("here") .nullableKeys("here") .ifNotExist().create(); + schema.vertexLabel("blah") + .properties("test") + .nullableKeys("test") + .ifNotExist().create(); schema.edgeLabel("self").link(defaultVL, defaultVL) .properties("__id", "test", "name", "some", "acl", "weight", "here", "to-change", "dropped", "not-dropped", "new", - "to-drop") + "to-drop", "short", "long") .nullableKeys("__id", "test", "name", "some", "acl", "weight", "here", "to-change", "dropped", "not-dropped", - "new", "to-drop") + "new", "to-drop", "short", "long") .ifNotExist().create(); schema.edgeLabel("aTOa").link(defaultVL, defaultVL) .properties("gremlin.partitionGraphStrategy.partition") @@ -754,15 +779,9 @@ public class TestGraph implements Graph { .properties("gremlin.partitionGraphStrategy.partition", "every") .nullableKeys("gremlin.partitionGraphStrategy.partition", "every") .ifNotExist().create(); - schema.edgeLabel("knows").link(defaultVL, defaultVL) - .properties("data", "test", "year", "boolean", "float", - "double", "string", "integer", "long", "weight", - "myEdgeId", "since", "acl", "stars", "aKey", - "gremlin.partitionGraphStrategy.partition") - .nullableKeys("data", "test", "year", "boolean", "float", - "double", "string", "integer", "long", "weight", - "myEdgeId", "since", "acl", "stars", "aKey", - "gremlin.partitionGraphStrategy.partition") + schema.edgeLabel("relatesTo").link(defaultVL, defaultVL) + .properties("gremlin.partitionGraphStrategy.partition", "every") + .nullableKeys("gremlin.partitionGraphStrategy.partition", "every") .ifNotExist().create(); schema.edgeLabel("test").link(defaultVL, defaultVL) .properties("test", "xxx", "yyy") @@ -812,10 +831,6 @@ public class TestGraph implements Graph { .properties("weight") .nullableKeys("weight") .ifNotExist().create(); - schema.edgeLabel("created").link(defaultVL, defaultVL) - .properties("weight") - .nullableKeys("weight") - .ifNotExist().create(); schema.edgeLabel("next").link(defaultVL, defaultVL) .ifNotExist().create(); @@ -842,4 +857,67 @@ public class TestGraph implements Graph { .by("gremlin.partitionGraphStrategy.partition") .ifNotExist().create(); } + + public void initEdgeLabelDefaultKnowsDefault(String defaultVL) { + SchemaManager schema = this.graph.schema(); + schema.edgeLabel("knows").link(defaultVL, defaultVL) + .properties("data", "test", "year", "boolean", "float", + "double", "string", "integer", "long", "weight", + "myEdgeId", "since", "acl", "stars", "aKey", + "gremlin.partitionGraphStrategy.partition", "color") + .nullableKeys("data", "test", "year", "boolean", "float", + "double", "string", "integer", "long", "weight", + "myEdgeId", "since", "acl", "stars", "aKey", + "gremlin.partitionGraphStrategy.partition", "color") + .ifNotExist().create(); + } + + public void initEdgeLabelDefaultCreatedDefault(String defaultVL) { + SchemaManager schema = this.graph.schema(); + schema.edgeLabel("created").link(defaultVL, defaultVL) + .properties("weight", "color") + .nullableKeys("weight", "color") + .ifNotExist().create(); + } + + public void initEdgeLabelPersonKnowsPerson() { + SchemaManager schema = this.graph.schema(); + schema.edgeLabel("knows").link("person", "person") + .properties("weight") + .nullableKeys("weight") + .ifNotExist().create(); + } + + public void initEdgeLabelPersonCreatedSoftware() { + SchemaManager schema = this.graph.schema(); + schema.edgeLabel("created").link("person", "software") + .properties("weight") + .nullableKeys("weight") + .ifNotExist().create(); + } + + public void initSinkSchema() { + SchemaManager schema = this.graph.schema(); + + schema.propertyKey("name").ifNotExist().create(); + + schema.vertexLabel("message") + .properties("name") + .nullableKeys("name") + .ifNotExist().create(); + + schema.vertexLabel("loops") + .properties("name") + .nullableKeys("name") + .ifNotExist().create(); + + schema.edgeLabel("link").link("message", "message") + .ifNotExist().create(); + schema.edgeLabel("self").link("loops", "loops") + .ifNotExist().create(); + + schema.indexLabel("loopsByName").onV("loops") + .secondary().by("name") + .ifNotExist().create(); + } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraphProvider.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraphProvider.java index 2b5ee41b6..23c1677ac 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraphProvider.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraphProvider.java @@ -283,8 +283,23 @@ public class TestGraphProvider extends AbstractGraphProvider { testGraph.initPropertyKey("aKey", aKeyType); } + if (testMethod.equals( + "shouldHaveTruncatedStringRepresentationForEdgeProperty")) { + testGraph.initPropertyKey("long", "String"); + } else { + testGraph.initPropertyKey("long", "Long"); + } + // Basic schema is initiated by default once a graph is open testGraph.initBasicSchema(idStrategy(config), TestGraph.DEFAULT_VL); + if (testClass.getName().equals( + "org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest$Traversals")) { + testGraph.initEdgeLabelPersonKnowsPerson(); + testGraph.initEdgeLabelPersonCreatedSoftware(); + } else { + testGraph.initEdgeLabelDefaultKnowsDefault(TestGraph.DEFAULT_VL); + testGraph.initEdgeLabelDefaultCreatedDefault(TestGraph.DEFAULT_VL); + } testGraph.tx().commit(); testGraph.loadedGraph(getIoType(testClass, testMethod)); @@ -392,12 +407,16 @@ public class TestGraphProvider extends AbstractGraphProvider { break; case CREW: break; + case SINK: + testGraph.initSinkSchema(); + break; default: throw new AssertionError(String.format( "Only support GRATEFUL, MODERN and CLASSIC " + "for @LoadGraphWith(), but '%s' is used ", loadGraphWith)); } + LOG.debug("Load graph with {} schema", loadGraphWith); testGraph.tx().commit(); } diff --git a/hugegraph-test/src/main/resources/fast-methods.filter b/hugegraph-test/src/main/resources/fast-methods.filter index 5053265b8..a93c26524 100644 --- a/hugegraph-test/src/main/resources/fast-methods.filter +++ b/hugegraph-test/src/main/resources/fast-methods.filter @@ -127,6 +127,28 @@ org.apache.tinkerpop.gremlin.process.traversal.step.ComplexTest.Traversals.class org.apache.tinkerpop.gremlin.process.traversal.step.ComplexTest.Traversals.playlistPaths: long time org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TreeTest.Traversals.g_V_out_out_treeXaX_capXaX: long time +# Unsupported query +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasIdXwithoutXemptyXX_count: Unsupported query 'NOT IN []' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasIdXemptyX_count: Unsupported query 'hasId(EmptyList)' + +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_containingXarkXX: Unsupported predicate 'containing(ark)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_endingWithXasXX: Unsupported predicate 'endingWith(as)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_startingWithXmarXX: Unsupported predicate 'startingWith(mar)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXage_withoutX27X_count: Unsupported relation 'NEQ' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXperson_name_containingXoX_andXltXmXXX: Unsupported predicate 'containing(o)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_startingWithXmarXX: Unsupported predicate 'notStartingWith(mar)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_containingXarkXX: Unsupported predicate 'notContaining(ark)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_endingWithXasXX: Unsupported predicate 'notEndingWith(as)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXage_withoutX27_29X_count: Unsupported relation 'NEQ' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_gtXmX_andXcontainingXoXXX: Unsupported predicate 'containing(o)' + +# Unsupport edge label 'created': 'software' -> 'person', has existed an edgelabel (created: person -> software) in this case +org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeTest.Traversals.g_V_hasXname_markoX_asXaX_outEXcreatedX_asXbX_inV_addEXselectXbX_labelX_toXaX: Unsupport edge from inV to outV + +# Can't customize vertex id when id strategy is 'AUTOMATIC': Firstly add vertex without id(id strategy is 'AUTOMATIC'), then write it into file, at last read file, call add vertex with id +org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest.Traversals.g_io_read_withXreader_graphmlX: Can't customize vertex id when id strategy is 'AUTOMATIC' +org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest.Traversals.g_io_readXxmlX: Can't customize vertex id when id strategy is 'AUTOMATIC' + #################### structure performance suite #################### org.apache.tinkerpop.gremlin.structure.GraphWritePerformanceTest.WriteToGraph.writeEmptyVertices: Vertices number exceeds 65536, can not delete by vertex label after tests diff --git a/hugegraph-test/src/main/resources/methods.filter b/hugegraph-test/src/main/resources/methods.filter index b9597433a..e732a6de3 100644 --- a/hugegraph-test/src/main/resources/methods.filter +++ b/hugegraph-test/src/main/resources/methods.filter @@ -91,6 +91,28 @@ org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexTest.Traversals org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexTest.Traversals.g_addVXanimalX_propertyXname_mateoX_propertyXname_gateoX_propertyXname_cateoX_propertyXage_5X: Expect multi properties after setting single property multi times org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexTest.Traversals.g_V_addVXanimalX_propertyXname_valuesXnameXX_propertyXname_an_animalX_propertyXvaluesXnameX_labelX: Expect multi properties after setting single property multi times +# unsupported predicate +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasIdXwithoutXemptyXX_count: Unsupported query 'NOT IN []' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasIdXemptyX_count: Unsupported query 'hasId(EmptyList)' + +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_containingXarkXX: Unsupported predicate 'containing(ark)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_endingWithXasXX: Unsupported predicate 'endingWith(as)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_startingWithXmarXX: Unsupported predicate 'startingWith(mar)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXage_withoutX27X_count: Unsupported relation 'NEQ' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXperson_name_containingXoX_andXltXmXXX: Unsupported predicate 'containing(o)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_startingWithXmarXX: Unsupported predicate 'notStartingWith(mar)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_containingXarkXX: Unsupported predicate 'notContaining(ark)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_endingWithXasXX: Unsupported predicate 'notEndingWith(as)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXage_withoutX27_29X_count: Unsupported relation 'NEQ' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_gtXmX_andXcontainingXoXXX: Unsupported predicate 'containing(o)' + +# Unsupport edge label 'created': 'software' -> 'person', has existed an edgelabel (created: person -> software) in this case +org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeTest.Traversals.g_V_hasXname_markoX_asXaX_outEXcreatedX_asXbX_inV_addEXselectXbX_labelX_toXaX: Unsupport edge from inV to outV + +# Can't customize vertex id when id strategy is 'AUTOMATIC': Firstly add vertex without id(id strategy is 'AUTOMATIC'), then write it into file, at last read file, call add vertex with id +org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest.Traversals.g_io_read_withXreader_graphmlX: Can't customize vertex id when id strategy is 'AUTOMATIC' +org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest.Traversals.g_io_readXxmlX: Can't customize vertex id when id strategy is 'AUTOMATIC' + #################### structure performance suite #################### org.apache.tinkerpop.gremlin.structure.GraphWritePerformanceTest.WriteToGraph.writeEmptyVertices: Vertices number exceeds 65536, can not delete by vertex label after tests diff --git a/pom.xml b/pom.xml index 9b90e1af6..01e99ecea 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.baidu.hugegraph hugegraph - 0.10.3 + 0.10.4 pom 3.3.9 @@ -98,7 +98,7 @@ 1.2.17 2.8.2 4.12 - 3.2.5 + 3.4.3 2.4 19.0 4.5.2 @@ -205,7 +205,7 @@ org.apache.tinkerpop gremlin-groovy-test - ${tinkerpop.version} + 3.2.11 org.apache.tinkerpop @@ -456,48 +456,6 @@ - - tinkerpop-structure-perf-test - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - - tinkerpop-structure-perf-test - - test - - test - - - - - - - - tinkerpop-process-perf-test - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - - tinkerpop-process-perf-test - - test - - test - - - - - - release