Last active
May 13, 2017 11:12
-
-
Save satendrakumar/2fae274dc08bbb8c382631438de211d9 to your computer and use it in GitHub Desktop.
Parse CSV using univocity parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.univocity.parsers.csv.{CsvParser, CsvParserSettings} | |
class CSVParser(delimiter: Char = ',') { | |
private val parser = { | |
val settings = new CsvParserSettings | |
val format = settings.getFormat | |
format.setLineSeparator("\n") | |
format.setDelimiter(delimiter) | |
format.setQuote('"') | |
format.setQuoteEscape('\\') | |
format.setComment('\0') | |
settings.setIgnoreLeadingWhitespaces(true) | |
settings.setIgnoreTrailingWhitespaces(true) | |
settings.setReadInputOnSeparateThread(false) | |
settings.setEmptyValue("") | |
settings.setMaxCharsPerColumn(-1) | |
settings.setMaxColumns(20000) | |
new CsvParser(settings) | |
} | |
def parse(line: String): Array[String] = { | |
parser.parseLine(line) | |
} | |
} | |
//sbt dependency | |
// "com.univocity" % "univocity-parsers" % "2.4.1", | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment