Skip to content

Commit

Permalink
improved fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Nov 27, 2023
1 parent 898081f commit ac406bd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions flow/connectors/postgres/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (
default:
return nil, fmt.Errorf("failed to parse UUID: %v", value)
}
case qvalue.QValueKindTSRange:
tmpVal, err := decodeRangeValue(value.([]byte), pgtype.TsrangeOID, qvalue.QValueKindTSRange)
if err != nil {
return nil, fmt.Errorf("failed to parse tsrange: %w", err)
}

val = tmpVal
case qvalue.QValueKindTSTzRange:
tmpVal, err := decodeRangeValue(value.([]byte), pgtype.TstzrangeOID, qvalue.QValueKindTSTzRange)
if err != nil {
return nil, fmt.Errorf("failed to parse tstzrange: %w", err)
}

val = tmpVal
case qvalue.QValueKindBytes:
rawBytes := value.([]byte)
val = &qvalue.QValue{Kind: qvalue.QValueKindBytes, Value: rawBytes}
Expand Down Expand Up @@ -374,6 +388,22 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (
return val, nil
}

func decodeRangeValue(value []byte, oid uint32, kind qvalue.QValueKind) (*qvalue.QValue, error) {
typeMap := pgtype.NewMap()
typ, ok := typeMap.TypeForOID(oid)
if !ok {
return nil, fmt.Errorf("failed to parse range: %v", value)
}

parsedData, err := typ.Codec.DecodeDatabaseSQLValue(
typeMap, oid, pgtype.TextFormatCode, value)
if err != nil {
return nil, fmt.Errorf("failed to parse range: %v", value)
}

return &qvalue.QValue{Kind: kind, Value: parsedData}, nil
}

func parseFieldFromPostgresOID(oid uint32, value interface{}) (*qvalue.QValue, error) {
return parseFieldFromQValueKind(postgresOIDToQValueKind(oid), value)
}
Expand Down

0 comments on commit ac406bd

Please sign in to comment.