hasura / ndc-spec

NDC Specification and Reference Implementation

Home Page:http://hasura.github.io/ndc-spec

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sorting semantics

plcplc opened this issue · comments

The spec for ordering by counting and column aggregations currently read (emphasis mine):

Type star_count_aggregate

An ordering of type star_count_aggregate orders rows by a count of rows in some related collection. If the respective counts are incomparable, the ordering should continue to the next OrderByElement.

and

Type single_count_aggregate

An ordering of type single_count_aggregate orders rows by an aggregate computed over rows in some related collection. If the respective aggregates are incomparable, the ordering should continue to the next OrderByElement.

What is the actual meaning of the highlighted phrases above, and what part of the engine/ndc/db complex is supposed to make that judgement?

How can a count be incomparable?

While the result of an arbitrary aggregation could conceivably be incomparable, it seems like a tall order to ask the ndc to make that judgement, and if the ndc just assumes comparability and passes the compiled query to the database it will likely just fail rather than be irrelevant to the resulting ordering as the spec suggests.

If it's meant to be an optional behavior I think it'd be nice to mark it more clearly as such (like how the W3C specifications typographically emphasise when the words "SHOULD", "MUST" etc. have a normative meaning, originally from https://www.ietf.org/rfc/rfc2119.txt I believe)

"incomparable" should maybe say "equal or incomparable". It says incomparable because an OrderByElement might describe a partial ordering in which two elements might not be equal, but might not be less-or-greater-than either. The point is that an array of OrderByElements should use the first, then the second only if the first fails to yield a distinction in ordering between two elements, and so on.