* svec_cast_positions_float8arr - turns a pair of arrays, the first an int4[] * denoting positions and the second a float8[] denoting values, into an * svec of a given size with a given default value everywhere else. */
| 621 | * svec of a given size with a given default value everywhere else. |
| 622 | */ |
| 623 | Datum svec_cast_positions_float8arr(PG_FUNCTION_ARGS) { |
| 624 | ArrayType *B_PG = PG_GETARG_ARRAYTYPE_P(0); |
| 625 | ArrayType *A_PG = PG_GETARG_ARRAYTYPE_P(1); |
| 626 | int64 size = PG_GETARG_INT64(2); |
| 627 | float8 base_value = PG_GETARG_FLOAT8(3); |
| 628 | SvecType *output_svec; |
| 629 | int i = 0; |
| 630 | |
| 631 | if (ARR_ELEMTYPE(A_PG) != FLOAT8OID) |
| 632 | ereport(ERROR, |
| 633 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 634 | errmsg("svec_cast_positions_float8arr valeus only defined over float8[]"))); |
| 635 | if (ARR_NDIM(A_PG) != 1) |
| 636 | ereport(ERROR, |
| 637 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 638 | errmsg("svec_cast_positions_float8arr only defined over 1 dimensional arrays"))); |
| 639 | |
| 640 | if (ARR_NULLBITMAP(A_PG)) |
| 641 | ereport(ERROR, |
| 642 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 643 | errmsg("svec_cast_positions_float8arr does not allow null bitmaps on arrays"))); |
| 644 | |
| 645 | if (ARR_ELEMTYPE(B_PG) != INT8OID) |
| 646 | ereport(ERROR, |
| 647 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 648 | errmsg("svec_cast_positions_float8arr positions only defined over int[]"))); |
| 649 | if (ARR_NDIM(B_PG) != 1) |
| 650 | ereport(ERROR, |
| 651 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 652 | errmsg("svec_cast_positions_float8arr only defined over 1 dimensional arrays"))); |
| 653 | |
| 654 | if (ARR_NULLBITMAP(B_PG)) |
| 655 | ereport(ERROR, |
| 656 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 657 | errmsg("svec_cast_positions_float8arr does not allow null bitmaps on arrays"))); |
| 658 | |
| 659 | /* Extract array */ |
| 660 | int dimension = ARR_DIMS(A_PG)[0]; |
| 661 | int dimension2 = ARR_DIMS(B_PG)[0]; |
| 662 | |
| 663 | if (dimension != dimension2) |
| 664 | ereport(ERROR, |
| 665 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 666 | errmsg("svec_cast_positions_float8arr position and value vectors must be of the same size"))); |
| 667 | |
| 668 | float8 *array = (float8 *)ARR_DATA_PTR(A_PG); |
| 669 | int64 *array_pos = (int64 *)ARR_DATA_PTR(B_PG); |
| 670 | |
| 671 | if (array_pos[dimension-1] > size) |
| 672 | ereport(ERROR, |
| 673 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 674 | errmsg("svec_cast_positions_float8arr some of the position values are larger than maximum array size declared"))); |
| 675 | |
| 676 | for(i=0;i < dimension;++i){ |
| 677 | if(array_pos[i] <= 0){ |
| 678 | ereport(ERROR, |
| 679 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 680 | errmsg("svec_cast_positions_float8arr only accepts position that are positive integers (x > 0)"))); |
nothing calls this directly
no test coverage detected