@@ -54,15 +54,15 @@ pub enum Cell {
5454 Timestamptz ( TimestampWithTimeZone ) ,
5555 Interval ( Interval ) ,
5656 Json ( JsonB ) ,
57- Bytea ( * mut bytea ) ,
57+ Bytea ( * mut pg_sys :: varlena ) ,
5858 Uuid ( Uuid ) ,
5959 BoolArray ( Vec < Option < bool > > ) ,
60+ StringArray ( Vec < Option < String > > ) ,
6061 I16Array ( Vec < Option < i16 > > ) ,
6162 I32Array ( Vec < Option < i32 > > ) ,
6263 I64Array ( Vec < Option < i64 > > ) ,
6364 F32Array ( Vec < Option < f32 > > ) ,
6465 F64Array ( Vec < Option < f64 > > ) ,
65- StringArray ( Vec < Option < String > > ) ,
6666}
6767
6868impl Clone for Cell {
@@ -83,15 +83,16 @@ impl Clone for Cell {
8383 Cell :: Timestamptz ( v) => Cell :: Timestamptz ( * v) ,
8484 Cell :: Interval ( v) => Cell :: Interval ( * v) ,
8585 Cell :: Json ( v) => Cell :: Json ( JsonB ( v. 0 . clone ( ) ) ) ,
86- Cell :: Bytea ( v) => Cell :: Bytea ( * v) ,
87- Cell :: Uuid ( v) => Cell :: Uuid ( * v) ,
86+ Cell :: Interval ( v) => Cell :: Interval ( v. clone ( ) ) ,
87+ Cell :: Bytea ( v) => Cell :: Bytea ( * v as * mut pg_sys:: varlena ) ,
88+ Cell :: Uuid ( v) => Cell :: Uuid ( v. clone ( ) ) ,
8889 Cell :: BoolArray ( v) => Cell :: BoolArray ( v. clone ( ) ) ,
90+ Cell :: StringArray ( v) => Cell :: StringArray ( v. clone ( ) ) ,
8991 Cell :: I16Array ( v) => Cell :: I16Array ( v. clone ( ) ) ,
9092 Cell :: I32Array ( v) => Cell :: I32Array ( v. clone ( ) ) ,
9193 Cell :: I64Array ( v) => Cell :: I64Array ( v. clone ( ) ) ,
9294 Cell :: F32Array ( v) => Cell :: F32Array ( v. clone ( ) ) ,
9395 Cell :: F64Array ( v) => Cell :: F64Array ( v. clone ( ) ) ,
94- Cell :: StringArray ( v) => Cell :: StringArray ( v. clone ( ) ) ,
9596 }
9697 }
9798}
@@ -182,27 +183,24 @@ impl fmt::Display for Cell {
182183 write ! ( f, "'{}'" , ts_cstr. to_str( ) . unwrap( ) )
183184 } ,
184185 Cell :: Json ( v) => write ! ( f, "{:?}" , v) ,
185- Cell :: Bytea ( v) => {
186- let byte_u8 = unsafe { pgrx:: varlena:: varlena_to_byte_slice ( * v) } ;
187- let hex = byte_u8
188- . iter ( )
189- . map ( |b| format ! ( "{:02X}" , b) )
190- . collect :: < Vec < String > > ( )
191- . join ( "" ) ;
192- if hex. is_empty ( ) {
193- write ! ( f, "''" )
194- } else {
195- write ! ( f, r#"'\x{}'"# , hex)
196- }
197- }
198- Cell :: Uuid ( v) => write ! ( f, "{}" , v) ,
199- Cell :: BoolArray ( v) => write_array ( v, f) ,
200- Cell :: I16Array ( v) => write_array ( v, f) ,
201- Cell :: I32Array ( v) => write_array ( v, f) ,
202- Cell :: I64Array ( v) => write_array ( v, f) ,
203- Cell :: F32Array ( v) => write_array ( v, f) ,
204- Cell :: F64Array ( v) => write_array ( v, f) ,
205- Cell :: StringArray ( v) => write_array ( v, f) ,
186+ Cell :: Interval ( v) => unsafe {
187+ let i = fcinfo:: direct_function_call_as_datum (
188+ pg_sys:: interval_out,
189+ & [ ( * v) . into_datum ( ) ] ,
190+ )
191+ . unwrap ( ) ;
192+ let i_cstr = CStr :: from_ptr ( i. cast_mut_ptr ( ) ) ;
193+ write ! ( f, "'{}'" , i_cstr. to_str( ) . unwrap( ) )
194+ } ,
195+ Cell :: Bytea ( v) => write ! ( f, "{:?}" , v) ,
196+ Cell :: Uuid ( v) => write ! ( f, "{:?}" , v) ,
197+ Cell :: BoolArray ( v) => write ! ( f, "{:?}" , v) ,
198+ Cell :: StringArray ( v) => write ! ( f, "{:?}" , v) ,
199+ Cell :: I16Array ( v) => write ! ( f, "{:?}" , v) ,
200+ Cell :: I32Array ( v) => write ! ( f, "{:?}" , v) ,
201+ Cell :: I64Array ( v) => write ! ( f, "{:?}" , v) ,
202+ Cell :: F32Array ( v) => write ! ( f, "{:?}" , v) ,
203+ Cell :: F64Array ( v) => write ! ( f, "{:?}" , v) ,
206204 }
207205 }
208206}
@@ -225,15 +223,16 @@ impl IntoDatum for Cell {
225223 Cell :: Timestamptz ( v) => v. into_datum ( ) ,
226224 Cell :: Interval ( v) => v. into_datum ( ) ,
227225 Cell :: Json ( v) => v. into_datum ( ) ,
228- Cell :: Bytea ( v) => Some ( Datum :: from ( v) ) ,
226+ Cell :: Interval ( v) => v. into_datum ( ) ,
227+ Cell :: Bytea ( v) => Some ( Datum :: from ( v as * mut pg_sys:: varlena ) ) ,
229228 Cell :: Uuid ( v) => v. into_datum ( ) ,
230229 Cell :: BoolArray ( v) => v. into_datum ( ) ,
230+ Cell :: StringArray ( v) => v. into_datum ( ) ,
231231 Cell :: I16Array ( v) => v. into_datum ( ) ,
232232 Cell :: I32Array ( v) => v. into_datum ( ) ,
233233 Cell :: I64Array ( v) => v. into_datum ( ) ,
234234 Cell :: F32Array ( v) => v. into_datum ( ) ,
235235 Cell :: F64Array ( v) => v. into_datum ( ) ,
236- Cell :: StringArray ( v) => v. into_datum ( ) ,
237236 }
238237 }
239238
@@ -258,15 +257,16 @@ impl IntoDatum for Cell {
258257 || other == pg_sys:: TIMESTAMPTZOID
259258 || other == pg_sys:: INTERVALOID
260259 || other == pg_sys:: JSONBOID
260+ || other == pg_sys:: INTERVALOID
261261 || other == pg_sys:: BYTEAOID
262262 || other == pg_sys:: UUIDOID
263263 || other == pg_sys:: BOOLARRAYOID
264+ || other == pg_sys:: TEXTARRAYOID
264265 || other == pg_sys:: INT2ARRAYOID
265266 || other == pg_sys:: INT4ARRAYOID
266267 || other == pg_sys:: INT8ARRAYOID
267268 || other == pg_sys:: FLOAT4ARRAYOID
268269 || other == pg_sys:: FLOAT8ARRAYOID
269- || other == pg_sys:: TEXTARRAYOID
270270 }
271271}
272272
@@ -320,33 +320,36 @@ impl FromDatum for Cell {
320320 PgOid :: BuiltIn ( PgBuiltInOids :: JSONBOID ) => {
321321 JsonB :: from_datum ( datum, is_null) . map ( Cell :: Json )
322322 }
323+ PgOid :: BuiltIn ( PgBuiltInOids :: INTERVALOID ) => {
324+ Some ( Cell :: Interval ( Interval :: from_datum ( datum, false ) . unwrap ( ) ) )
325+ }
323326 PgOid :: BuiltIn ( PgBuiltInOids :: BYTEAOID ) => {
324- Some ( Cell :: Bytea ( datum. cast_mut_ptr :: < bytea > ( ) ) )
327+ Some ( Cell :: Bytea ( datum. cast_mut_ptr :: < pg_sys :: varlena > ( ) ) )
325328 }
326329 PgOid :: BuiltIn ( PgBuiltInOids :: UUIDOID ) => {
327- Uuid :: from_datum ( datum, is_null) . map ( Cell :: Uuid )
328- }
329- PgOid :: BuiltIn ( PgBuiltInOids :: BOOLARRAYOID ) => {
330- Vec :: < Option < bool > > :: from_datum ( datum, false ) . map ( Cell :: BoolArray )
331- }
332- PgOid :: BuiltIn ( PgBuiltInOids :: INT2ARRAYOID ) => {
333- Vec :: < Option < i16 > > :: from_datum ( datum, false ) . map ( Cell :: I16Array )
334- }
335- PgOid :: BuiltIn ( PgBuiltInOids :: INT4ARRAYOID ) => {
336- Vec :: < Option < i32 > > :: from_datum ( datum, false ) . map ( Cell :: I32Array )
337- }
338- PgOid :: BuiltIn ( PgBuiltInOids :: INT8ARRAYOID ) => {
339- Vec :: < Option < i64 > > :: from_datum ( datum, false ) . map ( Cell :: I64Array )
340- }
341- PgOid :: BuiltIn ( PgBuiltInOids :: FLOAT4ARRAYOID ) => {
342- Vec :: < Option < f32 > > :: from_datum ( datum, false ) . map ( Cell :: F32Array )
343- }
344- PgOid :: BuiltIn ( PgBuiltInOids :: FLOAT8ARRAYOID ) => {
345- Vec :: < Option < f64 > > :: from_datum ( datum, false ) . map ( Cell :: F64Array )
346- }
347- PgOid :: BuiltIn ( PgBuiltInOids :: TEXTARRAYOID ) => {
348- Vec :: < Option < String > > :: from_datum ( datum, false ) . map ( Cell :: StringArray )
330+ Some ( Cell :: Uuid ( Uuid :: from_datum ( datum, false ) . unwrap ( ) ) )
349331 }
332+ PgOid :: BuiltIn ( PgBuiltInOids :: BOOLARRAYOID ) => Some ( Cell :: BoolArray (
333+ Vec :: < Option < bool > > :: from_datum ( datum, false ) . unwrap ( ) ,
334+ ) ) ,
335+ PgOid :: BuiltIn ( PgBuiltInOids :: TEXTARRAYOID ) => Some ( Cell :: StringArray (
336+ Vec :: < Option < String > > :: from_datum ( datum, false ) . unwrap ( ) ,
337+ ) ) ,
338+ PgOid :: BuiltIn ( PgBuiltInOids :: INT2ARRAYOID ) => Some ( Cell :: I16Array (
339+ Vec :: < Option < i16 > > :: from_datum ( datum, false ) . unwrap ( ) ,
340+ ) ) ,
341+ PgOid :: BuiltIn ( PgBuiltInOids :: INT4ARRAYOID ) => Some ( Cell :: I32Array (
342+ Vec :: < Option < i32 > > :: from_datum ( datum, false ) . unwrap ( ) ,
343+ ) ) ,
344+ PgOid :: BuiltIn ( PgBuiltInOids :: INT8ARRAYOID ) => Some ( Cell :: I64Array (
345+ Vec :: < Option < i64 > > :: from_datum ( datum, false ) . unwrap ( ) ,
346+ ) ) ,
347+ PgOid :: BuiltIn ( PgBuiltInOids :: FLOAT4ARRAYOID ) => Some ( Cell :: F32Array (
348+ Vec :: < Option < f32 > > :: from_datum ( datum, false ) . unwrap ( ) ,
349+ ) ) ,
350+ PgOid :: BuiltIn ( PgBuiltInOids :: FLOAT8ARRAYOID ) => Some ( Cell :: F64Array (
351+ Vec :: < Option < f64 > > :: from_datum ( datum, false ) . unwrap ( ) ,
352+ ) ) ,
350353 _ => None ,
351354 }
352355 }
0 commit comments