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

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

Comments

Projects
None yet
1 participant
@GoogleCodeExporter
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

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

Fixed by revision 385.

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

  • Changed state: Verified
Fixed by revision 385.

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

  • Changed state: Verified
@GoogleCodeExporter

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

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

  • Added labels: Release5.0.1

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

  • Added labels: Release5.0.1
@GoogleCodeExporter

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 16, 2015

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
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