marklogic/java-client-api

Numbers returned by MarkLogic do not use scientific notation

uniqueR-7 opened this issue · 1 comments

Version of MarkLogic Java Client API

5.5.3

Version of MarkLogic Server

10.0-9.5

Java version

java version "11.0.16.1" 2022-08-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.16.1+1-LTS-1)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.16.1+1-LTS-1, mixed mode)

OS and version

OS name: Microsoft Windows 11
OS version: 10.0.22000

Input: Some code to illustrate the problem, preferably in a state that can be independently reproduced on our end

Write the following RDF data into MarkLogic:

<http://John> <http://have> 2.1123519E7 .

Then execute the following query:

SELECT *
WHERE { ?s ?p ?o. }

Corresponding Java code:

import java.io.File;
import java.io.IOException;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.io.*;
import com.marklogic.client.semantics.*;

public class MarkLogic_Test {
    static DatabaseClient client = DatabaseClientFactory.newClient(
            "localhost", 8000, "Documents",
            new DatabaseClientFactory.DigestAuthContext(
                    "root", "123"));
    static private GraphManager graphMgr = client.newGraphManager();
    static private String graphURI = GraphManager.DEFAULT_GRAPH;
    static private String tripleFilename = "./example.ttl";

    // Load managed triples from a file into a graph in MarkLogic
    public static void loadGraph(String filename, String graphURI, String format) {
        FileHandle tripleHandle = new FileHandle(new File(filename)).withMimetype(format);
        graphMgr.write(graphURI, tripleHandle);
    }

    // Evaluate a SPARQL query.
    public static void sparqlQuery() throws IOException {
        SPARQLQueryManager qm = client.newSPARQLQueryManager();
        SPARQLQueryDefinition query = qm.newQueryDefinition(
                "SELECT *\n" +
                        "WHERE { ?s ?p ?o . }"
        );
        JacksonHandle results = new JacksonHandle();
        results.setMimetype(SPARQLMimeTypes.SPARQL_JSON);
        results = qm.executeSelect(query, results);
        results.write(System.out);
    }

    public static void main(String[] args) throws IOException {
        loadGraph(tripleFilename, graphURI, RDFMimeTypes.TURTLE);
        sparqlQuery();
        client.release();
    }
}

Triple file:
example.ttl

<http://John> <http://have> 2.1123519E7 .

Actual output: What did you observe? What errors did you see? Can you attach the logs? (Java logs, MarkLogic logs)

The query result is:

?s ?p ?o
<http://John> <http://have> "21123519"^^xsd:double

Expected output: What specifically did you expect to happen?

The expected query result is:

?s ?p ?o
<http://John> <http://have> "2.1123519E7"^^xsd:double

Alternatives: What else have you tried, actual/expected?

The written data is expressed in scientific notation, but the data returned in query result is not in scientific notation. Will there be some inconsistencies?

Executing the SparQL query with Java Client API will get the unexpected query result. But executing it in Query Console will get the expected query result.

This query can also return the expected query result in Apache Jena and RDF4j.

Can someone give me an answer or a hint about it?

As noted in the stackoverflow post - https://stackoverflow.com/questions/75412052/numbers-returned-by-marklogic-do-not-use-scientific-notation - you're seeing behavior from the server based on the response type, where a response type of JSON results in a value that does not use scientific notation. The Java Client does not have any bearing on this.

I'm verifying with some colleagues that this is expected behavior and that the two different ways of representing the same value are not an issue. We'll respond to the stackoverflow post to confirm, as this does not appear to have anything to do with the Java Client.