Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SO-5510: Fix decimal concrete value conversion (8.x) #1039

Merged
merged 3 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<setEntry value="com.b2international.index.tests@default:false"/>
<setEntry value="com.b2international.index@default:default"/>
<setEntry value="com.b2international.snowowl.logback.config@default:false"/>
<setEntry value="com.b2international.snowowl.test.dependencies@default:default"/>
</setAttribute>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<setEntry value="com.b2international.index.tests@default:false"/>
<setEntry value="com.b2international.index@default:default"/>
<setEntry value="com.b2international.snowowl.logback.config@default:false"/>
<setEntry value="com.b2international.snowowl.test.dependencies@default:default"/>
</setAttribute>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<setEntry value="com.b2international.index.tests@default:false"/>
<setEntry value="com.b2international.index@default:default"/>
<setEntry value="com.b2international.snowowl.logback.config@default:false"/>
<setEntry value="com.b2international.snowowl.test.dependencies@default:default"/>
<setEntry value="org.hamcrest.core@default:default"/>
</setAttribute>
<booleanAttribute key="show_selected_only" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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));
}

Expand Down