fluree / core

Fluree releases and public bug reports
0 stars 0 forks source link

issue with orderBy [BUG] #72

Open frydj opened 6 months ago

frydj commented 6 months ago

Describe the bug When querying and trying to sort results, I'm getting an error message.

To Reproduce Steps to reproduce the behavior:

  1. Transact some Yetis:

    {
    "ledger": "fluree-jld/369435906932737",
    "insert": [
    {
      "@id": "sarah",
      "@type": "Yeti",
      "name": "Sarah"
    },
    {
      "@id": "tim",
      "@type": "Yeti",
      "name": "Tim"
    },
    {
      "@id": "brad",
      "@type": "Yeti",
      "name": "Brad"
    },
    {
      "@id": "letty",
      "@type": "Yeti",
      "name": "Letty"
    },
    {
      "@id": "freddy",
      "@type": "Yeti",
      "name": "Freddy"
    }
    ]
    }
  2. Try to query the Yetis with orderBy:

    {
    "from": "fluree-jld/369435906932737",
    "select": {
    "?s": [
      "*"
    ]
    },
    "where": {
    "@id": "?s",
    "@type": "Yeti"
    },
    "orderBy": [
    "DESC",
    "?s"
    ]
    }

Expected behavior The result set should be sorted by @id, but an error message is returned.

also please note: the error message being returned points at the wrong URL:

{
  "message": "{\"error\":\"db/invalid-query\",\"message\":\"Error in value for \\\"orderBy\\\"; orderBy clause must be variable or two-tuple formatted ['ASC' or 'DESC', var]; Provided: [\\\"DESC\\\" \\\"?s\\\"];  See documentation for details: https://next.developers.flur.ee/docs/reference/errorcodes#query-invalid-orderby\"}"
}

I think this should point to https://next.developers.flur.ee/docs/reference/error-codes#query-invalid-orderby

System (please complete the following information):

mpoffald commented 6 months ago

Right now order-by expects a list, and non-capitalized sorting fns, eg: '(desc ?s). So the syntax used in this example is not intended to work.

However, we should also accept the same thing as a string, such as "(desc ?s)". And afaict this doesn't work atm. So we still need a fix, but for the string syntax rather than the vector syntax above.