* @param sdata The SparseData to be converted to an array of float8s * @return A float8[] representation of a SparseData */
| 1460 | * @return A float8[] representation of a SparseData |
| 1461 | */ |
| 1462 | double *sdata_to_float8arr(SparseData sdata) { |
| 1463 | double *array; |
| 1464 | int j, aptr; |
| 1465 | char *iptr; |
| 1466 | |
| 1467 | if (sdata->type_of_data != FLOAT8OID) { |
| 1468 | ereport(ERROR,(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1469 | errmsg("Data type of SparseData is not FLOAT64\n"))); |
| 1470 | } |
| 1471 | |
| 1472 | if ((array=(double *)palloc(sizeof(double)*(sdata->total_value_count))) |
| 1473 | == NULL) |
| 1474 | { |
| 1475 | ereport(ERROR,(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1476 | errmsg("Error allocating memory for array\n"))); |
| 1477 | } |
| 1478 | |
| 1479 | iptr = sdata->index->data; |
| 1480 | aptr = 0; |
| 1481 | for (int i=0; i<sdata->unique_value_count; i++) { |
| 1482 | for (j=0;j<compword_to_int8(iptr);j++,aptr++) { |
| 1483 | array[aptr] = ((double *)(sdata->vals->data))[i]; |
| 1484 | } |
| 1485 | iptr+=int8compstoragesize(iptr); |
| 1486 | } |
| 1487 | |
| 1488 | if ((aptr) != sdata->total_value_count) |
| 1489 | { |
| 1490 | ereport(ERROR,(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1491 | errmsg("Array size is incorrect, is: %d and should be %d\n", |
| 1492 | aptr,sdata->total_value_count))); |
| 1493 | |
| 1494 | pfree(array); |
| 1495 | return NULL; |
| 1496 | } |
| 1497 | |
| 1498 | return array; |
| 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * @return An array of integers given the (compressed) count array of a SparseData |
no test coverage detected