ArcadeData / arcadedb

ArcadeDB Multi-Model Database, one DBMS that supports SQL, Cypher, Gremlin, HTTP/JSON, MongoDB and Redis. ArcadeDB is a conceptual fork of OrientDB, the first Multi-Model DBMS. ArcadeDB supports Vector Embeddings.
https://arcadedb.com
Apache License 2.0
484 stars 60 forks source link

Remote database automatically converts Float to Double #1700

Open lvca opened 4 weeks ago

lvca commented 4 weeks ago

Test case to reproduce it:


  @Test
  public void testTypes() throws Exception {
    testEachServer((serverIndex) -> {
      Assertions.assertTrue(
          new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists(
              DATABASE_NAME));

      final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root",
          BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS);

      database.command("sql", "create vertex type SimpleVertex");

      database.begin();

      RemoteMutableVertex nvSaved = database.newVertex("SimpleVertex");
      nvSaved.set("s", "string");
      nvSaved.set("b", true);
      nvSaved.set("oB", true);
      nvSaved.set("f", 1.0f);
      nvSaved.set("oF", 1.0f);
      nvSaved.set("i", 1);
      nvSaved.set("oI", 1);
      Date targetDate = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
      nvSaved.set("fecha", targetDate);
      nvSaved.save();

      database.commit();
      RID rid = nvSaved.getIdentity();
      System.out.println("RID: " + rid.toString() + "\n\n");

      Vertex v = database.lookupByRID(rid).asVertex();
      System.out.println("retrieved: " + v.getIdentity().toString());
      System.out.println("s: " + v.get("s") + " - " + v.get("s").getClass().getName());
      System.out.println("b: " + v.get("b") + " - " + v.get("b").getClass().getName());
      System.out.println("ob: " + v.get("oB") + " - " + v.get("oB").getClass().getName());
      System.out.println("f: " + v.get("f") + " - " + v.get("f").getClass().getName());
      System.out.println("f: " + v.getFloat("f") + " - " + v.getFloat("f").getClass().getName());
      System.out.println("oF: " + v.get("oF") + " - " + v.get("oF").getClass().getName());
      System.out.println("i: " + v.get("i") + " - " + v.get("i").getClass().getName());
      System.out.println("oI: " + v.get("oI") + " - " + v.get("oI").getClass().getName());
      System.out.println("date: " + v.get("fecha") + " - " + v.get("fecha").getClass().getName());
      System.out.println("getDate: " + v.getDate("fecha") + " - " + v.getDate("fecha").getClass().getName());
      System.out.println("targetDate: " + targetDate.getTime() + " --> ret.date: " + v.getDate("fecha").getTime());
    });
  }
lvca commented 4 weeks ago

The issue is with the remote protocol: every record is serialized using JSON and JSON doesn't have a Float type, but rather a Double type. The server needs to serialize a special metadata attribute "@types" (like with OrientDB) containing the type of each field to be converted on the client side.