Very cool Andy!! It works after I moved those triples per your suggestion.
I thought '?email' in "?contactInfo abc:hasEmail ?email" is already bound, but 
the binding only happens in WHERE clause, now I got it.

Follow up questions:
There are two triples that match "?contactInfo abc:hasEmail ?email" (i.e. from 
2 persons), and three triples that match "?email ?emailPredicate ?emailObject"
I see the delete operation was called 6 times for "?email ?emailPredicate 
?emailObject", which is correct (2 * 3 = 6)
However, I see it is also called 6 times for "?contactInfo abc:hasEmail 
?email", while I'd expect it should be just 2 times.
Delete operation is idempotent, so this may not be big deal, but I am trying to 
optimize it , this is not good when n * m becomes bigger.
Is there a way to re-write the query so that that first pattern only apply 
delete operation not as many as multiplying with result from second pattern? Is 
separating them the only option?

Second question, I notice that update operation is instance of UpdateModify. Do 
you know why it is not UpdateDeleteWhere?


Thanks,
Z
________________________________________
From: Andy Seaborne <[email protected]>
Sent: Thursday, October 8, 2015 3:29 AM
To: [email protected]
Subject: Re: DELETE with WHERE clause

On 08/10/15 02:33, Zen 98052 wrote:
> If I pass this query:
>
>
> DELETE
> {
>    ?contactInfo abc:hasEmail ?email .
>    ?email ?emailPredicate ?emailObject .
> }
> WHERE
> {
>    ?person abc:name "foobar" .
>    ?person abc:hasContactInfo ?contactInfo .
> }
>
>
> to this example code below, the it doesn't do anything.

?email and ?emailObject are not bound so
"?contactInfo abc:hasEmail ?email . isn't a triple to delete.

WHERE {
   ?person abc:name "foobar" .
   ?person abc:hasContactInfo ?contactInfo .
   ?contactInfo abc:hasEmail ?email .
   ?email ?emailPredicate ?emailObject .
}

        Andy

>
>
>     UpdateRequest updateRequest = UpdateFactory.create(sparqlUpdateQuery);
>     for (Update update : updateRequest.getOperations()) {
>      UpdateAction.parseExecute(update.toString(), graphDataset);
>     }
>
>
>
> The graphDataset above is subclass of Jena's DatasetGraphBase class, where I 
> override the find, add, delete, deleteAny, and some other methods.
>
> I guess I have to query first using the triples in WHERE clause, and then 
> populate the query results into bindings, and pass the bindings to 
> UpdateAction.parseExecute method?
>
> I looked at Jena's code, and still have no idea where to add that code. 
> Perhaps I was wrong, so any hint, or better if there is already existing 
> sample code for the case I am looking for?
>
>
>
> Thanks,
>
> Z
>

Reply via email to