Skip to content

Commit

Permalink
[typing] Log if we observe a precision with a value of zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 28, 2024
1 parent be4ebf0 commit 8cdc6e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ type Field struct {
Parameters map[string]any `json:"parameters"`
}

func (f Field) Scale() (int32, error) {
return maputil.GetInt32FromMap(f.Parameters, "scale")
}

func (f Field) GetScaleAndPrecision() (int32, *int32, error) {
scale, scaleErr := maputil.GetInt32FromMap(f.Parameters, "scale")
scale, scaleErr := f.Scale()
if scaleErr != nil {
return 0, nil, scaleErr
}
Expand Down
8 changes: 8 additions & 0 deletions lib/typing/decimal/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package decimal

import (
"fmt"
"log/slog"
)

const (
Expand All @@ -17,6 +18,13 @@ type Details struct {
}

func NewDetails(precision int32, scale int32) Details {
if precision == 0 {
// MySQL, PostgreSQL, and SQLServer do not allow a zero precision, so this should never happen.
// Let's log if we observe it happening, and if we don't see it in the logs then we can use zero as the
// [PrecisionNotSpecified] value and change precision to a uint16.
slog.Error("Decimal precision is zero")
}

if scale > precision && precision != PrecisionNotSpecified {
// Note: -1 precision means it's not specified.

Expand Down

0 comments on commit 8cdc6e5

Please sign in to comment.