diff --git a/src/main/java/org/neo4j/sql2cypher/Translator.java b/src/main/java/org/neo4j/sql2cypher/Translator.java index b7502cb..ab408e9 100644 --- a/src/main/java/org/neo4j/sql2cypher/Translator.java +++ b/src/main/java/org/neo4j/sql2cypher/Translator.java @@ -601,6 +601,16 @@ else if (c instanceof QOM.RowIsNull e) { else if (c instanceof QOM.RowIsNotNull e) { return e.$arg1().$fields().stream().map(f -> expression(f).isNotNull()).reduce(Condition::and).get(); } + else if (c instanceof QOM.Like like) { + Expression rhs; + if (like.$arg2() instanceof Param p && p.$inline() && p.getValue() instanceof String s) { + rhs = Cypher.literalOf(s.replace("%", ".*")); + } + else { + rhs = expression(like.$arg2()); + } + return expression(like.$arg1()).matches(rhs); + } else { throw unsupported(c); } diff --git a/src/test/resources/predicates.adoc b/src/test/resources/predicates.adoc index aeec2e4..e05b758 100644 --- a/src/test/resources/predicates.adoc +++ b/src/test/resources/predicates.adoc @@ -167,3 +167,20 @@ WHERE OR (3 IS NOT NULL AND 4 IS NOT NULL) RETURN 1 ---- + +== `LIKE` can be used + +The `LIKE` comparator can be used, too: + +[source,sql,id=t5_0,name=predicates_like] +---- +SELECT * FROM movies m WHERE m.title LIKE '%Matrix%' +---- + +will be transpiled to + +[source,cypher,id=t5_0_expected] +---- +MATCH (m:`movies`) WHERE m.title =~ '.*Matrix.*' +RETURN * +----