ArcadeData / arcadedb

ArcadeDB Multi-Model Database, one DBMS that supports SQL, Cypher, Gremlin, HTTP/JSON, MongoDB and Redis. ArcadeDB is a conceptual fork of OrientDB, the first Multi-Model DBMS. ArcadeDB supports Vector Embeddings.
https://arcadedb.com
Apache License 2.0
486 stars 60 forks source link

SQL Script: BREAK is ignored when followed by other statements #1672

Closed finduspedersen closed 2 months ago

finduspedersen commented 2 months ago

ArcadeDB Version:

24.6.1

OS and JDK Version:

Official Docker image

Expected behavior

Should immediately terminate the FOREACH loop when reaching the BREAK statement

Actual behavior

The execution continues, and BREAK is ignored as seen in this console output:

2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=Element=1} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=After IF} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=Element=2} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=Hello World} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {REMOVE=This should never be reached} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=After IF} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=Element=3} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=After IF} 2024-07-25 16:10:05 2024-07-25 14:10:05.721 INFO [ConsoleStatement] {DEBUG=END}

Steps to reproduce

If the CONSOLE.log following the BREAK statement is removed, then the BREAK statement is executed as expected and the FOREACH loop is terminated.

LET $list = [1, 2, 3];

FOREACH ($element IN $list) { CONSOLE.log map('DEBUG', 'Element=' + $element.asString());

IF ($element = 2) { CONSOLE.log map('DEBUG', 'Hello World'); BREAK; CONSOLE.log map('REMOVE', 'This should never be reached'); }

CONSOLE.log map('DEBUG', 'After IF'); }

CONSOLE.log map('DEBUG', 'END');

lvca commented 2 months ago

This is the same issue as #1673. The break doesn't really break in some cases. Working on a fix.

lvca commented 2 months ago

Fixed.