[Mulgara-dev] perhaps before 2.0.6 released -- OrderedByRowComparator

David Smith DMS at viewpointusa.com
Thu Oct 16 12:56:27 UTC 2008


I'd appreciate someone looking at before 2.0.6 released
 
(I posted this back on Aug 1, 2008)
 
OrderedByRowComparator doesn't correctly handle negative numbers...


Thanks

Dave Smith
Viewpoint Data Management, LLC
 


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