diff --git a/lib/postgres/parse/parse.go b/lib/postgres/parse/parse.go index b5988b70..45e13c59 100644 --- a/lib/postgres/parse/parse.go +++ b/lib/postgres/parse/parse.go @@ -17,31 +17,6 @@ func ParseValue(colKind schema.DataType, value any) (any, error) { } switch colKind { - case schema.Geometry, schema.Geography: - valString, isOk := value.(string) - if !isOk { - return nil, fmt.Errorf("value: %v not of string type for geometry / geography", value) - } - - geometry, err := ToGeography([]byte(valString)) - if err != nil { - return nil, fmt.Errorf("failed to parse geometry / geography: %w", err) - } - - return geometry, nil - case schema.Point: - valString, isOk := value.(string) - if !isOk { - return nil, fmt.Errorf("value: %v not of string type for POINT", value) - } - - point, err := ToPoint(valString) - if err != nil { - return nil, fmt.Errorf("failed to parse POINT: %w", err) - } - - return point.ToMap(), nil - case schema.Bit: // This will be 0 (false) or 1 (true) valString, isOk := value.(string) @@ -49,14 +24,13 @@ func ParseValue(colKind schema.DataType, value any) (any, error) { return valString == "1", nil } return nil, fmt.Errorf("value: %v not of string type for bit", value) - case schema.JSON: - // Debezium sends JSON as a JSON string - byteSlice, isByteSlice := value.([]byte) - if !isByteSlice { - return nil, fmt.Errorf("value: %v not of []byte type for JSON", value) + case schema.UserDefinedText: + stringSlice, isOk := value.(string) + if !isOk { + return nil, fmt.Errorf("value: %v not of slice type", value) } - return string(byteSlice), nil + return stringSlice, nil case schema.Numeric, schema.VariableNumeric: stringVal, isStringVal := value.(string) if isStringVal { @@ -101,6 +75,14 @@ func ParseValue(colKind schema.DataType, value any) (any, error) { } return _uuid.String(), nil + case schema.JSON: + // Debezium sends JSON as a JSON string + byteSlice, isByteSlice := value.([]byte) + if !isByteSlice { + return nil, fmt.Errorf("value: %v not of []byte type for JSON", value) + } + + return string(byteSlice), nil case schema.HStore: var val pgtype.Hstore err := val.Scan(value) @@ -116,13 +98,30 @@ func ParseValue(colKind schema.DataType, value any) (any, error) { } return jsonMap, nil - case schema.UserDefinedText: - stringSlice, isOk := value.(string) + case schema.Point: + valString, isOk := value.(string) if !isOk { - return nil, fmt.Errorf("value: %v not of slice type", value) + return nil, fmt.Errorf("value: %v not of string type for POINT", value) } - return stringSlice, nil + point, err := ToPoint(valString) + if err != nil { + return nil, fmt.Errorf("failed to parse POINT: %w", err) + } + + return point.ToMap(), nil + case schema.Geometry, schema.Geography: + valString, isOk := value.(string) + if !isOk { + return nil, fmt.Errorf("value: %v not of string type for geometry / geography", value) + } + + geometry, err := ToGeography([]byte(valString)) + if err != nil { + return nil, fmt.Errorf("failed to parse geometry / geography: %w", err) + } + + return geometry, nil default: return value, nil } diff --git a/lib/postgres/schema/schema.go b/lib/postgres/schema/schema.go index 43dc3fc1..fac7be5e 100644 --- a/lib/postgres/schema/schema.go +++ b/lib/postgres/schema/schema.go @@ -22,6 +22,7 @@ const ( Bytea Inet Text + UserDefinedText Interval Array HStore @@ -31,7 +32,6 @@ const ( Int32 Int64 UUID - UserDefinedText JSON Timestamp Time