Hi Francesco, Note the a workaround query is to replace MAX() with SAMPLE() or IRI(MAX(str())) , although only the last one will provide a repeatable result:
SQL> SPARQL PREFIX km4c:<http://www.disit.org/km4city/schema <http://www.disit.org/km4city/schema>#> PREFIX foaf:<http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns <http://www.w3.org/1999/02/22-rdf-syntax-ns>#> SELECT ?ride (IRI(MAX(str(?avmr))) AS ?avmrLast) WHERE{ ?bs rdf:type km4c:BusStop. ?bs foaf:name "PIAZZA DI SAN MARCO". ?bsf km4c:isForecastOfBusStop ?bs. ?bsf km4c:isForecastOfAVM ?avmr. ?ride km4c:hasAVMRecord ?avmr. } GROUP BY ?ride ORDER BY DESC (?avmrLast) LIMIT 15; ride avmrLast LONG VARCHAR LONG VARCHAR _______________________________________________________________________________ http://www.disit.org/km4city/resource/4900006 <http://www.disit.org/km4city/resource/4900006> http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006 <http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006> 1 Rows. -- 16 msec. SQL> SQL> SPARQL PREFIX km4c:<http://www.disit.org/km4city/schema <http://www.disit.org/km4city/schema>#> PREFIX foaf:<http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns <http://www.w3.org/1999/02/22-rdf-syntax-ns>#> SELECT ?ride (SAMPLE(?avmr) AS ?avmrLast) WHERE{ ?bs rdf:type km4c:BusStop. ?bs foaf:name "PIAZZA DI SAN MARCO". ?bsf km4c:isForecastOfBusStop ?bs. ?bsf km4c:isForecastOfAVM ?avmr. ?ride km4c:hasAVMRecord ?avmr. } GROUP BY ?ride ORDER BY DESC (?avmrLast) LIMIT 15; ride avmrLast LONG VARCHAR LONG VARCHAR _______________________________________________________________________________ http://www.disit.org/km4city/resource/4900006 <http://www.disit.org/km4city/resource/4900006> http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006 <http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006> 1 Rows. -- 12 msec. SQL> Best Regards Hugh Williams Professional Services OpenLink Software, Inc. // http://www.openlinksw.com/ <http://www.openlinksw.com/> Weblog -- http://www.openlinksw.com/blogs/ <http://www.openlinksw.com/blogs/> LinkedIn -- http://www.linkedin.com/company/openlink-software/ <http://www.linkedin.com/company/openlink-software/> Twitter -- http://twitter.com/OpenLink <http://twitter.com/OpenLink> Google+ -- http://plus.google.com/100570109519069333827/ <http://plus.google.com/100570109519069333827/> Facebook -- http://www.facebook.com/OpenLinkSoftware <http://www.facebook.com/OpenLinkSoftware> Universal Data Access, Integration, and Management Technology Providers > On 12 Nov 2015, at 01:38, Hugh Williams <hwilli...@openlinksw.com > <mailto:hwilli...@openlinksw.com>> wrote: > > Hi Francesco, > > I have been able to recreate this issue with the latest open source develop/7 > build and reported to development to look into: > > SQL> SPARQL PREFIX km4c:<http://www.disit.org/km4city/schema# > <http://www.disit.org/km4city/schema#>> PREFIX > foaf:<http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>> PREFIX > rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns# > <http://www.w3.org/1999/02/22-rdf-syntax-ns#>> SELECT ?ride > (MAX(?avmr) AS ?avmrLast) WHERE{ ?bs rdf:type km4c:BusStop. > ?bs foaf:name "PIAZZA DI SAN MARCO". ?bsf km4c:isForecastOfBusStop > ?bs. ?bsf km4c:isForecastOfAVM ?avmr. ?ride km4c:hasAVMRecord > ?avmr. } GROUP BY ?ride ORDER BY DESC (?avmrLast) LIMIT 15; > ride > avmrLast > LONG VARCHAR > LONG VARCHAR > _______________________________________________________________________________ > > http://www.disit.org/km4city/resource/4900006 > <http://www.disit.org/km4city/resource/4900006> > iri_id_0_with_no_name_entry > > 1 Rows. -- 8 msec. > SQL> SPARQL PREFIX km4c:<http://www.disit.org/km4city/schema# > <http://www.disit.org/km4city/schema#>> PREFIX > foaf:<http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>> PREFIX > rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns# > <http://www.w3.org/1999/02/22-rdf-syntax-ns#>> SELECT ?ride (?avmr AS > ?avmrLast) WHERE{ ?bs rdf:type km4c:BusStop. ?bs > foaf:name "PIAZZA DI SAN MARCO". ?bsf km4c:isForecastOfBusStop ?bs. > ?bsf km4c:isForecastOfAVM ?avmr. ?ride km4c:hasAVMRecord ?avmr. > } GROUP BY ?ride ORDER BY DESC (?avmrLast) LIMIT 15; > ride > avmrLast > LONG VARCHAR > LONG VARCHAR > _______________________________________________________________________________ > > http://www.disit.org/km4city/resource/4900006 > <http://www.disit.org/km4city/resource/4900006> > > http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006 > > <http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006> > > 1 Rows. -- 9 msec. > SQL> status(''); > REPORT > VARCHAR > _______________________________________________________________________________ > > OpenLink Virtuoso VDB Server > Version 07.20.3214-pthreads for Linux as of Nov 5 2015 > Registered to OpenLink Development (Internal Use Only) (Personal Edition, 500 > connections) > Started on: 2015-11-12 02:15 GMT+1 > > Best Regards > Hugh Williams > Professional Services > OpenLink Software, Inc. // http://www.openlinksw.com/ > <http://www.openlinksw.com/> > Weblog -- http://www.openlinksw.com/blogs/ > <http://www.openlinksw.com/blogs/> > LinkedIn -- http://www.linkedin.com/company/openlink-software/ > <http://www.linkedin.com/company/openlink-software/> > Twitter -- http://twitter.com/OpenLink <http://twitter.com/OpenLink> > Google+ -- http://plus.google.com/100570109519069333827/ > <http://plus.google.com/100570109519069333827/> > Facebook -- http://www.facebook.com/OpenLinkSoftware > <http://www.facebook.com/OpenLinkSoftware> > Universal Data Access, Integration, and Management Technology Providers > >> On 11 Nov 2015, at 18:09, Francesco Balzu <i_ba...@hotmail.it >> <mailto:i_ba...@hotmail.it>> wrote: >> >> Excuse me if I submit again the same question, but it is important to me to >> know where I am mistaken. >> I have a problem with the MAX aggregate function in SPARQL. I provide the >> data and the query that generates the wrong (according to me) result. The >> query is slightly different from the one that I sent last time: this >> recreates the issue, in my pc. >> >> The two graphs needed are at >> https://www.dropbox.com/sh/fl1yzk98bg2de1r/AABoMoXSHYWZXqgi96I7URbca?dl=0 >> <https://www.dropbox.com/sh/fl1yzk98bg2de1r/AABoMoXSHYWZXqgi96I7URbca?dl=0> >> The file avm_dump_25K.ttl contains the graph >> <http://localhost:8890/avm_quadStore_25K >> <http://localhost:8890/avm_quadStore_25K>>, whereas the file >> Autobus_lotto_metropolitano_f.ttl contains the graph < >> http://www.disit.org/km4city/resource/Autobus/5_Lotto_Metropolitano_Firenze_f >> >> <http://www.disit.org/km4city/resource/Autobus/5_Lotto_Metropolitano_Firenze_f>> >> I load the two graphs into Virtuoso Quad Store >> I run the following query: >> >> >> PREFIX km4c:<http://www.disit.org/km4city/schema# >> <http://www.disit.org/km4city/schema#>> >> PREFIX foaf:<http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>> >> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns# >> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>> >> >> SELECT ?ride (MAX(?avmr) AS ?avmrLast) >> WHERE{ >> ?bs rdf:type km4c:BusStop. >> ?bs foaf:name "PIAZZA DI SAN MARCO". >> ?bsf km4c:isForecastOfBusStop ?bs. >> ?bsf km4c:isForecastOfAVM ?avmr. >> ?ride km4c:hasAVMRecord ?avmr. >> } >> GROUP BY ?ride ORDER BY DESC (?avmrLast) LIMIT 15 >> >> >> and I obtain as result >> >> >> ride avmrLast >> http://www.disit.org/km4city/resource/4900006 >> <http://www.disit.org/km4city/resource/4900006> >> iri_id_0_with_no_name_entry >> <http://localhost:8890/conductor/iri_id_0_with_no_name_entry> >> >> If I don't use MAX function, that is if I run >> >> >> PREFIX km4c:<http://www.disit.org/km4city/schema# >> <http://www.disit.org/km4city/schema#>> >> PREFIX foaf:<http://xmlns.com/foaf/0.1/ <http://xmlns.com/foaf/0.1/>> >> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns# >> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>> >> >> SELECT ?ride (?avmr AS ?avmrLast) >> WHERE{ >> ?bs rdf:type km4c:BusStop. >> ?bs foaf:name "PIAZZA DI SAN MARCO". >> ?bsf km4c:isForecastOfBusStop ?bs. >> ?bsf km4c:isForecastOfAVM ?avmr. >> ?ride km4c:hasAVMRecord ?avmr. >> } >> GROUP BY ?ride ORDER BY DESC (?avmrLast) LIMIT 15 >> >> I obtain >> ride avmrLast >> http://www.disit.org/km4city/resource/4900006 >> <http://www.disit.org/km4city/resource/4900006> >> http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006 >> >> <http://www.disit.org/km4city/resource/2015-12-11T10:10:02.3500006+02:00+4900006> >> >> In this case the dataset is small and I get only one row as result, but in >> general it may be much bigger and so I would need to use max function. >> >> Thanks for your precious help. >> Best regards, >> Francesco Balzano. >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Virtuoso-users mailing list >> Virtuoso-users@lists.sourceforge.net >> <mailto:Virtuoso-users@lists.sourceforge.net> >> https://lists.sourceforge.net/lists/listinfo/virtuoso-users >> <https://lists.sourceforge.net/lists/listinfo/virtuoso-users>
------------------------------------------------------------------------------
_______________________________________________ Virtuoso-users mailing list Virtuoso-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/virtuoso-users