arcadedb icon indicating copy to clipboard operation
arcadedb copied to clipboard

SQL: Setting "ORDER BY" Direction via Parameter

Open gramian opened this issue 1 year ago • 1 comments

ArcadeDB Version:

ArcadeDB Server v24.11.1 (build b466f487e42fbb39fd20965004ce88682335eaba/1730841732933/main)

OS and JDK Version:

Running on Linux 6.2.0-26-generic - OpenJDK 64-Bit Server VM 17.0.13

It is currently not possible to set the direction of sorting of ORDER BY via parameter (ie HTTP API, params object). I think this is due to the parameters in the params object being placed as data types into the query, so a string is enclosed in quotes. Hence the necessary keywords ASC or DESC cannot be set, as using a parameter would result in the strings "ASC" or "DESC".

To allow control somewhat safely without allowing keywords to be passed, the grammar could allow in addition to ASC and DESC also true and false? Alternatively the sort direction could be controlled by a top-level parameter like limit, but this would then be not SQL specific and maybe expected to work with all languages.

@lvca WDYT?

Steps to reproduce

wget -qO- --content-on-error "http://localhost:2480/api/v1/query/test" --post-data='{"language": "sql", "params": { "dir": "asc" }, "command": "SELECT num FROM Test ORDER BY num :dir"}' --user=root --password=password

gramian avatar Nov 28 '24 11:11 gramian

The necessary changes look rather easy, every:

[ <DESC> { lastItem.type = OrderByItem.DESC; }| <ASC>  { lastItem.type = OrderByItem.ASC; }]

would become

[ (<DESC>|<FALSE>) { lastItem.type = OrderByItem.DESC; }| (<ASC>|<TRUE>)  { lastItem.type = OrderByItem.ASC; }]

And could be read as "use default direction? true / false".

gramian avatar Nov 28 '24 11:11 gramian