-
-
Notifications
You must be signed in to change notification settings - Fork 253
Closed
Description
Hi,
I am trying to exclude the fields using settings.excludeFields() but it errors out. In my use case, incoming headers in the CSV can be dynamic. Meaning sometimes some field might be missing and sometimes not.
e.g.
incoming CSV has the following headers:
header1
settings.excludeFields() code is :
settings.excludeFields("header1","header2");
error:
Exception in thread "main" com.univocity.parsers.common.TextParsingException: java.lang.IllegalStateException - Unknown field names: [header2]
Parser Configuration: CsvParserSettings:
Auto configuration enabled=true
Auto-closing enabled=true
Autodetect column delimiter=false
Autodetect quotes=false
Column reordering enabled=true
Delimiters for detection=null
Empty value=
Escape unquoted values=false
Header extraction enabled=null
Headers=null
Ignore leading whitespaces=true
Ignore leading whitespaces in quotes=false
Ignore trailing whitespaces=true
Ignore trailing whitespaces in quotes=false
Input buffer size=1048576
Input reading on separate thread=true
Keep escape sequences=true
Keep quotes=true
Length of content displayed on error=-1
Line separator detection enabled=false
Maximum number of characters per column=12000
Maximum number of columns=3000
Normalize escaped line separators=true
Null value=
Number of records to read=all
Processor=com.univocity.parsers.common.processor.RowListProcessor
Restricting data in exceptions=false
RowProcessor error handler=null
Selected fields=undesired field selection: [header1, header2]
Skip bits as whitespace=true
Skip empty lines=true
Unescaped quote handling=nullFormat configuration:
CsvFormat:
Comment character=#
Field delimiter=;
Line separator (normalized)=\n
Line separator sequence=\n
Quote character="
Quote escape character="
Quote escape escape character=null
Internal state when error was thrown: line=1, column=1, record=0, charIndex=6, headers=[header1]
at com.univocity.parsers.common.AbstractParser.handleException(AbstractParser.java:395)
at com.univocity.parsers.common.AbstractParser.parseNext(AbstractParser.java:616)
at com.univocity.parsers.common.AbstractParser.parseNextRecord(AbstractParser.java:1212)
at com.univocity.parsers.common.AbstractParser.internalParseAllRecords(AbstractParser.java:1187)
at com.univocity.parsers.common.AbstractParser.parseAllRecords(AbstractParser.java:1178)
at com.univocity.parsers.common.AbstractParser.parseAllRecords(AbstractParser.java:1201)
at com.bsg.CSV_RowProcessor.main(CSV_RowProcessor.java:43)
Caused by: java.lang.IllegalStateException: Unknown field names: [header2]
at com.univocity.parsers.common.fields.ExcludeFieldNameSelector.getFieldIndexes(ExcludeFieldNameSelector.java:52)
at com.univocity.parsers.common.ParserOutput.initializeColumnsToExtract(ParserOutput.java:274)
at com.univocity.parsers.common.ParserOutput.initializeHeaders(ParserOutput.java:177)
at com.univocity.parsers.common.ParserOutput.rowParsed(ParserOutput.java:193)
at com.univocity.parsers.common.AbstractParser.parseNext(AbstractParser.java:576)
... 5 more
Although I use a non-existing header in settings.selectField(), it does not throw an error unless I use the header in my code.
Is there a way to overcome this limitation of excludeField()?? because the headers in the incoming CSV can be dynamic in my case.
I am using :
Univocity 2.8.4
Java 1.8
Thanks in advance.
Reactions are currently unavailable