You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Rob Vesse (JIRA)" <ji...@apache.org> on 2013/04/29 20:36:16 UTC
[jira] [Closed] (JENA-445) a problem in rewriting nested query by
AlgebraGenerator
[ https://issues.apache.org/jira/browse/JENA-445?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rob Vesse closed JENA-445.
--------------------------
> a problem in rewriting nested query by AlgebraGenerator
> -------------------------------------------------------
>
> Key: JENA-445
> URL: https://issues.apache.org/jira/browse/JENA-445
> Project: Apache Jena
> Issue Type: Bug
> Affects Versions: Jena 2.10.0
> Environment: Windows
> Reporter: John Liu
> Assignee: Rob Vesse
>
> I found a problem when rewriting a nested query by AlgebraGenerator, the generated query becomes syntax incorrect query. The version of JENA I tested is 2.7.1 and 2.10.1
>
> The code I rewrite the query is:
> Query query = QueryFactory.create(queryString);
> AlgebraGenerator ag =
> new AlgebraGenerator();
> Op op = ag.compile(query);
> Query query2 = OpAsQuery.asQuery(op);
> The original query is:
> PREFIX dcterms: <http://purl.org/dc/terms/>
> PREFIX dbpedia: <http://dbpedia.org/resource/>
> SELECT ?num_of_holidays ?celebrate_Chinese_New_Year WHERE {
> {SELECT ?country_cat (COUNT(?holiday) as ?num_of_holidays)
> WHERE {?country_cat <http://www.w3.org/2004/02/skos/core#broader> <http://dbpedia.org/resource/Category:Public_holidays_by_country>.
> ?holiday dcterms:subject ?country_cat
> }GROUP by ?country_cat
> }
> {
> SELECT ?country_cat (COUNT(?holiday) as ?celebrate_Chinese_New_Year)
> WHERE {
> ?country_cat <http://www.w3.org/2004/02/skos/core#broader> <http://dbpedia.org/resource/Category:Public_holidays_by_country>.
> ?holiday dcterms:subject ?country_cat
> FILTER(?holiday="http://dbpedia.org/resource/Lunar_New_Year's_Day")
> }GROUP by ?country_cat
> }
> }
> The generated query is:
> SELECT ?country_cat ?celebrate_Chinese_New_Year
> WHERE
> { { ?country_cat <http://www.w3.org/2004/02/skos/core#broader> <http://dbpedia.org/resource/Category:Public_holidays_by_country> .
> ?holiday <http://purl.org/dc/terms/subject> ?country_cat
> BIND(count(?holiday) AS ?num_of_holidays)
> }
> { ?country_cat <http://www.w3.org/2004/02/skos/core#broader> <http://dbpedia.org/resource/Category:Public_holidays_by_country> .
> ?holiday <http://purl.org/dc/terms/subject> ?country_cat
> FILTER ( ?holiday = "http://dbpedia.org/resource/Lunar_New_Year's_Day" )
> BIND(count(?holiday) AS ?celebrate_Chinese_New_Year)
> }
> }
> GROUP BY ?country_cat
> The generated query has a syntax error: "Line 5, column 12: Aggregate expression not legal at this point".
> The following is a java class to demonstrate the problem:
> import com.hp.hpl.jena.query.Query;
> import com.hp.hpl.jena.query.QueryFactory;
> import com.hp.hpl.jena.sparql.algebra.AlgebraGenerator;
> import com.hp.hpl.jena.sparql.algebra.Op;
> import com.hp.hpl.jena.sparql.algebra.OpAsQuery;
> public class TestJena {
> /**
> * @param args
> */
> public static void main(String[] args) {
>
> String queryString =
> "PREFIX dcterms: <http://purl.org/dc/terms/> \n" +
> "PREFIX dbpedia: <http://dbpedia.org/resource/> \n" +
>
> "SELECT ?num_of_holidays ?celebrate_Chinese_New_Year WHERE { \n" +
> "{" +
> "SELECT ?country_cat (COUNT(?holiday) as ?num_of_holidays) \n" +
> "WHERE {" +
> "?country_cat <http://www.w3.org/2004/02/skos/core#broader> <http://dbpedia.org/resource/Category:Public_holidays_by_country>. \n" +
> "?holiday dcterms:subject ?country_cat \n" +
> "}GROUP by ?country_cat \n" +
> "} \n" +
> "{ \n" +
> "SELECT ?country_cat (COUNT(?holiday) as ?celebrate_Chinese_New_Year) \n" +
> "WHERE { \n" +
> "?country_cat <http://www.w3.org/2004/02/skos/core#broader> <http://dbpedia.org/resource/Category:Public_holidays_by_country>. \n" +
> "?holiday dcterms:subject ?country_cat \n" +
> "FILTER(?holiday=\"http://dbpedia.org/resource/Lunar_New_Year\'s_Day\") \n" +
> "}GROUP by ?country_cat \n" +
> "} \n" +
> "}\n";
>
> System.out.println("Original query: \n" + queryString);
>
> Query query = QueryFactory.create(queryString);
>
> AlgebraGenerator ag = new AlgebraGenerator();
> Op op = ag.compile(query);
>
> Query query2 = OpAsQuery.asQuery(op);
>
> String queryString2 = query2.toString();
>
> System.out.println("Update query: \n" + queryString2);
>
> Query newQuery2 = QueryFactory.create(queryString2);
>
>
>
> }
> }
>
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira