-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvec_agg_min.c
45 lines (38 loc) · 1.07 KB
/
vec_agg_min.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Datum vec_agg_min_finalfn(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(vec_agg_min_finalfn);
/**
* Extract an array of mins from a VecAggAccumState.
*/
Datum
vec_agg_min_finalfn(PG_FUNCTION_ARGS)
{
ArrayType *result;
VecAggAccumState *state;
int16 typlen;
bool typbyval;
char typalign;
Datum *dvalues;
bool *dnulls;
int dims[1];
int lbs[1];
int i;
state = PG_ARGISNULL(0) ? NULL : (VecAggAccumState *)PG_GETARG_POINTER(0);
if (state == NULL || state->nelems < 1) {
PG_RETURN_NULL();
}
dvalues = palloc(state->nelems * sizeof(Datum));
dnulls = palloc(state->nelems * sizeof(bool));
get_typlenbyvalalign(state->elementType, &typlen, &typbyval, &typalign);
for (i = 0; i < state->nelems; i++) {
if (state->vec_counts[i]) {
dvalues[i] = datumCopy(state->vec_mins[i], typbyval, typlen);
dnulls[i] = false;
} else {
dnulls[i] = true;
}
}
dims[0] = state->nelems;
lbs[0] = 1;
result = construct_md_array(dvalues, dnulls, 1, dims, lbs, state->elementType, typlen, typbyval, typalign);
PG_RETURN_ARRAYTYPE_P(result);
}