[Mulgara-dev] trouble with doubles

David Smith DMS at viewpointusa.com
Fri Aug 1 20:05:14 UTC 2008


All,
 
We're back to trying to work with the datatyping model. We'd given up
for a while -- processing the results after the query, but it seems that
there's been some activity in this area lately that might be worth
looking at.
 
So the first thing we noticed was that order by didn't seem to
understand numerics.
After looking in the sources it appeared that
"OrderByRowComparator.java" was trying to get it right, but choked with
negative numbers.
 
I'm attaching a patch file with my attempt at a fix (it seems to work),
perhaps someone more familar could chime in.
 
The next problem we found was that have a negative literal in a
mulgara:lt or mulgara:gt statement causes a "Query Error"
I tried to figure this one out but have to admit I'm stumped.
The test ITQL file I've added shows the problem.
It also shows that even with a positive number in the lt/gt statement
Mulgara isn't correctly evaluating the results.
I'd also like to question the fact that the XSDResolver::Resolve method
seems to be trying to pull a range from the stringPool, which I'd bet is
trying to do lexically what it should be doing against the values of the
literals in the stringpool.
 
I'm game to try and figure some of this out, but am currently over my
head.
 
(
As a reminder...
We're using Mulgara via the SOAP interface on Windows 2003 x64 edition.
)
 
 
Thanks
 
Dave Smith
Viewpoint Data Management
 
 
=============
Index: OrderByRowComparator.java
===================================================================
--- OrderByRowComparator.java (revision 1118)
+++ OrderByRowComparator.java (working copy)
@@ -345,43 +345,37 @@
     Node rdfNode = value;
 
     if (rdfNode instanceof Literal) {
+
       String text = ((Literal) rdfNode).getLexicalForm();
 
-      // Check if the string is a number.
-      int len = text.length();
-      boolean isNumber = true;
-      boolean hasDecimalPoint = false;
+      if( text.length() > 0 )
+      {
+    char ch= text.charAt(0);
 
-      if (logger.isDebugEnabled()) {
+    // if it smells like a numeric (and not a DateTime)
+    //
+    if( ((ch >= '0' && ch <= '9') || ch == '.' || ch == '+' || ch ==
'-' ) && !(text.indexOf('T') >= 0) )
+    {
+     Float f= Float.NaN;
+     boolean isNumber= false;
+     try
+     {
+      f= new Float(text);
+      isNumber= true;
+     }
+     catch( NumberFormatException ex )
+     {
+     }
 
-        logger.debug("Checking if " + text + " is a number");
-      }
+     if( isNumber )
+     {
+      return f;
+     }
+    }
+   }
 
-      // Check if the string is empty
-      isNumber = len > 0;
-
-      for (int i = 0; i < len; ++i) {
-        char ch = text.charAt(i);
-        if (ch == '.') {
-          if (hasDecimalPoint) {
-            // A number can't have two decimal points.
-            isNumber = false;
-            break;
-          }
-
-          hasDecimalPoint = true;
-        } else if ( (ch < '0') || (ch > '9')) {
-          // A char which is not a digit.
-          isNumber = false;
-          break;
-        }
-      }
-
-      if (isNumber) {
-        return new Float(text);
-      }
-
       return text;
+
     } else if (rdfNode instanceof URIReference) {
       return ((URIReference) rdfNode).getURI().toString();
     } else if (rdfNode instanceof BlankNode) {

 
=============
 
create <rmi://dmstablet2.viewpoint.local/server1#sampledata>;
create <rmi://dmstablet2.viewpoint.local/server1#xsd>
<http://mulgara.org/mulgara#XMLSchemaModel>;

delete
select $s <urn:aValue> $o
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
where 
	$s <urn:aValue> $o 
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
	
;

insert
	<urn:0001> <urn:aValue>
'9000.0'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'-80.0'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'-8.8887'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'-8.00'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'6000'^^<http://www.w3.org/2001/XMLSchema#int>
	<urn:0001> <urn:aValue>
'444'^^<http://www.w3.org/2001/XMLSchema#int>
	<urn:0001> <urn:aValue>
'40.0'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'4.0'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'-11.0'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'-11.1'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'1'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'-1'^^<http://www.w3.org/2001/XMLSchema#double>
	<urn:0001> <urn:aValue>
'11'^^<http://www.w3.org/2001/XMLSchema#double>

	
into <rmi://dmstablet2.viewpoint.local/server1#sampledata> ;

select $s <urn:aValue> $o
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
where 
	$s <urn:aValue> $o 
	
;


select $s <urn:aValue> $o
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
where 
	$s <urn:aValue> $o 
	
	order by $o asc
	
;

select $s <urn:aValue> $o
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
where 
	$s <urn:aValue> $o 
	
	order by $o desc
	
;


select $s <urn:aValue> $o
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
where 
	$s <urn:aValue> $o and
	$o <http://mulgara.org/mulgara#lt>
'-1'^^<http://www.w3.org/2001/XMLSchema#double> in
<rmi://dmstablet2.viewpoint.local/server1#xsd>
	
;

select $s <urn:aValue> $o
from <rmi://dmstablet2.viewpoint.local/server1#sampledata> 
where 
	$s <urn:aValue> $o and
	$o <http://mulgara.org/mulgara#lt>
'7000'^^<http://www.w3.org/2001/XMLSchema#double> in
<rmi://dmstablet2.viewpoint.local/server1#xsd>
	
;

=============



More information about the Mulgara-dev mailing list