(pt *pgtype.Type, precision, scale int32)
| 175 | |
| 176 | func PostgresTypeToArrowType(p PostgresType) arrow.DataType { |
| 177 | return pgTypeToArrowType(p.PG, p.Precision, p.Scale) |
| 178 | } |
| 179 | |
| 180 | func pgTypeToArrowType(pt *pgtype.Type, precision, scale int32) arrow.DataType { |
| 181 | switch pt.OID { |
| 182 | case pgtype.BoolOID: |
| 183 | return arrow.FixedWidthTypes.Boolean |
| 184 | case pgtype.QCharOID: |
| 185 | return arrow.PrimitiveTypes.Uint8 |
| 186 | case pgtype.ByteaOID: |
| 187 | return arrow.BinaryTypes.Binary |
| 188 | case pgtype.NameOID, pgtype.TextOID, pgtype.VarcharOID, pgtype.BPCharOID, pgtype.JSONOID, pgtype.JSONBOID, pgtype.XMLOID: |
| 189 | return arrow.BinaryTypes.String |
| 190 | case pgtype.Int8OID: |
| 191 | return arrow.PrimitiveTypes.Int64 |
| 192 | case pgtype.Int2OID: |
| 193 | return arrow.PrimitiveTypes.Int16 |
| 194 | case pgtype.Int4OID: |
| 195 | return arrow.PrimitiveTypes.Int32 |
| 196 | case pgtype.OIDOID: |
| 197 | return arrow.PrimitiveTypes.Uint32 |
| 198 | case pgtype.TIDOID: |
| 199 | return arrow.PrimitiveTypes.Uint64 |
| 200 | case pgtype.Float4OID: |
| 201 | return arrow.PrimitiveTypes.Float32 |
| 202 | case pgtype.Float8OID: |
| 203 | return arrow.PrimitiveTypes.Float64 |
| 204 | case pgtype.DateOID: |
| 205 | return arrow.FixedWidthTypes.Date32 |
| 206 | case pgtype.TimeOID, pgtype.TimetzOID: |
| 207 | return arrow.FixedWidthTypes.Time64ns |
| 208 | case pgtype.TimestampOID: |
| 209 | return &arrow.TimestampType{Unit: arrow.Microsecond, TimeZone: ""} |
| 210 | case pgtype.TimestamptzOID: |
| 211 | return arrow.FixedWidthTypes.Timestamp_us |
| 212 | case pgtype.NumericOID: |
| 213 | if precision > 0 && scale >= 0 { |
| 214 | if precision <= 38 { |
| 215 | return &arrow.Decimal128Type{Precision: precision, Scale: scale} |
| 216 | // 256-bit decimal is not supported in DuckDB |
| 217 | // } else if precision <= 76 { |
| 218 | // return &arrow.Decimal256Type{Precision: precision, Scale: scale} |
| 219 | } else { |
| 220 | // Precision too large, default to string |
| 221 | return arrow.BinaryTypes.String |
| 222 | } |
| 223 | } else { |
| 224 | // Unknown precision and scale, default to string |
| 225 | return arrow.BinaryTypes.String |
| 226 | } |
| 227 | case pgtype.UUIDOID: |
| 228 | // TODO(fan): Currently, DuckDB does not support BLOB -> UUID conversion, |
| 229 | // so we use a string type for UUIDs. |
| 230 | // return &arrow.FixedSizeBinaryType{ByteWidth: 16} |
| 231 | return arrow.BinaryTypes.String |
| 232 | case pgtype.PointOID: |
| 233 | return arrow.StructOf( |
| 234 | arrow.Field{Name: "x", Type: arrow.PrimitiveTypes.Float64}, |
no outgoing calls
no test coverage detected