@@ -9,6 +9,8 @@ use crate::sources::postgres::{
99} ;
1010use crate :: typesystem:: TypeConversion ;
1111use chrono:: { DateTime , NaiveDate , NaiveDateTime , NaiveTime , Utc } ;
12+ use cidr_02:: IpInet ;
13+ use pgvector:: { Bit , HalfVector , SparseVector , Vector } ;
1214use postgres:: NoTls ;
1315use postgres_openssl:: MakeTlsConnector ;
1416use rust_decimal:: Decimal ;
@@ -40,26 +42,31 @@ macro_rules! impl_postgres_transport {
4042 systems = PostgresTypeSystem => ArrowTypeSystem ,
4143 route = PostgresSource <$proto, $tls> => ArrowDestination ,
4244 mappings = {
43- { Float4 [ f32 ] => Float64 [ f64 ] | conversion auto }
44- { Float8 [ f64 ] => Float64 [ f64 ] | conversion auto }
45- { Numeric [ Decimal ] => Decimal [ Decimal ] | conversion auto }
46- { Int2 [ i16 ] => Int64 [ i64 ] | conversion auto }
47- { Int4 [ i32 ] => Int64 [ i64 ] | conversion auto }
48- { Int8 [ i64 ] => Int64 [ i64 ] | conversion auto }
49- { Bool [ bool ] => Boolean [ bool ] | conversion auto }
50- { Text [ & ' r str ] => LargeUtf8 [ String ] | conversion owned }
51- { BpChar [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
52- { VarChar [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
53- { Name [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
54- { Timestamp [ NaiveDateTime ] => Date64 [ NaiveDateTime ] | conversion auto }
55- { Date [ NaiveDate ] => Date32 [ NaiveDate ] | conversion auto }
56- { Time [ NaiveTime ] => Time64 [ NaiveTime ] | conversion auto }
57- { TimestampTz [ DateTime <Utc >] => DateTimeTz [ DateTime <Utc >] | conversion auto }
58- { UUID [ Uuid ] => LargeUtf8 [ String ] | conversion option }
59- { Char [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
60- { ByteA [ Vec <u8 >] => LargeBinary [ Vec <u8 >] | conversion auto }
61- { JSON [ Value ] => LargeUtf8 [ String ] | conversion option }
62- { JSONB [ Value ] => LargeUtf8 [ String ] | conversion none }
45+ { Float4 [ f32 ] => Float64 [ f64 ] | conversion auto }
46+ { Float8 [ f64 ] => Float64 [ f64 ] | conversion auto }
47+ { Numeric [ Decimal ] => Decimal [ Decimal ] | conversion auto }
48+ { Int2 [ i16 ] => Int64 [ i64 ] | conversion auto }
49+ { Int4 [ i32 ] => Int64 [ i64 ] | conversion auto }
50+ { Int8 [ i64 ] => Int64 [ i64 ] | conversion auto }
51+ { Bool [ bool ] => Boolean [ bool ] | conversion auto }
52+ { Text [ & ' r str ] => LargeUtf8 [ String ] | conversion owned }
53+ { BpChar [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
54+ { VarChar [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
55+ { Name [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
56+ { Timestamp [ NaiveDateTime ] => Date64 [ NaiveDateTime ] | conversion auto }
57+ { Date [ NaiveDate ] => Date32 [ NaiveDate ] | conversion auto }
58+ { Time [ NaiveTime ] => Time64 [ NaiveTime ] | conversion auto }
59+ { TimestampTz [ DateTime <Utc >] => DateTimeTz [ DateTime <Utc >] | conversion auto }
60+ { UUID [ Uuid ] => LargeUtf8 [ String ] | conversion option }
61+ { Char [ & ' r str ] => LargeUtf8 [ String ] | conversion none }
62+ { ByteA [ Vec <u8 >] => LargeBinary [ Vec <u8 >] | conversion auto }
63+ { JSON [ Value ] => LargeUtf8 [ String ] | conversion option }
64+ { JSONB [ Value ] => LargeUtf8 [ String ] | conversion none }
65+ { Inet [ IpInet ] => LargeUtf8 [ String ] | conversion none }
66+ { Vector [ Vector ] => Float32Array [ Vec <Option <f32 >>] | conversion none }
67+ { HalfVec [ HalfVector ] => Float32Array [ Vec <Option <f32 >>] | conversion none }
68+ { Bit [ Bit ] => LargeBinary [ Vec <u8 >] | conversion none }
69+ { SparseVec [ SparseVector ] => Float32Array [ Vec <Option <f32 >>] | conversion none }
6370 }
6471 ) ;
6572 }
@@ -74,6 +81,18 @@ impl_postgres_transport!(CursorProtocol, MakeTlsConnector);
7481impl_postgres_transport ! ( SimpleProtocol , NoTls ) ;
7582impl_postgres_transport ! ( SimpleProtocol , MakeTlsConnector ) ;
7683
84+ impl < P , C > TypeConversion < IpInet , String > for PostgresArrowTransport < P , C > {
85+ fn convert ( val : IpInet ) -> String {
86+ val. to_string ( )
87+ }
88+ }
89+
90+ impl < P , C > TypeConversion < Option < IpInet > , Option < String > > for PostgresArrowTransport < P , C > {
91+ fn convert ( val : Option < IpInet > ) -> Option < String > {
92+ val. map ( |val| val. to_string ( ) )
93+ }
94+ }
95+
7796impl < P , C > TypeConversion < Uuid , String > for PostgresArrowTransport < P , C > {
7897 fn convert ( val : Uuid ) -> String {
7998 val. to_string ( )
@@ -85,3 +104,57 @@ impl<P, C> TypeConversion<Value, String> for PostgresArrowTransport<P, C> {
85104 val. to_string ( )
86105 }
87106}
107+
108+ impl < P , C > TypeConversion < Vector , Vec < Option < f32 > > > for PostgresArrowTransport < P , C > {
109+ fn convert ( val : Vector ) -> Vec < Option < f32 > > {
110+ val. to_vec ( ) . into_iter ( ) . map ( Some ) . collect ( )
111+ }
112+ }
113+
114+ impl < P , C > TypeConversion < Option < Vector > , Option < Vec < Option < f32 > > > >
115+ for PostgresArrowTransport < P , C >
116+ {
117+ fn convert ( val : Option < Vector > ) -> Option < Vec < Option < f32 > > > {
118+ val. map ( |val| val. to_vec ( ) . into_iter ( ) . map ( Some ) . collect ( ) )
119+ }
120+ }
121+
122+ impl < P , C > TypeConversion < HalfVector , Vec < Option < f32 > > > for PostgresArrowTransport < P , C > {
123+ fn convert ( val : HalfVector ) -> Vec < Option < f32 > > {
124+ val. to_vec ( ) . into_iter ( ) . map ( |v| Some ( v. to_f32 ( ) ) ) . collect ( )
125+ }
126+ }
127+
128+ impl < P , C > TypeConversion < Option < HalfVector > , Option < Vec < Option < f32 > > > >
129+ for PostgresArrowTransport < P , C >
130+ {
131+ fn convert ( val : Option < HalfVector > ) -> Option < Vec < Option < f32 > > > {
132+ val. map ( |val| val. to_vec ( ) . into_iter ( ) . map ( |v| Some ( v. to_f32 ( ) ) ) . collect ( ) )
133+ }
134+ }
135+
136+ impl < P , C > TypeConversion < Bit , Vec < u8 > > for PostgresArrowTransport < P , C > {
137+ fn convert ( val : Bit ) -> Vec < u8 > {
138+ val. as_bytes ( ) . into ( )
139+ }
140+ }
141+
142+ impl < P , C > TypeConversion < Option < Bit > , Option < Vec < u8 > > > for PostgresArrowTransport < P , C > {
143+ fn convert ( val : Option < Bit > ) -> Option < Vec < u8 > > {
144+ val. map ( |val| val. as_bytes ( ) . into ( ) )
145+ }
146+ }
147+
148+ impl < P , C > TypeConversion < SparseVector , Vec < Option < f32 > > > for PostgresArrowTransport < P , C > {
149+ fn convert ( val : SparseVector ) -> Vec < Option < f32 > > {
150+ val. to_vec ( ) . into_iter ( ) . map ( Some ) . collect ( )
151+ }
152+ }
153+
154+ impl < P , C > TypeConversion < Option < SparseVector > , Option < Vec < Option < f32 > > > >
155+ for PostgresArrowTransport < P , C >
156+ {
157+ fn convert ( val : Option < SparseVector > ) -> Option < Vec < Option < f32 > > > {
158+ val. map ( |val| val. to_vec ( ) . into_iter ( ) . map ( Some ) . collect ( ) )
159+ }
160+ }
0 commit comments