Changeset: 1ef88e930ae3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1ef88e930ae3
Modified Files:
monetdb5/modules/kernel/algebra.c
Branch: default
Log Message:
Extended algebra.firstn: if asc is nil, no ordering but return dense bat.
This can then be used as alternative interface to algebra.subslice.
diffs (48 lines):
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
@@ -966,6 +966,10 @@ ALGintersect(Client ctx, bat *r1, const
* nilslast:bit,
* distinct:bit)
* returns :bat[:oid] [ , :bat[:oid] ]
+ *
+ * if asc is nil, there is no sorting and a second return value is not
+ * allowed; the result is a dense sequence starting at offset (default
+ * 0) + hseqbase of length n.
*/
static str
ALGfirstn(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
@@ -1006,7 +1010,9 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
}
n = *getArgReference_lng(stk, pci, pci->retc + 3);
- if (n < 0) {
+ if (is_lng_nil(n)) {
+ n = BUN_MAX;
+ } else if (n < 0) {
BBPreclaim(b);
BBPreclaim(s);
BBPreclaim(g);
@@ -1037,7 +1043,21 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
nilslast = *getArgReference_bit(stk, pci, pci->argc - 2);
distinct = *getArgReference_bit(stk, pci, pci->argc - 1);
- if (o > 0) {
+ if (is_bit_nil(asc)) {
+ if (ret2) {
+ BBPreclaim(b);
+ BBPreclaim(s);
+ BBPreclaim(g);
+ throw(MAL, "algebra.firstn", ILLEGAL_ARGUMENT);
+ }
+ if (o > (lng) BATcount(b))
+ o = (lng) BATcount(b);
+ if (o + n > (lng) BATcount(b))
+ n = (lng) BATcount(b) - o;
+ bn = BATdense(0, b->hseqbase + o, n);
+ if (bn == NULL)
+ rc = GDK_FAIL;
+ } else if (o > 0) {
bn = BATfirstn_offset(b, s, g, (BUN) n, (BUN) o, asc, nilslast,
distinct);
if (bn == NULL)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]