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

FixedLengthTypeMapper ComplexProperty #79

Open
zcharleshebert opened this issue Nov 17, 2021 · 2 comments
Open

FixedLengthTypeMapper ComplexProperty #79

zcharleshebert opened this issue Nov 17, 2021 · 2 comments

Comments

@zcharleshebert
Copy link

Describe the bug
When you use a FixedLengthTypeMapper with ComplexProperty for a given window length, it seems to trim the value of that window prior to pass it to the ComplexProperty's mapper and thus throwing an exception saying the record length does not match the schema.

To Reproduce
Steps to reproduce the behaviour:

        class Person
        {
            public string Name { get; set; }
            public Pet Pet1 { get; set; }
            public Pet Pet2 { get; set; }

        }
        class Pet
        {
            public string Name { get; set; }
            public string UniversalPetIdentifier { get; set; }
            
        }
        
        [Fact]
        void Test()
        {
            var personMapper = FixedLengthTypeMapper.Define<Person>();
            personMapper.Property(f => f.Name, new Window(10));
            personMapper.Ignored(new Window(1));
            
            var petMapper = FixedLengthTypeMapper.Define<Pet>();
            petMapper.Property(pet => pet.Name, new Window(10));
            petMapper.Property(pet => pet.UniversalPetIdentifier, new Window(5));
            petMapper.Ignored(new Window(2));

            personMapper.ComplexProperty(p => p.Pet1, petMapper, new Window(17));
            personMapper.ComplexProperty(p => p.Pet2, petMapper, new Window(17));

            var line = "John       Doggy     dog01  Rain      cat01  ";

            var reader = personMapper.GetReader(new StringReader(line));
            var persons = reader.ReadAll().ToList();
            
            // Throws The record did not meet the length requirements specified in the schema. Record 1.
            // The ColumnValue that is throwing the exception is: Doggy     dog01
            // It has a length of 15 instead of 17.
        }

Expected behaviour
I expect that the value is not trimmed prior to pass it to the ComplexProperty's mapper and that the length match the schema.

Version:
4.16

@jehugaleahsa
Copy link
Owner

This does sound like a bug. I just need to override the Trim function in the underlying column class to do nothing.

@jehugaleahsa
Copy link
Owner

jehugaleahsa commented Feb 20, 2022

There were actually several bugs causing this. I had to mark the FixedLengthComplexColumn to not trim, like I mentioned above. I was also trimming inside of the outer fixed length reader because it always trims leading or trailing white space depending on what you set FixedLengthOptions.FillCharacter to. I now only trim off the fill character for normal columns, not complex columns. Finally, unrelated to your reported issue, the CSV parser would also trim trailing white space off text unless you explicitly told it not to - I updated the CSV parser to never strip white space off since none of my tests seemed to care (another piece of code does this already as part of parsing CSV files).

I debated going back to my current 4.x tag, branch off that, and doing a release off that; however, I decided it's too much of a pain have separate 4.x changes along side my master branch. I created a 5.0.0 release off the master branch with these bug fixes incorporated: https://www.nuget.org/packages/FlatFiles/. There are several breaking changes in 5.0.0, primary that SeparatedValue* classes were renamed to Delimited*. Hopefully this is not too much a pain.

Please let me know if you encounter any issues. If I don't hear back after a while, I will just close the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants