info.fingo.spata.schema

Members list

Type members

Classlikes

final class CSVSchema[T <: Tuple]

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 Options:

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 Object
trait Matchable
class Any
object CSVSchema

CSVSchema companion with convenience method to create empty schema.

CSVSchema companion with convenience method to create empty schema.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
CSVSchema.type
final class Column[K <: Key, V]

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 Object
trait Matchable
class Any
final class FieldFlaw

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 Object
trait Matchable
class Any
final class InvalidRecord

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 Object
trait Matchable
class Any
sealed trait NotPresent[K <: Key, T <: Tuple]

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 Object
trait Matchable
class Any
object NotPresent

Givens for NotPresent.

Givens for NotPresent.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
NotPresent.type
sealed trait SchemaEnforcer[T <: Tuple]

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 Object
trait Matchable
class Any
Known subtypes
object emptyEnforcer.type

Givens for SchemaEnforcer.

Givens for SchemaEnforcer.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
final class TypedRecord[KS <: Tuple, VS <: Tuple]

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

See also

CSVSchema for information about schema validation.

Companion
object
Supertypes
class Object
trait Matchable
class Any
object TypedRecord

Typed record helper object.

Typed record helper object.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Types

type Key = String & Singleton

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.

Attributes