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

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

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

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

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

示例1: deconstruct_expanded_array

/* * Create the Datum/isnull representation of an expanded array object * if we didn't do so previously */voiddeconstruct_expanded_array(ExpandedArrayHeader *eah){	if (eah->dvalues == NULL)	{		MemoryContext oldcxt = MemoryContextSwitchTo(eah->hdr.eoh_context);		Datum	   *dvalues;		bool	   *dnulls;		int			nelems;		dnulls = NULL;		deconstruct_array(eah->fvalue,						  eah->element_type,						  eah->typlen, eah->typbyval, eah->typalign,						  &dvalues,						  ARR_HASNULL(eah->fvalue) ? &dnulls : NULL,						  &nelems);		/*		 * Update header only after successful completion of this step.  If		 * deconstruct_array fails partway through, worst consequence is some		 * leaked memory in the object's context.  If the caller fails at a		 * later point, that's fine, since the deconstructed representation is		 * valid anyhow.		 */		eah->dvalues = dvalues;		eah->dnulls = dnulls;		eah->dvalueslen = eah->nelems = nelems;		MemoryContextSwitchTo(oldcxt);	}}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:35,


示例2: _doubleArray_coerceDatum

static jvalue _doubleArray_coerceDatum(Type self, Datum arg){	jvalue     result;	ArrayType* v      = DatumGetArrayTypeP(arg);	jsize      nElems = (jsize)ArrayGetNItems(ARR_NDIM(v), ARR_DIMS(v));	jdoubleArray doubleArray = JNI_newDoubleArray(nElems);#if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 2)	JNI_setDoubleArrayRegion(doubleArray, 0, nElems, (jdouble*)ARR_DATA_PTR(v));#else	if(ARR_HASNULL(v))	{		jsize idx;		jboolean isCopy = JNI_FALSE;		bits8* nullBitMap = ARR_NULLBITMAP(v);		jdouble* values = (jdouble*)ARR_DATA_PTR(v);		jdouble* elems  = JNI_getDoubleArrayElements(doubleArray, &isCopy);		for(idx = 0; idx < nElems; ++idx)		{			if(arrayIsNull(nullBitMap, idx))				elems[idx] = 0;			else				elems[idx] = *values++;		}		JNI_releaseDoubleArrayElements(doubleArray, elems, JNI_COMMIT);	}	else		JNI_setDoubleArrayRegion(doubleArray, 0, nElems, (jdouble*)ARR_DATA_PTR(v));#endif	result.l = (jobject)doubleArray;	return result;}
开发者ID:ChiralBehaviors,项目名称:pljava,代码行数:32,


示例3: pcpoint_from_double_array

Datum pcpoint_from_double_array(PG_FUNCTION_ARGS){	uint32 pcid = PG_GETARG_INT32(0);	ArrayType *arrptr = PG_GETARG_ARRAYTYPE_P(1);	int nelems;	float8 *vals;	PCPOINT *pt;	PCSCHEMA *schema = pc_schema_from_pcid(pcid, fcinfo);	SERIALIZED_POINT *serpt;	if ( ! schema )		elog(ERROR, "unable to load schema for pcid = %d", pcid);	if ( ARR_ELEMTYPE(arrptr) != FLOAT8OID )		elog(ERROR, "array must be of float8[]");	if ( ARR_NDIM(arrptr) != 1 )		elog(ERROR, "float8[] must have only one dimension");	if ( ARR_HASNULL(arrptr) )		elog(ERROR, "float8[] must not have null elements");	nelems = ARR_DIMS(arrptr)[0];	if ( nelems != schema->ndims || ARR_LBOUND(arrptr)[0] > 1 )		elog(ERROR, "array dimensions do not match schema dimensions of pcid = %d", pcid);	vals = (float8*) ARR_DATA_PTR(arrptr);	pt = pc_point_from_double_array(schema, vals, nelems);	serpt = pc_point_serialize(pt);	pc_point_free(pt);	PG_RETURN_POINTER(serpt);}
开发者ID:achidlow,项目名称:pointcloud,代码行数:33,


示例4: _booleanArray_coerceDatum

static jvalue _booleanArray_coerceDatum(Type self, Datum arg){	jvalue     result;	ArrayType* v      = DatumGetArrayTypeP(arg);	jsize      nElems = (jsize)ArrayGetNItems(ARR_NDIM(v), ARR_DIMS(v));	jbooleanArray booleanArray = JNI_newBooleanArray(nElems);	if(ARR_HASNULL(v))	{		jsize idx;		jboolean isCopy = JNI_FALSE;		bits8* nullBitMap = ARR_NULLBITMAP(v);		jboolean* values = (jboolean*)ARR_DATA_PTR(v);		jboolean* elems  = JNI_getBooleanArrayElements(booleanArray, &isCopy);		for(idx = 0; idx < nElems; ++idx)		{			if(arrayIsNull(nullBitMap, idx))				elems[idx] = 0;			else				elems[idx] = *values++;		}		JNI_releaseBooleanArrayElements(booleanArray, elems, JNI_COMMIT);	}	else		JNI_setBooleanArrayRegion(booleanArray, 0, nElems, (jboolean*)ARR_DATA_PTR(v));	result.l = (jobject)booleanArray;	return result;}
开发者ID:AnLingm,项目名称:gpdb,代码行数:28,


示例5: array_iterator

static boolarray_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found){	int			num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));	ltree	   *item = (ltree *) ARR_DATA_PTR(la);	if (ARR_NDIM(la) > 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array must be one-dimensional")));	if (ARR_HASNULL(la))		ereport(ERROR,				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),				 errmsg("array must not contain nulls")));	if (found)		*found = NULL;	while (num > 0)	{		if (DatumGetBool(DirectFunctionCall2(callback,							 PointerGetDatum(item), PointerGetDatum(param))))		{			if (found)				*found = item;			return true;		}		num--;		item = NEXTVAL(item);	}	return false;}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:33,


示例6: _lca

Datum_lca(PG_FUNCTION_ARGS){	ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);	int			num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));	ltree	   *item = (ltree *) ARR_DATA_PTR(la);	ltree	  **a,			   *res;	if (ARR_NDIM(la) > 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array must be one-dimensional")));	if (ARR_HASNULL(la))		ereport(ERROR,				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),				 errmsg("array must not contain nulls")));	a = (ltree **) palloc(sizeof(ltree *) * num);	while (num > 0)	{		num--;		a[num] = item;		item = NEXTVAL(item);	}	res = lca_inner(a, ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la)));	pfree(a);	PG_FREE_IF_COPY(la, 0);	if (res)		PG_RETURN_POINTER(res);	else		PG_RETURN_NULL();}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:35,


示例7: _lt_q_regex

Datum_lt_q_regex(PG_FUNCTION_ARGS){	ArrayType  *_tree = PG_GETARG_ARRAYTYPE_P(0);	ArrayType  *_query = PG_GETARG_ARRAYTYPE_P(1);	lquery	   *query = (lquery *) ARR_DATA_PTR(_query);	bool		res = false;	int			num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));	if (ARR_NDIM(_query) > 1)		ereport(ERROR,				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),				 errmsg("array must be one-dimensional")));	if (ARR_HASNULL(_query))		ereport(ERROR,				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),				 errmsg("array must not contain nulls")));	while (num > 0)	{		if (array_iterator(_tree, ltq_regex, (void *) query, NULL))		{			res = true;			break;		}		num--;		query = (lquery *) NEXTVAL(query);	}	PG_FREE_IF_COPY(_tree, 0);	PG_FREE_IF_COPY(_query, 1);	PG_RETURN_BOOL(res);}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:33,


示例8: 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, 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, no nulls */	if (ARR_NDIM(result) != 1 ||		ARR_HASNULL(result) ||		ARR_ELEMTYPE(result) != INT2OID)		ereport(ERROR,				(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),				 errmsg("invalid int2vector data")));	PG_RETURN_POINTER(result);}
开发者ID:rtzassociates,项目名称:postgresql-8.2.23,代码行数:38,


示例9: cube_a_f8_f8

/*** Allows the construction of a cube from 2 float[]'s*/Datumcube_a_f8_f8(PG_FUNCTION_ARGS){	int			i;	int			dim;	int			size;	NDBOX	   *result;	ArrayType  *ur,			   *ll;	double	   *dur,			   *dll;	ur = (ArrayType *) PG_GETARG_VARLENA_P(0);	ll = (ArrayType *) PG_GETARG_VARLENA_P(1);	if (ARR_HASNULL(ur) || ARR_HASNULL(ll))	{		ereport(ERROR,				(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),				 errmsg("Cannot work with NULL arrays")));	}	dim = ARRNELEMS(ur);	if (ARRNELEMS(ll) != dim)	{		ereport(ERROR,				(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),				 errmsg("UR and LL arrays must be of same length")));	}	dur = ARRPTR(ur);	dll = ARRPTR(ll);	size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;	result = (NDBOX *) palloc(size);	memset(result, 0, size);	result->size = size;	result->dim = dim;	for (i = 0; i < dim; i++)	{		result->x[i] = dur[i];		result->x[i + dim] = dll[i];	}	PG_RETURN_NDBOX(result);}
开发者ID:asurinsaka,项目名称:postgresql-8.2.19-lru,代码行数:50,


示例10: DatumGetHeapTupleHeader

/** * Convert postgres Datum into a ConcreteValue object. */AbstractValueSPtr AbstractPGValue::DatumToValue(bool inMemoryIsWritable,    Oid inTypeID, Datum inDatum) const {            // First check if datum is rowtype    if (type_is_rowtype(inTypeID)) {        HeapTupleHeader pgTuple = DatumGetHeapTupleHeader(inDatum);        return AbstractValueSPtr(new PGValue<HeapTupleHeader>(pgTuple));    } else if (type_is_array(inTypeID)) {        ArrayType *pgArray = DatumGetArrayTypeP(inDatum);                if (ARR_NDIM(pgArray) != 1)            throw std::invalid_argument("Multidimensional arrays not yet supported");                if (ARR_HASNULL(pgArray))            throw std::invalid_argument("Arrays with NULLs not yet supported");                switch (ARR_ELEMTYPE(pgArray)) {            case FLOAT8OID: {                MemHandleSPtr memoryHandle(new PGArrayHandle(pgArray));                                if (inMemoryIsWritable) {                    return AbstractValueSPtr(                        new ConcreteValue<Array<double> >(                            Array<double>(memoryHandle,                                boost::extents[ ARR_DIMS(pgArray)[0] ])                            )                        );                } else {                    return AbstractValueSPtr(                        new ConcreteValue<Array_const<double> >(                            Array_const<double>(memoryHandle,                                boost::extents[ ARR_DIMS(pgArray)[0] ])                            )                        );                }            }        }    }    switch (inTypeID) {        case BOOLOID: return AbstractValueSPtr(            new ConcreteValue<bool>( DatumGetBool(inDatum) ));        case INT2OID: return AbstractValueSPtr(            new ConcreteValue<int16_t>( DatumGetInt16(inDatum) ));        case INT4OID: return AbstractValueSPtr(            new ConcreteValue<int32_t>( DatumGetInt32(inDatum) ));        case INT8OID: return AbstractValueSPtr(            new ConcreteValue<int64_t>( DatumGetInt64(inDatum) ));        case FLOAT4OID: return AbstractValueSPtr(            new ConcreteValue<float>( DatumGetFloat4(inDatum) ));        case FLOAT8OID: return AbstractValueSPtr(            new ConcreteValue<double>( DatumGetFloat8(inDatum) ));    }        return AbstractValueSPtr();}
开发者ID:fabianofernandes,项目名称:contrib,代码行数:59,


示例11: array_has_null

static PyObjarray_has_null(PyObj self, void *closure){	PyObj rob;	if (ARR_HASNULL(DatumGetArrayTypeP(PyPgObject_GetDatum(self))))		rob = Py_True;	else		rob = Py_False;	Py_INCREF(rob);	return(rob);}
开发者ID:python-postgres,项目名称:be,代码行数:13,


示例12: rank_cd

Datumrank_cd(PG_FUNCTION_ARGS){	ArrayType  *win;	tsvector   *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));	QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(2));	int			method = DEF_NORM_METHOD;	float4		res;	/*	 * Pre-8.2, rank_cd took just a plain int as its first argument.	 * It was a mistake to keep the same C function name while changing the	 * signature, but it's too late to fix that.  Instead, do a runtime test	 * to make sure the expected datatype has been passed.  This is needed	 * to prevent core dumps if tsearch2 function definitions from an old	 * database are loaded into an 8.2 server.	 */	if (get_fn_expr_argtype(fcinfo->flinfo, 0) != FLOAT4ARRAYOID)		ereport(ERROR,				(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),				 errmsg("rank_cd() now takes real[] as its first argument, not integer")));	/* now safe to dereference the first arg */	win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));	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")));	if (PG_NARGS() == 4)		method = PG_GETARG_INT32(3);	res = calc_rank_cd((float4 *) ARR_DATA_PTR(win), 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,代码行数:51,


示例13: 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,


示例14: cube_subset

Datumcube_subset(PG_FUNCTION_ARGS){	NDBOX	   *c,			   *result;	ArrayType  *idx;	int			size,				dim,				i;	int		   *dx;	c = PG_GETARG_NDBOX(0);	idx = (ArrayType *) PG_GETARG_VARLENA_P(1);	if (ARR_HASNULL(idx))	{		ereport(ERROR,				(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),				 errmsg("Cannot work with NULL arrays")));	}	dx = (int4 *) ARR_DATA_PTR(idx);	dim = ARRNELEMS(idx);	size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;	result = (NDBOX *) palloc(size);	memset(result, 0, size);	result->size = size;	result->dim = dim;	for (i = 0; i < dim; i++)	{		if ((dx[i] <= 0) || (dx[i] > c->dim))		{			pfree(result);			ereport(ERROR,					(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),					 errmsg("Index out of bounds")));		}		result->x[i] = c->x[dx[i] - 1];		result->x[i + dim] = c->x[dx[i] + c->dim - 1];	}	PG_FREE_IF_COPY(c,0);	PG_RETURN_NDBOX(result);}
开发者ID:asurinsaka,项目名称:postgresql-8.2.19-lru,代码行数:46,


示例15: 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,


示例16: int2vectorrecv

/* *		int2vectorrecv			- converts external binary format to int2vector */Datumint2vectorrecv(PG_FUNCTION_ARGS){	LOCAL_FCINFO(locfcinfo, 3);	StringInfo	buf = (StringInfo) PG_GETARG_POINTER(0);	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->args[0].value = PointerGetDatum(buf);	locfcinfo->args[0].isnull = false;	locfcinfo->args[1].value = ObjectIdGetDatum(INT2OID);	locfcinfo->args[1].isnull = false;	locfcinfo->args[2].value = Int32GetDatum(-1);	locfcinfo->args[2].isnull = 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:eubide,项目名称:postgres,代码行数:47,


示例17: pc_typmod_in

Datum pc_typmod_in(PG_FUNCTION_ARGS){	uint32 typmod = 0;	Datum *elem_values;	int n = 0;	int i = 0;	ArrayType *arr = (ArrayType *) DatumGetPointer(PG_GETARG_DATUM(0));	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")));	if (ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr)) > 1)		ereport(ERROR,		        (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),		         errmsg("typmod array must have one element")));	deconstruct_array(arr,	                  CSTRINGOID, -2, false, 'c', /* hardwire cstring representation details */	                  &elem_values, NULL, &n);	for (i = 0; i < n; i++)	{		if ( i == 0 ) /* PCID */		{			char *s = DatumGetCString(elem_values[i]);			typmod = pg_atoi(s, sizeof(int32), '/0');		}	}	PG_RETURN_INT32(typmod);}
开发者ID:achidlow,项目名称:pointcloud,代码行数:43,


示例18: 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,


示例19: 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,


示例20: getWeights

static float *getWeights(ArrayType *win){	static float ws[lengthof(weights)];	int			i;	float4	   *arrdata;	if (win == 0)		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 (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")));	}	return ws;}
开发者ID:Joe-xXx,项目名称:postgres-old-soon-decommissioned,代码行数:37,


示例21: 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,


示例22: array_cat

//.........这里部分代码省略.........					errdetail("Arrays with differing element dimensions are "							  "not compatible for concatenation.")));			dims[i] = dims1[i];			lbs[i] = lbs1[i];		}	}	else if (ndims1 == ndims2 - 1)	{		/*		 * resulting array has the second argument as the outer array, with		 * the first argument inserted at the front of the outer dimension		 */		ndims = ndims2;		dims = (int *) palloc(ndims * sizeof(int));		lbs = (int *) palloc(ndims * sizeof(int));		memcpy(dims, dims2, ndims * sizeof(int));		memcpy(lbs, lbs2, ndims * sizeof(int));		/* increment number of elements in outer array */		dims[0] += 1;		/* make sure the added element matches our existing elements */		for (i = 0; i < ndims1; i++)		{			if (dims1[i] != dims[i + 1] || lbs1[i] != lbs[i + 1])				ereport(ERROR,						(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),						 errmsg("cannot concatenate incompatible arrays"),						 errdetail("Arrays with differing dimensions are not "								   "compatible for concatenation.")));		}	}	else	{		/*		 * (ndims1 == ndims2 + 1)		 *		 * resulting array has the first argument as the outer array, with the		 * second argument appended to the end of the outer dimension		 */		ndims = ndims1;		dims = (int *) palloc(ndims * sizeof(int));		lbs = (int *) palloc(ndims * sizeof(int));		memcpy(dims, dims1, ndims * sizeof(int));		memcpy(lbs, lbs1, ndims * sizeof(int));		/* increment number of elements in outer array */		dims[0] += 1;		/* make sure the added element matches our existing elements */		for (i = 0; i < ndims2; i++)		{			if (dims2[i] != dims[i + 1] || lbs2[i] != lbs[i + 1])				ereport(ERROR,						(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),						 errmsg("cannot concatenate incompatible arrays"),						 errdetail("Arrays with differing dimensions are not "								   "compatible for concatenation.")));		}	}	/* Do this mainly for overflow checking */	nitems = ArrayGetNItems(ndims, dims);	/* build the result array */	ndatabytes = ndatabytes1 + ndatabytes2;	if (ARR_HASNULL(v1) || ARR_HASNULL(v2))	{		dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);		nbytes = ndatabytes + dataoffset;	}	else	{		dataoffset = 0;			/* marker for no null bitmap */		nbytes = ndatabytes + ARR_OVERHEAD_NONULLS(ndims);	}	result = (ArrayType *) palloc(nbytes);	SET_VARSIZE(result, nbytes);	result->ndim = ndims;	result->dataoffset = dataoffset;	result->elemtype = element_type;	memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));	memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));	/* data area is arg1 then arg2 */	memcpy(ARR_DATA_PTR(result), dat1, ndatabytes1);	memcpy(ARR_DATA_PTR(result) + ndatabytes1, dat2, ndatabytes2);	/* handle the null bitmap if needed */	if (ARR_HASNULL(result))	{		array_bitmap_copy(ARR_NULLBITMAP(result), 0,						  bitmap1, 0,						  nitems1);		array_bitmap_copy(ARR_NULLBITMAP(result), nitems1,						  bitmap2, 0,						  nitems2);	}	PG_RETURN_ARRAYTYPE_P(result);}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:101,


示例23: 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,


示例24: kc_delete

Datum kc_delete(PG_FUNCTION_ARGS) {        char       *map_name = text_to_cstring(PG_GETARG_TEXT_PP(0));    char       *start_time = text_to_cstring(PG_GETARG_TEXT_PP(1));    ArrayType  *rids = PG_GETARG_ARRAYTYPE_P(2);    int        i;    Datum      *rid_datums;    bool       *rid_nulls;    int        rid_count;    char       *next_rid;    KCDB       *main_db;    char       *vbuf;    size_t      vsiz;    int64_t     num_keys_to_run;    int64_t     num_keys_deleted;    char        **keys_to_use;    Cloudflare__ZoneTimeBucket *msg_new;    // Open our DB.    main_db = kcdbnew();    if (!open_db (main_db, map_name, start_time)) {        PG_RETURN_INT64(0);    }    kcdbbegintran (main_db, 0);    // Now run over the array.    deconstruct_array(rids, TEXTOID, -1, false, 'i',                      &rid_datums, &rid_nulls, &rid_count);    if (ARR_HASNULL(rids)) {        ereport(ERROR,                (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),                 errmsg("cannot work with arrays containing NULLs")));    }    keys_to_use = (char **)palloc(KC_MAX_ENTRIES_PER_RID * sizeof(char));    num_keys_deleted = 0;    char prefixes_to_use[rid_count][KC_MAX_RID];    for (i = 0; i < rid_count; i++) {        next_rid = TextDatumGetCString(rid_datums[i]);        snprintf(prefixes_to_use[i], KC_MAX_RID, "%s%s", next_rid, CF_LABEL_SEP);        num_keys_to_run = kcdbmatchprefix (main_db,	prefixes_to_use[i], keys_to_use, KC_MAX_ENTRIES_PER_RID);        if (num_keys_to_run != -1) {            num_keys_deleted += num_keys_to_run;            int next_key;            for (next_key=0; next_key < num_keys_to_run; next_key++) {                vbuf = kcdbget(main_db, keys_to_use[next_key], strlen(keys_to_use[next_key]), &vsiz);                if (vbuf) {                    msg_new = cloudflare__zone_time_bucket__unpack(NULL, vsiz, (const uint8_t *)vbuf);                    if (msg_new == NULL) {   // Something failed                        ereport(ERROR,                                (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),                                 errmsg("error unpacking incoming message")));                    } else {                        if (msg_new->kv_map_file) {                            unlink(msg_new->kv_map_file);                        }                        kcdbremove (main_db, keys_to_use[next_key], strlen(keys_to_use[next_key]));	                    }                    cloudflare__zone_time_bucket__free_unpacked(msg_new, NULL);                    kcfree(vbuf);                    kcfree(keys_to_use[next_key]);                } else {                    ereport(NOTICE,                            (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),                             errmsg("get error on %s -- %s", keys_to_use[next_key], kcecodename(kcdbecode(main_db)))));                }            }        } else {            ereport(NOTICE,                    (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),                     errmsg("prefix error on %s -- %s", prefixes_to_use[i], kcecodename(kcdbecode(main_db)))));        }    }    pfree(keys_to_use);        // Done!    kcdbendtran (main_db, 1);    if (!kcdbclose(main_db)) {        ereport(ERROR,                (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),                 errmsg("Error Closeing db: /"%s/"", kcecodename(kcdbecode(main_db)))));    }    PG_RETURN_INT64(num_keys_deleted);}
开发者ID:cloudflare,项目名称:SortaSQL,代码行数:87,


示例25: kc_shrink

Datum kc_shrink(PG_FUNCTION_ARGS) {        char       *map_name = text_to_cstring(PG_GETARG_TEXT_PP(0));    char       *start_time = text_to_cstring(PG_GETARG_TEXT_PP(1)); // Start time + uid!!!    char       *new_rid = text_to_cstring(PG_GETARG_TEXT_PP(2));    ArrayType  *old_rids = PG_GETARG_ARRAYTYPE_P(3);    char       *classification = text_to_cstring(PG_GETARG_TEXT_PP(4));    char       *doctype = text_to_cstring(PG_GETARG_TEXT_PP(5));    char       *pop = text_to_cstring(PG_GETARG_TEXT_PP(6));    char       *psource = text_to_cstring(PG_GETARG_TEXT_PP(7));    text       *tout;       int        i,j;    Datum      *rid_datums;    bool       *rid_nulls;    int        rid_count;    char       *next_rid;    KCDB       *main_db;    char       *vbuf;    size_t      vsiz;    // Open our DB.    main_db = kcdbnew();    if (!open_db (main_db, map_name, start_time)) {        tout = cstring_to_text(new_rid);        PG_RETURN_TEXT_P(tout);            }    kcdbbegintran (main_db, 0);        // First fill in what we can from the input.    Cloudflare__ZoneTimeBucket msg = CLOUDFLARE__ZONE_TIME_BUCKET__INIT;        msg.map_name = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.doctype = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.classification = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.pop = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.psource = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.result_id = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.db_key = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.db_path = (char *)palloc(MAX_KC_ROW_ENTRY * sizeof(char));    msg.map_entry = palloc(MAX_KEYS_BEFORE_KV_MAP * sizeof(Cloudflare__ZoneTimeBucket__Counter));    msg.n_map_entry = 0;    strncpy(msg.map_name, map_name, MAX_KC_ROW_ENTRY);    strncpy(msg.classification, classification, MAX_KC_ROW_ENTRY);    strncpy(msg.doctype, doctype, MAX_KC_ROW_ENTRY);    strncpy(msg.pop, pop, MAX_KC_ROW_ENTRY);    strncpy(msg.psource, psource, MAX_KC_ROW_ENTRY);    strncpy(msg.result_id, new_rid, KC_MAX_RID);    snprintf(msg.db_path, MAX_KC_ROW_ENTRY, "%s%s%s",              map_name, "/", start_time);    snprintf(msg.db_key, KC_MAX_RID, "%s%s%s%s%s%s%s%s%s%s%s",              new_rid, CF_LABEL_SEP,             classification, CF_LABEL_SEP,              doctype, CF_LABEL_SEP,             pop, CF_LABEL_SEP,             psource, CF_LABEL_SEP,             map_name);    // Now run over the array.    deconstruct_array(old_rids, TEXTOID, -1, false, 'i',                      &rid_datums, &rid_nulls, &rid_count);    if (ARR_HASNULL(old_rids)) {        ereport(ERROR,                (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),                 errmsg("cannot work with arrays containing NULLs")));    }    int num_new_keys = 0;    int num_entries = 0;    char keys_to_use[rid_count][KC_MAX_RID];    Cloudflare__ZoneTimeBucket *msg_new[rid_count];    j=0;    for (i = 0; i < rid_count; i++) {        next_rid = TextDatumGetCString(rid_datums[i]);        snprintf(keys_to_use[i], KC_MAX_RID, "%s%s%s%s%s%s%s%s%s%s%s",                  next_rid, CF_LABEL_SEP,                  classification, CF_LABEL_SEP,                 doctype, CF_LABEL_SEP,                 pop, CF_LABEL_SEP,                 psource, CF_LABEL_SEP,                 map_name);        vbuf = kcdbget(main_db, keys_to_use[i], strlen(keys_to_use[i]), &vsiz);        if (vbuf) {            msg_new[j] = cloudflare__zone_time_bucket__unpack(NULL, vsiz, (const uint8_t *)vbuf);            if (msg_new[j] == NULL) {   // Something failed                ereport(ERROR,                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),                         errmsg("error unpacking incoming message")));            } else {                if (msg_new[j]->kv_map_file) {                    num_entries = MAX_KEYS_BEFORE_KV_MAP + 1;                                    } else {                    num_entries += msg_new[j]->n_map_entry;                 }                j++;            }            kcfree(vbuf);        } else {//.........这里部分代码省略.........
开发者ID:cloudflare,项目名称:SortaSQL,代码行数:101,


示例26: svec_in_internal

SvecType * svec_in_internal(char * str){	char *values;	ArrayType *pgarray_vals,*pgarray_ix;	double *vals, *vals_temp;	StringInfo index;	int64 *u_index;	int32_t num_values,total_value_count;	SparseData sdata;	SvecType *result;	bits8 *bitmap;	int bitmask;	int i,j;	/* Read in the two arrays defining the Sparse Vector, first is the array	 * of run lengths (the count array), the second is an array of the 	 * unique values (the data array).	 *	 * The input format is a pair of standard Postgres arrays separated by 	 * a colon, like this:	 * 	{1,10,1,5,1}:{4.3,0,0.2,0,7.4}	 *	 * For now, the data array must only have float8 elements.	 */	if ((values=strchr(str,':')) == NULL) {		ereport(ERROR,			(errcode(ERRCODE_INVALID_PARAMETER_VALUE),			 errmsg("Invalid input string for svec")));	} else {		*values = '/0';		values = values+1;	}	/* Get the count and data arrays */	pgarray_ix = DatumGetArrayTypeP(			    OidFunctionCall3(F_ARRAY_IN,CStringGetDatum(str),			    ObjectIdGetDatum(INT8OID),Int32GetDatum(-1)));	pgarray_vals = DatumGetArrayTypeP(			    OidFunctionCall3(F_ARRAY_IN,CStringGetDatum(values),			    ObjectIdGetDatum(FLOAT8OID),Int32GetDatum(-1)));	num_values = *(ARR_DIMS(pgarray_ix));	u_index = (int64 *)ARR_DATA_PTR(pgarray_ix);	vals = (double *)ARR_DATA_PTR(pgarray_vals);	/* The count and value arrays must be non-empty */	int size1 = ARR_NDIM(pgarray_ix);	int size2 = ARR_NDIM(pgarray_vals);	if (size1 == 0 || size2 == 0)		ereport(ERROR,			(errcode(ERRCODE_INVALID_PARAMETER_VALUE),			 errmsg("The count and value arrays must be non-empty")));	/* The count and value arrays must have the same dimension */	if (num_values != *(ARR_DIMS(pgarray_vals)))		ereport(ERROR,			(errcode(ERRCODE_INVALID_PARAMETER_VALUE),			 errmsg("Unique value count not equal to run length count %d != %d", num_values, *(ARR_DIMS(pgarray_vals)))));	/* Count array cannot have NULLs */	if (ARR_HASNULL(pgarray_ix))		ereport(ERROR,			(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),			 errmsg("NULL value in the count array.")));	/* If the data array has NULLs, then we need to create an array to	 * store the NULL values as NVP values defined in float_specials.h. 	 */	if (ARR_HASNULL(pgarray_vals)) {		vals_temp = vals;		vals = (double *)palloc(sizeof(float8) * num_values);		bitmap = ARR_NULLBITMAP(pgarray_vals);		bitmask = 1;		j = 0;		for (i=0; i<num_values; i++) {			if (bitmap && (*bitmap & bitmask) == 0) // if NULL				vals[i] = NVP;			else { 				vals[i] = vals_temp[j];				j++;			}			if (bitmap) { // advance bitmap pointer				bitmask <<= 1;				if (bitmask == 0x100) {					bitmap++;					bitmask = 1;				}			}		}	 }	/* Make an empty StringInfo because we have the data array already */	index = makeStringInfo();	total_value_count = 0;	for (int i=0;i<num_values;i++) {		if (u_index[i] <= 0) 			ereport(ERROR,				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),				 errmsg("Non-positive run length in input")));//.........这里部分代码省略.........
开发者ID:AI-Org,项目名称:madlib,代码行数:101,


示例27: hvault_table_count_step

Datumhvault_table_count_step(PG_FUNCTION_ARGS){    MemoryContext aggmemctx, oldmemctx;    ArrayType * ctx;    ArrayType * idx_array;    int i, pos_idx;    int32_t * ctx_data;        if (!AggCheckCallContext(fcinfo, &aggmemctx))        elog(ERROR, "hvault_table_group_step called in non-aggregate context");        ctx = PG_ARGISNULL(0) ? NULL : PG_GETARG_ARRAYTYPE_P(0);    if (ctx == NULL)    {        int ndim;        int32_t * bounds_data;        int dims[MAXDIM];        int lbs[MAXDIM];         ArrayType * bounds_array;        oldmemctx = MemoryContextSwitchTo(aggmemctx);        if (PG_ARGISNULL(2))            elog(ERROR, "bounds array must not be null");//        if (!get_fn_expr_arg_stable(fcinfo->flinfo, 2))//            elog(ERROR, "bounds array must be const");        bounds_array = PG_GETARG_ARRAYTYPE_P(2);        Assert(bounds_array != NULL);        Assert(bounds_array->elemtype == INT4OID);        if (bounds_array->ndim != 2 || ARR_DIMS(bounds_array)[1] != 2)            elog(ERROR, "bounds array size is invalid");        if (ARR_HASNULL(bounds_array))        {            int size = ARR_DIMS(bounds_array)[0] * ARR_DIMS(bounds_array)[1];             for (i = 0; i < (size + 7) / 8; i++)                if (ARR_NULLBITMAP(bounds_array)[i] != 0)                    elog(ERROR, "bounds array must not contain NULLs");        }        ndim = ARR_DIMS(bounds_array)[0];         if (ndim > MAXDIM)            elog(ERROR, "too many dimensions, max supported is %d", MAXDIM);        bounds_data = (int32_t *) ARR_DATA_PTR(bounds_array);        for (i = 0; i < ndim; i++)         {            int ubs;            lbs[i] = bounds_data[2*i];            ubs = bounds_data[2*i+1];            dims[i] = ubs - lbs[i];        }        ctx = intArrayInit(ndim, dims, lbs);        MemoryContextSwitchTo(oldmemctx);    }        Assert(!ARR_HASNULL(ctx));    Assert(ctx->elemtype == INT4OID);        if (PG_ARGISNULL(1))        elog(ERROR, "group index array must not be null");    idx_array = PG_GETARG_ARRAYTYPE_P(1);    Assert(idx_array != NULL);    Assert(idx_array->elemtype == INT4OID);    if (idx_array->ndim != 1)        elog(ERROR, "group index array must have single dimension");    if (ARR_DIMS(idx_array)[0] != ctx->ndim)        elog(ERROR, "group index array length is inconsistent");    if (ARR_HASNULL(idx_array))    {        int size = ARR_DIMS(idx_array)[0];        for (i = 0; i < (size + 7) / 8; i++)            /* Skip elements with nulls */            if (ARR_NULLBITMAP(idx_array)[i] != 0)            {                elog(WARNING, "index array contains NULL, skipping");                PG_RETURN_ARRAYTYPE_P(ctx);             }    }        pos_idx = intArrayIdx(ctx, (int *) ARR_DATA_PTR(idx_array), true);    if (pos_idx != -1)    {        Assert(pos_idx >= 0);        if (ARR_SIZE(ctx) - ARR_DATA_OFFSET(ctx) <= pos_idx * 4)        {            elog(ERROR, "Array out of bounds access: %ld %d",                  ARR_SIZE(ctx) - ARR_DATA_OFFSET(ctx), pos_idx * 4);//.........这里部分代码省略.........
开发者ID:kikht,项目名称:hvault,代码行数:101,



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


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