@@ -54,15 +54,15 @@ pub enum Cell {
54
54
Timestamptz ( TimestampWithTimeZone ) ,
55
55
Interval ( Interval ) ,
56
56
Json ( JsonB ) ,
57
- Bytea ( * mut bytea ) ,
57
+ Bytea ( * mut pg_sys :: varlena ) ,
58
58
Uuid ( Uuid ) ,
59
59
BoolArray ( Vec < Option < bool > > ) ,
60
+ StringArray ( Vec < Option < String > > ) ,
60
61
I16Array ( Vec < Option < i16 > > ) ,
61
62
I32Array ( Vec < Option < i32 > > ) ,
62
63
I64Array ( Vec < Option < i64 > > ) ,
63
64
F32Array ( Vec < Option < f32 > > ) ,
64
65
F64Array ( Vec < Option < f64 > > ) ,
65
- StringArray ( Vec < Option < String > > ) ,
66
66
}
67
67
68
68
impl Clone for Cell {
@@ -83,15 +83,16 @@ impl Clone for Cell {
83
83
Cell :: Timestamptz ( v) => Cell :: Timestamptz ( * v) ,
84
84
Cell :: Interval ( v) => Cell :: Interval ( * v) ,
85
85
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 ( ) ) ,
88
89
Cell :: BoolArray ( v) => Cell :: BoolArray ( v. clone ( ) ) ,
90
+ Cell :: StringArray ( v) => Cell :: StringArray ( v. clone ( ) ) ,
89
91
Cell :: I16Array ( v) => Cell :: I16Array ( v. clone ( ) ) ,
90
92
Cell :: I32Array ( v) => Cell :: I32Array ( v. clone ( ) ) ,
91
93
Cell :: I64Array ( v) => Cell :: I64Array ( v. clone ( ) ) ,
92
94
Cell :: F32Array ( v) => Cell :: F32Array ( v. clone ( ) ) ,
93
95
Cell :: F64Array ( v) => Cell :: F64Array ( v. clone ( ) ) ,
94
- Cell :: StringArray ( v) => Cell :: StringArray ( v. clone ( ) ) ,
95
96
}
96
97
}
97
98
}
@@ -182,27 +183,24 @@ impl fmt::Display for Cell {
182
183
write ! ( f, "'{}'" , ts_cstr. to_str( ) . unwrap( ) )
183
184
} ,
184
185
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) ,
206
204
}
207
205
}
208
206
}
@@ -225,15 +223,16 @@ impl IntoDatum for Cell {
225
223
Cell :: Timestamptz ( v) => v. into_datum ( ) ,
226
224
Cell :: Interval ( v) => v. into_datum ( ) ,
227
225
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 ) ) ,
229
228
Cell :: Uuid ( v) => v. into_datum ( ) ,
230
229
Cell :: BoolArray ( v) => v. into_datum ( ) ,
230
+ Cell :: StringArray ( v) => v. into_datum ( ) ,
231
231
Cell :: I16Array ( v) => v. into_datum ( ) ,
232
232
Cell :: I32Array ( v) => v. into_datum ( ) ,
233
233
Cell :: I64Array ( v) => v. into_datum ( ) ,
234
234
Cell :: F32Array ( v) => v. into_datum ( ) ,
235
235
Cell :: F64Array ( v) => v. into_datum ( ) ,
236
- Cell :: StringArray ( v) => v. into_datum ( ) ,
237
236
}
238
237
}
239
238
@@ -258,15 +257,16 @@ impl IntoDatum for Cell {
258
257
|| other == pg_sys:: TIMESTAMPTZOID
259
258
|| other == pg_sys:: INTERVALOID
260
259
|| other == pg_sys:: JSONBOID
260
+ || other == pg_sys:: INTERVALOID
261
261
|| other == pg_sys:: BYTEAOID
262
262
|| other == pg_sys:: UUIDOID
263
263
|| other == pg_sys:: BOOLARRAYOID
264
+ || other == pg_sys:: TEXTARRAYOID
264
265
|| other == pg_sys:: INT2ARRAYOID
265
266
|| other == pg_sys:: INT4ARRAYOID
266
267
|| other == pg_sys:: INT8ARRAYOID
267
268
|| other == pg_sys:: FLOAT4ARRAYOID
268
269
|| other == pg_sys:: FLOAT8ARRAYOID
269
- || other == pg_sys:: TEXTARRAYOID
270
270
}
271
271
}
272
272
@@ -320,33 +320,36 @@ impl FromDatum for Cell {
320
320
PgOid :: BuiltIn ( PgBuiltInOids :: JSONBOID ) => {
321
321
JsonB :: from_datum ( datum, is_null) . map ( Cell :: Json )
322
322
}
323
+ PgOid :: BuiltIn ( PgBuiltInOids :: INTERVALOID ) => {
324
+ Some ( Cell :: Interval ( Interval :: from_datum ( datum, false ) . unwrap ( ) ) )
325
+ }
323
326
PgOid :: BuiltIn ( PgBuiltInOids :: BYTEAOID ) => {
324
- Some ( Cell :: Bytea ( datum. cast_mut_ptr :: < bytea > ( ) ) )
327
+ Some ( Cell :: Bytea ( datum. cast_mut_ptr :: < pg_sys :: varlena > ( ) ) )
325
328
}
326
329
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 ( ) ) )
349
331
}
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
+ ) ) ,
350
353
_ => None ,
351
354
}
352
355
}
0 commit comments