Ticket #81 (new defect)

Opened 3 years ago

Casting a double value to a string does not produce the expected result (value)

Reported by: charnik Owned by: pyravlos-team
Priority: trivial Milestone:
Component: generaldb Version: 3.3.1
Keywords: type casting, double to string, strdf:distance, conversion degrees to metres, SPARQL Cc: bernard.valentin@…


When casting a double value (of type xsd:double) to a string (of type either xsd:string or using the constructor "str"), the resulting value seems changed and does not correspond to the original one. However, the constructors for xsd:string and str produce the same value, albeit using a different string representation.

The problem can be reproduced by accessing the endpoint at http://leo.spaceapplications.com/endpoint3/ and executing the following query (no exception is thrown):

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX strdf: <http://strdf.di.uoa.gr/ontology#>
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>

#    (str(?gr_title) as ?gr_name) 
#    (str(?gl_title) as ?gl_name) 
#    (strdf:area(?gr_geo_wkt) as ?gr_area)
#    (strdf:area(?gl_geo_wkt) as ?gl_area) 
    (strdf:distance(?gr_geo_wkt, ?gl_geo_wkt, uom:metre) as ?distance1)
    (xsd:string(strdf:distance(?gr_geo_wkt, ?gl_geo_wkt, uom:metre)) as ?distance2)
    (str(strdf:distance(?gr_geo_wkt, ?gl_geo_wkt, uom:metre)) as ?distance3)

where {
   ?gr_id a <http://cegis.usgs.gov/Ontology/Glacier> ;
          rdfs:label ?gr_title ;
          geo:hasGeometry [ geo:asWKT ?gr_geo_wkt ] .

   ?gl_id a <http://cegis.usgs.gov/Ontology/Lake>;
          geo:touches ?gr_id ;
          rdfs:label ?gl_title ;
          geo:hasGeometry [ geo:asWKT ?gl_geo_wkt ] .

} order by ?gr_name

Commenting the irrelevant projections, the first result is the following:

distance 	distance1 	distance2
"15609.404296875"^^<http://www.w3.org/2001/XMLSchema#double> 	"1.4095944502940216E-1"^^<http://www.w3.org/2001/XMLSchema#string> 	"0.14095944502940216" 

Now, if instead we had made the first computation of distance using degrees as the unit of measurement, then the result would be the following:

distance 	distance1 	distance2
"0.14095944166183472"^^<http://www.w3.org/2001/XMLSchema#double> 	"1.4095944502940216E-1"^^<http://www.w3.org/2001/XMLSchema#string> 	"0.14095944502940216" 

That is, all values seem equal or almost equal, although such behavior might be acceptable due to casting.

Therefore, the problem seems to be in the handling and the time the cast is applied. For example, to compute the above distance in meters, first we compute it in degrees and then we express the result in meters. That is also reported by Strabon in the log file:

INFO  org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluation  - [GeneraDBEvaluation] Computation of http://strdf.di.uoa.gr/ontology#distance will be done in degrees.

So, it seems that instead of waiting to have the value back in meters, we are more hurry that it should be and apply it to the result computed in degrees.

Note: See TracTickets for help on using tickets.