arcadedb icon indicating copy to clipboard operation
arcadedb copied to clipboard

Remote database automatically converts Float to Double

Open lvca opened this issue 1 year ago • 1 comments

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 avatar Aug 23 '24 22:08 lvca

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.

lvca avatar Aug 23 '24 22:08 lvca

@robfrank is working on supporting all the types that are not represented with JSON in the JSON exporter/importer tool. We could apply the same logic here, using a metadata to declare the special types for properties.

lvca avatar Jan 25 '25 15:01 lvca

Fixed in #2246.

lvca avatar Jun 06 '25 20:06 lvca