Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tolog count() should be able to count zero #80

Open
GoogleCodeExporter opened this issue Mar 16, 2015 · 7 comments
Open

tolog count() should be able to count zero #80

GoogleCodeExporter opened this issue Mar 16, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

The query

  select count($T) from instance-of($T, op:Person)?

produces nothing if there are no persons (not even zero). This causes code 
assuming there is a result to crash. It's possible to code around this 
defensively, but there seems to be no reason to force people to do it. 
Instead, count() should just produce zero if there are no results.

Original issue reported on code.google.com by lar...@gmail.com on 19 Jul 2009 at 10:02

@GoogleCodeExporter
Copy link
Author

This is how SQL behaves:

topicmaps=> select count(*) from tm_association where 1 = 2;
 count 
-------
     0
(1 row)

Original comment by lar...@gmail.com on 21 Jul 2009 at 7:52

@GoogleCodeExporter
Copy link
Author

i committed a fix for this issue, see r385:

if the select clause only contains counted variables, and the query does not 
match
anything, the result set contains a row with all zeros instead of an empty 
result set.

Original comment by thomas.n...@spaceapplications.com on 4 Aug 2009 at 9:29

@GoogleCodeExporter
Copy link
Author

Fixed by revision 385.

Original comment by lar...@gmail.com on 13 Aug 2009 at 12:10

  • Changed state: Verified

@GoogleCodeExporter
Copy link
Author

Original comment by lar...@gmail.com on 1 Sep 2009 at 12:00

  • Added labels: Release5.0.1

@GoogleCodeExporter
Copy link
Author

This should be reopened since r385 works only because the QueryProcessorTest 
manipulates the initial QueryMatches size in the setup method, see
<https://code.google.com/p/ontopia/source/browse/trunk/ontopia-engine/src/test/j
ava/net/ontopia/topicmaps/query/core/QueryProcessorTest.java#51>

Correct fix:
        // fixes issue 80: <https://code.google.com/p/ontopia/issues/detail?id=80> 
        // return 0 if the query did not match anything, and
        // the select clauses contain only counted variables
        if (countVars.size() == matches.colcount && matches.last == -1) {
            final Object[] row = matches.data[++matches.last];
            for (int i = 0; i < matches.colcount; i++) {
                row[i] = new Integer(0);
            }
            return matches;
        }

This increases the "last" property and does not rely on matches size which is 
usally set to 100 


Original comment by lars.he...@gmail.com on 29 Sep 2014 at 5:18

@GoogleCodeExporter
Copy link
Author

Slightly better (since it does not create new Integer instances):

        // fixes issue 80: <https://code.google.com/p/ontopia/issues/detail?id=80> 
        // return 0 if the query did not match anything, and
        // the select clauses contain only counted variables
        if (countVars.size() == matches.colcount && matches.last == -1) {
            final Object[] row = matches.data[++matches.last];
            for (int i = 0; i < matches.colcount; i++) {
                row[i] = Integer.valueOf(0);
            }
            return matches;
        }

Original comment by lars.he...@gmail.com on 29 Sep 2014 at 5:32

@GoogleCodeExporter
Copy link
Author

Re-opening conform https://code.google.com/p/ontopia/issues/detail?id=506#c2

Original comment by qsieb...@gmail.com on 2 Oct 2014 at 8:57

  • Changed state: New

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant