Changeset: 392772020e3d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=392772020e3d
Modified Files:
        gdk/gdk.h
        gdk/gdk_select.c
        monetdb5/modules/kernel/algebra.mx
Branch: default
Log Message:

Implemented algebra.thetasubselect similar to algebra.subselect.


diffs (129 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -3139,6 +3139,7 @@ gdk_export int BATtopN(BAT *b, BUN topN)
 #define JOIN_BAND      3
 
 gdk_export BAT *BATsubselect(BAT *b, BAT *s, const void *tl, const void *th, 
int li, int hi, int anti);
+gdk_export BAT *BATthetasubselect(BAT *b, BAT *s, const void *val, const char 
*op);
 gdk_export BAT *BATselect_(BAT *b, const void *tl, const void *th, bit li, bit 
hi);
 gdk_export BAT *BATuselect_(BAT *b, const void *tl, const void *th, bit li, 
bit hi);
 gdk_export BAT *BATantiuselect_(BAT *b, const void *tl, const void *th, bit 
li, bit hi);
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -730,3 +730,41 @@ BATuselect(BAT *b, const void *h, const 
 {
        return BATuselect_(b, h, t, TRUE, TRUE);
 }
+
+BAT *
+BATthetasubselect(BAT *b, BAT *s, const void *val, const char *op)
+{
+       const void *nil;
+
+       BATcheck(b, "BATthetasubselect");
+       BATcheck(val, "BATthetasubselect");
+       BATcheck(op, "BATthetasubselect");
+
+       if (op[0] == '=' && ((op[1] == '=' && op[2] == 0) || op[2] == 0)) {
+               /* "=" or "==" */
+               return BATsubselect(b, s, val, NULL, 1, 1, 0);
+       }
+       nil = ATOMnilptr(b->ttype);
+       if (op[0] == '<') {
+               if (op[1] == 0) {
+                       /* "<" */
+                       return BATsubselect(b, s, nil, val, 0, 0, 0);
+               }
+               if (op[1] == '=' && op[2] == 0) {
+                       /* "<=" */
+                       return BATsubselect(b, s, nil, val, 0, 1, 0);
+               }
+       }
+       if (op[0] == '>') {
+               if (op[1] == 0) {
+                       /* ">" */
+                       return BATsubselect(b, s, val, nil, 0, 0, 0);
+               }
+               if (op[1] == '=' && op[2] == 0) {
+                       /* ">=" */
+                       return BATsubselect(b, s, val, nil, 1, 0, 0);
+               }
+       }
+       GDKerror("BATthetasubselect: unknown operator.\n");
+       return NULL;
+}
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
@@ -135,6 +135,23 @@ comment "Select all head values of the f
        Note that the output is suitable as second input for this
        function.";
 
+command thetasubselect(b:bat[:oid,:any_1], val:any_1, op:str) :bat[:oid,:oid]
+address ALGthetasubselect1
+comment "Select all head values for which the tail value obeys the relation
+       value OP VAL.
+       Input is a dense-headed BAT, output is a dense-headed BAT with in
+       the tail the head value of the input BAT for which the
+       relationship holds.  The output BAT is sorted on the tail value.";
+
+command thetasubselect(b:bat[:oid,:any_1], s:bat[:oid,:oid], val:any_1, 
op:str) :bat[:oid,:oid]
+address ALGthetasubselect2
+comment "Select all head values of the first input BAT for which the tail value
+       obeys the relation value OP VAL and for which the head value occurs in
+       the tail of the second input BAT.
+       Input is a dense-headed BAT, output is a dense-headed BAT with in
+       the tail the head value of the input BAT for which the
+       relationship holds.  The output BAT is sorted on the tail value.";
+
 command select(b:bat[:any_1,:any_2], low:any_2, high:any_2) 
                :bat[:any_1,:any_2] 
 address ALGselect
@@ -981,6 +998,8 @@ algebra_export str ALGBATminimum(ptr *re
 algebra_export str ALGBATmaximum(ptr *result, int *bid);
 algebra_export str ALGsubselect1(bat *result, bat *bid, const void *low, const 
void *high, const bit *li, const bit *hi, const bit *anti);
 algebra_export str ALGsubselect2(bat *result, bat *bid, bat *sid, const void 
*low, const void *high, const bit *li, const bit *hi, const bit *anti);
+algebra_export str ALGthetasubselect1(bat *result, bat *bid, const void *val, 
const char **op);
+algebra_export str ALGthetasubselect2(bat *result, bat *bid, bat *sid, const 
void *val, const char **op);
 algebra_export str ALGselect1(int *result, int *bid, ptr value);
 algebra_export str ALGselect1Head(int *result, int *bid, ptr value);
 algebra_export str ALGuselect1(int *result, int *bid, ptr value);
@@ -1969,6 +1988,36 @@ ALGsubselect1(bat *result, bat *bid, con
 }
 
 str
+ALGthetasubselect2(bat *result, bat *bid, bat *sid, const void *val, const 
char **op)
+{
+       BAT *b, *s = NULL, *bn;
+
+       if ((b = BATdescriptor(*bid)) == NULL) {
+               throw(MAL, "algebra.select", RUNTIME_OBJECT_MISSING);
+       }
+       if (sid && (s = BATdescriptor(*sid)) == NULL) {
+               BBPreleaseref(b->batCacheid);
+               throw(MAL, "algebra.select", RUNTIME_OBJECT_MISSING);
+       }
+       @:derefStr(b,t,val)@
+       bn = BATthetasubselect(b, s, val, *op);
+       BBPreleaseref(b->batCacheid);
+       if (s)
+               BBPreleaseref(s->batCacheid);
+       if (bn == NULL)
+               throw(MAL, "algebra.subselect", GDK_EXCEPTION);
+       *result = bn->batCacheid;
+       BBPkeepref(bn->batCacheid);
+       return MAL_SUCCEED;
+}
+
+str
+ALGthetasubselect1(bat *result, bat *bid, const void *val, const char **op)
+{
+       return ALGthetasubselect2(result, bid, NULL, val, op);
+}
+
+str
 ALGselect1(int *result, int *bid, ptr value)
 {
        BAT *b, *bn = NULL;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to