You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation doesn't say anything about sorting order or special character (ASCENDING_ORDER_CHAR) at the beginning of property name to indicate sorting order (in case of sortNodes()). So users assume that the sorting is ascending (from smallest to largest). And if users want descending, they can additionally use apoc.coll.reverse().
Actual Behavior (Mandatory)
By default, sort() does ascending sorting. In contrast, sortNodes() does descending sorting. I think we should make their behavior consistent. Beside, reading the source code of sortNodes() (link), I found that there is a hidden trick of using "^" (ASCENDING_ORDER_CHAR defined in the code) to specify which sorting order to carry out. But this trick is not disclosed in the documentation for sortNodes(). It is in apoc.coll.sortMulti(); however, this is another section.
(In other words, the document has probably been improved in the meantime.)
Changing the default, i.e. making apoc.coll.sortNodes sort ASC be default would be breaking change.
Further, making the default ASC require a notation of DESC. The notation for ASC is ^-prefix on the property name. There is no obvious alternative for DESC.
In general, regular Cypher should be used instead of these functions.
Any
...
WITH ..., apoc.coll.sort(list) AS sortedList
...
can be written as
...
CALL (list) {
UNWIND list AS x
WITH x ORDER BY x ASC // or DESC if the use case requires
RETURN COLLECT(x) AS sortedList
}
...
or as
...
WITH ..., COLLECT {
UNWIND list AS x
RETURN x ORDER BY x ASC // or DESC if the use case requires
} AS sortedList
...
Any
...
WITH ..., apoc.coll.sortNodes(listOfNodes, 'prop') AS sortedListOfNodes
...
can be written as
...
CALL (listOfNodes) {
UNWIND listOfNodes AS x
WITH x ORDER BY x.prop DESC // or ASC in case of '^prop'
RETURN COLLECT(x) AS sortedListOfNodes
}
...
or as
...
WITH ..., COLLECT {
UNWIND listOfNodes AS x
RETURN x ORDER BY x.prop DESC // or ASC in case of '^prop'
} AS sortedListOfNodes
...
Issue by ThachNgocTran
Thursday Jun 11, 2020 at 10:59 GMT
Originally opened as neo4j-contrib/neo4j-apoc-procedures#1554
Expected Behavior (Mandatory)
The documentation doesn't say anything about sorting order or special character (
ASCENDING_ORDER_CHAR
) at the beginning of property name to indicate sorting order (in case ofsortNodes()
). So users assume that the sorting is ascending (from smallest to largest). And if users want descending, they can additionally useapoc.coll.reverse()
.Actual Behavior (Mandatory)
By default,
sort()
does ascending sorting. In contrast,sortNodes()
does descending sorting. I think we should make their behavior consistent. Beside, reading the source code ofsortNodes()
(link), I found that there is a hidden trick of using "^" (ASCENDING_ORDER_CHAR
defined in the code) to specify which sorting order to carry out. But this trick is not disclosed in the documentation forsortNodes()
. It is inapoc.coll.sortMulti()
; however, this is another section.Steps (Mandatory)
For
apoc.coll.sort()
, in Neo4j Browser:For
apoc.coll.sortNodes()
, in Neo4j Browser:Specifications (Mandatory)
Currently used versions
Versions
The text was updated successfully, but these errors were encountered: