Closed finduspedersen closed 2 months ago
Hi,
this is odd. Here is a simpler test case:
CREATE VERTEX TYPE Dummy IF NOT EXISTS;
LET $vertices = CREATE VERTEX Dummy;
SELECT $vertices.asJSON() AS a, $vertices.asJSON() AS b;
Yes, this fails as well.
BTW: "IF NOT EXISTS" is not documented in the manual for CREATE VERTEX :-)
Note CREATE VERTEX TYPE
and CREATE VERTEX
are very different animals. The former is a DDL statement defining a type, the latter is a DML statement instantiating a type. IF NOT EXISTS
is documented under CREATE TYPE
, see https://docs.arcadedb.com/#SQL-Create-Type .
Adding a .asList() seems to circumvent the bug:
CREATE VERTEX TYPE Dummy IF NOT EXISTS;
LET $vertices = CREATE VERTEX Dummy;
LET $vertices = $vertices.asList();
SELECT $vertices.asJSON() AS a, $vertices.asJSON() AS b;
This is because the resultset is read and exhausted once you execute asJSON()
. It's like in Java when you have an iterator and you browse the iterator to print the result. In the end that iterator is not usable. Some of ArcadeDB resultset have the .reset()
method to reuse it, but I'd stick with using asList()
as the best way to have something you can use multiple times.
Makes sense. Thank you for the explanation 😊
Improved the documentation detailing this behavior when asJSON()
is applied to result sets.
ArcadeDB Version:
24.5.1
OS and JDK Version:
Official Docker image
Expected behavior
Accessing a variable with a result set should be idempotent.
Actual behavior
The result set is modified as a side effect of accessing the variable.
This is the output:
Steps to reproduce