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"
}
}
]
}
}