MCPcopy Create free account
hub / github.com/apache/madlib / General_Array_to_Element

Function General_Array_to_Element

methods/array_ops/src/pg_gp/array_ops.c:1526–1610  ·  view source on GitHub ↗

------------------------------------------------------------------------ general helper functions ------------------------------------------------------------------------ * @brief Aggregates an array to a scalar. * * @param v Array. * @param exta_val An extra rgument for element_function. * @param element_function Transition function. * @param finalize_function Final function. * @returns Wha

Source from the content-addressed store, hash-verified

1524 * @returns Whatever finalize_function returns.
1525 */
1526Datum
1527General_Array_to_Element(
1528 ArrayType *v,
1529 Datum exta_val,
1530 float8 init_val,
1531 Datum(*element_function)(Datum,Oid,Datum,Oid,Datum,Oid),
1532 Datum(*finalize_function)(Datum,int,Oid)) {
1533
1534 // dimensions
1535 int ndims = ARR_NDIM(v);
1536 if (ndims == 0) {
1537 elog(WARNING, "input are empty arrays.");
1538 return Float8GetDatum(0);
1539 }
1540 int *dims = ARR_DIMS(v);
1541 int nitems = ArrayGetNItems(ndims, dims);
1542
1543 // type
1544 Oid element_type = ARR_ELEMTYPE(v);
1545 TypeCacheEntry *typentry = lookup_type_cache(element_type,TYPECACHE_CMP_PROC_FINFO);
1546 int type_size = typentry->typlen;
1547 bool typbyval = typentry->typbyval;
1548 char typalign = typentry->typalign;
1549
1550 // iterate
1551 Datum result = Float8GetDatum(init_val);
1552 char *dat = ARR_DATA_PTR(v);
1553 int i = 0;
1554 int null_count = 0;
1555 if(ARR_HASNULL(v)){
1556 bits8 *bitmap = ARR_NULLBITMAP(v);
1557 int bitmask = 1;
1558 for (i = 0; i < nitems; i++) {
1559 /* Get elements, checking for NULL */
1560 if (!(bitmap && (*bitmap & bitmask) == 0)) {
1561 Datum elt = fetch_att(dat, typbyval, type_size);
1562 dat = att_addlength_pointer(dat, type_size, dat);
1563 dat = (char *) att_align_nominal(dat, typalign);
1564
1565 // treating NaN as NULL
1566 if (!isnan(datum_float8_cast(elt,element_type))) {
1567 result = element_function(elt,
1568 element_type,
1569 result,
1570 FLOAT8OID,
1571 exta_val,
1572 FLOAT8OID);
1573 } else {
1574 null_count++;
1575 }
1576 }else{
1577 null_count++;
1578 }
1579
1580 /* advance bitmap pointers if any */
1581 if (bitmap) {
1582 bitmask <<= 1;
1583 if (bitmask == 0x100) {

Callers 8

array_stddevFunction · 0.85
array_meanFunction · 0.85
array_sum_bigFunction · 0.85
array_sumFunction · 0.85
array_abs_sumFunction · 0.85
array_minFunction · 0.85
array_maxFunction · 0.85
array_normalizeFunction · 0.85

Calls 1

datum_float8_castFunction · 0.85

Tested by

no test coverage detected