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

Function General_Array_to_Cumulative_Array

methods/array_ops/src/pg_gp/array_ops.c:2016–2108  ·  view source on GitHub ↗

* @brief Transforms an array to another array using cumulative operations. * * @param v1 Array. * @param initial Parameter. * @param element_function Map function. * @returns Transformed array. */

Source from the content-addressed store, hash-verified

2014 * @returns Transformed array.
2015 */
2016ArrayType*
2017General_Array_to_Cumulative_Array(
2018 ArrayType *v1,
2019 Datum initial,
2020 Datum(*element_function)(Datum,Oid,Datum,Oid,Datum,Oid)) {
2021
2022 // dimensions
2023 int ndims1 = ARR_NDIM(v1);
2024 if (ndims1 == 0) {
2025 elog(WARNING, "input are empty arrays.");
2026 return v1;
2027 }
2028 int ndims = ndims1;
2029 int *lbs1 = ARR_LBOUND(v1);
2030 int *dims1 = ARR_DIMS(v1);
2031 int *dims = (int *) palloc(ndims * sizeof(int));
2032 int *lbs = (int *) palloc(ndims * sizeof(int));
2033 int i = 0;
2034 for (i = 0; i < ndims; i ++) {
2035 dims[i] = dims1[i];
2036 lbs[i] = lbs1[i];
2037 }
2038 int nitems = ArrayGetNItems(ndims, dims);
2039
2040 // nulls
2041 if (ARR_HASNULL(v1)) {
2042 ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2043 errmsg("arrays cannot contain nulls"),
2044 errdetail("Arrays with element value NULL are not allowed.")));
2045 }
2046
2047 // type
2048 Oid element_type = ARR_ELEMTYPE(v1);
2049 TypeCacheEntry *typentry = lookup_type_cache(element_type,TYPECACHE_CMP_PROC_FINFO);
2050 int type_size = typentry->typlen;
2051 bool typbyval = typentry->typbyval;
2052 char typalign = typentry->typalign;
2053
2054 // allocate
2055 Datum *result = NULL;
2056 switch (element_type) {
2057 case INT2OID:
2058 case INT4OID:
2059 case INT8OID:
2060 case FLOAT4OID:
2061 case FLOAT8OID:
2062 case NUMERICOID:
2063 result = (Datum *)palloc(nitems * sizeof(Datum));break;
2064 default:
2065 ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2066 errmsg("type is not supported"),
2067 errdetail("Arrays with element type %s are not supported.",
2068 format_type_be(element_type))));
2069 break;
2070 }
2071
2072 // iterate
2073 Datum *resultp = result;

Callers 2

array_cum_sumFunction · 0.85
array_cum_prodFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected