You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@jena.apache.org by "Damien Obrist (Jira)" <ji...@apache.org> on 2024/10/03 11:37:00 UTC
[jira] [Comment Edited] (JENA-2361) TDB doesn't preserve lexical form of integer-valued decimals
[ https://issues.apache.org/jira/browse/JENA-2361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17886643#comment-17886643 ]
Damien Obrist edited comment on JENA-2361 at 10/3/24 11:36 AM:
---------------------------------------------------------------
[~andy] thanks for your comment!
{quote}The contract around TDB2 has not been to preserve terms for certain XSD datatypes
{quote}
I see, what is the contract around TDB2 regarding decimals?
{code:java}
model.add(
ResourceFactory.createResource("http://www.test.com/my-graph"),
RDF.type,
ResourceFactory.createTypedLiteral("2", XSDDatatype.XSDdecimal)
);
model.add(
ResourceFactory.createResource("http://www.test.com/my-graph"),
RDF.type,
ResourceFactory.createTypedLiteral("2.0", XSDDatatype.XSDdecimal)
);
StmtIterator stmts = model.listStatements();
Literal l1 = stmts.next().getObject().asLiteral();
Literal l2 = stmts.next().getObject().asLiteral();
System.out.println(l1);
System.out.println(l2);
System.out.println(l1.equals(l2));
{code}
The above code prints out:
* with version 5.0.0:
{code:java}
"2"^^xsd:decimal
"2.0"^^xsd:decimal
false{code}
* with version 5.1.0:
{code:java}
"2.0"^^xsd:decimal
"2.0"^^xsd:decimal
true
{code}
So effectively, contrary to 5.0.0, in 5.1.0 we cannot differentiate between 2 and 2.0 anymore. This feels a bit like a regression or at least a breaking change.
was (Author: dobrist):
[~andy] thanks for your comment!
{quote}The contract around TDB2 has not been to preserve terms for certain XSD datatypes
{quote}
I see, what is the contract around TDB2 regarding decimals?
{code:java}
model.add(
ResourceFactory.createResource("http://www.test.com/my-graph"),
RDF.type,
ResourceFactory.createTypedLiteral("2", XSDDatatype.XSDdecimal)
);
model.add(
ResourceFactory.createResource("http://www.test.com/my-graph"),
RDF.type,
ResourceFactory.createTypedLiteral("2.0", XSDDatatype.XSDdecimal)
);
StmtIterator stmts = model.listStatements();
Literal l1 = stmts.next().getObject().asLiteral();
Literal l2 = stmts.next().getObject().asLiteral();
System.out.println(l1);
System.out.println(l2);
System.out.println(l1.equals(l2));
{code}
The above code prints out:
* with version 5.0.0:
{code:java}
"2"^^xsd:decimal
"2.0"^^xsd:decimal
false{code}
* with version 5.1.0:
{code:java}
"2.0"^^xsd:decimal
"2.0"^^xsd:decimal
true
{code}
So effectively, contrary to 5.0.0, in 5.1.0 we cannot differentiate between 2 and 2.0 anymore. This feels a bit like a regression or at least a breaking change.
> TDB doesn't preserve lexical form of integer-valued decimals
> ------------------------------------------------------------
>
> Key: JENA-2361
> URL: https://issues.apache.org/jira/browse/JENA-2361
> Project: Apache Jena
> Issue Type: Bug
> Components: TDB2
> Affects Versions: Jena 5.1.0
> Reporter: Damien Obrist
> Priority: Minor
>
> The following sample code reproduces the issue:
>
> {code:java}
> public static void main(String[] arguments) {
> try {
> FileUtils.deleteDirectory(new File("sample-data"));
> } catch (IOException e) {
> throw new RuntimeException(e);
> }
> Dataset dataset = TDB2Factory.connectDataset("sample-data");
> Txn.executeWrite(dataset, () -> {
> // TDB: code wrongly prints out "2.0"
> Model model = dataset.getDefaultModel();
> // in-memory: code correctly prints out "2"
> //Model model = ModelFactory.createDefaultModel();
> model.add(
> ResourceFactory.createResource("http://www.test.com/my-graph"),
> RDF.type,
> ResourceFactory.createTypedLiteral("2", XSDDatatype.XSDdecimal)
> ); System.out.println(model.listStatements().next().getObject().asLiteral().getLexicalForm());
> });
> } {code}
> The behaviour is as follows:
> * When running the code with Jena 5.1.0, it wrongly prints out "2.0"
> * When running the code with Jena 5.0.0, it correctly prints out "2"
> * When running the code using the in-memory model instead of the TDB one, then with both Jena 5.0.0 and 5.1.0, it correctly prints out "2"
> It seems that the problem happens when writing the triple, not when reading it: if the above code is modified and run with Jena 5.0.0 to store, and with Jena 5.1.0 to read the triple, then it correctly prints out "2".
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: jira-unsubscribe@jena.apache.org
For additional commands, e-mail: jira-help@jena.apache.org