Skip to content

Commit

Permalink
Use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 26, 2024
1 parent 43afc79 commit 1a77256
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/typing/decimal/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
func NewDecimal(precision *int32, value *apd.Decimal) *Decimal {
if precision != nil {
scale := -value.Exponent
if scale > *precision && *precision != -1 {
if scale > *precision && *precision != PrecisionNotSpecified {
// Note: -1 precision means it's not specified.

// This is typically not possible, but Postgres has a design flaw that allows you to do things like: NUMERIC(5, 6) which actually equates to NUMERIC(7, 6)
Expand Down Expand Up @@ -58,7 +58,7 @@ func (d *Decimal) String() string {
func (d *Decimal) Value() any {
// -1 precision is used for variable scaled decimal
// We are opting to emit this as a STRING because the value is technically unbounded (can get to ~1 GB).
if d.precision != nil && (*d.precision > MaxPrecisionBeforeString || *d.precision == -1) {
if d.precision != nil && (*d.precision > MaxPrecisionBeforeString || *d.precision == PrecisionNotSpecified) {
return d.String()
}

Expand Down
2 changes: 1 addition & 1 deletion lib/typing/decimal/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type DecimalDetails struct {
}

func NewDecimalDetails(precision int32, scale int32) *DecimalDetails {
if scale > precision && precision != -1 {
if scale > precision && precision != PrecisionNotSpecified {
// Note: -1 precision means it's not specified.

// This is typically not possible, but Postgres has a design flaw that allows you to do things like: NUMERIC(5, 6) which actually equates to NUMERIC(7, 6)
Expand Down
3 changes: 2 additions & 1 deletion lib/typing/parquet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/artie-labs/transfer/lib/typing/decimal"
"github.com/artie-labs/transfer/lib/typing/ext"

"github.com/artie-labs/transfer/lib/ptr"
Expand Down Expand Up @@ -113,7 +114,7 @@ func (k *KindDetails) ParquetAnnotation(colName string) (*Field, error) {
}, nil
case EDecimal.Kind:
precision := k.ExtendedDecimalDetails.Precision()
if precision == -1 {
if precision == decimal.PrecisionNotSpecified {
// This is a variable precision decimal, so we'll just treat it as a string.
return &Field{
Tag: FieldTag{
Expand Down

0 comments on commit 1a77256

Please sign in to comment.