Gremlin and sparql Query for inserting iterative relationship on the basis on ascending dates for product purchase.

0

Suppose one customer purchased multiple products and we have dates for purchase now on the basis of date I want to make next next relationship. In aws Neptune in sparql and gremlin as well . Original graph Enter image description here

I want to insert Next output graph should have. Enter image description here

  • 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.

asked 8 months ago271 views
1 Answer
1

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
profile pictureAWS
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions