sum_double.c 1.7 KB
Newer Older
D
dapan1121 已提交
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 46 47 48 49 50 51 52 53 54 55 56 57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct SUdfInit{
 int maybe_null;       /* 1 if function can return NULL */
 int decimals;     /* for real functions */
 long long length;       /* For string functions */
 char  *ptr;            /* free pointer for function data */
 int const_item;       /* 0 if result is independent of arguments */
} SUdfInit;

void sum_double(char* data, char type, int numOfRows, long long* ts, char* dataOutput, char* tsOutput,
                        int* numOfOutput, SUdfInit* buf) {
   int i;
   int r = 0;
   printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, type, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
   if (type == 4) {
     r=*(int *)dataOutput;
     for(i=0;i<numOfRows;++i) {
       r+=*((int *)data + i);
       if (tsOutput) {
         *(long long*)tsOutput=1000000;
       }
     }
     *(int *)dataOutput=r;
     *numOfOutput=1;

     printf("sum_double out, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
   }
}



void sum_double_finalize(char* dataOutput, int* numOfOutput, SUdfInit* buf) {
   int i;
   int r = 0;
   printf("sum_double_finalize dataoutput:%p, numOfOutput:%p, buf:%p\n", dataOutput, numOfOutput, buf);
   *numOfOutput=1;
   *(int*)(buf->ptr)=*(int*)dataOutput*2;
   *(int*)dataOutput=*(int*)(buf->ptr);
   printf("sum_double finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
}

int sum_double_init(SUdfInit* buf) {
   buf->maybe_null=1;
   buf->ptr = malloc(sizeof(int));
   printf("sum_double init\n");
   return 0;
}


void sum_double_destroy(SUdfInit* buf) {
   free(buf->ptr);
   printf("sum_double destroy\n");
}