Skip to content

Commit

Permalink
Add support for SET params with array (#267)
Browse files Browse the repository at this point in the history
* Add support for SET params with array

Signed-off-by: Pavel Ershov <owner.mad.epa@gmail.com>
  • Loading branch information
mad authored and dwitry committed Apr 26, 2019
1 parent b8c3cfe commit f26e86e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.opencypher.gremlin.test.TestCommons.parameterMap;

import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -194,6 +195,10 @@ public void addPropertiesWithMapParameter() {
Map<Object, Object> props = new HashMap<>();
props.put("name1", 1);
props.put("name2", 2);
List<String> phones = new ArrayList<>();
phones.add("1");
phones.add("2");
props.put("phones", phones);

String cypher = "MATCH (n:person)" +
"SET n += {props} " +
Expand All @@ -206,7 +211,8 @@ public void addPropertiesWithMapParameter() {
.containsExactly(ImmutableMap.of(
"loc", "uk",
"name1", 1L,
"name2", 2L));
"name2", 2L,
"phones", phones));
}

@Test
Expand Down Expand Up @@ -289,7 +295,7 @@ public void copyPropertiesFromNull() {
submitAndGet("CREATE (:TO {prop1: 'x', prop3: 'y'})");

assertThatThrownBy(() -> submitAndGet("OPTIONAL MATCH (x:NOT_EXISTING) WITH x MATCH (to:TO) SET to=x RETURN to"))
.hasMessageContaining("Expected cypher.null to be Element");
.hasMessageContaining("Expected cypher.null to be Element");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ object NodeUtils {
}
}

def toListLiteral(obj: java.lang.Iterable[_]): ListLiteral = {
ListLiteral(obj.asScala.map(el => toLiteral(el)).toSeq)(InputPosition.NONE)
}

def toLiteral(obj: Any): Literal = {
obj match {
case _: java.lang.Integer | _: java.lang.Long =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ private class SetWalker[T, P](context: WalkerContext[T, P], g: GremlinSteps[T, P
case p: Parameter =>
val map = inlineExpressionValue(p, context, classOf[java.util.Map[String, _]])
map.asScala.map {
case (name, value) => (name, toLiteral(value))
case (name, value: java.lang.Iterable[_]) => (name, toListLiteral(value))
case (name, value) => (name, toLiteral(value))
}.toMap
}
}
Expand Down

0 comments on commit f26e86e

Please sign in to comment.