Skip to content

IF function does not work #564

Closed
Closed

Description

@gramian

ArcadeDB Version: v22.9.1 (build d082adc/1664822987697/main)

JDK Version: openjdk 11.0.16 2022-07-19

OS: Ubuntu 20.04

I tried to test some properties of comparison operators and ran into a series problems which I could be related. I bundled these three issues as they are likely related.

Expected behavior

  1. true
  2. true
  3. true

Actual behavior

1.Cannot execute command Encountered " <SELECT> "SELECT "" at line 1, column 1. Was expecting one of: <WHILE> ... <IF> ... <FOREACH> ... ";" ...

Trace
<ArcadeDB_0> Error on command execution (PostCommandHandler)
com.arcadedb.exception.CommandSQLParsingException: com.arcadedb.query.sql.parser.ParseException: Encountered " <SELECT> "SELECT "" at line 1, column 1.
Was expecting one of:
    <WHILE> ...
    <IF> ...
    <FOREACH> ...
    ";" ...
    
	at com.arcadedb.query.sql.executor.SQLEngine.parseScript(SQLEngine.java:110)
	at com.arcadedb.query.sql.executor.SQLEngine.parseScript(SQLEngine.java:102)
	at com.arcadedb.database.EmbeddedDatabase.execute(EmbeddedDatabase.java:1243)
	at com.arcadedb.server.ServerDatabase.execute(ServerDatabase.java:415)
	at com.arcadedb.server.http.handler.PostCommandHandler.executeScript(PostCommandHandler.java:100)
	at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:71)
	at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:85)
	at com.arcadedb.server.http.handler.AbstractHandler.handleRequest(AbstractHandler.java:111)
	at io.undertow.server.RoutingHandler.handleRequest(RoutingHandler.java:93)
	at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:104)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
	at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:256)
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136)
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:59)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
Caused by: com.arcadedb.query.sql.parser.ParseException: Encountered " <SELECT> "SELECT "" at line 1, column 1.
Was expecting one of:
    <WHILE> ...
    <IF> ...
    <FOREACH> ...
    ";" ...
  1. Cannot execute command Encountered " <SELECT> "SELECT "" at line 1, column 1. Was expecting one of: <WHILE> ... <IF> ... <FOREACH> ... ";" ...
Trace
<ArcadeDB_0> Error on command execution (PostCommandHandler)
com.arcadedb.exception.CommandSQLParsingException: com.arcadedb.query.sql.parser.ParseException: Encountered " <SELECT> "SELECT "" at line 1, column 1.
Was expecting one of:
    <WHILE> ...
    <IF> ...
    <FOREACH> ...
    ";" ...
    
	at com.arcadedb.query.sql.executor.SQLEngine.parseScript(SQLEngine.java:110)
	at com.arcadedb.query.sql.executor.SQLEngine.parseScript(SQLEngine.java:102)
	at com.arcadedb.database.EmbeddedDatabase.execute(EmbeddedDatabase.java:1243)
	at com.arcadedb.server.ServerDatabase.execute(ServerDatabase.java:415)
	at com.arcadedb.server.http.handler.PostCommandHandler.executeScript(PostCommandHandler.java:100)
	at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:71)
	at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:85)
	at com.arcadedb.server.http.handler.AbstractHandler.handleRequest(AbstractHandler.java:111)
	at io.undertow.server.RoutingHandler.handleRequest(RoutingHandler.java:93)
	at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:104)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
	at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:256)
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136)
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:59)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
Caused by: com.arcadedb.query.sql.parser.ParseException: Encountered " <SELECT> "SELECT "" at line 1, column 1.
Was expecting one of:
    <WHILE> ...
    <IF> ...
    <FOREACH> ...
    ";" ...
  1. Cannot execute command Unknown function name :eval see Unknown function eval() #563
Trace
<ArcadeDB_0> Error on command execution (PostCommandHandler)
com.arcadedb.exception.CommandExecutionException: Unknown function name :eval

Steps to reproduce

  1. SELECT 1 = 1;
  2. SELECT if(1 = 1, true, false);
  3. SELECT if(eval('1 = 1'), true, false);

Activity

  1. lvca commented on Oct 13, 2022

    @lvca
    Member

    Removed eval() from the docs following #563

  2. self-assigned this
    on Oct 13, 2022
  3. added
    documentation
    on Oct 13, 2022
  4. added this to the 22.10.1 milestone on Oct 13, 2022
  5. gramian commented on Oct 13, 2022

    @gramian
    CollaboratorAuthor

    @lvca Please reopen. Comparisons in projections still don't work, particularly if eval() is removed.

  6. gramian commented on Oct 13, 2022

    @gramian
    CollaboratorAuthor

    @lvca There is one thing I should probably add to this issue:
    The whole reason I started testing comparisons in projections, was that I wanted to probe the result of:

    SELECT NULL = NULL;
    

    to see whether equal comparisons are NULL-safe.

  7. reopened this on Oct 13, 2022
  8. lvca commented on Oct 13, 2022

    @lvca
    Member

    I'm guessing the = operator is not fully supported in our SQL grammar. Any idea @antarcticgiraffe?

  9. gramian commented on Oct 14, 2022

    @gramian
    CollaboratorAuthor

    Also, on this issue: the example for if() is not working as the condition is just a (falsy) string (now).

  10. modified the milestones: 22.10.1, 22.11.1 on Oct 24, 2022
  11. gramian commented on Nov 9, 2022

    @gramian
    CollaboratorAuthor

    Adding to this, I saw in the grammar, that either = and == are valid tokens. So, if both equality operator are valid, == should be added to the docu (I can do this); and is there a preferred way?

  12. lvca commented on Nov 9, 2022

    @lvca
    Member

    Correct, OrientDB had it, so we inherited it. Thanks in advance if you want to improve the docs on this!

  13. modified the milestones: 22.11.1, 22.12.1 on Dec 7, 2022
  14. modified the milestones: 22.12.1, 23.1.1 on Dec 23, 2022
  15. modified the milestones: 23.1.1, 23.1.2 on Jan 16, 2023
  16. lvca commented on Feb 1, 2023

    @lvca
    Member

    Reproduced, the IF doesn't work at all.

  17. lvca commented on Feb 1, 2023

    @lvca
    Member

    I'd also like to import the eval() function from OrientDB. it can still be useful...

  18. lvca commented on Feb 1, 2023

    @lvca
    Member

    Fixed.

  19. changed the title [-]SQL Comparison in Projections[/-] [+]IF function does not work[/+] on Feb 1, 2023
  20. gramian commented on Feb 1, 2023

    @gramian
    CollaboratorAuthor

    @lvca Cool, also the original problem, comparison in projections, work now. However, all comparison expressions need to be enclosed in parentheses, also inside the if. I think I will add some examples for this to the docu.

  21. lvca commented on Feb 1, 2023

    @lvca
    Member

    Yes, using parenthesis is the only way to let the parser understand it's a condition, otherwise, now we have the eval() in case you want to just use text, or the condition is a property of a record and must be evaluated at run-time. This is useful especially for custom permissions or rules

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

Metadata

Metadata

Assignees

Labels

documentation

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions