Skip to content

Commit

Permalink
[postgres] Emit float32 values for real columns (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Mar 18, 2024
1 parent 98cfb38 commit 760362b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration_tests/postgres/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ const expectedPayloadTemplate = `{
"x": 12.34,
"y": 56.78
},
"c_real": 45.678001403808594,
"c_real": 45.678,
"c_serial": 1000000123,
"c_smallint": 32767,
"c_text": "QWERTYUIOP",
Expand Down
4 changes: 2 additions & 2 deletions lib/debezium/converters/passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (FloatPassthrough) ToField(name string) debezium.Field {

func (FloatPassthrough) Convert(value any) (any, error) {
switch castValue := value.(type) {
case float32, float64:
case float32:
return castValue, nil
}
return nil, fmt.Errorf("expected float32/float64 got %T with value: %v", value, value)
return nil, fmt.Errorf("expected float32 got %T with value: %v", value, value)
}

// float32, float64 -> float64
Expand Down
8 changes: 8 additions & 0 deletions lib/postgres/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func ParseValue(colKind schema.DataType, value any) (any, error) {
return valString, nil
}
return nil, fmt.Errorf("value: %v not of string type for bit", value)
case schema.Real:
float64Value, ok := value.(float64)
if !ok {
return nil, fmt.Errorf("expected float64 got %T with value: %v", value, value)
}
// pgx returns `real`s as float64 even though they are always 32 bits
// https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-NUMERIC
return float32(float64Value), nil
case schema.UserDefinedText:
stringSlice, isOk := value.(string)
if !isOk {
Expand Down

0 comments on commit 760362b

Please sign in to comment.