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
502 stars 61 forks source link

HTTP/SQL: "params" cannot be bucket names #1625

Open gramian opened 5 months ago

gramian commented 5 months ago

ArcadeDB Version:

ArcadeDB Server v24.6.1-SNAPSHOT (build 6ff2d86d488fe6b3ca20f7a6554160d6017af118/1716919859476/main)

OS and JDK Version:

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

Using a parameter in POST request query where the parameter specifies a bucket name errors. This is maybe because the double colon, ie BUCKET::param cannot be parsed?

Expected behavior

Succesful query in bucket

Actual behavior

Error on command execution ``` Error on command execution (PostQueryHandler) com.arcadedb.exception.CommandSQLParsingException: SELECT FROM BUCKET::myparam limit 20000 at com.arcadedb.query.sql.parser.StatementCache.throwParsingException(StatementCache.java:126) at com.arcadedb.query.sql.parser.StatementCache.parse(StatementCache.java:116) at com.arcadedb.query.sql.parser.StatementCache.get(StatementCache.java:70) at com.arcadedb.query.sql.SQLQueryEngine.parse(SQLQueryEngine.java:216) at com.arcadedb.query.sql.SQLQueryEngine.query(SQLQueryEngine.java:80) at com.arcadedb.database.LocalDatabase.query(LocalDatabase.java:1378) at com.arcadedb.server.ServerDatabase.query(ServerDatabase.java:494) at com.arcadedb.server.http.handler.PostQueryHandler.executeCommand(PostQueryHandler.java:38) 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) Caused by: com.arcadedb.query.sql.parser.ParseException: Encountered "FROM" at line 1, column 8. Was expecting one of: ... ... ... ... ... ... ... ... ... at com.arcadedb.query.sql.parser.SqlParser.generateParseException(SqlParser.java:27774) at com.arcadedb.query.sql.parser.SqlParser.jj_consume_token(SqlParser.java:27619) at com.arcadedb.query.sql.parser.SqlParser.Projection(SqlParser.java:4892) at com.arcadedb.query.sql.parser.SqlParser.SelectWithoutTargetStatement(SqlParser.java:1548) at com.arcadedb.query.sql.parser.SqlParser.QueryStatement(SqlParser.java:1497) at com.arcadedb.query.sql.parser.SqlParser.StatementInternal(SqlParser.java:1287) at com.arcadedb.query.sql.parser.SqlParser.Statement(SqlParser.java:1055) at com.arcadedb.query.sql.parser.SqlParser.Parse(SqlParser.java:251) at com.arcadedb.query.sql.parser.StatementCache.parse(StatementCache.java:111) ... 16 more ```

Steps to reproduce

CREATE DOCUMENT TYPE doc BUCKET mybucket
wget -qO- http://localhost:2480/api/v1/query/test --post-data='{"language":"sql","params":{"myparam":"mybucket"},"command":"SELECT FROM BUCKET::myparam"}' --user root --password arcadedb
lvca commented 5 months ago

It should be BUCKET:myparam

gramian commented 5 months ago
Using `BUCKET:myparam` also errors ``` Error on command execution (PostQueryHandler) com.arcadedb.exception.SchemaException: Bucket with name 'myparam' was not found at com.arcadedb.schema.LocalSchema.getBucketByName(LocalSchema.java:281) at com.arcadedb.query.sql.executor.SelectExecutionPlanner.handleClustersAsTarget(SelectExecutionPlanner.java:2196) at com.arcadedb.query.sql.executor.SelectExecutionPlanner.handleFetchFromTarget(SelectExecutionPlanner.java:780) at com.arcadedb.query.sql.executor.SelectExecutionPlanner.createExecutionPlan(SelectExecutionPlanner.java:144) at com.arcadedb.query.sql.parser.SelectStatement.createExecutionPlan(SelectStatement.java:208) at com.arcadedb.query.sql.parser.SelectStatement.execute(SelectStatement.java:201) at com.arcadedb.query.sql.parser.Statement.execute(Statement.java:85) at com.arcadedb.query.sql.parser.Statement.execute(Statement.java:69) at com.arcadedb.query.sql.SQLQueryEngine.query(SQLQueryEngine.java:85) at com.arcadedb.database.LocalDatabase.query(LocalDatabase.java:1378) at com.arcadedb.server.ServerDatabase.query(ServerDatabase.java:494) at com.arcadedb.server.http.handler.PostQueryHandler.executeCommand(PostQueryHandler.java:38) 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) ```

since then the parameter is not identified as such.

lvca commented 5 months ago

Sorry, I didn't notice the parameter. Correct, you can't use parameters there.

gramian commented 5 months ago

Too bad. So, does this bug report become a feature request or is this too unlikely to be implemented and should hence be closed?

gramian commented 5 months ago

Hmm, so I tried using

wget -qO- http://localhost:2480/api/v1/query/test --post-data='{"language":"sql","params":{"myparam":"BUCKET:mybucket"},"command":"SELECT FROM :myparam"}' --user root --password arcadedb

which errors, but

wget -qO- http://localhost:2480/api/v1/query/test --post-data='{"language":"sql","params":{"myparam":"doc"},"command":"SELECT FROM :myparam"}' --user root --password arcadedb

works. So can you describe what the syntactic rule is, so I can add it to the docs?

lvca commented 5 months ago

If it works without the BUCKET: prefix, then it should be easy to implement it. I'm ok with this as an enhancement.