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
- Alphabetic
- By Inheritance
- Record
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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.
- 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.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def get[A]: Field[A]
Safely gets typed record value.
Safely gets typed record value.
The combination of
get
, Field constructor andapply
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.
- 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 failsLeft[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.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val lineNum: Int
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- val rowNum: Int
- def size: Int
Gets number of fields in record.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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 andapply
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
- 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
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- object unsafe
Access to unsafe (exception throwing) methods