Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypher WHERE + toLower on NULL property leads to java error instead of Cypher/Gremlin error #1562

Closed
ExtReMLapin opened this issue Apr 22, 2024 · 5 comments
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@ExtReMLapin
Copy link
Contributor

TLDR : With cypher, if you do a query like toLower on all nodes but not all of them (or not any of them) got the field inside Lower it will throw a Java error.

Not sure it should behave like that.

Just run MATCH (n) WHERE toLower(n.qsdfdfsdfsdf) CONTAINS 'anything' RETURN n on any of your DB.

ArcadeDB Version:

ArcadeDB Server v24.2.1 (build ce2658d9f43625df903d593f39604003b0512bd5/1710272406173/main)

OS and JDK Version:

Running on Linux 6.5.0-27-generic - OpenJDK 64-Bit Server VM 11.0.22

Expected behavior

No error or not a Java one at least

Actual behavior

avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]: com.arcadedb.exception.CommandParsingException: Error on executing Cypher query
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.cypher.query.CypherQueryEngine.command(CypherQueryEngine.java:80)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.database.LocalDatabase.command(LocalDatabase.java:1348)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.server.ServerDatabase.command(ServerDatabase.java:472)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.server.http.handler.PostCommandHandler.executeCommand(PostCommandHandler.java:131)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:110)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:100)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at com.arcadedb.server.http.handler.AbstractServerHttpHandler.handleRequest(AbstractServerHttpHandler.java:127)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]:         at java.base/java.lang.Thread.run(Thread.java:829)
avril 22 16:03:58 cfia-IDEXTEND server.sh[1023]: Caused by: java.lang.NullPointerException

Steps to reproduce

<add here>

Original query to execute :

MATCH (n) WHERE ('NER' IN labels(n) OR 'THEME' IN labels(n)) AND (toLower(n.identity) CONTAINS 'author' AND toLower(n.identity) CONTAINS 'reactions' AND toLower(n.identity) CONTAINS 'monsieur guillaume dureuil' AND toLower(n.identity) CONTAINS 'personality') RETURN n.identity as identity, ID(n) as id

Reduced the query to this to reproduce the error :

MATCH (n) WHERE  toLower(n.identity) CONTAINS 'author'  RETURN n

The reduced query is fixed by adding n.identity IS NOT NULL

which leads to

MATCH (n) WHERE n.identity IS NOT NULL AND toLower(n.identity) CONTAINS 'author' RETURN n

Database to toy :

mistralDB.zip

@ExtReMLapin ExtReMLapin changed the title Cypher WHERE on NULL property leads to java error instead of Cypher/Gremlin error Cypher WHERE + toLower on NULL property leads to java error instead of Cypher/Gremlin error Apr 22, 2024
@ExtReMLapin
Copy link
Contributor Author

ExtReMLapin commented Apr 22, 2024

Also gave a try with latest release, same issue

<ArcadeDB_0> Error on command execution (PostCommandHandler)
 com.arcadedb.exception.CommandParsingException: Error on executing Cypher query
         at com.arcadedb.cypher.query.CypherQueryEngine.command(CypherQueryEngine.java:80)
         at com.arcadedb.database.LocalDatabase.command(LocalDatabase.java:1348)
         at com.arcadedb.server.ServerDatabase.command(ServerDatabase.java:472)
         at com.arcadedb.server.http.handler.PostCommandHandler.executeCommand(PostCommandHandler.java:131)
         at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:110)
         at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:100)
         at com.arcadedb.server.http.handler.AbstractServerHttpHandler.handleRequest(AbstractServerHttpHandler.java:127)
         at io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
         at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
         at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
         at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
         at java.base/java.lang.Thread.run(Thread.java:829)
 Caused by: java.lang.NullPointerException
         at org.opencypher.gremlin.traversal.CustomFunctions.lambda$cypherFunction$19(CustomFunctions.java:436)
         at org.apache.tinkerpop.gremlin.process.traversal.step.map.LambdaMapStep.map(LambdaMapStep.java:42)
         at org.apache.tinkerpop.gremlin.process.traversal.step.map.ScalarMapStep.processNextStart(ScalarMapStep.java:40)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:155)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:55)
         at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:40)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:155)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:55)
         at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:40)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:155)
         at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:192)
         at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil.test(TraversalUtil.java:141)
         at org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep.filter(TraversalFilterStep.java:63)
         at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:41)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:155)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:55)
         at org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectOneStep.processNextStart(SelectOneStep.java:58)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:155)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:55)
         at org.apache.tinkerpop.gremlin.process.traversal.step.map.ScalarMapStep.processNextStart(ScalarMapStep.java:39)
         at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:155)
         at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:192)
         at com.arcadedb.gremlin.ArcadeGremlin$2.hasNext(ArcadeGremlin.java:112)
         at com.arcadedb.query.sql.executor.IteratorResultSet.hasNext(IteratorResultSet.java:37)
         at com.arcadedb.cypher.ArcadeCypher.execute(ArcadeCypher.java:75)
         at com.arcadedb.cypher.query.CypherQueryEngine.command(CypherQueryEngine.java:77)
         ... 13 more

@lvca lvca self-assigned this Apr 22, 2024
@lvca
Copy link
Contributor

lvca commented Apr 22, 2024

I see, the issue is in the open cypher's CustomFunctions class that doesn't check for nullity with arguments. Since OpenCypher's Java binding project is not active anymore, we're going to fork this class and add the fix.

It's not worth it to send a PR, because I can see the project has been dead for years...

@lvca lvca added the bug Something isn't working label Apr 22, 2024
@lvca lvca added this to the 24.5.1 milestone Apr 22, 2024
@lvca
Copy link
Contributor

lvca commented Apr 22, 2024

CustomFunctions is also final (why?!), so I've just copied the whole class as ArcadeCustomFunctions and now testing if this change breaks anything.

lvca added a commit that referenced this issue Apr 22, 2024
@lvca
Copy link
Contributor

lvca commented Apr 22, 2024

Ok, all tests pass and it's pushed on main. Please @ExtReMLapin let me know if you see any other similar issues.

@lvca lvca closed this as completed Apr 22, 2024
@lvca lvca added the fixed label Apr 22, 2024
@ExtReMLapin
Copy link
Contributor Author

Thanks for the fix @lvca there could be an underlying issue based on the original longer cypher request, opening another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants