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

Complex alteration of a result-set including numeric and text values leading to a numeric with the wrong decimal separator #573

Closed
Seddryck opened this issue Dec 17, 2019 · 1 comment

Comments

@Seddryck
Copy link
Owner

Seddryck commented Dec 17, 2019

This is rather complex to reproduce but at least with computer settings set to fr-be and the following test:

<?xml version="1.0" encoding="utf-8"?>
<testSuite xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://NBi/TestSuite">
  <test name="alteration with replacement of a text value by a numeric value">
    <system-under-test>
      <result-set>
        <row>
          <cell>39.500</cell>
          <cell>8.200</cell>
        </row>
      </result-set>
    </system-under-test>
    <assert>
      <equal-to behavior="single-row" values-default-type="text">
        <result-set>
          <row>
            <cell>2018-10-01</cell>
            <cell>8.200</cell>
          </row>
          <alteration>
            <lookup-replace>
              <missing behavior="default-value">0</missing>
              <join>
                <mapping candidate="#0" reference="#0" />
              </join>
              <result-set>
                <row>
                  <cell>2018-10-01</cell>
                  <cell>39.500</cell>
                </row>
                <alteration>
                  <summarize>
                    <sum column="#1" type="numeric" />
                    <group-by>
                      <column identifier="#0" />
                    </group-by>
                  </summarize>
                </alteration>
              </result-set>
              <replacement identifier="#1" />
            </lookup-replace>
          </alteration>
        </result-set>
      </equal-to>
    </assert>
  </test>
</testSuite>

We've the following result:

NBi.NUnit.Runtime.TestSuite.alteration with replacement of a text value by a numeric value:
NBi.NUnit.Runtime.CustomStackTraceAssertionException : 
Execution of the query doesn't match the expected result 

  Expected: 
Result-set with 1 row

     #0 (Column0) | #1 (Column1)
     VALUE (Text) | VALUE (Text)
     ------------ | ------------ 
     39,5         | 8.200       

  But was:  
Result-set with 1 row

     #0 (Column0) | #1 (Column1)
     VALUE (Text) | VALUE (Text)
     ------------ | ------------ 
     39.500       | 8.200       

Non matching value rows:
------------------------

Result-set with 1 row

     #0 (Column0)   | #1 (Column1)
     VALUE (Text)   | VALUE (Text)
     -------------- | ------------ 
     39.500 <> 39,5 | 8.200       
@Seddryck Seddryck added the bug label Dec 17, 2019
@Seddryck Seddryck added this to the v1.22 milestone Dec 17, 2019
@Seddryck
Copy link
Owner Author

Seddryck commented Dec 17, 2019

The bug is rather complex.

The summarize alteration is returning a numeric. During the lookup-replace, the replacement-values which have been calculated by the summarize (and so are numeric) are casted back to text. Due to the regional settings, the value 39.5(numeric) is casted to 39,5(text). Later during the equal-to, this value is recasted to a numeric ... but this is not possible due to the standard way of writing numbers not respected ... by "chance" the caster returns 395(numeric) ... and that's obviously wrong. Clearly, when writing the code for the TextCaster, I didn't think that this class could be called with something else than a text, I fixed this wrong assumption in this build and it should, now, cast the value 39.5(numeric) to 39.5(text) and this value will be casted back to a numeric in the equal-to with the value 39.5(numeric).

Nevertheless, we still have an issue: it's pointless to cast the replacement-values to a text. Unfortunately, the underlying method is called by many important classes and providing an alternative to not cast in a few cases is touchy. To avoid this, I introduced a new type untyped and asked to cast the replacement-values to this type (it doesn't do anything in fact). Again, a few things started to break. I fixed them, but this change is really in the core of NBi so be careful with this other build. Feedback on this build is especially welcome, sooner or later, I'll need to merge to the develop branch and it's probably better to test before it's merged.

Seddryck pushed a commit that referenced this issue Feb 4, 2020
# Conflicts:
#	NBi.Testing.Core/Scalar/Resolver/FormatScalarResolverTest.cs
@Seddryck Seddryck closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant