question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ChoFixedLengthRecordWriter issue with handling double quotes

See original GitHub issue

We are facing two issues with ChoFixedLengthRecordWriter, as detailed below, if the field value contains a double quote.

ISSUE #1: When the field value contains a double quote character, the ChoFixedLengthRecordWriter is doubling the double quote character by default. Since it adds additional double quote characters, it increases the size of that column where the double quote is present and shifts the starting positions of the subsequent columns. Since it is a fixed length file, it should use the actual size specified for that column.

For example, if below is the model data,

List<Employee> employee = new List<Employee>()
{
	new Employee() { Id = 20, Name = "John Smith", Address = "PO BOX 12165", Age = "25" },
	new Employee() { Id = 21, Name = "Bob Kevin", Address = "123 NEW LIVERPOOL RD \"APT 12\"", Age = "30" },
	new Employee() { Id = 22, Name = "Jack Robert", Address = "PO BOX 123", Age = "40" }
};

It is generating the fixed length file with below contents. Here, the Age column value for the second record is shifted by two positions since it added two double quotes (one for each occurance of doule quote in the Address column of the second record).

image

ISSUE #2: We basically don’t want to double the double quote if it is present in the field value. It would be great if you can add a configuration setting to enable or disable this feature. We would like to have this configuration for both CSV and Fixed Length Writer.

In order to handle this issue temporarily, we are basically setting the ‘QuoteChar’ configuration to a value that is not expected in the flat file, as shown below. Since ‘~’ (tilde) character never occurs in the file, it is able to bypass the below if condition that is replacing the double quote with two double quotes.

// Temporary Fix config.QuoteChar = ‘~’; // tilde character

// ChoFixedLengthRecordWriter implementation
if (fieldValue.Contains(Configuration.QuoteChar))
{
	fieldValue = fieldValue.Replace(Configuration.QuoteChar.ToString(), Configuration.DoubleQuoteChar);
}

But since we are changing the QuoteChar configuration to tilde character, the ChoFixedLengthRecordWriter will end up using that character to enclose the field value (it adds ‘~’ character to the starting and ending position of the field value) if the “QuoteField” column configuration is set to ‘true’, which is not correct. So having a configuration setting to enable or disable the feature to replace single double quote with two double quotes would solve this problem. Please help.

// ChoFixedLengthRecordWriter implementation
if (quoteValue)
fieldValue = "{1}{0}{1}".FormatString(fieldValue, Configuration.QuoteChar);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Cinchoocommented, Oct 4, 2021

Done, released v1.2.1.26 today

1reaction
kr-prashcommented, Sep 30, 2021

@Cinchoo, I would like to confirm that the fixes are working fine for us. Thank you so much again for providing the fix so quickly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChoETL CSVWriter is not handling double quotes correctly.
When a string has a Double Quote Char it needs to be doubled up... ... ChoFixedLengthRecordWriter issue with handling double quotes #155.
Read more >
Having trouble while adding double quotes to a string that ...
While storing string values if any double quotes are to be added they need to be escaped using backshlash(\). Single quotes are used...
Read more >
Handling Double Quotes in FCC Receiver of FTP.
What seem to happen is that, these double quotes vanishes in the end output, although present in monitoring until the last stage in...
Read more >
Loading data with double-quotes
I'm trying to load some data into TG, where the file is a CSV with double-quote enclosed fields. The problem I'm having is...
Read more >
Double Quotes - Power Platform Community
So I thought I had solved my issue with double quotes. It is very easy to replace with the escape identifiers I need....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found