* Assume the input array is of type numeric[]. */
| 308 | * Assume the input array is of type numeric[]. |
| 309 | */ |
| 310 | ArrayType* |
| 311 | array_to_float8_array(ArrayType *x) { |
| 312 | Oid element_type = ARR_ELEMTYPE(x); |
| 313 | if (element_type == FLOAT8OID) { |
| 314 | // this does not returning a copy, the caller needs to pay attention |
| 315 | return x; |
| 316 | } |
| 317 | |
| 318 | // deconstruct |
| 319 | TypeCacheEntry * TI = lookup_type_cache(element_type, |
| 320 | TYPECACHE_CMP_PROC_FINFO); |
| 321 | bool *nulls = NULL; |
| 322 | int len = 0; |
| 323 | Datum *array = NULL; |
| 324 | deconstruct_array(x, |
| 325 | element_type, |
| 326 | TI->typlen, |
| 327 | TI->typbyval, |
| 328 | TI->typalign, |
| 329 | &array, |
| 330 | &nulls, |
| 331 | &len); |
| 332 | |
| 333 | // casting |
| 334 | Datum *float8_array = (Datum *)palloc(len * sizeof(Datum)); |
| 335 | int i = 0; |
| 336 | for (i = 0; i < len; i ++) { |
| 337 | if (nulls[i]) { float8_array[i] = Float8GetDatum(0); } |
| 338 | else { |
| 339 | float8_array[i] = Float8GetDatum( |
| 340 | datum_float8_cast(array[i], element_type)); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // reconstruct |
| 345 | TypeCacheEntry * FLOAT8TI = lookup_type_cache(FLOAT8OID, |
| 346 | TYPECACHE_CMP_PROC_FINFO); |
| 347 | ArrayType *ret = construct_md_array(float8_array, |
| 348 | nulls, |
| 349 | ARR_NDIM(x), |
| 350 | ARR_DIMS(x), |
| 351 | ARR_LBOUND(x), |
| 352 | FLOAT8OID, |
| 353 | FLOAT8TI->typlen, |
| 354 | FLOAT8TI->typbyval, |
| 355 | FLOAT8TI->typalign); |
| 356 | |
| 357 | pfree(array); |
| 358 | pfree(float8_array); |
| 359 | pfree(nulls); |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | // ------------------------------------------------------------------------ |
| 365 | // exported functions |
no test coverage detected