Skip to content

openCypher: a parenthesized true or false in WHERE is read as a node pattern, so WITH 1 AS x WHERE (true) RETURN x returns no rows, and MATCH ... WHERE ... AND (true) fails to parse #8994

Closed

Description

@tae898

In a WHERE clause, (true) is parsed as the single-node pattern (true), not as the boolean literal in parentheses. After WITH, that pattern predicate never matches, so WHERE (true) removes every row and WHERE NOT (true) keeps every row. After MATCH, the same text is rejected with InvalidArgumentType: Single node pattern is not a valid predicate in WHERE (from the check in CypherSemanticValidator). The same literal without parentheses works (WITH 1 AS x WHERE true RETURN x returns [1]), and so does RETURN (true) AS x.

Neo4j 2026.08.1 returns, for the seven queries in order: [1], [], [1], [2, 3], [2, 3], [2, 3], and [1].

Repro

javac -cp 'lib/*' -d cls ParenthesizedLiteral.java
java -Xmx8g -XX:+UseCompactObjectHeaders --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp 'lib/*:cls' ParenthesizedLiteral /tmp/ParenthesizedLiteral-db

lib/ holds the engine jar and its dependencies. On Temurin 21, use the same command without -XX:+UseCompactObjectHeaders.

import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.query.sql.executor.ResultSet;

import java.util.ArrayList;
import java.util.List;

public class ParenthesizedLiteral {
  public static void main(String[] args) {
    Database db = fresh(args[0]);
    System.out.println("ArcadeDB " + com.arcadedb.Constants.getRawVersion() + " (" + com.arcadedb.Constants.getBuildNumber() + "), Java "
        + System.getProperty("java.version"));
    db.transaction(() -> db.command("opencypher", "CREATE (:N {id: 1}), (:N {id: 2}), (:N {id: 3})"));

    String[] queries = {
        "WITH 1 AS x WHERE (true) RETURN x",
        "WITH 1 AS x WHERE NOT (true) RETURN x",
        "WITH 1 AS x WHERE NOT (false) RETURN x",
        "MATCH (n:N) WITH n WHERE n.id > 1 AND (true) RETURN n.id AS id ORDER BY id",
        "MATCH (n:N) WITH n WHERE n.id > 1 AND true RETURN n.id AS id ORDER BY id",
        "MATCH (n:N) WHERE n.id > 1 AND (true) RETURN n.id AS id ORDER BY id",
        "MATCH (n:N) WHERE (n.id = 1) OR (false) RETURN n.id AS id ORDER BY id" };
    for (String q : queries)
      System.out.println(q + "  ->  " + rows(db, q));
    db.close();
  }

  static String rows(Database db, String q) {
    List<String> out = new ArrayList<>();
    try (ResultSet rs = db.query("opencypher", q)) {
      rs.stream().forEach(r -> out.add(r.toJSON().toString()));
    } catch (Exception e) {
      return e.getClass().getSimpleName() + ": " + e.getMessage();
    }
    return out.toString();
  }

  static Database fresh(String path) {
    DatabaseFactory factory = new DatabaseFactory(path);
    if (factory.exists())
      factory.open().drop();
    return factory.create();
  }
}

Output on main at cecb369df9 (2026-10-03), embedded, on Temurin 25 with compact object headers (the engine jar's build stamp names 04bb03ebec, the newest commit in cecb369df9 that is not a merge). Temurin 21 prints the same lines apart from the Java version on the first line.

ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
WITH 1 AS x WHERE (true) RETURN x  ->  []
WITH 1 AS x WHERE NOT (true) RETURN x  ->  [{"x":1}]
WITH 1 AS x WHERE NOT (false) RETURN x  ->  [{"x":1}]
MATCH (n:N) WITH n WHERE n.id > 1 AND (true) RETURN n.id AS id ORDER BY id  ->  []
MATCH (n:N) WITH n WHERE n.id > 1 AND true RETURN n.id AS id ORDER BY id  ->  [{"id":2}, {"id":3}]
MATCH (n:N) WHERE n.id > 1 AND (true) RETURN n.id AS id ORDER BY id  ->  CommandParsingException: InvalidArgumentType: Single node pattern is not a valid predicate in WHERE
MATCH (n:N) WHERE (n.id = 1) OR (false) RETURN n.id AS id ORDER BY id  ->  CommandParsingException: InvalidArgumentType: Single node pattern is not a valid predicate in WHERE

Versions affected: main cecb369df9, main 66541f57d9 (2026-10-02), main 417314c18 (2026-09-17), and 26.9.1 print the same lines, on Temurin 25 and Temurin 21.

Expected: a parenthesized literal is the literal: the seven queries return [{"x":1}], [], [{"x":1}], [{"id":2}, {"id":3}], [{"id":2}, {"id":3}], [{"id":2}, {"id":3}], and [{"id":1}].

Activity

  1. added
    severity:minor
    on Oct 3, 2026
  2. added this to the 26.10.1 milestone on Oct 3, 2026
  3. added
    in progress
    on Oct 4, 2026
  4. self-assigned this
    on Oct 4, 2026
  5. removed
    in progress
    on Oct 4, 2026
  6. lvca commented on Oct 4, 2026

    @lvca
    Member

    Confirmed and fixed in #9158 (26.10.1). A parenthesized true, false or null in WHERE is now the literal, not a node pattern. All seven queries return the Neo4j results.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. tae898 commented on Oct 4, 2026

    @tae898
    ContributorAuthor

    Verified the #9158 merge eba27561b8 on upstream main with the issue's reproduction, unchanged, against 0bb737d458, main before the PR (the two merges in between, #9163 and #9118, change other code), on Temurin 25 with -XX:+UseCompactObjectHeaders and on Temurin 21. All seven queries now return Neo4j 2026.08.1's rows, on both JDKs:

    query Neo4j 0bb737d458 JDK 25 0bb737d458 JDK 21 eba27561b8 JDK 25 eba27561b8 JDK 21
    WITH 1 AS x WHERE (true) RETURN x [1] [] [] [1] [1]
    WITH 1 AS x WHERE NOT (true) RETURN x [] [1] [1] [] []
    WITH 1 AS x WHERE NOT (false) RETURN x [1] [1] [1] [1] [1]
    MATCH (n:N) WITH n WHERE n.id > 1 AND (true) ... [2, 3] [] [] [2, 3] [2, 3]
    MATCH (n:N) WITH n WHERE n.id > 1 AND true ... (control) [2, 3] [2, 3] [2, 3] [2, 3] [2, 3]
    MATCH (n:N) WHERE n.id > 1 AND (true) ... [2, 3] parse error parse error [2, 3] [2, 3]
    MATCH (n:N) WHERE (n.id = 1) OR (false) ... [1] parse error parse error [1] [1]

    "parse error" is CommandParsingException: InvalidArgumentType: Single node pattern is not a valid predicate in WHERE. Main at 417314c18d, named in the issue, prints the same lines as 0bb737d458 on both JDKs.

    A second check on the same three nodes plus one R relationship also matches Neo4j on both JDKs: after MATCH, WHERE (null), WHERE (TRUE), WHERE (False), WHERE n.id = 1 OR (true), and WHERE (n)-[:R]->() AND (true) now return Neo4j's rows (all were the same parse error), WITH 1 AS x WHERE ((true)) now returns [1] (was []), and WITH 1 AS x WHERE NOT (null) now returns no row (was [1]). Pattern predicates are unchanged and still right: WHERE (n)-[:R]->(), WHERE NOT (n)-[:R]->(), and WHERE (n.id > 1) return the same rows on both builds.

    On the random test graphs behind the issue, the 128 queries with a parenthesized true, false, or null inside WHERE that failed to parse on 0bb737d458 now return Neo4j's rows on both JDKs. Across all 11,316 queries of those graphs, the only answers that changed between 0bb737d458 and eba27561b8 are these and the simple CASE and string function ones fixed by the same PR (#8996, #8998); no answer that matched Neo4j before changed.

    Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugopencypherseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions