`IllegalArgumentException` when trying to order by `xsd:dateTimeStamp`

Hello,

I have been trying to use SPARQL’s ORDER BY to order some blog posts by the date they were made public. Each blog post has a property called theo:date_made_public which is an xsd:dateTimeStamp (note: not an xsd:dateTime).

When I try to ORDER BY DESC(?date_made_public) I get an error (see Query A). But when I comment out that line, or change ?date_made_public to a string variable like ?piece_title, I get results (see Query B).

At first, I thought the issue might be the < operator, since the SPARQL spec only defines it for xsd:dateTime and does not mention xsd:dateTimeStamp. But then I realized the FILTER line works, so it can’t be that.

Am I doing something wrong, or is this a bug? (I am using Stardog Cloud.)

Query A

PREFIX theo: <https://rdf.provocateach.art/theory-ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?piece_title ?piece_slug ?date_made_public
WHERE {
	GRAPH ?g1 {
		?blog_piece
				a theo:Content_Piece ;
				theo:piece_slug ?piece_slug ;
				theo:piece_title ?piece_title ;
				theo:date_made_public ?date_made_public .
	}
	FILTER (?date_made_public < NOW())
}
ORDER BY DESC( ?date_made_public ) # this is the offending line
OFFSET 0
LIMIT 10

Result A

Failed to run query: com.complexible.stardog.plan.eval.operator.OperatorException: Uncaught error during query evaluation: IllegalArgumentException: 2020-05-02T10:00-05:00

Query B

PREFIX theo: <https://rdf.provocateach.art/theory-ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?piece_title ?piece_slug ?date_made_public
WHERE {
	GRAPH ?g1 {
		?blog_piece
				a theo:Content_Piece ;
				theo:piece_slug ?piece_slug ;
				theo:piece_title ?piece_title ;
				theo:date_made_public ?date_made_public .
	}
	FILTER (?date_made_public < NOW())
}
# ORDER BY DESC( ?date_made_public )
OFFSET 0
LIMIT 10

Result B

{
  "head": {
    "vars": [
      "piece_title",
      "piece_slug",
      "date_made_public"
    ]
  },
  "results": {
    "bindings": [
      {
        "piece_slug": {
          "datatype": "http://www.w3.org/2001/XMLSchema#token",
          "type": "literal",
          "value": "the-playful-magic-of-humor-in-education"
        },
        "piece_title": {
          "xml:lang": "en",
          "type": "literal",
          "value": "The Playful Magic of Humor in Education"
        },
        "date_made_public": {
          "datatype": "http://www.w3.org/2001/XMLSchema#dateTimeStamp",
          "type": "literal",
          "value": "2020-05-02T10:00-05:00"
        }
      },
      {
        "piece_slug": {
          "datatype": "http://www.w3.org/2001/XMLSchema#token",
          "type": "literal",
          "value": "media-literacy-is-not-a-checklist"
        },
        "piece_title": {
          "xml:lang": "en",
          "type": "literal",
          "value": "Media Literacy is Not a Checklist"
        },
        "date_made_public": {
          "datatype": "http://www.w3.org/2001/XMLSchema#dateTimeStamp",
          "type": "literal",
          "value": "2020-06-03T08:00-07:00"
        }
      },
      {
        "piece_slug": {
          "datatype": "http://www.w3.org/2001/XMLSchema#token",
          "type": "literal",
          "value": "how-to-drill-and-kill-responsibly"
        },
        "piece_title": {
          "xml:lang": "en",
          "type": "literal",
          "value": "How to Drill and Kill Responsibly"
        },
        "date_made_public": {
          "datatype": "http://www.w3.org/2001/XMLSchema#dateTimeStamp",
          "type": "literal",
          "value": "2023-07-07T08:00-07:00"
        }
      }
    ]
  }
}

Do you get the same error when creating the query plan? If not, could you share the plan?

Thanks,
-Paul

No, you're not doing anything wrong. What's your Cloud endpoint or username (so we can check the logs).

Best,
Pavel

1 Like

Paul, no errors when I run the query plan. Here’s the output:

prefix theo: <https://rdf.provocateach.art/theory-ontology#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

Slice(offset=0, limit=10) [#1]
`─ OrderBy(DESC(?date_made_public), offset=0, limit=10) [#1]
   `─ Projection(?piece_title, ?piece_slug, ?date_made_public) [#1]
      `─ NaryJoin(?blog_piece) [#1]
         +─ Scan[PSOC](?blog_piece, theo:piece_title, ?piece_title){?g1} [#1]
         +─ Scan[PSOC](?blog_piece, theo:piece_slug, ?piece_slug){?g1} [#1]
         +─ Scan[POSC](?blog_piece, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, theo:Content_Piece){?g1} [#1]
         `─ Filter(?date_made_public < "2023-07-14T20:26:29.625Z"^^xsd:dateTime) [#1]
            `─ Scan[PSOC](?blog_piece, theo:date_made_public, ?date_made_public){?g1} [#1]

Pavel, my endpoint is https://sd-0d8a4a54.stardog.cloud:5820/prte-development

Thanks, we got the logs and we will look into it. Regardless of the data, any data mistyping errors should not terminate query execution, can only make values incomparable. Filters handle these cases correctly but there might be an issue with ORDER BY.

I probably need to double check in the XMLSchema spec but it could be an invalid xsd:dateTimeStamp literal (missing seconds).

Thanks,
Pavel

1 Like

You were right, it was that I forgot to specify the seconds on the xsd:dateTimeStamp values. Thank you!

1 Like