Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/codecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ Avro decimals closely correspond to `BigDecimal`s with a fixed precision and sca
Codec.decimal(precision = 10, scale = 2)
```

`Codec.decimalFixed` encodes decimals as fixed types instead, where the precision cannot exceed the number of digits which fit in the size.

```scala mdoc
Codec.decimalFixed(
name = "Price",
namespace = "com.example",
size = 8,
precision = 18,
scale = 2
)
```

For `BigDecimal`s with any precision and scale, `Codec.bigDecimal` uses the `big-decimal` logical type, which includes the scale in every value.

```scala mdoc
Codec.bigDecimal
```

## Enumerations

Avro enumerations closely correspond to `sealed trait`s with `case object`s.
Expand Down Expand Up @@ -127,6 +145,12 @@ Codec.fixed[Pence](
)
```

`Codec.uuidFixed` and `Codec.duration` define fixed types for `UUID`s and `Codec.TimePeriod`s, with the `uuid` and `duration` logical types.

```scala mdoc
Codec.uuidFixed(name = "Id", namespace = "com.example")
```

## Records

Avro records closely correspond to `case class`es.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ object AvroException {
final class DuplicateUnionType private[vulcan] (key: String, union: Schema.Union)
extends AvroException(s"Duplicate $key in union $union")

/**
* Exception raised when encoding a duration with an amount of months,
* days or milliseconds outside the range of unsigned 32-bit integers.
*/
final class DurationOutOfRange private[vulcan] (unit: String, amount: Long)
extends AvroException(
s"Unable to encode duration with $amount $unit, expected $unit in range 0 to 4294967295"
)

/**
* Exception raised when decoding a non-empty collection from an empty array.
*/
Expand Down Expand Up @@ -210,10 +219,18 @@ object AvroException {
extends AvroException(s"Got unexpected String with length $length, expected length 1")

/**
* Exception raised when the precision of a decimal codec is not positive.
* Exception raised when the precision of a decimal codec is not positive,
* or exceeds the number of digits which fit in the size of its fixed schema.
*/
final class InvalidDecimalPrecision private[vulcan] (precision: Int)
extends AvroException(s"Invalid decimal precision $precision: must be positive")
final class InvalidDecimalPrecision private[vulcan] (precision: Int, fixedSize: Option[Int])
extends AvroException(
fixedSize match {
case Some(size) if precision > 0 =>
s"Invalid decimal precision $precision: cannot exceed ${LogicalType.maxPrecision(size)} for fixed size $size"
case _ =>
s"Invalid decimal precision $precision: must be positive"
}
)

/**
* Exception raised when the scale of a decimal codec
Expand Down
Loading
Loading