Skip to content

Changed hll_add_agg() to return hll_empty instead of NULL #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Jul 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 85 additions & 115 deletions hll.c
Original file line number Diff line number Diff line change
Expand Up @@ -2814,10 +2814,26 @@ hll_add_trans4(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("hll_add_trans4 outside transition context")));

// Is the first argument a NULL?
// If the first argument is a NULL on first call, init an hll_empty
if (PG_ARGISNULL(0))
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = PG_GETARG_INT32(3);
int64 expthresh = PG_GETARG_INT64(4);
int32 sparseon = PG_GETARG_INT32(5);

msap = setup_multiset(aggctx);

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(multiset_t));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}
else
{
Expand All @@ -2829,28 +2845,6 @@ hll_add_trans4(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(1);

// Was the first argument uninitialized?
if (msap->ms_type == MST_UNINIT)
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = PG_GETARG_INT32(3);
int64 expthresh = PG_GETARG_INT64(4);
int32 sparseon = PG_GETARG_INT32(5);

multiset_t ms;

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(ms));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}

multiset_add(msap, val);
}

Expand All @@ -2877,10 +2871,26 @@ hll_add_trans3(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("hll_add_trans3 outside transition context")));

// Is the first argument a NULL?
// If the first argument is a NULL on first call, init an hll_empty
if (PG_ARGISNULL(0))
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = PG_GETARG_INT32(3);
int64 expthresh = PG_GETARG_INT64(4);
int32 sparseon = g_default_sparseon;

msap = setup_multiset(aggctx);

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(multiset_t));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}
else
{
Expand All @@ -2892,28 +2902,6 @@ hll_add_trans3(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(1);

// Was the first argument uninitialized?
if (msap->ms_type == MST_UNINIT)
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = PG_GETARG_INT32(3);
int64 expthresh = PG_GETARG_INT64(4);
int32 sparseon = g_default_sparseon;

multiset_t ms;

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(ms));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}

multiset_add(msap, val);
}

Expand All @@ -2940,10 +2928,26 @@ hll_add_trans2(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("hll_add_trans2 outside transition context")));

// Is the first argument a NULL?
// If the first argument is a NULL on first call, init an hll_empty
if (PG_ARGISNULL(0))
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = PG_GETARG_INT32(3);
int64 expthresh = g_default_expthresh;
int32 sparseon = g_default_sparseon;

msap = setup_multiset(aggctx);

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(multiset_t));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}
else
{
Expand All @@ -2955,28 +2959,6 @@ hll_add_trans2(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(1);

// Was the first argument uninitialized?
if (msap->ms_type == MST_UNINIT)
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = PG_GETARG_INT32(3);
int64 expthresh = g_default_expthresh;
int32 sparseon = g_default_sparseon;

multiset_t ms;

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(ms));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}

multiset_add(msap, val);
}

Expand All @@ -3003,10 +2985,26 @@ hll_add_trans1(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("hll_add_trans1 outside transition context")));

// Is the first argument a NULL?
// If the first argument is a NULL on first call, init an hll_empty
if (PG_ARGISNULL(0))
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = g_default_regwidth;
int64 expthresh = g_default_expthresh;
int32 sparseon = g_default_sparseon;

msap = setup_multiset(aggctx);

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(multiset_t));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}
else
{
Expand All @@ -3018,28 +3016,6 @@ hll_add_trans1(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(1);

// Was the first argument uninitialized?
if (msap->ms_type == MST_UNINIT)
{
int32 log2m = PG_GETARG_INT32(2);
int32 regwidth = g_default_regwidth;
int64 expthresh = g_default_expthresh;
int32 sparseon = g_default_sparseon;

multiset_t ms;

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(ms));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}

multiset_add(msap, val);
}

Expand All @@ -3066,10 +3042,26 @@ hll_add_trans0(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("hll_add_trans0 outside transition context")));

// Is the first argument a NULL?
// If the first argument is a NULL on first call, init an hll_empty
if (PG_ARGISNULL(0))
{
int32 log2m = g_default_log2m;
int32 regwidth = g_default_regwidth;
int64 expthresh = g_default_expthresh;
int32 sparseon = g_default_sparseon;

msap = setup_multiset(aggctx);

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(multiset_t));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}
else
{
Expand All @@ -3081,28 +3073,6 @@ hll_add_trans0(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(1);

// Was the first argument uninitialized?
if (msap->ms_type == MST_UNINIT)
{
int32 log2m = g_default_log2m;
int32 regwidth = g_default_regwidth;
int64 expthresh = g_default_expthresh;
int32 sparseon = g_default_sparseon;

multiset_t ms;

check_modifiers(log2m, regwidth, expthresh, sparseon);

memset(msap, '\0', sizeof(ms));

msap->ms_type = MST_EMPTY;
msap->ms_nbits = regwidth;
msap->ms_nregs = 1 << log2m;
msap->ms_log2nregs = log2m;
msap->ms_expthresh = expthresh;
msap->ms_sparseon = sparseon;
}

multiset_add(msap, val);
}

Expand Down
37 changes: 37 additions & 0 deletions regress/add_agg.ref
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,42 @@ psql:add_agg.sql:56: ERROR: sparseon modifier must be 0 or 1
select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512, 2))
from test_khvengxf;
psql:add_agg.sql:59: ERROR: sparseon modifier must be 0 or 1
-- Check that we return hll_empty on null input.
select hll_print(hll_add_agg(NULL));
hll_print
-----------------------------------------------------------
EMPTY, nregs=2048, nbits=5, expthresh=-1(160), sparseon=1
(1 row)

select hll_print(hll_add_agg(NULL, 10));
hll_print
----------------------------------------------------------
EMPTY, nregs=1024, nbits=5, expthresh=-1(80), sparseon=1
(1 row)

select hll_print(hll_add_agg(NULL, 10, 4));
hll_print
----------------------------------------------------------
EMPTY, nregs=1024, nbits=4, expthresh=-1(64), sparseon=1
(1 row)

select hll_print(hll_add_agg(NULL, 10, 4, 512));
hll_print
-------------------------------------------------------
EMPTY, nregs=1024, nbits=4, expthresh=512, sparseon=1
(1 row)

select hll_print(hll_add_agg(NULL, 10, 4, -1));
hll_print
----------------------------------------------------------
EMPTY, nregs=1024, nbits=4, expthresh=-1(64), sparseon=1
(1 row)

select hll_print(hll_add_agg(NULL, 10, 4, 512, 0));
hll_print
-------------------------------------------------------
EMPTY, nregs=1024, nbits=4, expthresh=512, sparseon=0
(1 row)

DROP TABLE test_khvengxf;
DROP TABLE
14 changes: 14 additions & 0 deletions regress/add_agg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@ select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512, -1))
select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512, 2))
from test_khvengxf;

-- Check that we return hll_empty on null input.

select hll_print(hll_add_agg(NULL));

select hll_print(hll_add_agg(NULL, 10));

select hll_print(hll_add_agg(NULL, 10, 4));

select hll_print(hll_add_agg(NULL, 10, 4, 512));

select hll_print(hll_add_agg(NULL, 10, 4, -1));

select hll_print(hll_add_agg(NULL, 10, 4, 512, 0));

DROP TABLE test_khvengxf;