Changeset: 289aa78c09de for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=289aa78c09de
Modified Files:
clients/Tests/exports.stable.out
monetdb5/modules/kernel/algebra.mx
Branch: default
Log Message:
Rationalized algebra.sub*join functions, added algebra.subjoin.
The MAL interfaces now require all arguments, including the candidate
lists, but "optional" arguments can be nil:bat (and the size estimate
nil:lng).
diffs (281 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -812,10 +812,9 @@ str ALGssort(int *result, int *bid);
str ALGssort_rev(int *result, int *bid);
str ALGstdev(dbl *res, int *bid);
str ALGstdevp(dbl *res, int *bid);
-str ALGsubleftjoin(bat *r1, bat *r2, bat *l, bat *r);
-str ALGsubleftjoin4(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr);
-str ALGsubouterjoin(bat *r1, bat *r2, bat *l, bat *r);
-str ALGsubouterjoin4(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr);
+str ALGsubjoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr, lng
*estimate);
+str ALGsubleftjoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr, lng
*estimate);
+str ALGsubouterjoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr, lng
*estimate);
str ALGsubsample(int *result, int *bid, int *param);
str ALGsubselect1(bat *result, bat *bid, const void *low, const void *high,
const bit *li, const bit *hi, const bit *anti);
str ALGsubselect2(bat *result, bat *bid, bat *sid, const void *low, const void
*high, const bit *li, const bit *hi, const bit *anti);
@@ -829,8 +828,7 @@ str ALGsubsort23(bat *result, bat *norde
str ALGsubsort31(bat *result, bat *bid, bat *order, bat *group, bit *reverse,
bit *stable);
str ALGsubsort32(bat *result, bat *norder, bat *bid, bat *order, bat *group,
bit *reverse, bit *stable);
str ALGsubsort33(bat *result, bat *norder, bat *ngroup, bat *bid, bat *order,
bat *group, bit *reverse, bit *stable);
-str ALGsubthetajoin(bat *r1, bat *r2, bat *l, bat *r, str *op);
-str ALGsubthetajoin4(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr, str
*op);
+str ALGsubthetajoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat *sr, str
*op, lng *estimate);
str ALGsunion(int *result, int *lid, int *rid);
str ALGsunique(int *result, int *bid);
str ALGtdiff(int *result, int *lid, int *rid);
diff --git a/monetdb5/modules/kernel/algebra.mx
b/monetdb5/modules/kernel/algebra.mx
--- a/monetdb5/modules/kernel/algebra.mx
+++ b/monetdb5/modules/kernel/algebra.mx
@@ -679,25 +679,20 @@ comment "This is a join() for which the
command join(l:bat[:any_1,:any_2], rl:bat[:any_3,:any_2],
rh:bat[:any_3,:any_2], li:bit, hi:bit) :bat[:any_1,:any_3]
address ALGrangejoin;
-command subleftjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1])
(:bat[:oid,:oid],:bat[:oid,:oid])
+command
subjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid],estimate:lng)
(:bat[:oid,:oid],:bat[:oid,:oid])
+address ALGsubjoin
+comment "Join";
+
+command
subleftjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid],estimate:lng)
(:bat[:oid,:oid],:bat[:oid,:oid])
address ALGsubleftjoin
-comment "Left join";
-command
subleftjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid])
(:bat[:oid,:oid],:bat[:oid,:oid])
-address ALGsubleftjoin4
comment "Left join with candidate lists";
-command subouterjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1])
(:bat[:oid,:oid],:bat[:oid,:oid])
+command
subouterjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid],estimate:lng)
(:bat[:oid,:oid],:bat[:oid,:oid])
address ALGsubouterjoin
-comment "Left outer join";
-command
subouterjoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid])
(:bat[:oid,:oid],:bat[:oid,:oid])
-address ALGsubouterjoin4
comment "Left outer join with candidate lists";
-command subthetajoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],op:str)
(:bat[:oid,:oid],:bat[:oid,:oid])
+command
subthetajoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid],op:str,estimate:lng)
(:bat[:oid,:oid],:bat[:oid,:oid])
address ALGsubthetajoin
-comment "Theta join";
-command
subthetajoin(l:bat[:oid,:any_1],r:bat[:oid,:any_1],sl:bat[:oid,:oid],sr:bat[:oid,:oid],op:str)
(:bat[:oid,:oid],:bat[:oid,:oid])
-address ALGsubthetajoin4
comment "Theta join with candidate lists";
# @+ Projection operations
@@ -1004,12 +999,10 @@ algebra_export str ALGthetajoin(int *res
algebra_export str ALGbandjoin_default(int *result, int *lid, int *rid, ptr
*minus, ptr *plus);
algebra_export str ALGbandjoin(int *result, int *lid, int *rid, ptr *minus,
ptr *plus, bit *li, bit *hi);
algebra_export str ALGrangejoin(int *result, int *lid, int *rlid, int *rhid,
bit *li, bit *hi);
-algebra_export str ALGsubleftjoin(bat *r1, bat *r2, bat *l, bat *r);
-algebra_export str ALGsubleftjoin4(bat *r1, bat *r2, bat *l, bat *r, bat *sl,
bat *sr);
-algebra_export str ALGsubouterjoin(bat *r1, bat *r2, bat *l, bat *r);
-algebra_export str ALGsubouterjoin4(bat *r1, bat *r2, bat *l, bat *r, bat *sl,
bat *sr);
-algebra_export str ALGsubthetajoin(bat *r1, bat *r2, bat *l, bat *r, str *op);
-algebra_export str ALGsubthetajoin4(bat *r1, bat *r2, bat *l, bat *r, bat *sl,
bat *sr, str *op);
+algebra_export str ALGsubjoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl, bat
*sr, lng *estimate);
+algebra_export str ALGsubleftjoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl,
bat *sr, lng *estimate);
+algebra_export str ALGsubouterjoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl,
bat *sr, lng *estimate);
+algebra_export str ALGsubthetajoin(bat *r1, bat *r2, bat *l, bat *r, bat *sl,
bat *sr, str *op, lng *estimate);
@= ALGunaryExport
algebra_export str ALG@1(int *result, int *bid);
@@ -1675,7 +1668,7 @@ ALGsubselect2(bat *result, bat *bid, bat
if ((b = BATdescriptor(*bid)) == NULL) {
throw(MAL, "algebra.select", RUNTIME_OBJECT_MISSING);
}
- if (sid && (s = BATdescriptor(*sid)) == NULL) {
+ if (sid && *sid && (s = BATdescriptor(*sid)) == NULL) {
BBPreleaseref(b->batCacheid);
throw(MAL, "algebra.select", RUNTIME_OBJECT_MISSING);
}
@@ -1713,7 +1706,7 @@ ALGthetasubselect2(bat *result, bat *bid
if ((b = BATdescriptor(*bid)) == NULL) {
throw(MAL, "algebra.select", RUNTIME_OBJECT_MISSING);
}
- if (sid && (s = BATdescriptor(*sid)) == NULL) {
+ if (sid && *sid && (s = BATdescriptor(*sid)) == NULL) {
BBPreleaseref(b->batCacheid);
throw(MAL, "algebra.select", RUNTIME_OBJECT_MISSING);
}
@@ -2221,23 +2214,40 @@ ALGrangejoin(int *result, int *lid, int
throw(MAL, "algebra.rangejoin", GDK_EXCEPTION);
}
-str
-ALGsubleftjoin4(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid)
+static str
+do_join(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid,
+ const char *op, lng *estimate,
+ gdk_return (*joinfunc)(BAT **, BAT **, BAT *, BAT *, BAT *, BAT
*, BUN),
+ gdk_return (*thetafunc)(BAT **, BAT **, BAT *, BAT *, BAT *,
BAT *, const char *, BUN),
+ const char *funcname)
{
BAT *left = NULL, *right = NULL, *candleft = NULL, *candright = NULL;
BAT *result1, *result2;
+ BUN est;
if ((left = BATdescriptor(*lid)) == NULL)
goto fail;
if ((right = BATdescriptor(*rid)) == NULL)
goto fail;
- if (slid && (candleft = BATdescriptor(*slid)) == NULL)
+ if (slid && *slid && (candleft = BATdescriptor(*slid)) == NULL)
goto fail;
- if (srid && (candright = BATdescriptor(*srid)) == NULL)
+ if (srid && *srid && (candright = BATdescriptor(*srid)) == NULL)
goto fail;
-
- if (BATsubleftjoin(&result1, &result2, left, right, candleft,
candright, BUN_NONE) == GDK_FAIL)
- goto fail;
+ if (estimate == NULL || *estimate < 0 || *estimate == lng_nil ||
*estimate > (lng) BUN_MAX)
+ est = BUN_NONE;
+ else
+ est = (BUN) *estimate;
+
+ if (thetafunc) {
+ assert(op != NULL);
+ assert(joinfunc == NULL);
+ if ((*thetafunc)(&result1, &result2, left, right, candleft,
candright, op, est) == GDK_FAIL)
+ goto fail;
+ } else {
+ assert(op == NULL);
+ if ((*joinfunc)(&result1, &result2, left, right, candleft,
candright, est) == GDK_FAIL)
+ goto fail;
+ }
*r1 = result1->batCacheid;
*r2 = result2->batCacheid;
BBPkeepref(*r1);
@@ -2259,107 +2269,35 @@ ALGsubleftjoin4(bat *r1, bat *r2, bat *l
BBPreclaim(candleft);
if (candright)
BBPreclaim(candright);
- throw(MAL, "algebra.subleftjoin", RUNTIME_OBJECT_MISSING);
+ throw(MAL, funcname, RUNTIME_OBJECT_MISSING);
}
str
-ALGsubleftjoin(bat *r1, bat *r2, bat *l, bat *r)
+ALGsubjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid, lng
*estimate)
{
- return ALGsubleftjoin4(r1, r2, l, r, NULL, NULL);
+ return do_join(r1, r2, lid, rid, slid, srid, NULL, estimate,
+ BATsubjoin, NULL, "algebra.subjoin");
}
str
-ALGsubouterjoin4(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid)
+ALGsubleftjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid, lng
*estimate)
{
- BAT *left = NULL, *right = NULL, *candleft = NULL, *candright = NULL;
- BAT *result1, *result2;
-
- if ((left = BATdescriptor(*lid)) == NULL)
- goto fail;
- if ((right = BATdescriptor(*rid)) == NULL)
- goto fail;
- if (slid && (candleft = BATdescriptor(*slid)) == NULL)
- goto fail;
- if (srid && (candright = BATdescriptor(*srid)) == NULL)
- goto fail;
-
- if (BATsubouterjoin(&result1, &result2, left, right, candleft,
candright, BUN_NONE) == GDK_FAIL)
- goto fail;
- *r1 = result1->batCacheid;
- *r2 = result2->batCacheid;
- BBPkeepref(*r1);
- BBPkeepref(*r2);
- BBPreleaseref(left->batCacheid);
- BBPreleaseref(right->batCacheid);
- if (candleft)
- BBPreleaseref(candleft->batCacheid);
- if (candright)
- BBPreleaseref(candright->batCacheid);
- return MAL_SUCCEED;
-
- fail:
- if (left)
- BBPreclaim(left);
- if (right)
- BBPreclaim(right);
- if (candleft)
- BBPreclaim(candleft);
- if (candright)
- BBPreclaim(candright);
- throw(MAL, "algebra.subouterjoin", RUNTIME_OBJECT_MISSING);
+ return do_join(r1, r2, lid, rid, slid, srid, NULL, estimate,
+ BATsubleftjoin, NULL, "algebra.subleftjoin");
}
str
-ALGsubouterjoin(bat *r1, bat *r2, bat *l, bat *r)
+ALGsubouterjoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid,
lng *estimate)
{
- return ALGsubouterjoin4(r1, r2, l, r, NULL, NULL);
+ return do_join(r1, r2, lid, rid, slid, srid, NULL, estimate,
+ BATsubouterjoin, NULL,
"algebra.subouterjoin");
}
str
-ALGsubthetajoin4(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid,
str *op)
+ALGsubthetajoin(bat *r1, bat *r2, bat *lid, bat *rid, bat *slid, bat *srid,
str *op, lng *estimate)
{
- BAT *left = NULL, *right = NULL, *candleft = NULL, *candright = NULL;
- BAT *result1, *result2;
-
- if ((left = BATdescriptor(*lid)) == NULL)
- goto fail;
- if ((right = BATdescriptor(*rid)) == NULL)
- goto fail;
- if (slid && (candleft = BATdescriptor(*slid)) == NULL)
- goto fail;
- if (srid && (candright = BATdescriptor(*srid)) == NULL)
- goto fail;
-
- if (BATsubthetajoin(&result1, &result2, left, right, candleft,
candright, *op, BUN_NONE) == GDK_FAIL)
- goto fail;
- *r1 = result1->batCacheid;
- *r2 = result2->batCacheid;
- BBPkeepref(*r1);
- BBPkeepref(*r2);
- BBPreleaseref(left->batCacheid);
- BBPreleaseref(right->batCacheid);
- if (candleft)
- BBPreleaseref(candleft->batCacheid);
- if (candright)
- BBPreleaseref(candright->batCacheid);
- return MAL_SUCCEED;
-
- fail:
- if (left)
- BBPreclaim(left);
- if (right)
- BBPreclaim(right);
- if (candleft)
- BBPreclaim(candleft);
- if (candright)
- BBPreclaim(candright);
- throw(MAL, "algebra.subthetajoin", RUNTIME_OBJECT_MISSING);
-}
-
-str
-ALGsubthetajoin(bat *r1, bat *r2, bat *l, bat *r, str *op)
-{
- return ALGsubthetajoin4(r1, r2, l, r, NULL, NULL, op);
+ return do_join(r1, r2, lid, rid, slid, srid, *op, estimate,
+ NULL, BATsubthetajoin,
"algebra.subthetajoin");
}
static str
@@ -3152,11 +3090,11 @@ ALGsubsort33(bat *result, bat *norder, b
if ((b = BATdescriptor(*bid)) == NULL)
throw(MAL, "algebra.subsort", RUNTIME_OBJECT_MISSING);
- if (order && (o = BATdescriptor(*order)) == NULL) {
+ if (order && *order && (o = BATdescriptor(*order)) == NULL) {
BBPreleaseref(b->batCacheid);
throw(MAL, "algebra.subsort", RUNTIME_OBJECT_MISSING);
}
- if (group && (g = BATdescriptor(*group)) == NULL) {
+ if (group && *group && (g = BATdescriptor(*group)) == NULL) {
if (o)
BBPreleaseref(o->batCacheid);
BBPreleaseref(b->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list