@@ -15,8 +15,9 @@ import (
1515 "github.com/lib/pq/oid"
1616 "github.com/shopspring/decimal"
1717
18- datatypes "github.com/PeerDB-io/peerdb/flow/datatypes"
1918 "github.com/PeerDB-io/peerdb/flow/shared"
19+ "github.com/PeerDB-io/peerdb/flow/shared/datatypes"
20+ "github.com/PeerDB-io/peerdb/flow/shared/postgres"
2021 "github.com/PeerDB-io/peerdb/flow/shared/types"
2122)
2223
@@ -51,106 +52,17 @@ func (c *PostgresConnector) postgresOIDToQValueKind(
5152 recvOID uint32 ,
5253 customTypeMapping map [uint32 ]shared.CustomDataType ,
5354) types.QValueKind {
54- switch recvOID {
55- case pgtype .BoolOID :
56- return types .QValueKindBoolean
57- case pgtype .Int2OID :
58- return types .QValueKindInt16
59- case pgtype .Int4OID :
60- return types .QValueKindInt32
61- case pgtype .Int8OID :
62- return types .QValueKindInt64
63- case pgtype .Float4OID :
64- return types .QValueKindFloat32
65- case pgtype .Float8OID :
66- return types .QValueKindFloat64
67- case pgtype .QCharOID :
68- return types .QValueKindQChar
69- case pgtype .TextOID , pgtype .VarcharOID , pgtype .BPCharOID :
70- return types .QValueKindString
71- case pgtype .ByteaOID :
72- return types .QValueKindBytes
73- case pgtype .JSONOID :
74- return types .QValueKindJSON
75- case pgtype .JSONBOID :
76- return types .QValueKindJSONB
77- case pgtype .UUIDOID :
78- return types .QValueKindUUID
79- case pgtype .TimeOID :
80- return types .QValueKindTime
81- case pgtype .DateOID :
82- return types .QValueKindDate
83- case pgtype .CIDROID :
84- return types .QValueKindCIDR
85- case pgtype .MacaddrOID :
86- return types .QValueKindMacaddr
87- case pgtype .InetOID :
88- return types .QValueKindINET
89- case pgtype .TimestampOID :
90- return types .QValueKindTimestamp
91- case pgtype .TimestamptzOID :
92- return types .QValueKindTimestampTZ
93- case pgtype .NumericOID :
94- return types .QValueKindNumeric
95- case pgtype .Int2ArrayOID :
96- return types .QValueKindArrayInt16
97- case pgtype .Int4ArrayOID :
98- return types .QValueKindArrayInt32
99- case pgtype .Int8ArrayOID :
100- return types .QValueKindArrayInt64
101- case pgtype .PointOID :
102- return types .QValueKindPoint
103- case pgtype .Float4ArrayOID :
104- return types .QValueKindArrayFloat32
105- case pgtype .Float8ArrayOID :
106- return types .QValueKindArrayFloat64
107- case pgtype .BoolArrayOID :
108- return types .QValueKindArrayBoolean
109- case pgtype .DateArrayOID :
110- return types .QValueKindArrayDate
111- case pgtype .TimestampArrayOID :
112- return types .QValueKindArrayTimestamp
113- case pgtype .TimestamptzArrayOID :
114- return types .QValueKindArrayTimestampTZ
115- case pgtype .UUIDArrayOID :
116- return types .QValueKindArrayUUID
117- case pgtype .TextArrayOID , pgtype .VarcharArrayOID , pgtype .BPCharArrayOID :
118- return types .QValueKindArrayString
119- case pgtype .JSONArrayOID :
120- return types .QValueKindArrayJSON
121- case pgtype .JSONBArrayOID :
122- return types .QValueKindArrayJSONB
123- case pgtype .IntervalOID :
124- return types .QValueKindInterval
125- case pgtype .TstzrangeOID :
126- return types .QValueKindTSTZRange
127- default :
128- if typeName , ok := c .typeMap .TypeForOID (recvOID ); ok {
129- colType := types .QValueKindString
130- if typeData , ok := customTypeMapping [recvOID ]; ok {
131- colType = customTypeToQKind (typeData )
132- }
133- if _ , warned := c .hushWarnOID [recvOID ]; ! warned {
134- c .logger .Warn ("unsupported field type" ,
135- slog .Int64 ("oid" , int64 (recvOID )), slog .String ("typeName" , typeName .Name ), slog .String ("mapping" , string (colType )))
136- c .hushWarnOID [recvOID ] = struct {}{}
137- }
138- return colType
139- } else {
140- // workaround for some types not being defined by pgtype
141- switch oid .Oid (recvOID ) {
142- case oid .T_timetz :
143- return types .QValueKindTimeTZ
144- case oid .T_point :
145- return types .QValueKindPoint
146- default :
147- if typeData , ok := customTypeMapping [recvOID ]; ok {
148- return customTypeToQKind (typeData )
149- }
150- return types .QValueKindString
151- }
152- }
55+ colType , err := postgres .PostgresOIDToQValueKind (recvOID , customTypeMapping , c .typeMap )
56+ _ , warned := c .hushWarnOID [recvOID ]
57+ if err != nil && ! warned {
58+ c .logger .Warn (
59+ "unsupported field type" ,
60+ slog .Int64 ("oid" , int64 (recvOID )),
61+ slog .String ("typeName" , err .Error ()),
62+ slog .String ("mapping" , string (colType )))
63+ c .hushWarnOID [recvOID ] = struct {}{}
15364 }
65+ return colType
15466}
15567
15668func qValueKindToPostgresType (colTypeStr string ) string {
@@ -616,31 +528,6 @@ func numericToDecimal(numVal pgtype.Numeric) (types.QValue, error) {
616528 }
617529}
618530
619- func customTypeToQKind (typeData shared.CustomDataType ) types.QValueKind {
620- if typeData .Type == 'e' {
621- if typeData .Delim != 0 {
622- return types .QValueKindArrayEnum
623- } else {
624- return types .QValueKindEnum
625- }
626- }
627-
628- if typeData .Delim != 0 {
629- return types .QValueKindArrayString
630- }
631-
632- switch typeData .Name {
633- case "geometry" :
634- return types .QValueKindGeometry
635- case "geography" :
636- return types .QValueKindGeography
637- case "hstore" :
638- return types .QValueKindHStore
639- default :
640- return types .QValueKindString
641- }
642- }
643-
644531// Postgres does not like timestamps of the form 2006-01-02 15:04:05 +0000 UTC
645532// in tstzrange.
646533// convertTimeRangeBound removes the +0000 UTC part
0 commit comments