@@ -23,6 +23,7 @@ void pc_cstring_array_free(const char **array, int nelems);
2323Datum pcpoint_get_value (PG_FUNCTION_ARGS );
2424Datum pcpoint_get_values (PG_FUNCTION_ARGS );
2525Datum pcpatch_from_pcpoint_array (PG_FUNCTION_ARGS );
26+ Datum pcpatch_from_float_array (PG_FUNCTION_ARGS );
2627Datum pcpatch_from_pcpatch_array (PG_FUNCTION_ARGS );
2728Datum pcpatch_uncompress (PG_FUNCTION_ARGS );
2829Datum pcpatch_compress (PG_FUNCTION_ARGS );
@@ -329,6 +330,60 @@ Datum pcpatch_from_pcpoint_array(PG_FUNCTION_ARGS)
329330 PG_RETURN_POINTER (serpa );
330331}
331332
333+
334+ PG_FUNCTION_INFO_V1 (pcpatch_from_float_array );
335+ Datum pcpatch_from_float_array (PG_FUNCTION_ARGS )
336+ {
337+ int i , ndims , nelems , npoints ;
338+ float8 * vals ;
339+ PCPATCH * pa ;
340+ PCPOINTLIST * pl ;
341+ SERIALIZED_PATCH * serpa ;
342+ uint32 pcid = PG_GETARG_INT32 (0 );
343+ ArrayType * arrptr = PG_GETARG_ARRAYTYPE_P (1 );
344+ PCSCHEMA * schema = pc_schema_from_pcid (pcid , fcinfo );
345+
346+ if ( ! schema )
347+ elog (ERROR , "unable to load schema for pcid = %d" , pcid );
348+
349+ if ( ARR_ELEMTYPE (arrptr ) != FLOAT8OID )
350+ elog (ERROR , "array must be of float8[]" );
351+
352+ if ( ARR_NDIM (arrptr ) != 1 )
353+ elog (ERROR , "float8[] must have one dimension" );
354+
355+ if ( ARR_HASNULL (arrptr ) )
356+ elog (ERROR , "float8[] must not have null elements" );
357+
358+ ndims = schema -> ndims ;
359+ nelems = ARR_DIMS (arrptr )[0 ];
360+
361+ if ( nelems % ndims != 0 ) {
362+ elog (ERROR , "array dimensions do not match schema dimensions of pcid = %d" , pcid );
363+ }
364+
365+ npoints = nelems / ndims ;
366+
367+ vals = (float8 * ) ARR_DATA_PTR (arrptr );
368+ pl = pc_pointlist_make (nelems );
369+
370+ for ( i = 0 ; i < npoints ; ++ i ) {
371+
372+ PCPOINT * pt = pc_point_from_double_array (schema , vals , i * ndims , ndims );
373+ pc_pointlist_add_point (pl , pt );
374+ }
375+
376+ pa = pc_patch_from_pointlist (pl );
377+ pc_pointlist_free (pl );
378+ if ( ! pa )
379+ PG_RETURN_NULL ();
380+
381+ serpa = pc_patch_serialize (pa , NULL );
382+
383+ pc_patch_free (pa );
384+ PG_RETURN_POINTER (serpa );
385+ }
386+
332387typedef struct
333388{
334389 ArrayBuildState * s ;
0 commit comments