Ejemplo n.º 1
0
Datum
cmsketch_empty(PG_FUNCTION_ARGS)
{
	CountMinSketch *cms = CountMinSketchCreate();
	SET_VARSIZE(cms, CountMinSketchSize(cms));
	PG_RETURN_POINTER(cms);
}
Ejemplo n.º 2
0
Datum
cmsketch_add(PG_FUNCTION_ARGS)
{
	CountMinSketch *cms;

	if (PG_ARGISNULL(0))
		cms = CountMinSketchCreate();
	else
		cms = (CountMinSketch *) PG_GETARG_VARLENA_P(0);

	fcinfo->flinfo->fn_extra = lookup_type_cache(get_fn_expr_argtype(fcinfo->flinfo, 1), 0);
	cms = cmsketch_add_datum(fcinfo, cms, PG_GETARG_DATUM(1), 1);
	PG_RETURN_POINTER(cms);
}
Ejemplo n.º 3
0
static CountMinSketch *
cmsketch_startup(FunctionCallInfo fcinfo, float8 eps, float8 p)
{
	CountMinSketch *cms;
	Oid type = AggGetInitialArgType(fcinfo);

	fcinfo->flinfo->fn_extra = lookup_type_cache(type, 0);

	if (p && eps)
		cms = cmsketch_create(eps, p);
	else
		cms = CountMinSketchCreate();

	return cms;
}
Ejemplo n.º 4
0
Datum
cmsketch_addn(PG_FUNCTION_ARGS)
{
	CountMinSketch *cms;
	int32 n = PG_GETARG_INT32(2);

	if (PG_ARGISNULL(0))
		cms = CountMinSketchCreate();
	else
		cms = (CountMinSketch *) PG_GETARG_VARLENA_P(0);

	if (n < 0)
		ereport(ERROR,
				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
				errmsg("cmsketch type doesn't support negative increments")));

	if (n)
	{
		fcinfo->flinfo->fn_extra = lookup_type_cache(get_fn_expr_argtype(fcinfo->flinfo, 1), 0);
		cms = cmsketch_add_datum(fcinfo, cms, PG_GETARG_DATUM(1), n);
	}

	PG_RETURN_POINTER(cms);
}
Ejemplo n.º 5
0
Datum
cmsketch_empty(PG_FUNCTION_ARGS)
{
	CountMinSketch *cms = CountMinSketchCreate();
	PG_RETURN_POINTER(cms);
}