opencypher / cypher-for-gremlin

Cypher for Gremlin adds Cypher support to any Gremlin graph database.
Apache License 2.0
359 stars 48 forks source link

Improve GroupStepFilter #329

Closed mad closed 5 years ago

mad commented 5 years ago

Currently this query can not evaluated effectively

 MATCH (p:Person) WHERE id(p) in {ids} RETURN p.name

Where {ids} is a collection of ids

Seems to small addition of GroupStepFilter might improve this case

Index: translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/GroupStepFilters.scala
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/GroupStepFilters.scala (revision 13a6ea11c13e448524afd03db288fefce875eb3d)
+++ translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/GroupStepFilters.scala (date 1572989235672)
@@ -99,6 +99,9 @@
       case ChooseT3(Seq(Constant(value)), _, _) :: Is(_) :: As(_) :: SelectK(stepLabel) :: ChooseP2(_, Seq(Id)) :: Is(_) :: WhereP(
             _: Eq) :: Nil =>
         (stepLabel, HasP(T.id.getAccessor, Eq(value))) :: Nil
+      case ChooseT3(Seq(Constant(value)), _, _) :: Is(_) :: As(_) :: SelectK(stepLabel) :: ChooseP2(_, Seq(Id)) :: Is(_) :: WhereP(
+            _: Within) :: Nil =>
+        (stepLabel, HasP(T.id.getAccessor, Within(value))) :: Nil
       case SelectK(stepLabel) :: rest if rest.forall(_.isInstanceOf[HasLabel]) =>
         rest.map((stepLabel, _))
       case _ =>
@@ -115,6 +118,9 @@
         None
       case ChooseT3(Seq(Constant(_)), _, _) :: Is(_) :: As(_) :: SelectK(alias) :: ChooseP2(_, Seq(Id)) :: Is(_) :: WhereP(
             _: Eq) :: Nil if aliases.contains(alias) =>
+        None
+      case ChooseT3(Seq(Constant(_)), _, _) :: Is(_) :: As(_) :: SelectK(alias) :: ChooseP2(_, Seq(Id)) :: Is(_) :: WhereP(
+            _: Within) :: Nil if aliases.contains(alias) =>
         None
       case SelectK(alias) :: rest if aliases.contains(alias) && rest.forall(_.isInstanceOf[HasLabel]) =>
         None
dwitry commented 5 years ago

Hello @mad,

thank you for contribution. Good improvement, I will merge this in #331.