Packages

class Record extends AnyRef

CSV record representation. A record is basically a map from string to string. Values are indexed by header row if present or by tuple-style header: "_1", "_2" etc.

lineNum is the last line in source file which content is part of this record - in other words it is the number of lines consumed so far to load this record. It starts with 1, including header line - first data record has typically line number 2. There may be many lines per record when some fields contain line breaks. New line is interpreted independently from CSV record separator, as the standard platform EOL character sequence.

rowNum is record counter. It start with 1 for data, with header row having number 0. It differs from lineNum for sources with header or fields containing line breaks.

Self Type
Record
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Record
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. class Field[A] extends AnyRef

    Intermediary to delegate parsing to in order to infer type of formatter used by parser.

    Intermediary to delegate parsing to in order to infer type of formatter used by parser. Provides exception-free parsing method.

    A

    target type for parsing

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply(idx: Int): Option[String]

    Gets field value.

    Gets field value.

    idx

    the index of retrieved field, starting from 0.

    returns

    field value in original, string format or None if index is out of bounds.

  5. def apply(key: String): Option[String]

    Gets field value.

    Gets field value.

    key

    the key of retrieved field

    returns

    field value in its original, string format if correct key is provided or None otherwise.

  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def get[A]: Field[A]

    Safely gets typed record value.

    Safely gets typed record value.

    The combination of get, Field constructor and apply method allows value retrieval in following form:

    val date: Decoded[LocalDate] = record.get[LocalDate]("key", DateTimeFormatter.ofPattern("dd.MM.yy"))

    (type of formatter is inferred based on target type).

    Parsers for basic types are provided through StringParser object. Additional ones may be provided as implicits.

    To parse optional values provide Option[_] as type parameter. Parsing empty value to simple type will result in an error.

    A

    type to parse the field to

    returns

    intermediary to retrieve value according to custom format

    See also

    StringParser for information on providing custom parsers.

  11. def get[A](key: String)(implicit arg0: StringParser[A]): Decoded[A]

    Safely gets typed record value.

    Safely gets typed record value.

    Parsers for basic types are provided through StringParser object.

    To parse optional values provide Option[_] as type parameter. Parsing empty value to simple type will result in an error.

    If wrong header key is provided this function will return Left[error.HeaderError,_]. If parsing fails Left[error.DataError,_] will be returned.

    A

    type to parse the field to

    key

    the key of retrieved field

    returns

    either parsed value or an error

    Note

    This function assumes "standard" string formatting, without any locale support, e.g. point as decimal separator or ISO date and time formats. Use get if more control over source format is required.

    See also

    StringParser for information on providing custom parsers.

  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. val lineNum: Int
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. val rowNum: Int
  20. def size: Int

    Gets number of fields in record.

  21. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  22. def to[P <: Product]: ToProduct[P]

    Converts this record to scala.Product, e.g.

    Converts this record to scala.Product, e.g. case class.

    The combination of to, Record.ToProduct constructor and apply method allows conversion in following form:

    // Assume following CSV source
    // ----------------
    // name,born
    // Nicolaus Copernicus,1473-02-19,1543-05-24
    // Johannes Hevelius,1611-01-28,
    // ----------------
    // and a Record created based on it
    val record: Record = ???
    case class Person(name: String, born: LocalDate, died: Option[LocalDate])
    val person: Decoded[Person] = record.to[Person]() // this line may cause IntelliJ to mistakenly show an error

    Please note, that the conversion is name-based (case class field names have to match CSV header) and is case sensitive. The order of fields doesn't matter. Case class may be narrower and effectively retrieve only a subset of record's fields.

    It is possible to use a tuple instead of case class. In such case the header must match the tuple field naming convention: _1, _2 etc.

    Current implementation supports only shallow conversion - each product field has to be retrieved from single CSV field through StringParser.

    Because conversion to product requires parsing of all fields through StringParser, there is no way to provide custom formatter, like while using get method. If other then the default formatting has to be handled, a custom implicit stringParser has to be provided:

    // Assume following CSV source
    // ----------------
    // name,born,died
    // Nicolaus Copernicus,19.02.1473,24.05.1543
    // Johannes Hevelius,28.01.1611,
    // ----------------
    // and a Record created based on it
    val record: Record = ???
    case class Person(name: String, born: LocalDate, died: Option[LocalDate])
    implicit val ldsp: StringParser[LocalDate] = (str: String) =>
        LocalDate.parse(str.strip, DateTimeFormatter.ofPattern("dd.MM.yyyy"))
    val person: Decoded[Person] = record.to[Person]() // this line may cause IntelliJ to mistakenly show an error
    P

    the Product type to converter this record to

    returns

    intermediary to infer representation type and return proper type

  23. def toString(): String

    Gets text representation of record, with fields separated by comma.

    Gets text representation of record, with fields separated by comma.

    Definition Classes
    Record → AnyRef → Any
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. object unsafe

    Access to unsafe (exception throwing) methods

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped