您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ARR_NDIM函数代码示例

51自学网 2021-06-01 19:36:32
  C++
这篇教程C++ ARR_NDIM函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中ARR_NDIM函数的典型用法代码示例。如果您正苦于以下问题:C++ ARR_NDIM函数的具体用法?C++ ARR_NDIM怎么用?C++ ARR_NDIM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ARR_NDIM函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: getWeights

static float *getWeights(ArrayType *win){	static float ws[lengthof(weights)];	int			i;	float4	   *arrdata;	if (win == NULL)		return weights;	if (ARR_NDIM(win) != 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array of weight must be one-dimensional")));	if (ArrayGetNItems(ARR_NDIM(win), ARR_DIMS(win)) < lengthof(weights))		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array of weight is too short")));	if (array_contains_nulls(win))		ereport(ERROR,				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),				 errmsg("array of weight must not contain nulls")));	arrdata = (float4 *) ARR_DATA_PTR(win);	for (i = 0; i < lengthof(weights); i++)	{		ws[i] = (arrdata[i] >= 0) ? arrdata[i] : weights[i];		if (ws[i] > 1.0)			ereport(ERROR,					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),					 errmsg("weight out of range")));	}	return ws;}
开发者ID:avontd2868,项目名称:postgres,代码行数:37,


示例2: _ReadChunkArray1El

/*------------------------------------------------------------------------ * _ReadChunkArray1El -- *       returns one element of the chunked array as specified by the index "st" *       the chunked file descriptor is "fp" *------------------------------------------------------------------------- */struct varlena *_ReadChunkArray1El(int st[],		   int bsize,		   int fp,		   ArrayType *array,		   bool *isNull){    int i, j, n, temp, srcOff;    int chunk_st[MAXDIM];        int  *C, csize, *dim, *lb;    int PCHUNK[MAXDIM], PC[MAXDIM];        CHUNK_INFO *A = (CHUNK_INFO *) ARR_DATA_PTR(array);        n = ARR_NDIM(array);     lb = ARR_LBOUND(array);     C = A->C;    dim = ARR_DIMS(array);        csize = C[n-1];    PC[n-1] = 1;    temp = dim[n - 1]/C[n-1];    for (i = n-2; i >= 0; i--){        PC[i] = PC[i+1] * temp;        temp = dim[i] / C[i];        csize *= C[i];    }        for (i = 0; i < n; st[i] -= lb[i], i++);    mda_get_prod(n, C, PCHUNK);        array2chunk_coord(n, C, st, chunk_st);        for (i = j = 0; i < n; i++)        j+= chunk_st[i]*PC[i];    srcOff = j * csize;        for(i = 0; i < n; i++)        srcOff += (st[i]-chunk_st[i]*C[i])*PCHUNK[i];        srcOff *= bsize;    if (lo_lseek(fp, srcOff, SEEK_SET) < 0)	RETURN_NULL;#ifdef LOARRAY    return (struct varlena *) LOread(fp, bsize);#endif    return (struct varlena *) 0;}
开发者ID:jarulraj,项目名称:postgres95,代码行数:55,


示例3: rank

Datumrank(PG_FUNCTION_ARGS){	ArrayType  *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));	tsvector   *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));	QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));	int			method = DEF_NORM_METHOD;	float		res = 0.0;	float		ws[lengthof(weights)];	float4	   *arrdata;	int			i;	if (ARR_NDIM(win) != 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array of weight must be one-dimensional")));	if (ARRNELEMS(win) < lengthof(weights))		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array of weight is too short")));	if (ARR_HASNULL(win))		ereport(ERROR,				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),				 errmsg("array of weight must not contain nulls")));	arrdata = (float4 *) ARR_DATA_PTR(win);	for (i = 0; i < lengthof(weights); i++)	{		ws[i] = (arrdata[i] >= 0) ? arrdata[i] : weights[i];		if (ws[i] > 1.0)			ereport(ERROR,					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),					 errmsg("weight out of range")));	}	if (PG_NARGS() == 4)		method = PG_GETARG_INT32(3);	res = calc_rank(ws, txt, query, method);	PG_FREE_IF_COPY(win, 0);	PG_FREE_IF_COPY(txt, 1);	PG_FREE_IF_COPY(query, 2);	PG_RETURN_FLOAT4(res);}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:47,


示例4: extract_INT2OID_array

/* * Extract len and pointer to buffer from an int16[] (vector) Datum * representing a PostgreSQL INT2OID type. */static voidextract_INT2OID_array(Datum array_datum, int *lenp, int16 **vecp){	ArrayType  *array_type;	Assert(lenp != NULL);	Assert(vecp != NULL);	array_type = DatumGetArrayTypeP(array_datum);	Assert(ARR_NDIM(array_type) == 1);	Assert(ARR_ELEMTYPE(array_type) == INT2OID);	Assert(ARR_LBOUND(array_type)[0] == 1);	*lenp = ARR_DIMS(array_type)[0];	*vecp = (int16 *) ARR_DATA_PTR(array_type);	return;}
开发者ID:BenjaminYu,项目名称:gpdb,代码行数:21,


示例5: jsonb_set

/* * jsonb_set: * Replace/create value of jsonb key or jsonb element, which can be found by the specified path. * Path must be replesented as an array of key names or indexes. If indexes will be used, * the same rules implied as for jsonb_delete_idx (negative indexing and edge cases) */Datumjsonb_set(PG_FUNCTION_ARGS){	Jsonb 				*in = PG_GETARG_JSONB(0);	ArrayType 			*path = PG_GETARG_ARRAYTYPE_P(1);	Jsonb 				*newval = PG_GETARG_JSONB(2);	bool       			create = PG_GETARG_BOOL(3);	JsonbValue 			*res = NULL;	Datum 				*path_elems;	bool 				*path_nulls;	int					path_len;	JsonbIterator 		*it;	JsonbParseState 	*st = NULL;	if (ARR_NDIM(path) > 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("wrong number of array subscripts")));	if (JB_ROOT_IS_SCALAR(in))		ereport(ERROR,				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("cannot set path in scalar")));	if (JB_ROOT_COUNT(in) == 0 && !create)	{		PG_RETURN_JSONB(in);	}	deconstruct_array(path, TEXTOID, -1, false, 'i',					  &path_elems, &path_nulls, &path_len);	if (path_len == 0)	{		PG_RETURN_JSONB(in);	}	it = JsonbIteratorInit(&in->root);	res = setPath(&it, path_elems, path_nulls, path_len, &st, 0, newval, create);	Assert (res != NULL);	PG_RETURN_JSONB(JsonbValueToJsonb(res));}
开发者ID:dreamsxin,项目名称:jsonbx,代码行数:52,


示例6: new_intArrayType

/* Create a new int array with room for "num" elements */ArrayType *new_intArrayType(int num){	ArrayType  *r;	int			nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;	r = (ArrayType *) palloc0(nbytes);	SET_VARSIZE(r, nbytes);	ARR_NDIM(r) = 1;	r->dataoffset = 0;			/* marker for no null bitmap */	ARR_ELEMTYPE(r) = INT4OID;	ARR_DIMS(r)[0] = num;	ARR_LBOUND(r)[0] = 1;	return r;}
开发者ID:kjkszpj,项目名称:PG-SQL,代码行数:18,


示例7: float8_mregr_get_state

/* * Check that a valid state is passed to the aggregate's final function. * If we return false, the calling function should return NULL. */static boolfloat8_mregr_get_state(FunctionCallInfo fcinfo,					   MRegrState *outState){	ArrayType	*in;	float8		*data;		/* Input should be a single parameter, the aggregate state */	if (PG_NARGS() != 1)		ereport(ERROR, 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("final calculation function /"%s/" called with invalid parameters",					format_procedure(fcinfo->flinfo->fn_oid))));		if (PG_ARGISNULL(0))		return false;		/* Validate array type */	in = PG_GETARG_ARRAYTYPE_P(0);	if (ARR_ELEMTYPE(in) != FLOAT8OID || ARR_NDIM(in) != 1 || ARR_NULLBITMAP(in))		ereport(ERROR, 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("final calculation function /"%s/" called with invalid parameters",					format_procedure(fcinfo->flinfo->fn_oid))));		/* Validate the correct size input */	if (ARR_DIMS(in)[0] < 2)		return false;  /* no input */		data = (float8*) ARR_DATA_PTR(in);	outState->len    = (int) data[0];   /* scalar:           len(X[]) */	if ((uint64) ARR_DIMS(in)[0] != 4ULL + outState->len + outState->len * outState->len) 		ereport(ERROR, 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("final calculation function /"%s/" called with invalid parameters",					format_procedure(fcinfo->flinfo->fn_oid))));		outState->count  = data[1];         /* scalar:           count(*) */	outState->sumy   = data[2];         /* scalar:           sum(y)   */	outState->sumy2  = data[3];         /* scalar:           sum(y*y) */	outState->Xty    = &data[4];        /* vector:           X^t * y  */	outState->XtX    = &data[4 + outState->len]; /* matrix:  X^t * X  */	return true;}
开发者ID:BenjaminYu,项目名称:gpdb,代码行数:49,


示例8: int2vectorrecv

/* *		int2vectorrecv			- converts external binary format to int2_vector_s */datum_t int2vectorrecv(PG_FUNC_ARGS){	struct string* buf = (struct string*) ARG_POINTER(0);	struct fc_info locfcinfo;	int2_vector_s *result;	/*	 * Normally one would call array_recv() using DIRECT_FC3, but	 * that does not work since array_recv wants to cache some data using	 * fcinfo->flinfo->fn_extra.  So we need to pass it our own flinfo	 * parameter.	 */	INIT_FC_INFO(locfcinfo, fcinfo->flinfo, 3, INVALID_OID, NULL, NULL);	locfcinfo.arg[0] = PTR_TO_D(buf);	locfcinfo.arg[1] = OID_TO_D(INT2OID);	locfcinfo.arg[2] = INT32_TO_D(-1);	locfcinfo.argnull[0] = false;	locfcinfo.argnull[1] = false;	locfcinfo.argnull[2] = false;	result = (int2_vector_s *) D_TO_PTR(array_recv(&locfcinfo));	ASSERT(!locfcinfo.isnull);	/* sanity checks: int2_vector_s must be 1-D, 0-based, no nulls */	if (ARR_NDIM(result) != 1		|| ARR_HASNULL(result)		|| ARR_ELEMTYPE(result) != INT2OID		|| ARR_LBOUND(result)[0] != 0) {		ereport(ERROR, (		errcode(E_INVALID_BINARY_REPRESENTATION),		errmsg("invalid int2_vector_s data")));	}	/* check length for consistency with int2vectorin() */	if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS) {		ereport(ERROR, (		errcode(E_INVALID_PARAMETER_VALUE),		errmsg("oidvector has too many elements")));	}	RET_POINTER(result);}
开发者ID:colinet,项目名称:sqlix,代码行数:48,


示例9: array_to_jsonb_internal

/* * Turn an array into JSON. */static voidarray_to_jsonb_internal(Datum array, JsonbInState *result){	ArrayType  *v = DatumGetArrayTypeP(array);	Oid			element_type = ARR_ELEMTYPE(v);	int		   *dim;	int			ndim;	int			nitems;	int			count = 0;	Datum	   *elements;	bool	   *nulls;	int16		typlen;	bool		typbyval;	char		typalign;	JsonbTypeCategory tcategory;	Oid			outfuncoid;	ndim = ARR_NDIM(v);	dim = ARR_DIMS(v);	nitems = ArrayGetNItems(ndim, dim);	if (nitems <= 0)	{		result->res = pushJsonbValue(&result->parseState, WJB_BEGIN_ARRAY, NULL);		result->res = pushJsonbValue(&result->parseState, WJB_END_ARRAY, NULL);		return;	}	get_typlenbyvalalign(element_type,						 &typlen, &typbyval, &typalign);	jsonb_categorize_type(element_type,						  &tcategory, &outfuncoid);	deconstruct_array(v, element_type, typlen, typbyval,					  typalign, &elements, &nulls,					  &nitems);	array_dim_to_jsonb(result, 0, ndim, dim, elements, nulls, &count, tcategory,					   outfuncoid);	pfree(elements);	pfree(nulls);}
开发者ID:DataSystemsLab,项目名称:hippo-postgresql,代码行数:47,


示例10: int2vectorrecv

/* *		int2vectorrecv			- converts external binary format to int2vector */Datumint2vectorrecv(PG_FUNCTION_ARGS){	StringInfo	buf = (StringInfo) PG_GETARG_POINTER(0);	FunctionCallInfoData locfcinfo;	int2vector *result;	/*	 * Normally one would call array_recv() using DirectFunctionCall3, but	 * that does not work since array_recv wants to cache some data using	 * fcinfo->flinfo->fn_extra.  So we need to pass it our own flinfo	 * parameter.	 */	InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3,							 InvalidOid, NULL, NULL);	locfcinfo.arg[0] = PointerGetDatum(buf);	locfcinfo.arg[1] = ObjectIdGetDatum(INT2OID);	locfcinfo.arg[2] = Int32GetDatum(-1);	locfcinfo.argnull[0] = false;	locfcinfo.argnull[1] = false;	locfcinfo.argnull[2] = false;	result = (int2vector *) DatumGetPointer(array_recv(&locfcinfo));	Assert(!locfcinfo.isnull);	/* sanity checks: int2vector must be 1-D, 0-based, no nulls */	if (ARR_NDIM(result) != 1 ||		ARR_HASNULL(result) ||		ARR_ELEMTYPE(result) != INT2OID ||		ARR_LBOUND(result)[0] != 0)		ereport(ERROR,				(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),				 errmsg("invalid int2vector data")));	/* check length for consistency with int2vectorin() */	if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)		ereport(ERROR,				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("oidvector has too many elements")));	PG_RETURN_POINTER(result);}
开发者ID:CadillacBupt,项目名称:recdb-postgresql,代码行数:47,


示例11: hash_array

Datum hash_array( PG_FUNCTION_ARGS){	ArrayType *state  = PG_GETARG_ARRAYTYPE_P(0);	int dimstate = ARR_NDIM(state);    int *dimsstate = ARR_DIMS(state);	int numstate = ArrayGetNItems(dimstate,dimsstate);    int32 *vals_state=(int32 *)ARR_DATA_PTR(state);	    unsigned long hash = 65599;    unsigned short c;    int i = 0;        for (;i<numstate;i++)	{		c = vals_state[i];		hash = c + (hash << 7) + (hash << 16) - hash;	}	PG_RETURN_INT32(hash);}
开发者ID:abhigp,项目名称:madlib,代码行数:20,


示例12: resize_intArrayType

ArrayType *resize_intArrayType(ArrayType *a, int num){	int			nbytes = ARR_DATA_OFFSET(a) + sizeof(int) * num;	int			i;	if (num == ARRNELEMS(a))		return a;	a = (ArrayType *) repalloc(a, nbytes);	SET_VARSIZE(a, nbytes);	/* usually the array should be 1-D already, but just in case ... */	for (i = 0; i < ARR_NDIM(a); i++)	{		ARR_DIMS(a)[i] = num;		num = 1;	}	return a;}
开发者ID:kjkszpj,项目名称:PG-SQL,代码行数:20,


示例13: internal_kmeans_canopy_transition

Datuminternal_kmeans_canopy_transition(PG_FUNCTION_ARGS) {    ArrayType      *canopies_arr;    Datum          *canopies;    int             num_canopies;    SvecType       *point;    PGFunction      metric_fn;    float8          threshold;    MemoryContext   mem_context_for_function_calls;        canopies_arr = PG_GETARG_ARRAYTYPE_P(verify_arg_nonnull(fcinfo, 0));    get_svec_array_elms(canopies_arr, &canopies, &num_canopies);    point = PG_GETARG_SVECTYPE_P(verify_arg_nonnull(fcinfo, 1));    metric_fn = get_metric_fn(PG_GETARG_INT32(verify_arg_nonnull(fcinfo, 2)));    threshold = PG_GETARG_FLOAT8(verify_arg_nonnull(fcinfo, 3));        mem_context_for_function_calls = setup_mem_context_for_functional_calls();    for (int i = 0; i < num_canopies; i++) {        if (compute_metric(metric_fn, mem_context_for_function_calls,            PointerGetDatum(point), canopies[i]) < threshold)            PG_RETURN_ARRAYTYPE_P(canopies_arr);    }    MemoryContextDelete(mem_context_for_function_calls);        int idx = (ARR_NDIM(canopies_arr) == 0)        ? 1        : ARR_LBOUND(canopies_arr)[0] + ARR_DIMS(canopies_arr)[0];    return PointerGetDatum(        array_set(            canopies_arr, /* array: the initial array object (mustn't be NULL) */            1, /* nSubscripts: number of subscripts supplied */            &idx, /* indx[]: the subscript values */            PointerGetDatum(point), /* dataValue: the datum to be inserted at the given position */            false, /* isNull: whether dataValue is NULL */            -1, /* arraytyplen: pg_type.typlen for the array type */            -1, /* elmlen: pg_type.typlen for the array's element type */            false, /* elmbyval: pg_type.typbyval for the array's element type */            'd') /* elmalign: pg_type.typalign for the array's element type */        );}
开发者ID:0x0all,项目名称:madlib,代码行数:41,


示例14: plr_array_push

Datumplr_array_push(PG_FUNCTION_ARGS){	ArrayType  *v;	Datum		newelem;	int		   *dimv,			   *lb, ub;	ArrayType  *result;	int			indx;	Oid			element_type;	int16		typlen;	bool		typbyval;	char		typalign;	v = PG_GETARG_ARRAYTYPE_P(0);	newelem = PG_GETARG_DATUM(1);	/* Sanity check: do we have a one-dimensional array */	if (ARR_NDIM(v) != 1)		ereport(ERROR,				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),				 errmsg("input must be one-dimensional array")));	lb = ARR_LBOUND(v);	dimv = ARR_DIMS(v);	ub = dimv[0] + lb[0] - 1;	indx = ub + 1;	element_type = ARR_ELEMTYPE(v);	/* Sanity check: do we have a non-zero element type */	if (element_type == 0)		/* internal error */		elog(ERROR, "invalid array element type");	get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign);	result = array_set(v, 1, &indx, newelem, FALSE, -1,						typlen, typbyval, typalign);	PG_RETURN_ARRAYTYPE_P(result);}
开发者ID:bhavinkamani,项目名称:plr,代码行数:41,


示例15: get_func_trftypes

/* * get_func_trftypes * * Returns a number of transformated types used by function. */intget_func_trftypes(HeapTuple procTup,				  Oid **p_trftypes){	Datum		protrftypes;	ArrayType  *arr;	int			nelems;	bool			isNull;	protrftypes = SysCacheGetAttr(PROCOID, procTup,									 Anum_pg_proc_protrftypes,									 &isNull);	if (!isNull)	{		/*		 * We expect the arrays to be 1-D arrays of the right types; verify		 * that.  For the OID and char arrays, we don't need to use		 * deconstruct_array() since the array data is just going to look like		 * a C array of values.		 */		arr = DatumGetArrayTypeP(protrftypes);		/* ensure not toasted */		nelems = ARR_DIMS(arr)[0];		if (ARR_NDIM(arr) != 1 ||			nelems < 0 ||			ARR_HASNULL(arr) ||			ARR_ELEMTYPE(arr) != OIDOID)			elog(ERROR, "protrftypes is not a 1-D Oid array");		Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs);		*p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));		memcpy(*p_trftypes, ARR_DATA_PTR(arr),			   nelems * sizeof(Oid));		return nelems;	}	else		return 0;}
开发者ID:EccentricLoggers,项目名称:peloton,代码行数:43,


示例16: ginarrayconsistent

Datumginarrayconsistent(PG_FUNCTION_ARGS){	bool	   *check = (bool *) PG_GETARG_POINTER(0);	StrategyNumber strategy = PG_GETARG_UINT16(1);	ArrayType  *query = PG_GETARG_ARRAYTYPE_P(2);	int			res,				i,				nentries;	/* ARRAYCHECK was already done by previous ginarrayextract call */	switch (strategy)	{		case GinOverlapStrategy:		case GinContainedStrategy:			/* at least one element in check[] is true, so result = true */			res = TRUE;			break;		case GinContainsStrategy:		case GinEqualStrategy:			nentries = ArrayGetNItems(ARR_NDIM(query), ARR_DIMS(query));			res = TRUE;			for (i = 0; i < nentries; i++)				if (!check[i])				{					res = FALSE;					break;				}			break;		default:			elog(ERROR, "ginarrayconsistent: unknown strategy number: %d",				 strategy);			res = FALSE;	}	PG_RETURN_BOOL(res);}
开发者ID:AnLingm,项目名称:gpdb,代码行数:38,


示例17: ArrayGetIntegerTypmods

/* * ArrayGetIntegerTypmods: verify that argument is a 1-D cstring array, * and get the contents converted to integers.	Returns a palloc'd array * and places the length at *n. */int32 *ArrayGetIntegerTypmods(ArrayType *arr, int *n){	int32	   *result;	Datum	   *elem_values;	int			i;	if (ARR_ELEMTYPE(arr) != CSTRINGOID)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),				 errmsg("typmod array must be type cstring[]")));	if (ARR_NDIM(arr) != 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("typmod array must be one-dimensional")));	if (ARR_HASNULL(arr))		ereport(ERROR,				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),				 errmsg("typmod array must not contain nulls")));	/* hardwired knowledge about cstring's representation details here */	deconstruct_array(arr, CSTRINGOID,					  -2, false, 'c',					  &elem_values, NULL, n);	result = (int32 *) palloc(*n * sizeof(int32));	for (i = 0; i < *n; i++)		result[i] = pg_atoi(DatumGetCString(elem_values[i]),							sizeof(int32), '/0');	pfree(elem_values);	return result;}
开发者ID:AnLingm,项目名称:gpdb,代码行数:42,


示例18: aggr_InfoGain

Datum aggr_InfoGain(PG_FUNCTION_ARGS) {	ArrayType *state  = PG_GETARG_ARRAYTYPE_P(0);	int dimstate = ARR_NDIM(state);    int *dimsstate = ARR_DIMS(state);	int numstate = ArrayGetNItems(dimstate,dimsstate);    float8 *vals_state=(float8 *)ARR_DATA_PTR(state);    	float8 truevalue = PG_GETARG_FLOAT8(1);	float8 trueweight = PG_GETARG_FLOAT8(2);	int32 posclasses = PG_GETARG_INT32(3);	int32 trueclass = PG_GETARG_INT32(5);   	ArrayType *pgarray;	vals_state[0] += trueweight;	vals_state[trueclass] += trueweight;		vals_state[(int)(truevalue*(posclasses+1))] += trueweight;	vals_state[(int)(truevalue*(posclasses+1) + trueclass)] += trueweight;      pgarray = construct_array((Datum *)vals_state,		numstate,FLOAT8OID,		sizeof(float8),true,'d');    PG_RETURN_ARRAYTYPE_P(pgarray);}
开发者ID:abhigp,项目名称:madlib,代码行数:24,


示例19: array_push

/*----------------------------------------------------------------------------- * array_push : *		push an element onto either end of a one-dimensional array *---------------------------------------------------------------------------- */Datumarray_push(PG_FUNCTION_ARGS){	ArrayType  *v;	Datum		newelem;	bool		isNull;	int		   *dimv,			   *lb;	ArrayType  *result;	int			indx;	Oid			element_type;	int16		typlen;	bool		typbyval;	char		typalign;	Oid			arg0_typeid = get_fn_expr_argtype(fcinfo->flinfo, 0);	Oid			arg1_typeid = get_fn_expr_argtype(fcinfo->flinfo, 1);	Oid			arg0_elemid;	Oid			arg1_elemid;	ArrayMetaState *my_extra;	if (arg0_typeid == InvalidOid || arg1_typeid == InvalidOid)		ereport(ERROR,				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("could not determine input data types")));	arg0_elemid = get_element_type(arg0_typeid);	arg1_elemid = get_element_type(arg1_typeid);	if (arg0_elemid != InvalidOid)	{		if (PG_ARGISNULL(0))			v = construct_empty_array(arg0_elemid);		else			v = PG_GETARG_ARRAYTYPE_P(0);		isNull = PG_ARGISNULL(1);		if (isNull)			newelem = (Datum) 0;		else			newelem = PG_GETARG_DATUM(1);	}	else if (arg1_elemid != InvalidOid)	{		if (PG_ARGISNULL(1))			v = construct_empty_array(arg1_elemid);		else			v = PG_GETARG_ARRAYTYPE_P(1);		isNull = PG_ARGISNULL(0);		if (isNull)			newelem = (Datum) 0;		else			newelem = PG_GETARG_DATUM(0);	}	else	{		/* Shouldn't get here given proper type checking in parser */		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("neither input type is an array")));		PG_RETURN_NULL();		/* keep compiler quiet */	}	element_type = ARR_ELEMTYPE(v);	if (ARR_NDIM(v) == 1)	{		lb = ARR_LBOUND(v);		dimv = ARR_DIMS(v);		if (arg0_elemid != InvalidOid)		{			/* append newelem */			int			ub = dimv[0] + lb[0] - 1;			indx = ub + 1;			/* overflow? */			if (indx < ub)				ereport(ERROR,						(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),						 errmsg("integer out of range")));		}		else		{			/* prepend newelem */			indx = lb[0] - 1;			/* overflow? */			if (indx > lb[0])				ereport(ERROR,						(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),						 errmsg("integer out of range")));		}	}	else if (ARR_NDIM(v) == 0)		indx = 1;	else		ereport(ERROR,//.........这里部分代码省略.........
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:101,


示例20: array_cat

/*----------------------------------------------------------------------------- * array_cat : *		concatenate two nD arrays to form an nD array, or *		push an (n-1)D array onto the end of an nD array *---------------------------------------------------------------------------- */Datumarray_cat(PG_FUNCTION_ARGS){	ArrayType  *v1,			   *v2;	ArrayType  *result;	int		   *dims,			   *lbs,				ndims,				nitems,				ndatabytes,				nbytes;	int		   *dims1,			   *lbs1,				ndims1,				nitems1,				ndatabytes1;	int		   *dims2,			   *lbs2,				ndims2,				nitems2,				ndatabytes2;	int			i;	char	   *dat1,			   *dat2;	bits8	   *bitmap1,			   *bitmap2;	Oid			element_type;	Oid			element_type1;	Oid			element_type2;	int32		dataoffset;	/* Concatenating a null array is a no-op, just return the other input */	if (PG_ARGISNULL(0))	{		if (PG_ARGISNULL(1))			PG_RETURN_NULL();		result = PG_GETARG_ARRAYTYPE_P(1);		PG_RETURN_ARRAYTYPE_P(result);	}	if (PG_ARGISNULL(1))	{		result = PG_GETARG_ARRAYTYPE_P(0);		PG_RETURN_ARRAYTYPE_P(result);	}	v1 = PG_GETARG_ARRAYTYPE_P(0);	v2 = PG_GETARG_ARRAYTYPE_P(1);	element_type1 = ARR_ELEMTYPE(v1);	element_type2 = ARR_ELEMTYPE(v2);	/* Check we have matching element types */	if (element_type1 != element_type2)		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("cannot concatenate incompatible arrays"),				 errdetail("Arrays with element types %s and %s are not "						   "compatible for concatenation.",						   format_type_be(element_type1),						   format_type_be(element_type2))));	/* OK, use it */	element_type = element_type1;	/*----------	 * We must have one of the following combinations of inputs:	 * 1) one empty array, and one non-empty array	 * 2) both arrays empty	 * 3) two arrays with ndims1 == ndims2	 * 4) ndims1 == ndims2 - 1	 * 5) ndims1 == ndims2 + 1	 *----------	 */	ndims1 = ARR_NDIM(v1);	ndims2 = ARR_NDIM(v2);	/*	 * short circuit - if one input array is empty, and the other is not, we	 * return the non-empty one as the result	 *	 * if both are empty, return the first one	 */	if (ndims1 == 0 && ndims2 > 0)		PG_RETURN_ARRAYTYPE_P(v2);	if (ndims2 == 0)		PG_RETURN_ARRAYTYPE_P(v1);	/* the rest fall under rule 3, 4, or 5 */	if (ndims1 != ndims2 &&		ndims1 != ndims2 - 1 &&		ndims1 != ndims2 + 1)		ereport(ERROR,//.........这里部分代码省略.........
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:101,


示例21: hstore_from_array

Datumhstore_from_array(PG_FUNCTION_ARGS){	ArrayType  *in_array = PG_GETARG_ARRAYTYPE_P(0);	int			ndims = ARR_NDIM(in_array);	int			count;	int4		buflen;	HStore	   *out;	Pairs	   *pairs;	Datum	   *in_datums;	bool	   *in_nulls;	int			in_count;	int			i;	Assert(ARR_ELEMTYPE(in_array) == TEXTOID);	switch (ndims)	{		case 0:			out = hstorePairs(NULL, 0, 0);			PG_RETURN_POINTER(out);		case 1:			if ((ARR_DIMS(in_array)[0]) % 2)				ereport(ERROR,						(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),						 errmsg("array must have even number of elements")));			break;		case 2:			if ((ARR_DIMS(in_array)[1]) != 2)				ereport(ERROR,						(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),						 errmsg("array must have two columns")));			break;		default:			ereport(ERROR,					(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),					 errmsg("wrong number of array subscripts")));	}	deconstruct_array(in_array,					  TEXTOID, -1, false, 'i',					  &in_datums, &in_nulls, &in_count);	count = in_count / 2;	pairs = palloc(count * sizeof(Pairs));	for (i = 0; i < count; ++i)	{		if (in_nulls[i * 2])			ereport(ERROR,					(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),					 errmsg("null value not allowed for hstore key")));		if (in_nulls[i * 2 + 1])		{			pairs[i].key = VARDATA_ANY(in_datums[i * 2]);			pairs[i].val = NULL;			pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));			pairs[i].vallen = 4;			pairs[i].isnull = true;			pairs[i].needfree = false;		}		else		{			pairs[i].key = VARDATA_ANY(in_datums[i * 2]);			pairs[i].val = VARDATA_ANY(in_datums[i * 2 + 1]);			pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));			pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i * 2 + 1]));			pairs[i].isnull = false;			pairs[i].needfree = false;		}	}	count = hstoreUniquePairs(pairs, count, &buflen);	out = hstorePairs(pairs, count, buflen);	PG_RETURN_POINTER(out);}
开发者ID:d,项目名称:gpdb,代码行数:83,


示例22: hstore_from_arrays

Datumhstore_from_arrays(PG_FUNCTION_ARGS){	int4		buflen;	HStore	   *out;	Pairs	   *pairs;	Datum	   *key_datums;	bool	   *key_nulls;	int			key_count;	Datum	   *value_datums;	bool	   *value_nulls;	int			value_count;	ArrayType  *key_array;	ArrayType  *value_array;	int			i;	if (PG_ARGISNULL(0))		PG_RETURN_NULL();	key_array = PG_GETARG_ARRAYTYPE_P(0);	Assert(ARR_ELEMTYPE(key_array) == TEXTOID);	/*	 * must check >1 rather than != 1 because empty arrays have 0 dimensions,	 * not 1	 */	if (ARR_NDIM(key_array) > 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("wrong number of array subscripts")));	deconstruct_array(key_array,					  TEXTOID, -1, false, 'i',					  &key_datums, &key_nulls, &key_count);	/* value_array might be NULL */	if (PG_ARGISNULL(1))	{		value_array = NULL;		value_count = key_count;		value_datums = NULL;		value_nulls = NULL;	}	else	{		value_array = PG_GETARG_ARRAYTYPE_P(1);		Assert(ARR_ELEMTYPE(value_array) == TEXTOID);		if (ARR_NDIM(value_array) > 1)			ereport(ERROR,					(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),					 errmsg("wrong number of array subscripts")));		if ((ARR_NDIM(key_array) > 0 || ARR_NDIM(value_array) > 0) &&			(ARR_NDIM(key_array) != ARR_NDIM(value_array) ||			 ARR_DIMS(key_array)[0] != ARR_DIMS(value_array)[0] ||			 ARR_LBOUND(key_array)[0] != ARR_LBOUND(value_array)[0]))			ereport(ERROR,					(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),					 errmsg("arrays must have same bounds")));		deconstruct_array(value_array,						  TEXTOID, -1, false, 'i',						  &value_datums, &value_nulls, &value_count);		Assert(key_count == value_count);	}	pairs = palloc(key_count * sizeof(Pairs));	for (i = 0; i < key_count; ++i)	{		if (key_nulls[i])			ereport(ERROR,					(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),					 errmsg("null value not allowed for hstore key")));		if (!value_nulls || value_nulls[i])		{			pairs[i].key = VARDATA_ANY(key_datums[i]);			pairs[i].val = NULL;			pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(key_datums[i]));			pairs[i].vallen = 4;			pairs[i].isnull = true;			pairs[i].needfree = false;		}		else		{			pairs[i].key = VARDATA_ANY(key_datums[i]);			pairs[i].val = VARDATA_ANY(value_datums[i]);			pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(key_datums[i]));			pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(value_datums[i]));			pairs[i].isnull = false;			pairs[i].needfree = false;		}	}//.........这里部分代码省略.........
开发者ID:d,项目名称:gpdb,代码行数:101,


示例23: rewrite_accum

Datumrewrite_accum(PG_FUNCTION_ARGS){	QUERYTYPE  *acc = (QUERYTYPE *) PG_GETARG_POINTER(0);	ArrayType  *qa = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1)));	QUERYTYPE  *q;	QTNode	   *qex,			   *subs = NULL,			   *acctree;	bool		isfind = false;	Datum	   *elemsp;	int			nelemsp;	AggregateContext = ((AggState *) fcinfo->context)->aggcontext;	if (acc == NULL || PG_ARGISNULL(0))	{		acc = (QUERYTYPE *) MEMALLOC(AggMemory, sizeof(QUERYTYPE));		acc->len = HDRSIZEQT;		acc->size = 0;	}	if (qa == NULL || PG_ARGISNULL(1))	{		PG_FREE_IF_COPY(qa, 1);		PG_RETURN_POINTER(acc);	}	if (ARR_NDIM(qa) != 1)		elog(ERROR, "array must be one-dimensional, not %d dimension", ARR_NDIM(qa));	if (ArrayGetNItems(ARR_NDIM(qa), ARR_DIMS(qa)) != 3)		elog(ERROR, "array should have only three elements");	if (tsqOid == InvalidOid)	{		SPI_connect();		get_tsq_Oid();		SPI_finish();	}	if (ARR_ELEMTYPE(qa) != tsqOid)		elog(ERROR, "array should contain tsquery type");	deconstruct_array(qa, tsqOid, -1, false, 'i', &elemsp, NULL, &nelemsp);	q = (QUERYTYPE *) DatumGetPointer(elemsp[0]);	if (q->size == 0)	{		pfree(elemsp);		PG_RETURN_POINTER(acc);	}	if (!acc->size)	{		if (acc->len > HDRSIZEQT)		{			pfree(elemsp);			PG_RETURN_POINTER(acc);		}		else			acctree = QT2QTN(GETQUERY(q), GETOPERAND(q));	}	else		acctree = QT2QTN(GETQUERY(acc), GETOPERAND(acc));	QTNTernary(acctree);	QTNSort(acctree);	q = (QUERYTYPE *) DatumGetPointer(elemsp[1]);	if (q->size == 0)	{		pfree(elemsp);		PG_RETURN_POINTER(acc);	}	qex = QT2QTN(GETQUERY(q), GETOPERAND(q));	QTNTernary(qex);	QTNSort(qex);	q = (QUERYTYPE *) DatumGetPointer(elemsp[2]);	if (q->size)		subs = QT2QTN(GETQUERY(q), GETOPERAND(q));	acctree = findsubquery(acctree, qex, PlainMemory, subs, &isfind);	if (isfind || !acc->size)	{		/* pfree( acc ); do not pfree(p), because nodeAgg.c will */		if (acctree)		{			QTNBinary(acctree);			acc = QTN2QT(acctree, AggMemory);		}		else		{			acc = (QUERYTYPE *) MEMALLOC(AggMemory, HDRSIZEQT * 2);			acc->len = HDRSIZEQT * 2;			acc->size = 0;		}	}//.........这里部分代码省略.........
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:101,


示例24: check_functional_grouping

/* * Determine whether a relation can be proven functionally dependent on * a set of grouping columns.  If so, return TRUE and add the pg_constraint * OIDs of the constraints needed for the proof to the *constraintDeps list. * * grouping_columns is a list of grouping expressions, in which columns of * the rel of interest are Vars with the indicated varno/varlevelsup. * * Currently we only check to see if the rel has a primary key that is a * subset of the grouping_columns.  We could also use plain unique constraints * if all their columns are known not null, but there's a problem: we need * to be able to represent the not-null-ness as part of the constraints added * to *constraintDeps.  FIXME whenever not-null constraints get represented * in pg_constraint. */boolcheck_functional_grouping(Oid relid,						  Index varno, Index varlevelsup,						  List *grouping_columns,						  List **constraintDeps){	bool		result = false;	Relation	pg_constraint;	HeapTuple	tuple;	SysScanDesc scan;	ScanKeyData skey[1];	/* Scan pg_constraint for constraints of the target rel */	pg_constraint = heap_open(ConstraintRelationId, AccessShareLock);	ScanKeyInit(&skey[0],				Anum_pg_constraint_conrelid,				BTEqualStrategyNumber, F_OIDEQ,				ObjectIdGetDatum(relid));	scan = systable_beginscan(pg_constraint, ConstraintRelidIndexId, true,							  NULL, 1, skey);	while (HeapTupleIsValid(tuple = systable_getnext(scan)))	{		Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple);		Datum		adatum;		bool		isNull;		ArrayType  *arr;		int16	   *attnums;		int			numkeys;		int			i;		bool		found_col;		/* Only PK constraints are of interest for now, see comment above */		if (con->contype != CONSTRAINT_PRIMARY)			continue;		/* Constraint must be non-deferrable */		if (con->condeferrable)			continue;		/* Extract the conkey array, ie, attnums of PK's columns */		adatum = heap_getattr(tuple, Anum_pg_constraint_conkey,							  RelationGetDescr(pg_constraint), &isNull);		if (isNull)			elog(ERROR, "null conkey for constraint %u",				 HeapTupleGetOid(tuple));		arr = DatumGetArrayTypeP(adatum);		/* ensure not toasted */		numkeys = ARR_DIMS(arr)[0];		if (ARR_NDIM(arr) != 1 ||			numkeys < 0 ||			ARR_HASNULL(arr) ||			ARR_ELEMTYPE(arr) != INT2OID)			elog(ERROR, "conkey is not a 1-D smallint array");		attnums = (int16 *) ARR_DATA_PTR(arr);		found_col = false;		for (i = 0; i < numkeys; i++)		{			AttrNumber	attnum = attnums[i];			ListCell   *gl;			found_col = false;			foreach(gl, grouping_columns)			{				Var		   *gvar = (Var *) lfirst(gl);				if (IsA(gvar, Var) &&					gvar->varno == varno &&					gvar->varlevelsup == varlevelsup &&					gvar->varattno == attnum)				{					found_col = true;					break;				}			}			if (!found_col)				break;		}		if (found_col)		{			/* The PK is a subset of grouping_columns, so we win */			*constraintDeps = lappend_oid(*constraintDeps,										  HeapTupleGetOid(tuple));//.........这里部分代码省略.........
开发者ID:PJMODOS,项目名称:postgres,代码行数:101,


示例25: array_to_hist

/** * Returns a histogram from an array of numbers. * by Paul A. Jungwirth */Datumarray_to_hist(PG_FUNCTION_ARGS){  // Our arguments:  ArrayType *vals;  pgnum bucketsStart;  pgnum bucketsSize;  int32 bucketsCount;  // The array element type:  Oid valsType;  // The array element type widths for our input and output arrays:  int16 valsTypeWidth;  int16 histTypeWidth;  // The array element type "is passed by value" flags (not really used):  bool valsTypeByValue;  bool histTypeByValue;  // The array element type alignment codes (not really used):  char valsTypeAlignmentCode;  char histTypeAlignmentCode;  // The array contents, as PostgreSQL "Datum" objects:  Datum *valsContent;  Datum *histContent;  // List of "is null" flags for the array contents (not used):  bool *valsNullFlags;  // The size of the input array:  int valsLength;  // The output array:  ArrayType* histArray;  pgnum histMax;  pgnum v;  int i;  if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3)) {    ereport(ERROR, (errmsg("Null arguments not accepted")));  }  vals = PG_GETARG_ARRAYTYPE_P(0);  if (ARR_NDIM(vals) > 1) {    ereport(ERROR, (errmsg("One-dimesional arrays are required")));  }  if (array_contains_nulls(vals)) {    ereport(ERROR, (errmsg("Array contains null elements")));  }  // Determine the array element types.  valsType = ARR_ELEMTYPE(vals);  if (valsType != INT2OID &&      valsType != INT4OID &&      valsType != INT8OID &&      valsType != FLOAT4OID &&      valsType != FLOAT8OID) {    ereport(ERROR, (errmsg("Histogram subject must be SMALLINT, INTEGER, BIGINT, REAL, or DOUBLE PRECISION values")));  }  valsLength = (ARR_DIMS(vals))[0];  switch (valsType) {    case INT2OID:      bucketsStart.i16 = PG_GETARG_INT16(1);      bucketsSize.i16 = PG_GETARG_INT16(2);      break;    case INT4OID:      bucketsStart.i32 = PG_GETARG_INT32(1);      bucketsSize.i32 = PG_GETARG_INT32(2);      break;    case INT8OID:      bucketsStart.i64 = PG_GETARG_INT64(1);      bucketsSize.i64 = PG_GETARG_INT64(2);      break;    case FLOAT4OID:      bucketsStart.f4 = PG_GETARG_FLOAT4(1);      bucketsSize.f4 = PG_GETARG_FLOAT4(2);      break;    case FLOAT8OID:      bucketsStart.f8 = PG_GETARG_FLOAT8(1);      bucketsSize.f8 = PG_GETARG_FLOAT8(2);      break;    default:      break;  }  bucketsCount = PG_GETARG_INT32(3);  get_typlenbyvalalign(valsType, &valsTypeWidth, &valsTypeByValue, &valsTypeAlignmentCode);//.........这里部分代码省略.........
开发者ID:johnsonc,项目名称:aggs_for_arrays,代码行数:101,


示例26: xmlelement

Datumxmlelement(PG_FUNCTION_ARGS){	Datum		nameText;	ArrayType  *attrs = NULL;	char	   *elName;	unsigned int nameLen,				resSizeMax;	unsigned int childSize = 0;	char	   *c,			   *result,			   *resData,			   *resCursor,			   *nameDst;	XMLCompNodeHdr element;	XMLNodeOffset *rootOffPtr;	bool		nameFirstChar = true;	char	  **attrNames = NULL;	char	  **attrValues = NULL;	char	   *attrValFlags = NULL;	XMLNodeHdr *attrNodes = NULL;	XMLNodeHdr	child = NULL;	char	  **newNds = NULL;	char	   *newNd = NULL;	unsigned int attrCount = 0;	unsigned int attrsSizeTotal = 0;	unsigned short childCount = 0;	if (PG_ARGISNULL(0))	{		elog(ERROR, "invalid element name");	}	nameText = PG_GETARG_DATUM(0);	elName = TextDatumGetCString(nameText);	nameLen = strlen(elName);	if (nameLen == 0)	{		elog(ERROR, "invalid element name");	}	if (!PG_ARGISNULL(1))	{		int		   *dims;		Oid			elType,					arrType;		int16		arrLen,					elLen;		bool		elByVal,					elIsNull;		char		elAlign;		unsigned int i;		attrs = PG_GETARG_ARRAYTYPE_P(1);		if (ARR_NDIM(attrs) != 2)		{			elog(ERROR, "attributes must be passed in 2 dimensional array");		}		dims = ARR_DIMS(attrs);		if (dims[1] != 2)		{			elog(ERROR, "the second dimension of attribute array must be 2");		}		attrCount = dims[0];		Assert(attrCount > 0);		elType = attrs->elemtype;		arrType = get_array_type(elType);		arrLen = get_typlen(arrType);		Assert(arrType != InvalidOid);		get_typlenbyvalalign(elType, &elLen, &elByVal, &elAlign);		attrNames = (char **) palloc(attrCount * sizeof(char *));		attrValues = (char **) palloc(attrCount * sizeof(char *));		attrValFlags = (bool *) palloc(attrCount * sizeof(char));		for (i = 1; i <= attrCount; i++)		{			int			subscrName[] = {i, 1};			int			subscrValue[] = {i, 2};			Datum		elDatum;			char	   *nameStr,					   *valueStr;			bool		valueHasRefs = false;			elDatum = array_ref(attrs, 2, subscrName, arrLen, elLen, elByVal, elAlign, &elIsNull);			if (elIsNull)			{				elog(ERROR, "attribute name must not be null");			}			nameStr = text_to_cstring(DatumGetTextP(elDatum));			if (strlen(nameStr) == 0)			{				elog(ERROR, "attribute name must be a string of non-zero length");			}			else			{					/* Check validity of characters. */				char	   *c = nameStr;				int			cWidth = pg_utf_mblen((unsigned char *) c);//.........这里部分代码省略.........
开发者ID:andreypopp,项目名称:pg_xnode,代码行数:101,


示例27: ProcedureCreate

/* ---------------------------------------------------------------- *		ProcedureCreate * * Note: allParameterTypes, parameterModes, parameterNames, trftypes, and proconfig * are either arrays of the proper types or NULL.  We declare them Datum, * not "ArrayType *", to avoid importing array.h into pg_proc.h. * ---------------------------------------------------------------- */ObjectAddressProcedureCreate(const char *procedureName,				Oid procNamespace,				bool replace,				bool returnsSet,				Oid returnType,				Oid proowner,				Oid languageObjectId,				Oid languageValidator,				const char *prosrc,				const char *probin,				char prokind,				bool security_definer,				bool isLeakProof,				bool isStrict,				char volatility,				char parallel,				oidvector *parameterTypes,				Datum allParameterTypes,				Datum parameterModes,				Datum parameterNames,				List *parameterDefaults,				Datum trftypes,				Datum proconfig,				float4 procost,				float4 prorows){	Oid			retval;	int			parameterCount;	int			allParamCount;	Oid		   *allParams;	char	   *paramModes = NULL;	bool		genericInParam = false;	bool		genericOutParam = false;	bool		anyrangeInParam = false;	bool		anyrangeOutParam = false;	bool		internalInParam = false;	bool		internalOutParam = false;	Oid			variadicType = InvalidOid;	Acl		   *proacl = NULL;	Relation	rel;	HeapTuple	tup;	HeapTuple	oldtup;	bool		nulls[Natts_pg_proc];	Datum		values[Natts_pg_proc];	bool		replaces[Natts_pg_proc];	NameData	procname;	TupleDesc	tupDesc;	bool		is_update;	ObjectAddress myself,				referenced;	int			i;	Oid			trfid;	/*	 * sanity checks	 */	Assert(PointerIsValid(prosrc));	parameterCount = parameterTypes->dim1;	if (parameterCount < 0 || parameterCount > FUNC_MAX_ARGS)		ereport(ERROR,				(errcode(ERRCODE_TOO_MANY_ARGUMENTS),				 errmsg_plural("functions cannot have more than %d argument",							   "functions cannot have more than %d arguments",							   FUNC_MAX_ARGS,							   FUNC_MAX_ARGS)));	/* note: the above is correct, we do NOT count output arguments */	/* Deconstruct array inputs */	if (allParameterTypes != PointerGetDatum(NULL))	{		/*		 * We expect the array to be a 1-D OID array; verify that. We don't		 * need to use deconstruct_array() since the array data is just going		 * to look like a C array of OID values.		 */		ArrayType  *allParamArray = (ArrayType *) DatumGetPointer(allParameterTypes);		allParamCount = ARR_DIMS(allParamArray)[0];		if (ARR_NDIM(allParamArray) != 1 ||			allParamCount <= 0 ||			ARR_HASNULL(allParamArray) ||			ARR_ELEMTYPE(allParamArray) != OIDOID)			elog(ERROR, "allParameterTypes is not a 1-D Oid array");		allParams = (Oid *) ARR_DATA_PTR(allParamArray);		Assert(allParamCount >= parameterCount);		/* we assume caller got the contents right */	}	else	{		allParamCount = parameterCount;//.........这里部分代码省略.........
开发者ID:eubide,项目名称:postgres,代码行数:101,


示例28: array_to_count

/** * Returns a count from an array of numbers. * by Paul A. Jungwirth */Datumarray_to_count(PG_FUNCTION_ARGS){  // Our arguments:  ArrayType *vals;  // The array element type:  Oid valsType;  // The array element type widths for our input array:  int16 valsTypeWidth;  // The array element type "is passed by value" flags (not really used):  bool valsTypeByValue;  // The array element type alignment codes (not really used):  char valsTypeAlignmentCode;  // The array contents, as PostgreSQL "Datum" objects:  Datum *valsContent;  // List of "is null" flags for the array contents:  bool *valsNullFlags;  // I'd prefer int64 here but deconstruct_array wants a plain int.  int valsLength;  int valsCount = 0;   int i;  if (PG_ARGISNULL(0)) {    ereport(ERROR, (errmsg("Null arrays not accepted")));  }  vals = PG_GETARG_ARRAYTYPE_P(0);  if (ARR_NDIM(vals) == 0) {    PG_RETURN_NULL();  }  if (ARR_NDIM(vals) > 1) {    ereport(ERROR, (errmsg("One-dimesional arrays are required")));  }  valsType = ARR_ELEMTYPE(vals);  valsLength = (ARR_DIMS(vals))[0];  get_typlenbyvalalign(valsType, &valsTypeWidth, &valsTypeByValue, &valsTypeAlignmentCode);  // Extract the array contents (as Datum objects).  // It's kind of a shame we even need to fill valsContent,  // but if we pass a NULL it crashes:  deconstruct_array(vals, valsType, valsTypeWidth, valsTypeByValue, valsTypeAlignmentCode,      &valsContent, &valsNullFlags, &valsLength);  // Compute the count.  for (i = 0; i < valsLength; i++) {    if (!valsNullFlags[i]) valsCount++;  }  PG_RETURN_INT64(valsCount);}
开发者ID:pjungwir,项目名称:aggs_for_arrays,代码行数:67,



注:本文中的ARR_NDIM函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ ARR_SIZE函数代码示例
C++ ARR_LBOUND函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。