dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Date-related RDF types are not following the specs

Open fucking-signup opened this issue 8 years ago • 4 comments

I have been trying to load Wikidata N-Triples dump into Dgraph and faced an error:

While processing file Error while parsing RDF: parsing time "-8000-01-01T00:00:00Z" as "2006": cannot parse "-8000-01-01T00:00:00Z" as "2006", on line:22137 <http://www.wikidata.org/entity/Q146> <http://www.wikidata.org/prop/direct/P580> "-8000-01-01T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .

The problem is that XML Schema date and time formats are based on ISO 8601 with deviations: https://www.w3.org/TR/xmlschema-2/#isoformats

More specifically:

  • It treats truncated and reduced formats differently
  • It allows optional minus sign for duration, dateTime, date, gYearMonth, gYear
  • The year "0000" is an illegal year value
  • More than four digits are allowed in the year representations of dateTime, date, gYearMonth, and gYear
  • The lexical representations for the datatypes date, gYearMonth, gMonthDay, gDay, gMonth and gYear permit an optional trailing time zone specificiation.

However, Dgraph is not following the official specification and tries to parse dates in four most common formats instead:

https://github.com/dgraph-io/dgraph/blob/0a01c52fdc2e9365bae2e57fefb248b42bbb97df/types/scalar_types.go#L180-L183

So date and dateTime are not really supported, as described here: https://docs.dgraph.io/mutations/#language-and-rdf-types

And the other issue is that documentation on supported RDF types is not complete. For instance, there are more supported datatypes in the source code:

https://github.com/dgraph-io/dgraph/blob/56c99ea6784bfa9f9954e349b314deab9d2243b9/rdf/parse.go#L309-L331

Info about Dgraph:

  • What version of Dgraph are you using?
    1.0.2

  • Have you tried reproducing the issue with latest release? There are no related changes in 1.0.3

  • What is the hardware spec (RAM, OS)? OS: macOS High Sierra 10.13.3 RAM: 24 GB

fucking-signup avatar Feb 09 '18 20:02 fucking-signup

ISO 8601 isn't natively supported by Go language, and we're not necessarily aiming for 100% compatibility with RDF spec. The best way around this limitation would be to normalize your date times in RFC3339.

manishrjain avatar Mar 29 '18 06:03 manishrjain

we're not necessarily aiming for 100% compatibility with RDF spec

Then it needs to be clarified in the documentation. More specifically, it needs to say that Dgraph supports date and time formats only if they are RFC3339 compatible. Date and time formats are not supported as they are described in XML Schema specification.

The current state of the documentation doesn't have any notes/warnings about this, which is misleading.

The best way around this limitation would be to normalize your date times in RFC3339.

I am afraid it is not possible when dealing with previous era dates as RFC3339 deals only with current era dates. Converting to string or removing parts of data are the only options sadly.

fucking-signup avatar Mar 29 '18 14:03 fucking-signup

Note added at https://docs.dgraph.io/master/query-language/#schema-types. Feel free to submit doc fixes in the future. The code is located at https://github.com/dgraph-io/dgraph/tree/master/wiki/content.

pawanrawal avatar Apr 03 '18 04:04 pawanrawal

Great, thank you!

fucking-signup avatar Apr 03 '18 18:04 fucking-signup