unexpected result of group by

4 views
Skip to first unread message

Marcel Karnstedt-Hulpus

unread,
Jan 20, 2017, 5:36:55 AM1/20/17
to sta...@clarkparsia.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi,

when we run queries like

SELECT ?s (count(DISTINCT ?f) AS ?cnt)
WHERE { ?s a nat:ABC . ?f ?p ?o }
GROUP BY ?s

where nat:ABC does not exist (i.e., there is no single binding for
?s), we would expect an empty result.

But we rather get the result

s cnt
0

i.e., no binding for ?s but a 0 for ?cnt.

Why is that? It unfortunately breaks our automated processing of the
query.


Thanks,
Marcel


- --
Dr. Marcel Karnstedt-Hulpus
www.marcel.karnstedt.com

Senior Data Architect
IT & Production Corporate Markets / Databases
Springer Nature
www.springernature.com

tel +49-6221-4878868
mob +49-151-23125052
Tiergartenstrasse 17, 69121 Heidelberg, Germany

- ---
Springer Nature is a major new force in scientific, scholarly,
professional and educational publishing, created in May 2015 through
the combination of Nature Publishing Group, Palgrave Macmillan,
Macmillan Education and Springer Science+Business Media.
- ---
Branch of Springer-Verlag GmbH, Heidelberger Platz 3,
14197 Berlin, Germany
Registered Office: Berlin / Amtsgericht Berlin-Charlottenburg,
HRB 91881 B
Directors: Derk Haank, Martin Mos, Petrus W. J. Hendriks
- ---
- ---
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJYgehFAAoJELjmZAjIQprmr/UH/03kV3Ay9xW21wQoQYyZMxkP
y9NzZFj9gzGtQbGIzw4AsDtbk+uR2jAHdVSzTSBkqlxq1QJ57i4ip2P0oQlHG0mn
croBQZa2LAqppEcVHfp+VO0xKX1iEvJL+LDCqvEjSJK92OCX+6blcNIVdv6Irr0O
LQiuau78ZHOpA0fKBoWXkNBCwx5mSF1T1gjclPg+gwfvA5bspzKJFyOlwZdPnIST
y2PsNfK9ktk1dQINWYRQvkhEpDJJk4Gwoy83fdV+agn5GPfe2arcNu6RUJ2Z3C6T
Nlbzb6rGFhKk1HD1asOLSnJAaxIt7Ze9WkW1TsmXL5s/3kKLGlWB6MTRXG5rrnk=
=hj4N
-----END PGP SIGNATURE-----

Zachary Whitley

unread,
Jan 20, 2017, 9:51:04 AM1/20/17
to Stardog
I believe that this is correct. The query will return an empty graph over which the aggregate will be applied. I think this previous discussion might be relevant to your question [1].

[1] https://groups.google.com/a/clarkparsia.com/forum/#!topic/stardog/VcO5kylcEgU


--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+unsubscribe@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
---
You received this message because you are subscribed to the Google Groups "Stardog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stardog+unsubscribe@clarkparsia.com.


Zachary Whitley

unread,
Jan 20, 2017, 4:03:28 PM1/20/17
to Stardog
I should probably acknowledge that I only said that I think the result that you're getting is correct without providing a solution to your problem. Is there a particular reason why you can't process that response?

On Fri, Jan 20, 2017 at 9:51 AM, Zachary Whitley <zachary...@wavestrike.com> wrote:
I believe that this is correct. The query will return an empty graph over which the aggregate will be applied. I think this previous discussion might be relevant to your question [1].

[1] https://groups.google.com/a/clarkparsia.com/forum/#!topic/stardog/VcO5kylcEgU

Evren Sirin

unread,
Jan 21, 2017, 5:28:42 PM1/21/17
to Stardog
Adding "HAVING (bound(?s))" at the end of the query would get rid of
the empty result.

Best,
Evren

On Fri, Jan 20, 2017 at 4:03 PM, Zachary Whitley
>>> stardog+u...@clarkparsia.com
>>> For more options, visit this group at
>>> http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google Groups
>>> "Stardog" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to stardog+u...@clarkparsia.com.
>>>
>>
>
> --
> -- --
> You received this message because you are subscribed to the C&P "Stardog"
> group.
> To post to this group, send email to sta...@clarkparsia.com
> To unsubscribe from this group, send email to
> stardog+u...@clarkparsia.com

Marcel Karnstedt-Hulpus

unread,
Jan 23, 2017, 8:16:09 AM1/23/17
to sta...@clarkparsia.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Evren, Zachary,

thanks a lot for the explanation and the suggestion. Evren's hint
should indeed help us to overcome this issue.

Zachary, quick explanation: We automatically process the result of
different SPARQL queries to make sure that our data follows some sort
of contract. In this case here, the test passes when the query result
is empty. But it wasn't - although the data itself was not faulty.


Cheers,
Marcel
>>>> -- -- -- You received this message because you are subscribed
>>>> to the C&P "Stardog" group. To post to this group, send email
>>>> to sta...@clarkparsia.com To unsubscribe from this group,
>>>> send email to stardog+u...@clarkparsia.com For more
>>>> options, visit this group at
>>>> http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
>>>>
>>>>
- ---
>>>> You received this message because you are subscribed to the
>>>> Google Groups "Stardog" group. To unsubscribe from this group
>>>> and stop receiving emails from it, send an email to
>>>> stardog+u...@clarkparsia.com.
>>>>
>>>
>>
>> -- -- -- You received this message because you are subscribed to
>> the C&P "Stardog" group. To post to this group, send email to
>> sta...@clarkparsia.com To unsubscribe from this group, send
>> email to stardog+u...@clarkparsia.com For more options,
>> visit this group at
>> http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
>

iQEcBAEBCgAGBQJYhgIXAAoJELjmZAjIQprmIwYH/36rd+c3SoTk+rcookMTp/5w
qr5SME69/2w8lcFi+dLCBjAehbp3r6ShokbEmPImNk9Og9xJwo+O1J/mNRNJOznH
jX17p4HLxzLwDEgZ4H4u7b8ukz0Of4yxgmmF9BboD3YcG6lqTYbOsQwQmtFYaOjW
v4Vc0oDT7w4QAtOBA67TOg3Wr2msWGVNTsFom4avRwIb7YPLeGSYcCk8aZgm8waX
sR74ik6yov1Mbqo+0qo+fHBNUtsLb7zMaa3wnM4+NYj+3ULy0QHEbxYxi2d5AMNO
fQujtU3nmfChMmzjq1vtcCBGkEMc6tRMO1rBJHYz/SVHzM3GSGuaktHHbE4oRyw=
=7k7X
-----END PGP SIGNATURE-----

Zachary Whitley

unread,
Jan 23, 2017, 9:10:31 AM1/23/17
to Stardog
On Mon, Jan 23, 2017 at 8:16 AM, Marcel Karnstedt-Hulpus <marcel.k...@springernature.com> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Evren, Zachary,

thanks a lot for the explanation and the suggestion. Evren's hint
should indeed help us to overcome this issue.

Zachary, quick explanation: We automatically process the result of
different SPARQL queries to make sure that our data follows some sort
of contract. In this case here, the test passes when the query result
is empty. But it wasn't - although the data itself was not faulty.


Thanks for sharing. Sounds somewhat like what ICV does [1]. Ever try looking into using ICV for what you're doing? It might have some advantages to the approach you're using. I'm just interested in hearing how people are using Stardog, what worked, what didn't, why. etc.

[1] http://docs.stardog.com/#_validating_constraints
 
>>>> send email to stardog+unsubscribe@clarkparsia.com For more

>>>> options, visit this group at
>>>> http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
>>>>
>>>>
- ---
>>>> You received this message because you are subscribed to the
>>>> Google Groups "Stardog" group. To unsubscribe from this group
>>>> and stop receiving emails from it, send an email to

>>>>
>>>
>>
>> -- -- -- You received this message because you are subscribed to
>> the C&P "Stardog" group. To post to this group, send email to
>> sta...@clarkparsia.com To unsubscribe from this group, send
>> email to stardog+unsubscribe@clarkparsia.com For more options,
-----END PGP SIGNATURE-----

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
---
You received this message because you are subscribed to the Google Groups "Stardog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stardog+unsubscribe@clarkparsia.com.


Marcel Karnstedt-Hulpus

unread,
Jan 26, 2017, 10:09:58 AM1/26/17
to sta...@clarkparsia.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Zachary,

ICV is indeed something interesting that we briefly expected before.
We didn't use it in the first place since pure SPARQL leaves us in the
smallest technical debt for this task.

Anyhow, we'll have a look at what advantages ICV has to offer.


Cheers,
Marcel


On 23/01/2017 15:10, Zachary Whitley wrote:
>
>
> On Mon, Jan 23, 2017 at 8:16 AM, Marcel Karnstedt-Hulpus
> <marcel.k...@springernature.com
> <mailto:marcel.k...@springernature.com>> wrote:
>
> Hi Evren, Zachary,
>
> thanks a lot for the explanation and the suggestion. Evren's hint
> should indeed help us to overcome this issue.
>
> Zachary, quick explanation: We automatically process the result of
> different SPARQL queries to make sure that our data follows some
> sort of contract. In this case here, the test passes when the query
> result is empty. But it wasn't - although the data itself was not
> faulty.
>
>
>> Thanks for sharing. Sounds somewhat like what ICV does [1]. Ever
>> try looking into using ICV for what you're doing? It might have
>> some advantages to the approach you're using. I'm just interested
>> in hearing how people are using Stardog, what worked, what
>> didn't, why. etc.
>
>> [1] http://docs.stardog.com/#_validating_constraints
>
>
>
> Cheers, Marcel
>
>
> On 21/01/2017 23:28, Evren Sirin wrote:
>> Adding "HAVING (bound(?s))" at the end of the query would get
>> rid of the empty result.
>
>> Best, Evren
>
>> On Fri, Jan 20, 2017 at 4:03 PM, Zachary Whitley
>> <zachary...@wavestrike.com
> <mailto:zachary...@wavestrike.com>> wrote:
>>> I should probably acknowledge that I only said that I think
>>> the result that you're getting is correct without providing a
>>> solution to your problem. Is there a particular reason why you
>>> can't process that response?
>>>
>>> On Fri, Jan 20, 2017 at 9:51 AM, Zachary Whitley
>>> <zachary...@wavestrike.com
> <mailto:zachary...@wavestrike.com>> wrote:
>>>>
>>>> I believe that this is correct. The query will return an
>>>> empty graph over which the aggregate will be applied. I think
>>>> this previous discussion might be relevant to your question
>>>> [1].
>>>>
>>>> [1]
>>>> https://groups.google.com/a/clarkparsia.com/forum/#!topic/stardog/VcO5kylcEgU
>
>>>>
<https://groups.google.com/a/clarkparsia.com/forum/#%21topic/stardog/VcO5kylcEgU>
>>>>
>>>>
>>>>
> On Fri, Jan 20, 2017 at 5:36 AM, Marcel Karnstedt-Hulpus
>>>> <marcel.k...@springernature.com
> <mailto:marcel.k...@springernature.com>> wrote:
>>>>>
>> Hi,
>
>> when we run queries like
>
>> SELECT ?s (count(DISTINCT ?f) AS ?cnt) WHERE { ?s a nat:ABC . ?f
>> ?p ?o } GROUP BY ?s
>
>> where nat:ABC does not exist (i.e., there is no single binding
>> for ?s), we would expect an empty result.
>
>> But we rather get the result
>
>> s cnt 0
>
>> i.e., no binding for ?s but a 0 for ?cnt.
>
>> Why is that? It unfortunately breaks our automated processing of
>> the query.
>
>
>> Thanks, Marcel
>
>
>>>>>
>>>>> -- -- -- You received this message because you are
>>>>> subscribed to the C&P "Stardog" group. To post to this
>>>>> group, send email to sta...@clarkparsia.com
>>>>> <mailto:sta...@clarkparsia.com> To
> unsubscribe from this group,
>>>>> send email to stardog+u...@clarkparsia.com
> <mailto:stardog%2Bunsu...@clarkparsia.com> For more
>>>>> options, visit this group at
>>>>> http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
>
>>>>>
<http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en>
>>>>>
>>>>>
> ---
>>>>> You received this message because you are subscribed to
>>>>> the Google Groups "Stardog" group. To unsubscribe from this
>>>>> group and stop receiving emails from it, send an email to
>>>>> stardog+u...@clarkparsia.com
> <mailto:stardog%2Bunsu...@clarkparsia.com>.
>>>>>
>>>>
>>>
>>> -- -- -- You received this message because you are subscribed
>>> to the C&P "Stardog" group. To post to this group, send email
>>> to sta...@clarkparsia.com <mailto:sta...@clarkparsia.com> To
> unsubscribe from this group, send
>>> email to stardog+u...@clarkparsia.com
> <mailto:stardog%2Bunsu...@clarkparsia.com> For more options,
> <http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en>
>
>
>
> -- -- -- You received this message because you are subscribed to
> the C&P "Stardog" group. To post to this group, send email to
> sta...@clarkparsia.com <mailto:sta...@clarkparsia.com> To
> unsubscribe from this group, send email to
> stardog+u...@clarkparsia.com
> <mailto:stardog%2Bunsu...@clarkparsia.com> For more options,
> <http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en>
> --- You received this message because you are subscribed to the
> Google Groups "Stardog" group. To unsubscribe from this group and
> stop receiving emails from it, send an email to
> stardog+u...@clarkparsia.com
> <mailto:stardog%2Bunsu...@clarkparsia.com>.
>
>
> -- -- -- You received this message because you are subscribed to
> the C&P "Stardog" group. To post to this group, send email to
> sta...@clarkparsia.com To unsubscribe from this group, send email
> to stardog+u...@clarkparsia.com For more options, visit this
> group at
> http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en ---
> You received this message because you are subscribed to the Google
> Groups "Stardog" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> stardog+u...@clarkparsia.com
> <mailto:stardog+u...@clarkparsia.com>.
iQEbBAEBCgAGBQJYihFEAAoJELjmZAjIQprmdkAH+It2yOt5rNj6uIg9+IG5st34
5gq8oBXmwwjwcSPk9fvtAXKECPGGZI2UM+54x0iECBf77RDT6z8RZAqQwdRUrvtK
Xia7b/VtyUgp7Xg2JMO5hb4m9Gt2zJjZ8ZgKVNh5GOBCbOYEGYC6tLO15v3MKiNh
Jol3PIxD2FHZwlnhsFlAtVKfTuUmaVGnBkSpjcyPC2QoATPnmZKWokH5PZ21hNh1
7pdQvJRSVnPck/J5rNCI//DSAPFaU1DmOF2xbAYgeX96i5wbkPnWAQu+eOOCXuBE
TBEE3XI4C5Hjh4nzsR1dRoO4RKzl4NqtnTsw4nlieS5yGl1qYPZ/An2upFN0EQ==
=CdoA
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages