1

Using Univocity framework to do custom parsing requirements. we have an iterator outputing each line as an event by calling parseNext(), we do not want to use "parse(File file)" .

We have this Scala case class as the final output but at the moment we are handling output from parser and using a factory class to create scala case classes.

Is there an iterator way to generate case class objects from univocity (I did find BeanListProcessor but which does not work for iterator way)?

Answer can be in Java or Scala..

Thanks, R

  def parseRecord(field: Array[String], univocityContext: Option[ParsingContext]): Option[lineEvent] = {

        val parsingContext = univocityContext.get
        val parsedEvent = new ParsedEventConstructor()

      for ((index, counter) <- parsingContext.extractedFieldIndexes().zipWithIndex){

        val columnHeader  = parsingContext.headers()(index)

        columnHeader match {

          case "header1" => {
            parsedEvent.parsedheader1 += field(counter)
          }
          case "header2" => {
            parsedEvent.parsedheader2 += field(counter)
          }
          case _ => parsedEvent.parsedOtherValues += field(counter)
        }
      }

    Some(parsedEvent.getParsedEvent())
  }
Ramesh Sivaraman
  • 1,295
  • 3
  • 19
  • 32

1 Answers1

1

uniVocity-parsers has a BeanProcessor (without "List" in the name) that will submit each parsed bean to a "beanProcessed" callback method you need to implement. The BeanListProcessor is just a convenience class that extends BeanProcessor to add each object into a list, it's not the only way to get the objects.

You can also use a CsvRoutines object and its iterate method to iterate over beans without using the callback mentioned above. Check this example.

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29
  • Thank you so much Jeronimo.. that helps, I found out from your other threads that you developed Univocity?? Great work, I m very impressed with the performance.. I'd like to contribute if I can in any ways if possible? Cheers, R – Ramesh Sivaraman Sep 12 '16 at 10:10
  • Glad to help and to hear you are interested in contributing. Feel free to submit pull requests with improvements or report any bugs you find. Cheers! – Jeronimo Backes Sep 12 '16 at 10:20