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: INSERT INTO FROM fails with NPE #1615

Closed gramian closed 4 months ago

gramian commented 4 months ago

ArcadeDB Version:

ArcadeDB Server v24.5.1-SNAPSHOT (build a6fcd5ffcb052e4d1f009093f3cba680bd56c8ce/1716500652832/main)

OS and JDK Version:

Running on Mac OS X 12.7.4 - OpenJDK 64-Bit Server VM 17.0.11 (Homebrew)

Expected behavior

Records should be copied into the destination from the source query.

Actual behavior

Internal error Cannot invoke "com.arcadedb.database.Document.getRecord()" because the return value of "com.arcadedb.query.sql.executor.Result.toElement()" is null ``` Error on command execution (PostCommandHandler) java.lang.NullPointerException: Cannot invoke "com.arcadedb.database.Document.getRecord()" because the return value of "com.arcadedb.query.sql.executor.Result.toElement()" is null at com.arcadedb.query.sql.executor.CopyDocumentStep$1.next(CopyDocumentStep.java:71) at com.arcadedb.query.sql.executor.RemoveEdgePointersStep$1.next(RemoveEdgePointersStep.java:51) at com.arcadedb.query.sql.executor.SetDocumentStepStep$1.next(SetDocumentStepStep.java:51) at com.arcadedb.query.sql.executor.SaveElementStep$1.next(SaveElementStep.java:53) at com.arcadedb.query.sql.executor.InsertExecutionPlan.executeInternal(InsertExecutionPlan.java:67) at com.arcadedb.query.sql.executor.ScriptLineStep.syncPull(ScriptLineStep.java:47) at com.arcadedb.query.sql.executor.ScriptExecutionPlan.doExecute(ScriptExecutionPlan.java:96) at com.arcadedb.query.sql.executor.ScriptExecutionPlan.fetchNext(ScriptExecutionPlan.java:61) at com.arcadedb.query.sql.parser.LocalResultSet.fetchNext(LocalResultSet.java:44) at com.arcadedb.query.sql.parser.LocalResultSet.(LocalResultSet.java:40) at com.arcadedb.query.sql.SQLScriptQueryEngine.executeInternal(SQLScriptQueryEngine.java:218) at com.arcadedb.query.sql.SQLScriptQueryEngine.command(SQLScriptQueryEngine.java:108) 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:134) at com.arcadedb.server.http.handler.PostCommandHandler.execute(PostCommandHandler.java:113) 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:840) ```

The NPE happens here

Steps to reproduce

CREATE DOCUMENT TYPE src;
CREATE DOCUMENT TYPE dst;

INSERT INTO src SET a = 1;
INSERT INTO src SET a = 2;
INSERT INTO src SET a = 3; 

INSERT INTO dst FROM SELECT a FROM src;
gramian commented 4 months ago

So the problem seems to be the projection in the query, as

INSERT INTO dst FROM SELECT FROM src;

works, which is tested [here](INSERT INTO dst FROM SELECT FROM src;).

lvca commented 4 months ago

Fixed!

gramian commented 4 months ago

Works on the example, but also on a large database with query including a filter and an UNWIND! Awesome.