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

Issue with CSV Parsing for Embedded Quotes Using EntityDataLoader #641

Open
puru-khedre opened this issue Aug 16, 2024 · 0 comments · May be fixed by #642
Open

Issue with CSV Parsing for Embedded Quotes Using EntityDataLoader #641

puru-khedre opened this issue Aug 16, 2024 · 0 comments · May be fixed by #642

Comments

@puru-khedre
Copy link

When using EntityDataLoader to import CSV files, I encountered issues with CSV values containing double quotes ("). The error encountered was:

{'message':'IOException reading next record: java.io.IOException: (line 3) invalid char between encapsulated token and delimiter (line 3) invalid char between encapsulated token and delimiter','errorName':'Internal Server Error','error':500,'path':'/apps/tools/Entity/DataImport/load'}

Example CSV Data:

co.example.bi.fact.OrderItemFulfillmentFact
orderId,orderItemSeqId,externalId,orderName,orderTypeId,productStoreId,salesChannelEnumId,entryDate,orderDate,shippingCharges,productId,itemDescription,
FAO10117,101,5669763023132,"#1010101240",SALES_ORDER,STORE,POS_SALES_CHANNEL,1705232954323,1705232896000,,10016,"\"And\" Pride Tank in Grey Mix",

Current Behavior:

The parser throws an IOException due to embedded quotes in the data.

Proposed Solution:

To handle this, I found that using the withEscape method of CSVFormat helps manage escape characters effectively

escapeSeq = '\\'
CSVFormat format = CSVFormat.newFormat(edli.csvDelimiter)
        .withCommentMarker(edli.csvCommentStart)
        .withQuote(edli.csvQuoteChar)
        .withSkipHeaderRecord(true) // TODO: remove this? does it even do anything?
        .withIgnoreEmptyLines(true)
        .withIgnoreSurroundingSpaces(true)

format = format.withEscape(escapeSeq) // Added escape character support
CSVParser parser = format.parse(reader)

If my proposed solution is good, I'd be happy to create a pull request for it

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

Successfully merging a pull request may close this issue.

1 participant