CsvInputFormat: Create a parser per InputEntityReader. (#10923)

RFC4180Parser is not thread safe and cannot be shared across readers.
This commit is contained in:
Gian Merlino 2021-02-27 18:37:05 -08:00 committed by GitHub
parent 99198c02af
commit 05e8f8fe06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -28,6 +28,8 @@ import java.io.IOException;
* InputEntityReader knows how to parse data into {@link InputRow}.
* This class is <i>stateful</i> and a new InputEntityReader should be created per {@link InputEntity}.
*
* Not thread-safe.
*
* @see IntermediateRowParsingReader
* @see TextReader
*/

View File

@ -38,7 +38,6 @@ import java.util.List;
public class CsvInputFormat extends FlatTextInputFormat
{
private static final char SEPARATOR = ',';
private static final RFC4180Parser PARSER = createOpenCsvParser();
@JsonCreator
public CsvInputFormat(
@ -68,6 +67,8 @@ public class CsvInputFormat extends FlatTextInputFormat
@Override
public InputEntityReader createReader(InputRowSchema inputRowSchema, InputEntity source, File temporaryDirectory)
{
final RFC4180Parser parser = createOpenCsvParser();
return new DelimitedValueReader(
inputRowSchema,
source,
@ -75,7 +76,7 @@ public class CsvInputFormat extends FlatTextInputFormat
getColumns(),
isFindColumnsFromHeader(),
getSkipHeaderRows(),
line -> Arrays.asList(PARSER.parseLine(line))
line -> Arrays.asList(parser.parseLine(line))
);
}

View File

@ -25,6 +25,8 @@ import java.util.Map;
/**
* Class that can parse Strings into Maps.
*
* Not thread-safe.
*/
public interface Parser<K, V>
{