You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Milorad Tosic <mb...@yahoo.com> on 2012/03/05 08:39:49 UTC
DROP query
Hi,
DROP clause is part of UPDATE SPARQL specification and in ARQ queries it is processed accordingly with UpdateRequest as well as other UPDATE type requests, while SELECT type queries are processed with QueryExecution. So, in a query processor code, that accepts arbitrary SPARQL query, one must resolve type of the input query first and then apply appropriate class. I do the query type resolution as follows:
Query query = QueryFactory.create(querystr);
if( query.isAskType() ){
executeAskSPARQL(querystr,out,outFormat);
}else if( query.isConstructType() ){
executeConstructSPARQL(querystr,out,outFormat);
}else if( query.isDescribeType() ){
executeDescribeSPARQL(querystr,out,outFormat);
}else if( query.isSelectType() ){
executeQuerySPARQL(querystr, out, outFormat);
}else{
// UPDATE is handled here
executeUpdateSPARQL(querystr);
}
However, DROP evaluates true on query.isSelectType() and ends up firing exception within executeQuerySPARQL. If DROP is processed by executeUpdateSPARQL, as it should be, everithing is fine.
I would say that DROP evaluating true by query.isSelectType() is a bug?
Regards,
Milorad
Re: DROP query
Posted by Andy Seaborne <an...@apache.org>.
On 05/03/12 19:41, Milorad Tosic wrote:
> Andy,
>
> You are right, I overlooked the source of the exception as you correctly indicated. So, the code now looks like follows. Maybe not the most elegant code ever, but it does the work for me.
Great - glad that's sorted.
>
> String querystr = "DROP ALL";
> try {
> //SPARQL 1.0 QUERY is handled here
SPARQL 1.1
(if you want SPARQL 1.0, add Syntax.syntaxSPARQL_10)
> Query query = QueryFactory.create(querystr);
> if( query.isAskType() ){
> log.debug("QueryExecution started. ASK");
> executeAskSPARQL(querystr,out,outFormat);
> }else if( query.isConstructType() ){
> log.debug("QueryExecution started. CONSTRUCT");
> executeConstructSPARQL(querystr,out,outFormat);
> }else if( query.isDescribeType() ){
> log.debug("QueryExecution started. DESCRIBE");
> executeDescribeSPARQL(querystr,out,outFormat);
> }else if( query.isSelectType() ){
> log.debug("QueryExecution started. SELECT");
> executeSelectSPARQL(querystr, out, outFormat);
> }else{
> // UPDATE is handled here
> log.debug("QueryExecution started. UPDATE");
> executeUpdateSPARQL(querystr);
> }
> }catch (Exception e){
> // UPDATE is handled here because UPDATE queries throws exception when
> // we try to do QueryFactory.create(querystr)
> log.debug("QueryExecution started. UPDATE after exception");
> try{
> executeUpdateSPARQL(querystr);
> }catch (Exception ex){
> log.debug("executeSPARQL: something definitelly wrong with the query: \n"+querystr+"\n"+e);
> }
> }
>
> Thanks,
> Milorad
>
>
>
>
>> ________________________________
>> From: Andy Seaborne<an...@apache.org>
>> To: jena-users@incubator.apache.org
>> Sent: Monday, March 5, 2012 2:47 PM
>> Subject: Re: DROP query
>>
>> On 05/03/12 13:07, Milorad Tosic wrote:
>>> I provided a code snippet.
>>
>> Except it does not do as you describe!
>>
>> When I run
>>
>> Query query = QueryFactory.create("DROP ALL") ;
>>
>> I get an exception as expected: Jena 2.7.0 and Jena 2.6.5.
>>
>>> Sure, I would provide the example as you suggested but I am not exactly sure that I understand what it should look like. Here is my best try:
>>> /**
>>> * This section throws exception
>>> **/
>>>
>>
>> complete => code so that I don't have to guess how to complete it.
>> Every guess is risk the root issue is being overlooked.
>> "Complete" mean I can cut and paste it into my development environment.
>>
>> (Also, I'd rather spend my time on the report, not fixing code - the
>> longer it will take, the longer it has to wait before I can find time to
>> do it)
>>
>> minimal => no large than necessary to illusrate the point.
>>
>>> String querystr = "DROP ALL";
>>> Query query = QueryFactory.create(querystr);
>>
>> As above. I get an exception and it never gets to the next line.
>>
>>> if( query.isSelectType() ){ // evaluated TRUE
>>> m_triplestore.enterCriticalSection(Lock.READ) ;
>>> try {
>>> QueryExecution qexec = QueryExecutionFactory.create(query, m_triplestore) ;
>>> ResultSet results = qexec.execSelect() ;
>>> print(outFormat, out, results);
>>> qexec.close();
>>> } finally {
>>> m_triplestore.leaveCriticalSection();
>>> }
>>> }
>>>
>>>
>>> /**
>>> * This section works fine
>>> **/
>>>
>>> String querystr = "DROP ALL";
>>> Query query = QueryFactory.create(querystr);
>>> m_triplestore.enterCriticalSection(Lock.WRITE);
>>> try {
>>> UpdateRequest updateRequest = UpdateFactory.create(querystr);
>>> UpdateAction.execute(updateRequest, m_triplestore);
>>> }catch (Exception e){
>>> log.debug(e);
>>> } finally {
>>> m_triplestore.commit();
>>> TDB.sync(m_triplestore);
>>> m_triplestore.leaveCriticalSection();
>>> }
>>>
>>>
>>> So, the problem is that the query "DROP ALL" is evaluated as a SELECT query by query.isSelectType() method instead of being evaluated as an update query.
>>>
>>> Milorad
>>>
>>>
>>> ps. We use jena 2.6.4/arq 2.8.7/tdb 0.8.10 and we still didn't hit the limits in our development, so far so good (we are limited to Java 5). Migrating to new versions of Jena would usually require some efforts investment, so we will probably stick with the current version for some time. Does Jena 7 require Java 6 or not?
>>
>> Jena 2.70 requires Java 6 - we don't support Java 5 anymore. Generally,
>> we aim for two major versions, currently java 6 and 7. Java 5 is past
>> it's end-of-life, depending on the system and support you have
>>
>> Andy
>>
>>
>>
Re: DROP query
Posted by Milorad Tosic <mb...@yahoo.com>.
Andy,
You are right, I overlooked the source of the exception as you correctly indicated. So, the code now looks like follows. Maybe not the most elegant code ever, but it does the work for me.
String querystr = "DROP ALL";
try {
//SPARQL 1.0 QUERY is handled here
Query query = QueryFactory.create(querystr);
if( query.isAskType() ){
log.debug("QueryExecution started. ASK");
executeAskSPARQL(querystr,out,outFormat);
}else if( query.isConstructType() ){
log.debug("QueryExecution started. CONSTRUCT");
executeConstructSPARQL(querystr,out,outFormat);
}else if( query.isDescribeType() ){
log.debug("QueryExecution started. DESCRIBE");
executeDescribeSPARQL(querystr,out,outFormat);
}else if( query.isSelectType() ){
log.debug("QueryExecution started. SELECT");
executeSelectSPARQL(querystr, out, outFormat);
}else{
// UPDATE is handled here
log.debug("QueryExecution started. UPDATE");
executeUpdateSPARQL(querystr);
}
}catch (Exception e){
// UPDATE is handled here because UPDATE queries throws exception when
// we try to do QueryFactory.create(querystr)
log.debug("QueryExecution started. UPDATE after exception");
try{
executeUpdateSPARQL(querystr);
}catch (Exception ex){
log.debug("executeSPARQL: something definitelly wrong with the query: \n"+querystr+"\n"+e);
}
}
Thanks,
Milorad
>________________________________
> From: Andy Seaborne <an...@apache.org>
>To: jena-users@incubator.apache.org
>Sent: Monday, March 5, 2012 2:47 PM
>Subject: Re: DROP query
>
>On 05/03/12 13:07, Milorad Tosic wrote:
>> I provided a code snippet.
>
>Except it does not do as you describe!
>
>When I run
>
> Query query = QueryFactory.create("DROP ALL") ;
>
>I get an exception as expected: Jena 2.7.0 and Jena 2.6.5.
>
>> Sure, I would provide the example as you suggested but I am not exactly sure that I understand what it should look like. Here is my best try:
>> /**
>> * This section throws exception
>> **/
>>
>
>complete => code so that I don't have to guess how to complete it.
>Every guess is risk the root issue is being overlooked.
>"Complete" mean I can cut and paste it into my development environment.
>
>(Also, I'd rather spend my time on the report, not fixing code - the
>longer it will take, the longer it has to wait before I can find time to
>do it)
>
>minimal => no large than necessary to illusrate the point.
>
>> String querystr = "DROP ALL";
>> Query query = QueryFactory.create(querystr);
>
>As above. I get an exception and it never gets to the next line.
>
>> if( query.isSelectType() ){ // evaluated TRUE
>> m_triplestore.enterCriticalSection(Lock.READ) ;
>> try {
>> QueryExecution qexec = QueryExecutionFactory.create(query, m_triplestore) ;
>> ResultSet results = qexec.execSelect() ;
>> print(outFormat, out, results);
>> qexec.close();
>> } finally {
>> m_triplestore.leaveCriticalSection();
>> }
>> }
>>
>>
>> /**
>> * This section works fine
>> **/
>>
>> String querystr = "DROP ALL";
>> Query query = QueryFactory.create(querystr);
>> m_triplestore.enterCriticalSection(Lock.WRITE);
>> try {
>> UpdateRequest updateRequest = UpdateFactory.create(querystr);
>> UpdateAction.execute(updateRequest, m_triplestore);
>> }catch (Exception e){
>> log.debug(e);
>> } finally {
>> m_triplestore.commit();
>> TDB.sync(m_triplestore);
>> m_triplestore.leaveCriticalSection();
>> }
>>
>>
>> So, the problem is that the query "DROP ALL" is evaluated as a SELECT query by query.isSelectType() method instead of being evaluated as an update query.
>>
>> Milorad
>>
>>
>> ps. We use jena 2.6.4/arq 2.8.7/tdb 0.8.10 and we still didn't hit the limits in our development, so far so good (we are limited to Java 5). Migrating to new versions of Jena would usually require some efforts investment, so we will probably stick with the current version for some time. Does Jena 7 require Java 6 or not?
>
>Jena 2.70 requires Java 6 - we don't support Java 5 anymore. Generally,
>we aim for two major versions, currently java 6 and 7. Java 5 is past
>it's end-of-life, depending on the system and support you have
>
> Andy
>
>
>
Re: DROP query
Posted by Andy Seaborne <an...@apache.org>.
On 05/03/12 13:07, Milorad Tosic wrote:
> I provided a code snippet.
Except it does not do as you describe!
When I run
Query query = QueryFactory.create("DROP ALL") ;
I get an exception as expected: Jena 2.7.0 and Jena 2.6.5.
> Sure, I would provide the example as you suggested but I am not exactly sure that I understand what it should look like. Here is my best try:
> /**
> * This section throws exception
> **/
>
complete => code so that I don't have to guess how to complete it.
Every guess is risk the root issue is being overlooked.
"Complete" mean I can cut and paste it into my development environment.
(Also, I'd rather spend my time on the report, not fixing code - the
longer it will take, the longer it has to wait before I can find time to
do it)
minimal => no large than necessary to illusrate the point.
> String querystr = "DROP ALL";
> Query query = QueryFactory.create(querystr);
As above. I get an exception and it never gets to the next line.
> if( query.isSelectType() ){ // evaluated TRUE
> m_triplestore.enterCriticalSection(Lock.READ) ;
> try {
> QueryExecution qexec = QueryExecutionFactory.create(query, m_triplestore) ;
> ResultSet results = qexec.execSelect() ;
> print(outFormat, out, results);
> qexec.close();
> } finally {
> m_triplestore.leaveCriticalSection();
> }
> }
>
>
> /**
> * This section works fine
> **/
>
> String querystr = "DROP ALL";
> Query query = QueryFactory.create(querystr);
> m_triplestore.enterCriticalSection(Lock.WRITE);
> try {
> UpdateRequest updateRequest = UpdateFactory.create(querystr);
> UpdateAction.execute(updateRequest, m_triplestore);
> }catch (Exception e){
> log.debug(e);
> } finally {
> m_triplestore.commit();
> TDB.sync(m_triplestore);
> m_triplestore.leaveCriticalSection();
> }
>
>
> So, the problem is that the query "DROP ALL" is evaluated as a SELECT query by query.isSelectType() method instead of being evaluated as an update query.
>
> Milorad
>
>
> ps. We use jena 2.6.4/arq 2.8.7/tdb 0.8.10 and we still didn't hit the limits in our development, so far so good (we are limited to Java 5). Migrating to new versions of Jena would usually require some efforts investment, so we will probably stick with the current version for some time. Does Jena 7 require Java 6 or not?
Jena 2.70 requires Java 6 - we don't support Java 5 anymore. Generally,
we aim for two major versions, currently java 6 and 7. Java 5 is past
it's end-of-life, depending on the system and support you have
Andy
Re: DROP query
Posted by Milorad Tosic <mb...@yahoo.com>.
I provided a code snippet. Sure, I would provide the example as you suggested but I am not exactly sure that I understand what it should look like. Here is my best try:
/**
* This section throws exception
**/
String querystr = "DROP ALL";
Query query = QueryFactory.create(querystr);
if( query.isSelectType() ){ // evaluated TRUE
m_triplestore.enterCriticalSection(Lock.READ) ;
try {
QueryExecution qexec = QueryExecutionFactory.create(query, m_triplestore) ;
ResultSet results = qexec.execSelect() ;
print(outFormat, out, results);
qexec.close();
} finally {
m_triplestore.leaveCriticalSection();
}
}
/**
* This section works fine
**/
String querystr = "DROP ALL";
Query query = QueryFactory.create(querystr);
m_triplestore.enterCriticalSection(Lock.WRITE);
try {
UpdateRequest updateRequest = UpdateFactory.create(querystr);
UpdateAction.execute(updateRequest, m_triplestore);
}catch (Exception e){
log.debug(e);
} finally {
m_triplestore.commit();
TDB.sync(m_triplestore);
m_triplestore.leaveCriticalSection();
}
So, the problem is that the query "DROP ALL" is evaluated as a SELECT query by query.isSelectType() method instead of being evaluated as an update query.
Milorad
ps. We use jena 2.6.4/arq 2.8.7/tdb 0.8.10 and we still didn't hit the limits in our development, so far so good (we are limited to Java 5). Migrating to new versions of Jena would usually require some efforts investment, so we will probably stick with the current version for some time. Does Jena 7 require Java 6 or not?
>________________________________
> From: Andy Seaborne <an...@apache.org>
>To: jena-users@incubator.apache.org
>Sent: Monday, March 5, 2012 1:44 PM
>Subject: Re: DROP query
>
>On 05/03/12 12:31, Milorad Tosic wrote:
>> jena 2.6.4
>
>I get parse error for that as well.
>
>If you think it's a bug, please could provide a complete, minimal example?
>
>(Jena 2.7.0 has been released)
>
> Andy
>
>>
>>
>>
>>
>>> ________________________________
>>> From: Andy Seaborne<an...@apache.org>
>>> To: jena-users@incubator.apache.org
>>> Sent: Monday, March 5, 2012 12:34 PM
>>> Subject: Re: DROP query
>>>
>>> On 05/03/12 07:39, Milorad Tosic wrote:
>>>> Hi,
>>>>
>>>> DROP clause is part of UPDATE SPARQL specification and in ARQ queries it is processed accordingly with UpdateRequest as well as other UPDATE type requests, while SELECT type queries are processed with QueryExecution. So, in a query processor code, that accepts arbitrary SPARQL query, one must resolve type of the input query first and then apply appropriate class. I do the query type resolution as follows:
>>>>
>>>> Query query = QueryFactory.create(querystr);
>>>> if( query.isAskType() ){
>>>> executeAskSPARQL(querystr,out,outFormat);
>>>> }else if( query.isConstructType() ){
>>>> executeConstructSPARQL(querystr,out,outFormat);
>>>> }else if( query.isDescribeType() ){
>>>> executeDescribeSPARQL(querystr,out,outFormat);
>>>> }else if( query.isSelectType() ){
>>>> executeQuerySPARQL(querystr, out, outFormat);
>>>> }else{
>>>> // UPDATE is handled here
>>>> executeUpdateSPARQL(querystr);
>>>> }
>>>>
>>>> However, DROP evaluates true on query.isSelectType() and ends up firing exception within executeQuerySPARQL. If DROP is processed by executeUpdateSPARQL, as it should be, everithing is fine.
>>>
>>> Query query = QueryFactory.create(querystr);
>>>
>>> This should throw an exception if a DROP update request is passed in then the rest of the code does not execute.
>>>
>>>
>>> Query query = QueryFactory.create("DROP GRAPH<http://example/g>") ;
>>> ==>
>>> Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "drop" "DROP "" at line 1, column 1.
>>> Was expecting one of:
>>> "base" ...
>>> "prefix" ...
>>> "select" ...
>>> "describe" ...
>>> "construct" ...
>>> "ask" ...
>>>
>>>>
>>>> I would say that DROP evaluating true by query.isSelectType() is a bug?
>>>
>>> Which version are you running?
>>>
>>> Andy
>>>
>>>>
>>>> Regards,
>>>> Milorad
>>>>
>>>
>>>
>>>
>>>
>
>
>
>
Re: DROP query
Posted by Andy Seaborne <an...@apache.org>.
On 05/03/12 12:31, Milorad Tosic wrote:
> jena 2.6.4
I get parse error for that as well.
If you think it's a bug, please could provide a complete, minimal example?
(Jena 2.7.0 has been released)
Andy
>
>
>
>
>> ________________________________
>> From: Andy Seaborne<an...@apache.org>
>> To: jena-users@incubator.apache.org
>> Sent: Monday, March 5, 2012 12:34 PM
>> Subject: Re: DROP query
>>
>> On 05/03/12 07:39, Milorad Tosic wrote:
>>> Hi,
>>>
>>> DROP clause is part of UPDATE SPARQL specification and in ARQ queries it is processed accordingly with UpdateRequest as well as other UPDATE type requests, while SELECT type queries are processed with QueryExecution. So, in a query processor code, that accepts arbitrary SPARQL query, one must resolve type of the input query first and then apply appropriate class. I do the query type resolution as follows:
>>>
>>> Query query = QueryFactory.create(querystr);
>>> if( query.isAskType() ){
>>> executeAskSPARQL(querystr,out,outFormat);
>>> }else if( query.isConstructType() ){
>>> executeConstructSPARQL(querystr,out,outFormat);
>>> }else if( query.isDescribeType() ){
>>> executeDescribeSPARQL(querystr,out,outFormat);
>>> }else if( query.isSelectType() ){
>>> executeQuerySPARQL(querystr, out, outFormat);
>>> }else{
>>> // UPDATE is handled here
>>> executeUpdateSPARQL(querystr);
>>> }
>>>
>>> However, DROP evaluates true on query.isSelectType() and ends up firing exception within executeQuerySPARQL. If DROP is processed by executeUpdateSPARQL, as it should be, everithing is fine.
>>
>> Query query = QueryFactory.create(querystr);
>>
>> This should throw an exception if a DROP update request is passed in then the rest of the code does not execute.
>>
>>
>> Query query = QueryFactory.create("DROP GRAPH<http://example/g>") ;
>> ==>
>> Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "drop" "DROP "" at line 1, column 1.
>> Was expecting one of:
>> "base" ...
>> "prefix" ...
>> "select" ...
>> "describe" ...
>> "construct" ...
>> "ask" ...
>>
>>>
>>> I would say that DROP evaluating true by query.isSelectType() is a bug?
>>
>> Which version are you running?
>>
>> Andy
>>
>>>
>>> Regards,
>>> Milorad
>>>
>>
>>
>>
>>
Re: DROP query
Posted by Milorad Tosic <mb...@yahoo.com>.
jena 2.6.4
>________________________________
> From: Andy Seaborne <an...@apache.org>
>To: jena-users@incubator.apache.org
>Sent: Monday, March 5, 2012 12:34 PM
>Subject: Re: DROP query
>
>On 05/03/12 07:39, Milorad Tosic wrote:
>> Hi,
>>
>> DROP clause is part of UPDATE SPARQL specification and in ARQ queries it is processed accordingly with UpdateRequest as well as other UPDATE type requests, while SELECT type queries are processed with QueryExecution. So, in a query processor code, that accepts arbitrary SPARQL query, one must resolve type of the input query first and then apply appropriate class. I do the query type resolution as follows:
>>
>> Query query = QueryFactory.create(querystr);
>> if( query.isAskType() ){
>> executeAskSPARQL(querystr,out,outFormat);
>> }else if( query.isConstructType() ){
>> executeConstructSPARQL(querystr,out,outFormat);
>> }else if( query.isDescribeType() ){
>> executeDescribeSPARQL(querystr,out,outFormat);
>> }else if( query.isSelectType() ){
>> executeQuerySPARQL(querystr, out, outFormat);
>> }else{
>> // UPDATE is handled here
>> executeUpdateSPARQL(querystr);
>> }
>>
>> However, DROP evaluates true on query.isSelectType() and ends up firing exception within executeQuerySPARQL. If DROP is processed by executeUpdateSPARQL, as it should be, everithing is fine.
>
> Query query = QueryFactory.create(querystr);
>
>This should throw an exception if a DROP update request is passed in then the rest of the code does not execute.
>
>
>Query query = QueryFactory.create("DROP GRAPH <http://example/g>") ;
>==>
>Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "drop" "DROP "" at line 1, column 1.
>Was expecting one of:
> "base" ...
> "prefix" ...
> "select" ...
> "describe" ...
> "construct" ...
> "ask" ...
>
>>
>> I would say that DROP evaluating true by query.isSelectType() is a bug?
>
>Which version are you running?
>
> Andy
>
>>
>> Regards,
>> Milorad
>>
>
>
>
>
Re: DROP query
Posted by Andy Seaborne <an...@apache.org>.
On 05/03/12 07:39, Milorad Tosic wrote:
> Hi,
>
> DROP clause is part of UPDATE SPARQL specification and in ARQ queries it is processed accordingly with UpdateRequest as well as other UPDATE type requests, while SELECT type queries are processed with QueryExecution. So, in a query processor code, that accepts arbitrary SPARQL query, one must resolve type of the input query first and then apply appropriate class. I do the query type resolution as follows:
>
> Query query = QueryFactory.create(querystr);
> if( query.isAskType() ){
> executeAskSPARQL(querystr,out,outFormat);
> }else if( query.isConstructType() ){
> executeConstructSPARQL(querystr,out,outFormat);
> }else if( query.isDescribeType() ){
> executeDescribeSPARQL(querystr,out,outFormat);
> }else if( query.isSelectType() ){
> executeQuerySPARQL(querystr, out, outFormat);
> }else{
> // UPDATE is handled here
> executeUpdateSPARQL(querystr);
> }
>
> However, DROP evaluates true on query.isSelectType() and ends up firing exception within executeQuerySPARQL. If DROP is processed by executeUpdateSPARQL, as it should be, everithing is fine.
Query query = QueryFactory.create(querystr);
This should throw an exception if a DROP update request is passed in
then the rest of the code does not execute.
Query query = QueryFactory.create("DROP GRAPH <http://example/g>") ;
==>
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered " "drop" "DROP "" at line 1, column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"describe" ...
"construct" ...
"ask" ...
>
> I would say that DROP evaluating true by query.isSelectType() is a bug?
Which version are you running?
Andy
>
> Regards,
> Milorad
>