Skip to content

ObdalibQuestDataTypes

juliencorman edited this page Aug 8, 2017 · 24 revisions

valid for Ontop Version 1

Table of Contents

Data Types in OBDA System

Ontop supports data-typing in query answering. Currently, the reasoner can handle seven primitive data types which are LITERAL, STRING, INTEGER, DOUBLE, DECIMAL, DATE-TIME and BOOLEAN. NOTE: check behaviour for Ontop versions after 1.13 in the next section .

This document provides you a guideline how to write data types properly in your SPARQL queries. Particularly, in the case when you need constants in the query (e.g., for filtering). This is important so that the system can process the input data-types and produce a correct semantic output.

The table below shows you the correct and incorrect constant writing in SPARQL queries. The first column lists the data types that are supported by Ontop. The second column shows you several options for writing the constant values. And the last column shows you some examples that would trigger parsing error in the system.

Data Type Valid Writing Invalid Writing
LITERAL and STRING Writing these data types requires double-quote signs. Alternatively, you may put the XSD string flag. "Via Roma 33"
"Via Roma 33"^^<http://www.w3.org/2001/XMLSchema#string>
Via Roma 33 (without quotes)
INTEGER Writing an integer can be done in three ways, i.e., with or without the quotes, or using the XSD integer flag. "123456789"
123456789
"123456789"^^<http://www.w3.org/2001/XMLSchema#integer>
"+12345678"
+12345678
"+123456789"^^<http://www.w3.org/2001/XMLSchema#integer>
"-12345678"
-12345678
"-123456789"^^<http://www.w3.org/2001/XMLSchema#integer>
-
DECIMAL
"1234.5678"
1234.5678
"1234.5678"^^<http://www.w3.org/2001/XMLSchema#decimal>
"+1234.5678"
+1234.5678
"+1234.5678"^^<http://www.w3.org/2001/XMLSchema#decimal>
"-1234.5678"
-1234.5678
"-1234.5678"^^<http://www.w3.org/2001/XMLSchema#decimal>
-
DOUBLE
Writing a double-precision number should use the scientific notation.
"1.2345678e+03"
1.2345678e+03
"1.2345678e+03"^^<http://www.w3.org/2001/XMLSchema#double>
"+1.2345678e+03"
+1.2345678e+03
"+1.2345678e+03"^^<http://www.w3.org/2001/XMLSchema#double>
"-1.2345678e+03"
-1.2345678e+03
"-1.2345678e+03"^^<http://www.w3.org/2001/XMLSchema#double>
-
DATE-TIME
Writing a date-time value requires double-quote signs or using the XSD date time flag. However, when using the XSD date time flag, the string must follow to the international standard of date-time ISO8601.
"2012-02-06"
"2012-02-06 10:48:12"
"2012-02-06T10:48:12Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>
"2012-02-06T10:48:12.3Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>
2012-02-06
2012-02-06 10:48:12
2012-02-06T10:48:12Z
"2012-02-06"^^<http://www.w3.org/2001/XMLSchema#dateTime>
"2012-02-06 10:48:12"^^<http://www.w3.org/2001/XMLSchema#dateTime>
BOOLEAN
Writing a boolean value can be with or without double-quote signs, or using the XSD boolean flag.
"true"
"TRUE"
"1"
true
TRUE
1
"true"^^<http://www.w3.org/2001/XMLSchema#boolean>
"1"^^<http://www.w3.org/2001/XMLSchema#boolean>
"TRUE"^^<http://www.w3.org/2001/XMLSchema#boolean>

Cross compatibility

Table below shows the cross compatibility of data types between different DBMS (i.e., H2, MySQL and PostgreSQL), Ontop and XSD Type.

Data Type DBMS Ontop XSD Type
H2 MySQL PostgreSQL Oracle DB2 MsSQL
LITERAL varchar(n) varchar(n) varchar(n) varchar2(n) varchar(n) varchar(n) COL_TYPE.LITERAL xsd:string
STRING varchar(n) varchar(n) varchar(n) varchar2(n) varchar(n) nvarchar(n) COL_TYPE.STRING xsd:string
INTEGER integer integer integer number(10,0) integer integer COL_TYPE.INTEGER xsd:integer, xsd:int
DECIMAL* decimal decimal decimal number(x,y) decimal decimal COL_TYPE.DECIMAL xsd:decimal
DOUBLE* double precision double precision double precision float(24) double precision double precision COL_TYPE.DOUBLE xsd:double
DATE-TIME timestamp timestamp timestamp date timestamp datetime COL_TYPE.DATETIME xsd:dateTime
BOOLEAN boolean boolean boolean boolean --- bit COL_TYPE.BOOLEAN xsd:boolean

Note: * The difference between double-precision and decimal is that the first suggests the approximation value and the latter is the exact value. Thus, using double-precision (or float) may cause rounding and some digits are truncated.

Recommendation

In order to maintain the cross-compatibility between different libraries in the system, we recommend you to use (and write) the constants in SPARQL queries as follows:

  • LITERAL/STRING: Always put the double-quote signs. e.g.
    PREFIX : ...
    SELECT DISTINCT $x $street WHERE { $x a :Address; :inStreet $street; :inCity "Bolzano"^^<http://www.w3.org/2001/XMLSchema#string>. }
    
  • INTEGER: Do not put double-quote signs and the input must in numerical characters. e.g.
    PREFIX : ...
    SELECT DISTINCT $x $street WHERE { $x a :Address; :inStreet $street; :hasNumber 3. } 
    
  • DECIMAL: Similar to the INTEGER, do not put the double-quote signs. e.g.
    PREFIX : ...
    SELECT DISTINCT $x $name WHERE { $x a :Company; :companyName $name; :netWorth 1234.5678 . } 
    
  • DOUBLE: Similar to the INTEGER, do not put the double-quote signs. e.g.
    PREFIX : ...
    SELECT DISTINCT $x $name WHERE { $x a :Company; :companyName $name; :netWorth 1.2345678e+03. } 
    
  • DATE-TIME: Write the value using the format 'YYYY-MM-dd hh:mm:ss' and with double-quote signs. Additionally, use TIMESTAMP instead of DATE type in the SQL table definition. e.g.
    PREFIX : ...
    SELECT DISTINCT $x $id WHERE { $x a :Transaction; :transactionID $id; :transactionDate "2008-04-02T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>. } 
    
  • BOOLEAN: Write the boolean value in 'true' or 'false' (without quotes). e.g.
    PREFIX : ...
    SELECT DISTINCT $x $amount WHERE { $x a :Stock; :amountOfShares $amount; :typeOfShares true. } 
    

After Ontop 1.13

We consider the datatype given in the ontology and not only the datatype in the mappings. If both are present they have to match. In the mappings, it is possible to have the same property with different datatypes, if in the ontology no information about the datatype is given.

Note: rdfs:Literal is different from all other datatypes (ex. rdfs:Literal is different from xsd:string). When a value is written in quotes, but no information about datatype is given we assume the value it's an rdfs:Literal. New Datatype has been added xsd:date, xsd:time and xsd:gYear tested with mysql, postgres, oracle, hsqldb.

In Ontop 1.14 we added xsd:positiveInteger, xsd:negativeInteger, xsd:nonPositiveInteger, xsd:nonNegativeInteger, xsd:int, xsd:unsignedInt, xsd:float.

In Ontop 1.15 we added xsd:dateTimeStamp.

Issues:

  • Oracle driver With oracle driver v11 and up, theres a problem with date, oracle returns the wrong SQL type for DATE columns, it returns TIMESTAMP instead of DATE and ontop assigned xsd:dateTime instead of xsd:date. Manually type those columns. Different driver versions for oracle return different formats for TIMESTAMP, we support v11 and less format as: dd-MMM-yy HH.mm.ss.SSSSSS aa
  • Mapping Datatype repair When no information about the datatype is given in the ontology and in the mapping we consider the type of the database.
The same for particular cases of property that are not defined in the ontology and annotation properties .
  • SPARQL query When we query datatype in SPARQL we do not support subtype. For example if we ask for xsd:integer only type defined as xsd:integer will be returned. If we want between the result also the type defined as xsd:positiveInteger, we have to ask for them explicitly in the query.



              
Clone this wiki locally