passed tp3 test suites.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/1af749f6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/1af749f6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/1af749f6 Branch: refs/heads/master Commit: 1af749f63dbdf78b5d54023e60287191691b1389 Parents: a16a58d Author: DO YUNG YOON <[email protected]> Authored: Mon Jul 17 09:59:36 2017 +0900 Committer: DO YUNG YOON <[email protected]> Committed: Mon Jul 17 09:59:36 2017 +0900 ---------------------------------------------------------------------- .../core/io/tinkerpop/optimize/S2GraphStep.java | 37 ++++++----- .../scala/org/apache/s2graph/core/S2Graph.scala | 2 +- .../s2graph/core/index/IndexProvider.scala | 66 ++++++++++++-------- .../core/tinkerpop/structure/S2GraphTest.scala | 2 +- 4 files changed, 64 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1af749f6/s2core/src/main/java/org/apache/s2graph/core/io/tinkerpop/optimize/S2GraphStep.java ---------------------------------------------------------------------- diff --git a/s2core/src/main/java/org/apache/s2graph/core/io/tinkerpop/optimize/S2GraphStep.java b/s2core/src/main/java/org/apache/s2graph/core/io/tinkerpop/optimize/S2GraphStep.java index 8107dd3..e39bdd5 100644 --- a/s2core/src/main/java/org/apache/s2graph/core/io/tinkerpop/optimize/S2GraphStep.java +++ b/s2core/src/main/java/org/apache/s2graph/core/io/tinkerpop/optimize/S2GraphStep.java @@ -18,6 +18,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep; import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer; import org.apache.tinkerpop.gremlin.structure.Element; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import java.util.*; @@ -45,6 +47,8 @@ public class S2GraphStep<S, E extends Element> extends GraphStep<S, E> { public S2GraphStep(final GraphStep<S, E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.isStartStep(), originalStep.getIds()); + if (!(traversal.asAdmin().getGraph().get() instanceof S2Graph)) return ; + foldInHasContainers(originalStep); originalStep.getLabels().forEach(this::addLabel); // 1. build S2Graph QueryParams for this step. @@ -58,22 +62,25 @@ public class S2GraphStep<S, E extends Element> extends GraphStep<S, E> { return iteratorList((Iterator)graph.vertices(this.ids)); } // full scan - - String queryString = IndexProvider$.MODULE$.buildQueryString(hasContainers); Boolean isVertex = Vertex.class.isAssignableFrom(this.returnClass); - - List<VertexId> vids = new ArrayList<>(); - List<EdgeId> eids = new ArrayList<>(); - - if (isVertex) { - List<VertexId> ids = graph.indexProvider().fetchVertexIds(queryString); - if (ids.isEmpty()) return (Iterator) graph.vertices(); - else return (Iterator) graph.vertices(ids.toArray()); - } - else { - List<EdgeId> ids = graph.indexProvider().fetchEdgeIds(queryString); - if (ids.isEmpty()) return (Iterator) graph.edges(); - else return (Iterator) graph.edges(ids.toArray()); + if (hasContainers.isEmpty()) { + return (Iterator) (isVertex ? graph.vertices() : graph.edges()); + } else { + String queryString = IndexProvider$.MODULE$.buildQueryString(hasContainers); + + List<VertexId> vids = new ArrayList<>(); + List<EdgeId> eids = new ArrayList<>(); + + if (isVertex) { + List<VertexId> ids = graph.indexProvider().fetchVertexIds(queryString); + if (ids.isEmpty()) return (Iterator) graph.vertices(); + else return (Iterator) graph.vertices(ids.toArray()); + } + else { + List<EdgeId> ids = graph.indexProvider().fetchEdgeIds(queryString); + if (ids.isEmpty()) return (Iterator) graph.edges(); + else return (Iterator) graph.edges(ids.toArray()); + } } }); } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1af749f6/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala index 8ee675d..318c092 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala @@ -738,7 +738,7 @@ object S2Graph { /* compliance */ -// new Graph.OptOut(test = "org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest", method = "*", reason = "no"), + new Graph.OptOut(test = "org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest", method = "shouldThrowExceptionWhenIdsMixed", reason = "VertexId is not Element."), // passed: all new Graph.OptOut(test = "org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest", method = "*", reason = "not supported yet."), http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1af749f6/s2core/src/main/scala/org/apache/s2graph/core/index/IndexProvider.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/index/IndexProvider.scala b/s2core/src/main/scala/org/apache/s2graph/core/index/IndexProvider.scala index 7152449..0a3ac33 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/index/IndexProvider.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/index/IndexProvider.scala @@ -4,13 +4,14 @@ import com.typesafe.config.Config import org.apache.lucene.analysis.standard.StandardAnalyzer import org.apache.lucene.document.{Document, Field, StringField, TextField} import org.apache.lucene.index.{DirectoryReader, IndexWriter, IndexWriterConfig} -import org.apache.lucene.queryparser.classic.QueryParser +import org.apache.lucene.queryparser.classic.{ParseException, QueryParser} import org.apache.lucene.search.IndexSearcher import org.apache.lucene.store.RAMDirectory import org.apache.s2graph.core.io.Conversions import org.apache.s2graph.core.{EdgeId, S2Edge, S2Vertex} import org.apache.s2graph.core.mysqls._ import org.apache.s2graph.core.types.{InnerValLike, VertexId} +import org.apache.s2graph.core.utils.logger import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer import play.api.libs.json.Json @@ -90,41 +91,54 @@ class LuceneIndexProvider(config: Config) extends IndexProvider { override def fetchEdgeIds(queryString: String): java.util.List[EdgeId] = { val field = eidField val ids = new java.util.ArrayList[EdgeId] - val q = new QueryParser(field, analyzer).parse(queryString) - val hitsPerPage = 10 - val reader = DirectoryReader.open(directory) - val searcher = new IndexSearcher(reader) - - val docs = searcher.search(q, hitsPerPage) + try { + val q = new QueryParser(field, analyzer).parse(queryString) + val hitsPerPage = 10 + val reader = DirectoryReader.open(directory) + val searcher = new IndexSearcher(reader) + + val docs = searcher.search(q, hitsPerPage) + + docs.scoreDocs.foreach { scoreDoc => + val document = searcher.doc(scoreDoc.doc) + val id = Conversions.s2EdgeIdReads.reads(Json.parse(document.get(field))).get + ids.add(id); + } - docs.scoreDocs.foreach { scoreDoc => - val document = searcher.doc(scoreDoc.doc) - val id = Conversions.s2EdgeIdReads.reads(Json.parse(document.get(field))).get - ids.add(id); + reader.close() + ids + } catch { + case ex: ParseException => + logger.error(s"[IndexProvider]: ${queryString} parse failed.", ex) + ids } - reader.close() - ids } override def fetchVertexIds(queryString: String): java.util.List[VertexId] = { val field = vidField val ids = new java.util.ArrayList[VertexId] - val q = new QueryParser(field, analyzer).parse(queryString) - val hitsPerPage = 10 - val reader = DirectoryReader.open(directory) - val searcher = new IndexSearcher(reader) - - val docs = searcher.search(q, hitsPerPage) + try { + val q = new QueryParser(field, analyzer).parse(queryString) + val hitsPerPage = 10 + val reader = DirectoryReader.open(directory) + val searcher = new IndexSearcher(reader) + + val docs = searcher.search(q, hitsPerPage) + + docs.scoreDocs.foreach { scoreDoc => + val document = searcher.doc(scoreDoc.doc) + val id = Conversions.s2VertexIdReads.reads(Json.parse(document.get(field))).get + ids.add(id) + } - docs.scoreDocs.foreach { scoreDoc => - val document = searcher.doc(scoreDoc.doc) - val id = Conversions.s2VertexIdReads.reads(Json.parse(document.get(field))).get - ids.add(id) + reader.close() + ids + } catch { + case ex: ParseException => + logger.error(s"[IndexProvider]: ${queryString} parse failed.", ex) + ids } - - reader.close() - ids } override def shutdown(): Unit = { writer.close() http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1af749f6/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala index a72b562..3fcfb2b 100644 --- a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala +++ b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala @@ -468,7 +468,7 @@ class S2GraphTest extends FunSuite with Matchers with TestCommonWithModels { val l = ls.toList println(s"[Size]: ${l.size}") println(l.toArray.toSeq.mkString("\n")) - + ls } } \ No newline at end of file
