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

Function General_Array_to_Array

methods/array_ops/src/pg_gp/array_ops.c:1915–2005  ·  view source on GitHub ↗

* @brief Transforms an array. * * @param v1 Array. * @param elt2 Parameter. * @param element_function Map function. * @returns Transformed array. */

Source from the content-addressed store, hash-verified

1913 * @returns Transformed array.
1914 */
1915ArrayType*
1916General_Array_to_Array(
1917 ArrayType *v1,
1918 Datum elt2,
1919 Datum(*element_function)(Datum,Oid,Datum,Oid,Datum,Oid)) {
1920
1921 // dimensions
1922 int ndims1 = ARR_NDIM(v1);
1923 if (ndims1 == 0) {
1924 elog(WARNING, "input are empty arrays.");
1925 return v1;
1926 }
1927 int ndims = ndims1;
1928 int *lbs1 = ARR_LBOUND(v1);
1929 int *dims1 = ARR_DIMS(v1);
1930 int *dims = (int *) palloc(ndims * sizeof(int));
1931 int *lbs = (int *) palloc(ndims * sizeof(int));
1932 int i = 0;
1933 for (i = 0; i < ndims; i ++) {
1934 dims[i] = dims1[i];
1935 lbs[i] = lbs1[i];
1936 }
1937 int nitems = ArrayGetNItems(ndims, dims);
1938
1939 // nulls
1940 if (ARR_HASNULL(v1)) {
1941 ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1942 errmsg("arrays cannot contain nulls"),
1943 errdetail("Arrays with element value NULL are not allowed.")));
1944 }
1945
1946 // type
1947 Oid element_type = ARR_ELEMTYPE(v1);
1948 TypeCacheEntry *typentry = lookup_type_cache(element_type,TYPECACHE_CMP_PROC_FINFO);
1949 int type_size = typentry->typlen;
1950 bool typbyval = typentry->typbyval;
1951 char typalign = typentry->typalign;
1952
1953 // allocate
1954 Datum *result = NULL;
1955 switch (element_type) {
1956 case INT2OID:
1957 case INT4OID:
1958 case INT8OID:
1959 case FLOAT4OID:
1960 case FLOAT8OID:
1961 case NUMERICOID:
1962 result = (Datum *)palloc(nitems * sizeof(Datum));break;
1963 default:
1964 ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1965 errmsg("type is not supported"),
1966 errdetail("Arrays with element type %s are not supported.",
1967 format_type_be(element_type))));
1968 break;
1969 }
1970
1971 // iterate
1972 Datum *resultp = result;

Callers 9

array_absFunction · 0.85
array_sqrtFunction · 0.85
array_powFunction · 0.85
array_squareFunction · 0.85
array_fillFunction · 0.85
array_cosFunction · 0.85
array_scalar_multFunction · 0.85
array_scalar_addFunction · 0.85
array_normalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected