info.fingo.spata.schema
Members list
Type members
Classlikes
CSV schema definition and validation utility.
CSV schema definition and validation utility.
Schema declares fields which are expected in CSV stream - their names and types. Fields with optional values have to be defined as Option
s:
val schema = CSVSchema()
.add[String]("name")
.add[Option[LocalDate]]("birthday")
Optional fields still have to exist in source data, only their values may be empty. Not all fields have to be declared by schema, any subset of them is sufficient.
In case of header mapping through CSVConfig.mapHeader, the names provided in schema are the final ones, after mapping.
Additionally, it is possible to specify per-field validators, posing additional requirements on CSV data:
val schema = CSVSchema()
.add[String]("code", RegexValidator("[A-Z][A-Z0-9]+"))
.add[BigDecimal]("price", MinValidator(0.01))
For more information on available, built-in validators or how to create additional ones see Validator.
CSV schema is verified through its validate method. It may yield an InvalidRecord, containing validation error together with original Record data or a TypedRecord, containing selected, strongly typed data - in both cases wrapped in cats.data.Validated.
Type parameters
- T
-
tuple encoding the schema
Value parameters
- columns
-
the typle containing typed columns with optional validators
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
CSV column representing schema field definition.
CSV column representing schema field definition.
Columns are created by the schema add method.
Type parameters
- K
-
type of column name - the singleton string
- V
-
column type - CSV field value type
Value parameters
- name
-
the name of column - CSV field name
- validators
-
collection of optional validators for field value
Attributes
- See also
- Supertypes
-
class Objecttrait Matchableclass Any
CSV field which has not passed validation.
CSV field which has not passed validation.
Value parameters
- error
-
validation error
- name
-
the name of this field
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
CSV record which has not passed validation against schema.
CSV record which has not passed validation against schema.
Value parameters
- flaws
-
list of conflicting fields with their errors
- record
-
the original record
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Proof of column name uniqueness in schema.
Proof of column name uniqueness in schema.
Witnesses that given candidate key type (singleton string) is not present on column list yet.
Type parameters
- K
-
type of column name
- T
-
type of tuple of columns
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Givens for NotPresent.
Givens for NotPresent.
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
NotPresent.type
Actual verifier of CSV data. Checks if CSV record is congruent with schema.
Actual verifier of CSV data. Checks if CSV record is congruent with schema.
The verification is achieved through recursive implicits for tuple of columns (as input type) and tuple of typed record data (as output type).
Type parameters
- T
-
the tuple (of columns) representing schema
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object emptyEnforcer.type
Givens for SchemaEnforcer.
Givens for SchemaEnforcer.
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
SchemaEnforcer.type
CSV record representation with type-safe access to its values. Typed records are created as result of schema validation.
CSV record representation with type-safe access to its values. Typed records are created as result of schema validation.
Typed records values are accessed similarly to regular records, as values referenced by string keys. In contract to regular record, however, the keys are verified at compile time. See apply method for more. The returned value has already required type, as declared by schema definition:
val id: Int = record("id")
Thanks to this, in contrast to a regular Record, field access operation through apply and conversion to case class through to return required type directly, without wrapping it in Either
.
For lineNum
and rowNum
description see Record.
Type parameters
- KS
-
keys type - a tuple
- VS
-
values type - a tuple
Value parameters
- keys
-
actual record's keys
- lineNum
-
last line number in source file this record is built from
- rowNum
-
row number in source file this record comes from
- values
-
actual record's values
Attributes
Typed record helper object.
Typed record helper object.
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
TypedRecord.type
Types
Type alias for typed record field name.
Type alias for typed record field name.
Attributes
Type alias for validation result.
Type alias for validation result.