- Newest
- Most votes
- Most comments
Here's an example (with sample dataset) of filtering by dates using SPARQL in Neptune. One big callout - datetime values must be in ISO8601 format and must be tagged with the appropriate xsd:dateTime
data type value on ingest.
Sample dataset:
INSERT DATA {
<customer:c1> <objProp:PURCHASED> <transaction:t1> .
<customer:c1> <objProp:PURCHASED> <transaction:t2> .
<customer:c1> <objProp:PURCHASED> <transaction:t3> .
<customer:c1> <objProp:PURCHASED> <transaction:t4> .
<customer:c1> <objProp:PURCHASED> <transaction:t5> .
<transaction:t1> <dataProp:DATE> "2023-09-01T11:58:21.190885"^^xsd:dateTime .
<transaction:t2> <dataProp:DATE> "2023-09-04T11:58:21.190885"^^xsd:dateTime .
<transaction:t3> <dataProp:DATE> "2023-09-15T11:58:21.190885"^^xsd:dateTime .
<transaction:t4> <dataProp:DATE> "2023-09-09T11:58:21.190885"^^xsd:dateTime .
<transaction:t5> <dataProp:DATE> "2023-09-30T11:58:21.190885"^^xsd:dateTime .
<transaction:t1> <objProp:IN_BAG> <product:p1> .
<transaction:t1> <objProp:IN_BAG> <product:p2> .
<transaction:t1> <objProp:IN_BAG> <product:p3> .
<transaction:t2> <objProp:IN_BAG> <product:p1> .
<transaction:t2> <objProp:IN_BAG> <product:p3> .
<transaction:t3> <objProp:IN_BAG> <product:p1> .
<transaction:t3> <objProp:IN_BAG> <product:p2> .
<transaction:t4> <objProp:IN_BAG> <product:p3> .
<transaction:t5> <objProp:IN_BAG> <product:p2> .
<transaction:t5> <objProp:IN_BAG> <product:p3> .
<product:p1> <dataProp:NAME> "Product 1" .
<product:p2> <dataProp:NAME> "Product 2" .
<product:p3> <dataProp:NAME> "Product 3" .
}
Query:
SELECT ?c ?tdate ?pname WHERE {
?c <objProp:PURCHASED> ?t .
?t <dataProp:DATE> ?tdate .
FILTER (?tdate > "2023-09-05T00:00:00.000000"^^xsd:dateTime && ?tdate < "2023-09-25T00:00:00.000000"^^xsd:dateTime) .
?t <objProp:IN_BAG> ?p .
?p <dataProp:NAME> ?pname
}
Results:
c,tdate,pname
customer:c1,2023-09-09T11:58:21.190Z,Product 3
customer:c1,2023-09-15T11:58:21.190Z,Product 1
customer:c1,2023-09-15T11:58:21.190Z,Product 2
I want to insert Next relationship on the basis of the dates .in select statement we can do but what if I want to insert relationship for example I want this code to be done using sparql MATCH (l3:Level3:MgS{lotNumber: "20016618"})-[r:USED_IN_TRAIL_ON]->(run:Runday) WITH l3, run ORDER BY run.date WITH collect(run) AS dates CALL apoc.nodes.link(dates, 'NEXT') RETURN dates
So
apoc.nodes.link
creates a linked list of the items that is given. Interestingly enough, Lists (or a Collection) in RDF are stored as a Linked List. Likely the easiest way to handle this would be to fetch your ordered results in one query and then use an RDF library within code to handle the creation of a collection based on your results. For Java there is Jena (https://www.javadoc.io/static/org.apache.jena/jena-core/3.3.0/org/apache/jena/rdf/model/RDFList.html) or Python's rdflib (https://rdflib.readthedocs.io/en/stable/intro_to_creating_rdf.html#creating-containers-collections).I am not getting proper code can you help me in that to run in aws neptune using %%sparql
It may be worth having a call to discuss all of your questions in detail. If you don't mind, drop us an email at neptune-repost@amazon.com
How it can be done using gremlin?
Relevant content
- asked 2 years ago
- asked 8 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated a year ago
Hello - thanks for the question. Could you please expand the description a little to make it clear exactly what you are trying to do? Perhaps you could include an example of the data model or the queries that you have so far.