You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Zen 98052 <z9...@outlook.com> on 2016/03/16 16:18:11 UTC

delete insert where

Hi,

I am trying to understand how DELETE/INSERT WHERE query is working since I see unexpected behavior.

According to http://www.w3.org/TR/sparql11-update/#deleteInsert, the DELETE will be executed before INSERT.

In this simple Sparql query for example:

DELETE

{

  ?old rdf:b rdf:thing .

}

INSERT

{

  ?new rdf:b rdf:thing .

}

WHERE

{

  ?new rdf:m "blah" .

  OPTIONAL

  {

    ?old rdf:b rdf:thing .

  }

}


Let say ?new and ?old are referring to same node, then what I see is triple ?new rdf:b rdf:thing (in INSERT section above) never got added.

I'd expect it first deletes that triple, and then add it back. Did I miss something here?



Thanks,

Z

Re: delete insert where

Posted by Andy Seaborne <an...@apache.org>.
On 16/03/16 19:47, Zen 98052 wrote:
> I take it back, OpExecutor only applies to the WHERE clause, and in this example nothing much being done from my custom code.
> This is the actual Sparql query (my previous example was too simplified):
>
> DELETE {
>    ?snapshotOld <http://foo/bar/isLatest> <http://foo/bar#Latest> .
> }
> INSERT {
>    ?snapshotNew <http://foo/bar/isLatest> <http://foo/bar#Latest> .
>    ?snapshotNew <http://foo/bar/updateTimeStamp> "20160315" .
> }
> WHERE
>    { ?snapshotNew <http://foo/bar/metadataId> "1" .
>      ?snapshotNew <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://foo/bar/barSnapshot>
>      OPTIONAL
>        { ?snapshotOld <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://foo/bar/barSnapshot> .
>          ?snapshotOld <http://foo/bar/isLatest> <http://foo/bar#Latest>
>        }
>    }
>
> My code simply pass the whole query string to UpdateAction.parseExecute() as shown in the code snippet below:
>
>          InputStream stream = new ByteArrayInputStream(query.getBytes("UTF-8"));
>          UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
>
>
> Do you know what can be possibly wrong here? I really can't figure it out :-(

Note in WHERE , the two sections aren't connected by anything.

If the INSERT happens and not the DELETE, the OPTIONAL does not match.

If the DELETE happens and not the INSERT, then maybe ?snapshotNew is a 
literal (which is bad RDF).

Try:
SELECT *
WHERE
   { ?snapshotNew <http://foo/bar/metadataId> "1" .
     ?snapshotNew <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://foo/bar/barSnapshot>
     OPTIONAL
       { ?snapshotOld <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://foo/bar/barSnapshot> .
         ?snapshotOld <http://foo/bar/isLatest> <http://foo/bar#Latest>
       }
   }

which is what the processor does.

I tried:

  update --file U.ru --dump

on
---------------------
PREFIX ns: <http://www.example.org/>

INSERT DATA {
   ns:A ns:m "blah" .
   ns:B ns:b ns:thing .
}
;

DELETE { ?old ns:b ns:thing }
INSERT { ?new ns:b ns:thing }
WHERE  {
   ?new ns:m "blah" .
   OPTIONAL {
     ?old ns:b ns:thing .
   }
}
---------------------


> Unrelated question, I remember I used to be able to search for a keyword/string in Jena's code base on https://github.com/apache/jena, but somehow I don't see that Search code feature anymore :-(
>
>
> Thanks,
> Z
>
> ________________________________________
> From: Zen 98052 <z9...@outlook.com>
> Sent: Wednesday, March 16, 2016 12:14 PM
> To: users@jena.apache.org
> Subject: Re: delete insert where
>
> Thanks Andy! I guess then it may be somewhere in my implementation (since I implement OpExecutor interface)
> That SELECT query will return ?old and ?new are referring to a same node.
>
> ________________________________________
> From: Andy Seaborne <an...@apache.org>
> Sent: Wednesday, March 16, 2016 11:45 AM
> To: users@jena.apache.org
> Subject: Re: delete insert where
>
> Works for me.
>
> What's SELECT * {
>       ?new rdf:m "blah" .
>       OPTIONAL
>       {
>         ?old rdf:b rdf:thing .
>       }
> }
>
> On 16/03/16 15:18, Zen 98052 wrote:
>> Hi,
>>
>> I am trying to understand how DELETE/INSERT WHERE query is working since I see unexpected behavior.
>>
>> According to http://www.w3.org/TR/sparql11-update/#deleteInsert, the DELETE will be executed before INSERT.
>>
>> In this simple Sparql query for example:
>>
>> DELETE
>>
>> {
>>
>>     ?old rdf:b rdf:thing .
>>
>> }
>>
>> INSERT
>>
>> {
>>
>>     ?new rdf:b rdf:thing .
>>
>> }
>>
>> WHERE
>>
>> {
>>
>>     ?new rdf:m "blah" .
>>
>>     OPTIONAL
>>
>>     {
>>
>>       ?old rdf:b rdf:thing .
>>
>>     }
>>
>> }
>>
>>
>> Let say ?new and ?old are referring to same node, then what I see is triple ?new rdf:b rdf:thing (in INSERT section above) never got added.
>>
>> I'd expect it first deletes that triple, and then add it back. Did I miss something here?
>>
>>
>>
>> Thanks,
>>
>> Z
>>


Re: delete insert where

Posted by Zen 98052 <z9...@outlook.com>.
I take it back, OpExecutor only applies to the WHERE clause, and in this example nothing much being done from my custom code.
This is the actual Sparql query (my previous example was too simplified):

DELETE {
  ?snapshotOld <http://foo/bar/isLatest> <http://foo/bar#Latest> .
}
INSERT {
  ?snapshotNew <http://foo/bar/isLatest> <http://foo/bar#Latest> .
  ?snapshotNew <http://foo/bar/updateTimeStamp> "20160315" .
}
WHERE
  { ?snapshotNew <http://foo/bar/metadataId> "1" .
    ?snapshotNew <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://foo/bar/barSnapshot>
    OPTIONAL
      { ?snapshotOld <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://foo/bar/barSnapshot> .
        ?snapshotOld <http://foo/bar/isLatest> <http://foo/bar#Latest>
      }
  }

My code simply pass the whole query string to UpdateAction.parseExecute() as shown in the code snippet below:

        InputStream stream = new ByteArrayInputStream(query.getBytes("UTF-8"));
        UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);


Do you know what can be possibly wrong here? I really can't figure it out :-(
Unrelated question, I remember I used to be able to search for a keyword/string in Jena's code base on https://github.com/apache/jena, but somehow I don't see that Search code feature anymore :-(


Thanks,
Z

________________________________________
From: Zen 98052 <z9...@outlook.com>
Sent: Wednesday, March 16, 2016 12:14 PM
To: users@jena.apache.org
Subject: Re: delete insert where

Thanks Andy! I guess then it may be somewhere in my implementation (since I implement OpExecutor interface)
That SELECT query will return ?old and ?new are referring to a same node.

________________________________________
From: Andy Seaborne <an...@apache.org>
Sent: Wednesday, March 16, 2016 11:45 AM
To: users@jena.apache.org
Subject: Re: delete insert where

Works for me.

What's SELECT * {
     ?new rdf:m "blah" .
     OPTIONAL
     {
       ?old rdf:b rdf:thing .
     }
}

On 16/03/16 15:18, Zen 98052 wrote:
> Hi,
>
> I am trying to understand how DELETE/INSERT WHERE query is working since I see unexpected behavior.
>
> According to http://www.w3.org/TR/sparql11-update/#deleteInsert, the DELETE will be executed before INSERT.
>
> In this simple Sparql query for example:
>
> DELETE
>
> {
>
>    ?old rdf:b rdf:thing .
>
> }
>
> INSERT
>
> {
>
>    ?new rdf:b rdf:thing .
>
> }
>
> WHERE
>
> {
>
>    ?new rdf:m "blah" .
>
>    OPTIONAL
>
>    {
>
>      ?old rdf:b rdf:thing .
>
>    }
>
> }
>
>
> Let say ?new and ?old are referring to same node, then what I see is triple ?new rdf:b rdf:thing (in INSERT section above) never got added.
>
> I'd expect it first deletes that triple, and then add it back. Did I miss something here?
>
>
>
> Thanks,
>
> Z
>

Re: delete insert where

Posted by Zen 98052 <z9...@outlook.com>.
Thanks Andy! I guess then it may be somewhere in my implementation (since I implement OpExecutor interface)
That SELECT query will return ?old and ?new are referring to a same node.

________________________________________
From: Andy Seaborne <an...@apache.org>
Sent: Wednesday, March 16, 2016 11:45 AM
To: users@jena.apache.org
Subject: Re: delete insert where

Works for me.

What's SELECT * {
     ?new rdf:m "blah" .
     OPTIONAL
     {
       ?old rdf:b rdf:thing .
     }
}

On 16/03/16 15:18, Zen 98052 wrote:
> Hi,
>
> I am trying to understand how DELETE/INSERT WHERE query is working since I see unexpected behavior.
>
> According to http://www.w3.org/TR/sparql11-update/#deleteInsert, the DELETE will be executed before INSERT.
>
> In this simple Sparql query for example:
>
> DELETE
>
> {
>
>    ?old rdf:b rdf:thing .
>
> }
>
> INSERT
>
> {
>
>    ?new rdf:b rdf:thing .
>
> }
>
> WHERE
>
> {
>
>    ?new rdf:m "blah" .
>
>    OPTIONAL
>
>    {
>
>      ?old rdf:b rdf:thing .
>
>    }
>
> }
>
>
> Let say ?new and ?old are referring to same node, then what I see is triple ?new rdf:b rdf:thing (in INSERT section above) never got added.
>
> I'd expect it first deletes that triple, and then add it back. Did I miss something here?
>
>
>
> Thanks,
>
> Z
>


Re: delete insert where

Posted by Andy Seaborne <an...@apache.org>.
Works for me.

What's SELECT * {
     ?new rdf:m "blah" .
     OPTIONAL
     {
       ?old rdf:b rdf:thing .
     }
}

On 16/03/16 15:18, Zen 98052 wrote:
> Hi,
>
> I am trying to understand how DELETE/INSERT WHERE query is working since I see unexpected behavior.
>
> According to http://www.w3.org/TR/sparql11-update/#deleteInsert, the DELETE will be executed before INSERT.
>
> In this simple Sparql query for example:
>
> DELETE
>
> {
>
>    ?old rdf:b rdf:thing .
>
> }
>
> INSERT
>
> {
>
>    ?new rdf:b rdf:thing .
>
> }
>
> WHERE
>
> {
>
>    ?new rdf:m "blah" .
>
>    OPTIONAL
>
>    {
>
>      ?old rdf:b rdf:thing .
>
>    }
>
> }
>
>
> Let say ?new and ?old are referring to same node, then what I see is triple ?new rdf:b rdf:thing (in INSERT section above) never got added.
>
> I'd expect it first deletes that triple, and then add it back. Did I miss something here?
>
>
>
> Thanks,
>
> Z
>