Github user interma commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1345#discussion_r174721111
  
    --- Diff: contrib/vexecutor/vadt.c ---
    @@ -0,0 +1,388 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +#include "postgres.h"
    +#include "catalog/pg_type.h"
    +#include "utils/builtins.h"
    +#include "vadt.h"
    +
    +/* Get the size of vectorized data */
    +#define FUNCTION_VTYPESIZE(type) \
    +size_t v##type##Size(vheader *vh) \
    +{\
    +   size_t len = offsetof(vheader,isnull);\
    +   return  len + vh->dim * sizeof(bool) + vh->dim * sizeof(type);\
    +}
    +
    +/* Build the vectorized data */
    +#define FUNCTION_BUILD(type, typeoid) \
    +vheader* buildv##type(int n) \
    +{ \
    +   vheader* result; \
    +   result = (vheader*) palloc0(offsetof(v##type,values) + n * 
sizeof(type)); \
    +   result->dim = n; \
    +   result->elemtype = typeoid; \
    +   result->isnull = palloc(sizeof(bool) * n); \
    +   SET_VARSIZE(result,v##type##Size(result)); \
    +   return result; \
    +}
    +
    +/* Destroy the vectorized data */
    +#define FUNCTION_DESTORY(type, typeoid) \
    +void destoryv##type(v##header **header) \
    +{ \
    +   v##type** ptr = (v##type**) header; \
    +   free((*header)->isnull); \
    +   free((*ptr)->values); \
    +   free(*ptr); \
    +   *ptr = NULL; \
    +}
    +
    +/*
    + * Serialize functions and deserialize functions for the abstract data 
types
    + */
    +#define FUNCTION_SERIALIZATION(type,typeoid) \
    +size_t v##type##serialization(vheader* vh,unsigned char *buf) \
    +{ \
    +   size_t len = 0; \
    +   v##type *vt = (v##type *)vh; \
    + \
    +   memcpy(buf + len,vt,offsetof(vheader,isnull)); \
    +   len += offsetof(vheader,isnull); \
    + \
    +   memcpy(buf + len,vh->isnull,sizeof(bool) * vh->dim); \
    +   len += sizeof(bool) * vh->dim; \
    + \
    +   memcpy(buf + len,vt->values,sizeof(type) * vh->dim); \
    +   len += sizeof(type) * vh->dim; \
    + \
    +   return len; \
    +} \
    +\
    +\
    +Datum v##type##deserialization(unsigned char* buf,size_t* len) \
    +{\
    +   vheader* vh = (vheader *) buf;\
    +   *len = 0;\
    +   \
    +   v##type* vt = palloc(sizeof(v##type) + sizeof(type) * vh->dim);\
    +   memcpy(vt,buf,offsetof(vheader,isnull));\
    +   *len += offsetof(vheader,isnull);\
    +   \
    +   vt->header.isnull = palloc(vh->dim * sizeof(bool));\
    +   memcpy(vt->header.isnull, buf + *len,vh->dim * sizeof(bool));\
    +   *len += vh->dim * sizeof(bool);\
    +   \
    +   memcpy(vt->values,buf + *len,vh->dim * sizeof(type)); \
    +   *len += vh->dim * sizeof(type); \
    +   \
    +   return PointerGetDatum(vt); \
    +}
    +
    +/*
    + * IN function for the abstract data types
    + * e.g. Datum vint2in(PG_FUNCTION_ARGS)
    + */
    +#define FUNCTION_IN(type, typeoid, MACRO_DATUM) \
    +PG_FUNCTION_INFO_V1(v##type##in); \
    +Datum \
    +v##type##in(PG_FUNCTION_ARGS) \
    +{ \
    +    char *intString = PG_GETARG_CSTRING(0); \
    +    v##type *res = NULL; \
    +    char tempstr[MAX_VECTOR_SIZE] = {0}; \
    --- End diff --
    
    Use a new DEFINE for the temp string length?


---

Reply via email to