jlowenz / hypergraphdb

Automatically exported from code.google.com/p/hypergraphdb
0 stars 0 forks source link

hg.count fails for And when the query changes during normalization #63

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. hg.count(graph, hg.and(hg.or(hg.type(TestBean.class))

What is the expected output? What do you see instead?
The number of TestBean atoms, an exception occurs instaed.

What version of the product are you using? On what operating system?
trunk, SVN 1371

Please provide any additional information below.

Exception in thread "main" java.lang.ClassCastException: 
org.hypergraphdb.query.AtomTypeCondition cannot be cast to 
org.hypergraphdb.query.And
    at org.hypergraphdb.ResultSizeEstimation$12.count(ResultSizeEstimation.java:345)
    at org.hypergraphdb.HGQuery$hg$5.call(HGQuery.java:953)
    at org.hypergraphdb.HGQuery$hg$5.call(HGQuery.java:1)
    at org.hypergraphdb.transaction.HGTransactionManager.transact(HGTransactionManager.java:397)
    at org.hypergraphdb.transaction.HGTransactionManager.ensureTransaction(HGTransactionManager.java:323)
    at org.hypergraphdb.transaction.HGTransactionManager.ensureTransaction(HGTransactionManager.java:294)
    at org.hypergraphdb.HGQuery$hg.count(HGQuery.java:946)

The normalized version of the query is: hg.type(TestBean.class).

Suggested fix:

Index: java/org/hypergraphdb/ResultSizeEstimation.java
===================================================================
--- java/org/hypergraphdb/ResultSizeEstimation.java (revision 1371)
+++ java/org/hypergraphdb/ResultSizeEstimation.java (working copy)
@@ -342,11 +342,9 @@
            x = q.getCondition();
            if (x == Nothing.Instance)
                return 0;
-           And cond = (And)q.getCondition();
-           if (cond.size() == 1)
+           if (!(x instanceof And))
            {
-               x = cond.get(0);
-               Counter c = countersMap.get(cond.get(0).getClass());
+               Counter c = countersMap.get(x.getClass());
                if (c != null)
                    return c.count(graph, x);
            }

The "cond.size() == 1" check is no longer necessary as of the SVN 1371 changes.

Original issue reported on code.google.com by cgbeek...@gmail.com on 25 Jun 2011 at 8:27