Changeset: c0b37d366ae4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c0b37d366ae4
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
clients/Tests/exports.stable.out
gdk/gdk_aggr.c
gdk/gdk_calc.h
monetdb5/modules/kernel/algebra.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_statistics.c
sql/backends/monet5/sql_subquery.c
Branch: pushcands
Log Message:
aggr.{min,max} now have optional candidate lists.
diffs (truncated from 394 to 300 lines):
diff --git a/clients/Tests/MAL-signatures.stable.out
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -142,11 +142,15 @@ stdout of test 'MAL-signatures` in direc
[ "aggr", "jsonaggr", "command aggr.jsonaggr(X_0:bat[:dbl]):str ",
"JSONgroupStr;", "" ]
[ "aggr", "jsonaggr", "command aggr.jsonaggr(X_0:bat[:str]):str ",
"JSONgroupStr;", "" ]
[ "aggr", "max", "command aggr.max(X_0:bat[:any_1], X_1:bat[:oid],
X_2:bat[:any_2]):bat[:any_1] ", "AGGRmax3;", "" ]
+[ "aggr", "max", "command aggr.max(X_0:bat[:any_2], X_1:bat[:oid]):any_2
", "ALGmaxany2;", "" ]
+[ "aggr", "max", "command aggr.max(X_0:bat[:any_2], X_1:bit,
X_2:bat[:oid]):any_2 ", "ALGmaxany2_skipnil;", "" ]
[ "aggr", "max", "command aggr.max(X_0:bat[:any_2]):any_2 ",
"ALGmaxany;", "" ]
[ "aggr", "max", "command aggr.max(X_0:bat[:any_2], X_1:bit):any_2 ",
"ALGmaxany_skipnil;", "" ]
[ "aggr", "median", "command aggr.median(X_0:bat[:any_1]):any_1 ",
"AGGRmedian;", "" ]
[ "aggr", "median_avg", "command aggr.median_avg(X_0:bat[:any_1]):dbl
", "AGGRmedian_avg;", "" ]
[ "aggr", "min", "command aggr.min(X_0:bat[:any_1], X_1:bat[:oid],
X_2:bat[:any_2]):bat[:any_1] ", "AGGRmin3;", "" ]
+[ "aggr", "min", "command aggr.min(X_0:bat[:any_2], X_1:bat[:oid]):any_2
", "ALGminany2;", "" ]
+[ "aggr", "min", "command aggr.min(X_0:bat[:any_2], X_1:bit,
X_2:bat[:oid]):any_2 ", "ALGminany2_skipnil;", "" ]
[ "aggr", "min", "command aggr.min(X_0:bat[:any_2]):any_2 ",
"ALGminany;", "" ]
[ "aggr", "min", "command aggr.min(X_0:bat[:any_2], X_1:bit):any_2 ",
"ALGminany_skipnil;", "" ]
[ "aggr", "not_anyequal", "pattern aggr.not_anyequal(X_0:any_1,
X_1:any_1):bit ", "CMDvarNE;", "" ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -153,11 +153,15 @@ stdout of test 'MAL-signatures` in direc
[ "aggr", "jsonaggr", "command aggr.jsonaggr(X_0:bat[:dbl]):str ",
"JSONgroupStr;", "" ]
[ "aggr", "jsonaggr", "command aggr.jsonaggr(X_0:bat[:str]):str ",
"JSONgroupStr;", "" ]
[ "aggr", "max", "command aggr.max(X_0:bat[:any_1], X_1:bat[:oid],
X_2:bat[:any_2]):bat[:any_1] ", "AGGRmax3;", "" ]
+[ "aggr", "max", "command aggr.max(X_0:bat[:any_2], X_1:bat[:oid]):any_2
", "ALGmaxany2;", "" ]
+[ "aggr", "max", "command aggr.max(X_0:bat[:any_2], X_1:bit,
X_2:bat[:oid]):any_2 ", "ALGmaxany2_skipnil;", "" ]
[ "aggr", "max", "command aggr.max(X_0:bat[:any_2]):any_2 ",
"ALGmaxany;", "" ]
[ "aggr", "max", "command aggr.max(X_0:bat[:any_2], X_1:bit):any_2 ",
"ALGmaxany_skipnil;", "" ]
[ "aggr", "median", "command aggr.median(X_0:bat[:any_1]):any_1 ",
"AGGRmedian;", "" ]
[ "aggr", "median_avg", "command aggr.median_avg(X_0:bat[:any_1]):dbl
", "AGGRmedian_avg;", "" ]
[ "aggr", "min", "command aggr.min(X_0:bat[:any_1], X_1:bat[:oid],
X_2:bat[:any_2]):bat[:any_1] ", "AGGRmin3;", "" ]
+[ "aggr", "min", "command aggr.min(X_0:bat[:any_2], X_1:bat[:oid]):any_2
", "ALGminany2;", "" ]
+[ "aggr", "min", "command aggr.min(X_0:bat[:any_2], X_1:bit,
X_2:bat[:oid]):any_2 ", "ALGminany2_skipnil;", "" ]
[ "aggr", "min", "command aggr.min(X_0:bat[:any_2]):any_2 ",
"ALGminany;", "" ]
[ "aggr", "min", "command aggr.min(X_0:bat[:any_2], X_1:bit):any_2 ",
"ALGminany_skipnil;", "" ]
[ "aggr", "not_anyequal", "pattern aggr.not_anyequal(X_0:any_1,
X_1:any_1):bit ", "CMDvarNE;", "" ]
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
@@ -159,12 +159,12 @@ gdk_return BATkey(BAT *b, bool onoff);
bool BATkeyed(BAT *b);
gdk_return BATleftjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr,
bool nil_matches, BUN estimate) __attribute__((__warn_unused_result__));
BAT *BATmaskedcands(oid hseq, BUN nr, BAT *masked, bool selected);
-void *BATmax(BAT *b, void *aggr);
-void *BATmax_skipnil(BAT *b, void *aggr, bit skipnil);
+void *BATmax(void *aggr, BAT *b, BAT *s);
+void *BATmax_skipnil(void *aggr, BAT *b, BAT *s, bit skipnil);
BAT *BATmergecand(BAT *a, BAT *b);
BAT *BATmergecand(BAT *a, BAT *b);
-void *BATmin(BAT *b, void *aggr);
-void *BATmin_skipnil(BAT *b, void *aggr, bit skipnil);
+void *BATmin(void *aggr, BAT *b, BAT *s);
+void *BATmin_skipnil(void *aggr, BAT *b, BAT *s, bit skipnil);
gdk_return BATmode(BAT *b, bool transient);
void BATmsync(BAT *b);
BAT *BATnegcands(BUN nr, BAT *odels);
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -3515,12 +3515,13 @@ BATgroupmin(BAT *b, BAT *g, BAT *e, BAT
/* return pointer to smallest non-nil value in b, or pointer to nil if
* there is no such value (no values at all, or only nil) */
void *
-BATmin_skipnil(BAT *b, void *aggr, bit skipnil)
+BATmin_skipnil(void *aggr, BAT *b, BAT *s, bit skipnil)
{
const ValRecord *prop;
const void *res;
- size_t s;
+ size_t sz;
BATiter bi;
+ struct canditer ci;
lng t0 = 0;
TRC_DEBUG_IF(ALGO) t0 = GDKusec();
@@ -3531,9 +3532,10 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
GDKerror("non-linear type");
return NULL;
}
- if (BATcount(b) == 0) {
+ if (canditer_init(&ci, b, s) == 0) {
res = ATOMnilptr(b->ttype);
- } else if ((prop = BATgetprop(b, GDK_MIN_VALUE)) != NULL) {
+ } else if (ci.tpe == cand_dense && ci.ncand == BATcount(b) &&
+ (prop = BATgetprop(b, GDK_MIN_VALUE)) != NULL) {
res = VALptr(prop);
} else {
oid pos;
@@ -3587,14 +3589,12 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
}
}
} else {
- struct canditer ci;
- BUN ncand = canditer_init(&ci, b, NULL);
- (void) do_groupmin(&pos, b, NULL, 1, 0, 0, &ci, ncand,
+ (void) do_groupmin(&pos, b, NULL, 1, 0, 0, &ci,
ci.ncand,
BATcount(b), skipnil, false);
}
if (is_oid_nil(pos)) {
res = ATOMnilptr(b->ttype);
- } else {
+ } else if (ci.tpe == cand_dense && ci.ncand == BATcount(b)) {
bi = bat_iterator(b);
res = BUNtail(bi, pos - b->hseqbase);
BATsetprop(b, GDK_MIN_VALUE, b->ttype, res);
@@ -3602,22 +3602,22 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
}
}
if (aggr == NULL) {
- s = ATOMlen(b->ttype, res);
- aggr = GDKmalloc(s);
+ sz = ATOMlen(b->ttype, res);
+ aggr = GDKmalloc(sz);
} else {
- s = ATOMsize(ATOMtype(b->ttype));
+ sz = ATOMsize(ATOMtype(b->ttype));
}
if (aggr != NULL) /* else: malloc error */
- memcpy(aggr, res, s);
+ memcpy(aggr, res, sz);
TRC_DEBUG(ALGO, "b=" ALGOBATFMT ",skipnil=%d; (" LLFMT " usec)\n",
ALGOBATPAR(b), skipnil, GDKusec() - t0);
return aggr;
}
void *
-BATmin(BAT *b, void *aggr)
+BATmin(void *aggr, BAT *b, BAT *s)
{
- return BATmin_skipnil(b, aggr, 1);
+ return BATmin_skipnil(aggr, b, s, 1);
}
BAT *
@@ -3629,12 +3629,13 @@ BATgroupmax(BAT *b, BAT *g, BAT *e, BAT
}
void *
-BATmax_skipnil(BAT *b, void *aggr, bit skipnil)
+BATmax_skipnil(void *aggr, BAT *b, BAT *s, bit skipnil)
{
const ValRecord *prop;
const void *res;
- size_t s;
+ size_t sz;
BATiter bi;
+ struct canditer ci;
lng t0 = 0;
TRC_DEBUG_IF(ALGO) t0 = GDKusec();
@@ -3643,9 +3644,10 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
GDKerror("non-linear type");
return NULL;
}
- if (BATcount(b) == 0) {
+ if (canditer_init(&ci, b, s) == 0) {
res = ATOMnilptr(b->ttype);
- } else if ((prop = BATgetprop(b, GDK_MAX_VALUE)) != NULL) {
+ } else if (ci.tpe == cand_dense && ci.ncand == BATcount(b) &&
+ (prop = BATgetprop(b, GDK_MAX_VALUE)) != NULL) {
res = VALptr(prop);
} else {
oid pos;
@@ -3690,14 +3692,12 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
}
}
} else {
- struct canditer ci;
- BUN ncand = canditer_init(&ci, b, NULL);
- (void) do_groupmax(&pos, b, NULL, 1, 0, 0, &ci, ncand,
+ (void) do_groupmax(&pos, b, NULL, 1, 0, 0, &ci,
ci.ncand,
BATcount(b), skipnil, false);
}
if (is_oid_nil(pos)) {
res = ATOMnilptr(b->ttype);
- } else {
+ } else if (ci.tpe == cand_dense && ci.ncand == BATcount(b)) {
bi = bat_iterator(b);
res = BUNtail(bi, pos - b->hseqbase);
if (b->tnonil) {
@@ -3707,22 +3707,22 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
}
}
if (aggr == NULL) {
- s = ATOMlen(b->ttype, res);
- aggr = GDKmalloc(s);
+ sz = ATOMlen(b->ttype, res);
+ aggr = GDKmalloc(sz);
} else {
- s = ATOMsize(ATOMtype(b->ttype));
+ sz = ATOMsize(ATOMtype(b->ttype));
}
if (aggr != NULL) /* else: malloc error */
- memcpy(aggr, res, s);
+ memcpy(aggr, res, sz);
TRC_DEBUG(ALGO, "b=" ALGOBATFMT ",skipnil=%d; (" LLFMT " usec)\n",
ALGOBATPAR(b), skipnil, GDKusec() - t0);
return aggr;
}
void *
-BATmax(BAT *b, void *aggr)
+BATmax(void *aggr, BAT *b, BAT *s)
{
- return BATmax_skipnil(b, aggr, 1);
+ return BATmax_skipnil(aggr, b, s, 1);
}
diff --git a/gdk/gdk_calc.h b/gdk/gdk_calc.h
--- a/gdk/gdk_calc.h
+++ b/gdk/gdk_calc.h
@@ -143,10 +143,10 @@ gdk_export const char *BATgroupaggrinit(
gdk_export gdk_return BATsum(void *res, int tp, BAT *b, BAT *s, bool
skip_nils, bool abort_on_error, bool nil_if_empty);
gdk_export gdk_return BATprod(void *res, int tp, BAT *b, BAT *s, bool
skip_nils, bool abort_on_error, bool nil_if_empty);
-gdk_export void *BATmax(BAT *b, void *aggr);
-gdk_export void *BATmin(BAT *b, void *aggr);
-gdk_export void *BATmax_skipnil(BAT *b, void *aggr, bit skipnil);
-gdk_export void *BATmin_skipnil(BAT *b, void *aggr, bit skipnil);
+gdk_export void *BATmax(void *aggr, BAT *b, BAT *s);
+gdk_export void *BATmin(void *aggr, BAT *b, BAT *s);
+gdk_export void *BATmax_skipnil(void *aggr, BAT *b, BAT *s, bit skipnil);
+gdk_export void *BATmin_skipnil(void *aggr, BAT *b, BAT *s, bit skipnil);
gdk_export dbl BATcalcstdev_population(dbl *avgp, BAT *b, BAT *s);
gdk_export dbl BATcalcstdev_sample(dbl *avgp, BAT *b, BAT *s);
diff --git a/monetdb5/modules/kernel/algebra.c
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -126,13 +126,16 @@ slice(BAT **retval, BAT *b, lng start, l
*/
static str
-ALGminany_skipnil(ptr result, const bat *bid, const bit *skipnil)
+ALGminany2_skipnil(ptr result, const bat *bid, const bit *skipnil, const bat
*sid)
{
BAT *b;
+ BAT *s = NULL;
ptr p;
str msg = MAL_SUCCEED;
- if (result == NULL || (b = BATdescriptor(*bid)) == NULL)
+ if (result == NULL ||
+ (b = BATdescriptor(*bid)) == NULL ||
+ (sid == NULL && !is_bat_nil(*sid) && (s = BATdescriptor(*sid))
== NULL))
throw(MAL, "algebra.min", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
if (!ATOMlinear(b->ttype)) {
@@ -141,9 +144,9 @@ ALGminany_skipnil(ptr result, const bat
ATOMname(b->ttype));
} else {
if (ATOMextern(b->ttype)) {
- * (ptr *) result = p = BATmin_skipnil(b, NULL,
*skipnil);
+ * (ptr *) result = p = BATmin_skipnil(NULL, b, NULL,
*skipnil);
} else {
- p = BATmin_skipnil(b, result, *skipnil);
+ p = BATmin_skipnil(result, b, s, *skipnil);
if ( p != result )
msg = createException(MAL, "algebra.min",
SQLSTATE(HY002) "INTERNAL ERROR");
}
@@ -155,20 +158,34 @@ ALGminany_skipnil(ptr result, const bat
}
static str
+ALGminany_skipnil(ptr result, const bat *bid, const bit *skipnil)
+{
+ return ALGminany2_skipnil(result, bid, skipnil, NULL);
+}
+
+static str
ALGminany(ptr result, const bat *bid)
{
- bit skipnil = TRUE;
- return ALGminany_skipnil(result, bid, &skipnil);
+ return ALGminany2_skipnil(result, bid, &(bit){TRUE}, NULL);
}
static str
-ALGmaxany_skipnil(ptr result, const bat *bid, const bit *skipnil)
+ALGminany2(ptr result, const bat *bid, const bat *sid)
+{
+ return ALGminany2_skipnil(result, bid, &(bit){TRUE}, sid);
+}
+
+static str
+ALGmaxany2_skipnil(ptr result, const bat *bid, const bit *skipnil, const bat
*sid)
{
BAT *b;
+ BAT *s = NULL;
ptr p;
str msg = MAL_SUCCEED;
- if (result == NULL || (b = BATdescriptor(*bid)) == NULL)
+ if (result == NULL ||
+ (b = BATdescriptor(*bid)) == NULL ||
+ (sid == NULL && !is_bat_nil(*sid) && (s = BATdescriptor(*sid))
== NULL))
throw(MAL, "algebra.max", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list