From a1c5a7c5e09f9b82f32286bfd132aaf859af29c9 Mon Sep 17 00:00:00 2001 From: Andreas Eberhart Date: Fri, 27 Sep 2024 17:20:52 +0200 Subject: [PATCH] fix integer / number type sensing --- .../java/org/dashjoin/mapping/AbstractSource.java | 14 ++++++++++---- .../org/dashjoin/mapping/AbstractSourceTest.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/dashjoin-core/src/main/java/org/dashjoin/mapping/AbstractSource.java b/dashjoin-core/src/main/java/org/dashjoin/mapping/AbstractSource.java index 17204a708..3c272b25c 100644 --- a/dashjoin-core/src/main/java/org/dashjoin/mapping/AbstractSource.java +++ b/dashjoin-core/src/main/java/org/dashjoin/mapping/AbstractSource.java @@ -316,12 +316,18 @@ public static String type(String pk, List> table) { } if (o instanceof Date) types.add("date"); - if (o instanceof Integer) - types.add("integer"); + + if (o instanceof Integer) { + if (!types.contains("number")) + types.add("integer"); + } else if (o instanceof Number) { + if (types.contains("integer")) + types.remove("integer"); + types.add("number"); + } + if (o instanceof Boolean) types.add("boolean"); - if (o instanceof Number) - types.add("number"); if (o instanceof List) types.add("array"); if (o instanceof Map) diff --git a/dashjoin-core/src/test/java/org/dashjoin/mapping/AbstractSourceTest.java b/dashjoin-core/src/test/java/org/dashjoin/mapping/AbstractSourceTest.java index 24ed35b8e..3a1168b9e 100644 --- a/dashjoin-core/src/test/java/org/dashjoin/mapping/AbstractSourceTest.java +++ b/dashjoin-core/src/test/java/org/dashjoin/mapping/AbstractSourceTest.java @@ -27,6 +27,18 @@ public void testMixed() { Assertions.assertEquals("string", Provider.type("x", asList(of("x", 1), of("x", "string")))); } + @Test + public void testIntNumber() { + Assertions.assertEquals("integer", Provider.type("x", asList(of("x", 1)))); + Assertions.assertEquals("integer", Provider.type("x", asList(of("x", 1), of("x", 1)))); + } + + @Test + public void testNumber() { + Assertions.assertEquals("number", Provider.type("x", asList(of("x", 1.2)))); + Assertions.assertEquals("number", Provider.type("x", asList(of("x", 1), of("x", 1.2)))); + } + @Test public void testNull() { Assertions.assertEquals("string", Provider.type("x", asList(of("x", null), of("x", null))));