From dee81103accb2a1d1f5c97ed67b0ede29d05381a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Thu, 7 Jul 2022 11:15:02 +0200 Subject: [PATCH 1/3] test(index): Add characterization test case for BigDecimal indexing --- .../index/DecimalFieldTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/commons/com.b2international.index.tests/src/com/b2international/index/DecimalFieldTest.java b/commons/com.b2international.index.tests/src/com/b2international/index/DecimalFieldTest.java index cf31f62eee9..da8d7b71efa 100644 --- a/commons/com.b2international.index.tests/src/com/b2international/index/DecimalFieldTest.java +++ b/commons/com.b2international.index.tests/src/com/b2international/index/DecimalFieldTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2021 B2i Healthcare Pte Ltd, http://b2i.sg + * Copyright 2011-2022 B2i Healthcare Pte Ltd, http://b2i.sg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,7 @@ public class DecimalFieldTest extends BaseIndexTest { private static final BigDecimal VALUE_05 = new BigDecimal("0.5"); private static final BigDecimal VALUE_10 = new BigDecimal("1.0"); private static final BigDecimal VALUE_20 = new BigDecimal("2.0"); + private static final BigDecimal VALUE_TEN = new BigDecimal("10.000"); private static final String KEY3 = "key3"; private static final String KEY4 = "key4"; @@ -170,6 +171,25 @@ public void indexReallySmallPositiveDecimal() throws Exception { .containsOnly(new DataWithDecimal(KEY1, REALLY_SMALL)); } + @Test + public void indexRemovesTrailingZeros() throws Exception { + final DataWithDecimal expected = new DataWithDecimal(KEY1, VALUE_TEN); + indexDocument(expected); + final DataWithDecimal actual = getDocument(DataWithDecimal.class, KEY1); + + // The sortable compact BigDecimal representation we use from Solr removes excess zeros + assertEquals(expected.getValue().stripTrailingZeros(), actual.getValue()); + + // The change in precision and scale in the two representations changes the output of "toString()" as well + assertEquals("10.000", expected.getValue().toString()); + assertEquals(5, expected.getValue().precision()); // "10000 x 10^-3" + assertEquals(3, expected.getValue().scale()); + + assertEquals("1E+1", actual.getValue().toString()); + assertEquals(1, actual.getValue().precision()); // "1 x 10^1" + assertEquals(-1, actual.getValue().scale()); + } + @Doc static class DataWithDecimal { From 5e907d68e2b64052e75b78b21923846567d89960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Thu, 7 Jul 2022 11:17:12 +0200 Subject: [PATCH 2/3] fix(snomed): Trim trailing zeros, use "toPlainString" when converting... ...RelationshipValues to ConcreteValues --- .../rest/classification/SnomedClassificationApiTest.java | 7 ++++++- .../datastore/request/SnomedOWLRelationshipConverter.java | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/snomed/com.b2international.snowowl.snomed.core.rest.tests/src/com/b2international/snowowl/snomed/core/rest/classification/SnomedClassificationApiTest.java b/snomed/com.b2international.snowowl.snomed.core.rest.tests/src/com/b2international/snowowl/snomed/core/rest/classification/SnomedClassificationApiTest.java index 2b659525355..1648bbe4473 100644 --- a/snomed/com.b2international.snowowl.snomed.core.rest.tests/src/com/b2international/snowowl/snomed/core/rest/classification/SnomedClassificationApiTest.java +++ b/snomed/com.b2international.snowowl.snomed.core.rest.tests/src/com/b2international/snowowl/snomed/core/rest/classification/SnomedClassificationApiTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2021 B2i Healthcare Pte Ltd, http://b2i.sg + * Copyright 2011-2022 B2i Healthcare Pte Ltd, http://b2i.sg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -188,6 +188,11 @@ public void persistDataHasValueAxiom_Decimal() throws Exception { persistDataHasValueAxiom("\"3.6\"^^xsd:decimal", new RelationshipValue(new BigDecimal("3.6"))); } + @Test + public void persistDataHasValueAxiom_DecimalWithTrailingZeros() throws Exception { + persistDataHasValueAxiom("\"100.00\"^^xsd:decimal", new RelationshipValue(new BigDecimal("100"))); + } + @Test public void persistDataHasValueAxiom_String() throws Exception { persistDataHasValueAxiom("\"Hello world\"^^xsd:string", new RelationshipValue("Hello world")); diff --git a/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/SnomedOWLRelationshipConverter.java b/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/SnomedOWLRelationshipConverter.java index f74c2f6c610..52f82623cfd 100644 --- a/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/SnomedOWLRelationshipConverter.java +++ b/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/SnomedOWLRelationshipConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 B2i Healthcare Pte Ltd, http://b2i.sg + * Copyright 2019-2022 B2i Healthcare Pte Ltd, http://b2i.sg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,7 +102,7 @@ public String fromSnomedOwlRelationships( private ConcreteValue toConcreteValue(final RelationshipValue value) { return value.map( i -> new ConcreteValue(ConcreteValue.Type.INTEGER, i.toString()), - d -> new ConcreteValue(ConcreteValue.Type.DECIMAL, d.toString()), + d -> new ConcreteValue(ConcreteValue.Type.DECIMAL, d.stripTrailingZeros().toPlainString()), s -> new ConcreteValue(ConcreteValue.Type.STRING, s)); } From dc3251063619471514413dad9805d47a439db35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Thu, 7 Jul 2022 14:45:36 +0200 Subject: [PATCH 3/3] chore(index.tests): Add dependency to index test launch configurations --- .../.launch/index-http-unit-tests (es8).launch | 1 + .../.launch/index-http-unit-tests.launch | 1 + .../.launch/index-tcp-unit-tests.launch | 1 + 3 files changed, 3 insertions(+) diff --git a/commons/com.b2international.index.tests/.launch/index-http-unit-tests (es8).launch b/commons/com.b2international.index.tests/.launch/index-http-unit-tests (es8).launch index 38c0ff1bf16..9dbed6aa6d7 100644 --- a/commons/com.b2international.index.tests/.launch/index-http-unit-tests (es8).launch +++ b/commons/com.b2international.index.tests/.launch/index-http-unit-tests (es8).launch @@ -122,6 +122,7 @@ + diff --git a/commons/com.b2international.index.tests/.launch/index-http-unit-tests.launch b/commons/com.b2international.index.tests/.launch/index-http-unit-tests.launch index 84f5544a3a5..835fd19ff24 100644 --- a/commons/com.b2international.index.tests/.launch/index-http-unit-tests.launch +++ b/commons/com.b2international.index.tests/.launch/index-http-unit-tests.launch @@ -122,6 +122,7 @@ + diff --git a/commons/com.b2international.index.tests/.launch/index-tcp-unit-tests.launch b/commons/com.b2international.index.tests/.launch/index-tcp-unit-tests.launch index a213e0f8f66..dd743a3b50b 100644 --- a/commons/com.b2international.index.tests/.launch/index-tcp-unit-tests.launch +++ b/commons/com.b2international.index.tests/.launch/index-tcp-unit-tests.launch @@ -121,6 +121,7 @@ +