Changeset: b29566957bc1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b29566957bc1
Modified Files:
        gdk/gdk.h
        gdk/gdk_join.c
        gdk/gdk_select.c
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/kernel/algebra.h
        monetdb5/modules/kernel/algebra.mal
        sql/backends/monet5/sql_gencode.c
Branch: arrays
Log Message:

handling not-equal case, e.g. select * from array where x<>9


diffs (truncated from 326 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -3197,6 +3197,7 @@ gdk_export void BATsetprop(BAT *b, int i
 gdk_export BAT *BATsubselect(BAT *b, BAT *s, const void *tl, const void *th, 
int li, int hi, int anti);
 gdk_export BAT *BATdimensionSubselect(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 *BATdimensionThetasubselect(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 *BATselect(BAT *b, const void *tl, const void *th);
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3445,6 +3445,7 @@ BAT* BATdimensionProject(BAT* oidsBAT, B
                 break; \
             } \
         } \
+fprintf(stderr, "repeat1 = %ld\n", repeat1); \
 \
         elementsNum = floor((max-min)/step) + 1; \
 \
@@ -3460,7 +3461,7 @@ BAT* BATdimensionProject(BAT* oidsBAT, B
                    resBAT->tkey = 0;                   \
            } else {                        \
                                long el = (*o%(repeat1*elementsNum))/repeat1; \
-                               fprintf(stderr, "element: %ld\n", el); \
+                               fprintf(stderr, "oid=%u : element: %ld\n", 
*(int*)o, el); \
                    *bt = min+el*step;           \
                }                           \
        }                               \
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1697,9 +1697,9 @@ BATsubselect(BAT *b, BAT *s, const void 
 
 BAT *
 BATdimensionSubselect(BAT *inBAT, BAT *candBAT, const void *low, const void 
*high, int li, int hi, int anti) {
+       oid elements_in_result =0;
        int type;
        const void *nil;
-       oid elements_in_result =0;
        BAT *b_tmp, *resBAT;
 
        type = inBAT->ttype;
@@ -1749,7 +1749,6 @@ BATdimensionSubselect(BAT *inBAT, BAT *c
                 break; \
         } \
 \
-               element_oid *= repeat1; \
        } while(0)
                
                switch (ATOMtype(type)) {
@@ -1784,39 +1783,86 @@ BATdimensionSubselect(BAT *inBAT, BAT *c
             return NULL;
        }
 
-               elements_in_result = repeat1*repeat2;
+               if(element_oid >= elementsNum) { //the element dows not exist
+                       elements_in_result = 0;
 
-               //create new BAT
-               if((b_tmp = BATnew(TYPE_void, TYPE_oid, elements_in_result, 
TRANSIENT)) == NULL)   \
-                       return NULL;
+                       //create new empty BAT
+                       if((b_tmp = BATnew(TYPE_void, TYPE_oid, 
elements_in_result, TRANSIENT)) == NULL)   \
+                               return NULL;
+
+               } else {
+                       element_oid *= repeat1;
+
+                       elements_in_result = repeat1*repeat2;
+
+                       //create new BAT
+                       if((b_tmp = BATnew(TYPE_void, TYPE_oid, 
elements_in_result, TRANSIENT)) == NULL)   \
+                               return NULL;
                
-               res = (oid*) Tloc(b_tmp, BUNfirst(b_tmp));
-               //add the oids in the result
-               for(j=0; j<repeat2; j++) {
-                       for(i=0; i<repeat1; i++) {
-                               fprintf(stderr, "Added oid: %ld\n", 
element_oid);
-                               *res = element_oid;
-                               res++;
-                               element_oid++;
+                       res = (oid*) Tloc(b_tmp, BUNfirst(b_tmp));
+                       //add the oids in the result
+                       for(j=0; j<repeat2; j++) {
+                               for(i=0; i<repeat1; i++) {
+                                       fprintf(stderr, "Added oid: %ld\n", 
element_oid);
+                                       *res = element_oid;
+                                       res++;
+                                       element_oid++;
+                               }
+               
+                               element_oid += ((elementsNum*repeat1) - 
repeat1);
                        }
+               }
                
-                       element_oid += ((elementsNum*repeat1) - repeat1);
+               if(anti) { //the oids that do not qualify are those that should 
be returned
+                       oid io, jo;
+                       oid endOid = elementsNum*repeat1*repeat2;
+                       oid* res_anti;
+                       BAT *b_anti = BATnew(TYPE_void, TYPE_oid, 
endOid-elements_in_result, TRANSIENT);
+
+                       if(!b_anti)
+                               return NULL;
+
+                       res_anti = (oid*)Tloc(b_anti, BUNfirst(b_anti));
+                       res = (oid*) Tloc(b_tmp, BUNfirst(b_tmp));
+
+                       for(io=0, jo=0; io<endOid && jo<elements_in_result; 
io++) {
+                               if(io == res[jo]) { //the oid is in the result 
-> skip it
+                                       jo++;
+                               } else {
+                                       fprintf(stderr, "Added anti oid: 
%ld\n", io);
+                                       *res_anti = io;
+                                       res_anti++;     
+                               }
+                       }
+
+                       //add any oids that are greater than the last qualifying
+                       for(; io<endOid; io++) {
+                               fprintf(stderr, "Added anti oid: %ld\n", io);
+                               *res_anti=io;
+                               res_anti++;
+                       }
+
+                       elements_in_result = endOid-elements_in_result;
+                       b_tmp = b_anti;
                }
                
                BATsetcount(b_tmp,elements_in_result);
-               
+
        } else {
-               if((b_tmp = BATnew(TYPE_void, TYPE_oid, elements_in_result, 
TRANSIENT)) == NULL)   \
+               if((b_tmp = BATnew(TYPE_void, TYPE_oid, elements_in_result, 
TRANSIENT)) == NULL)
             return NULL;
+
+               BATsetcount(b_tmp, elements_in_result);
        }
 
+       //if the result should be 
        if(candBAT) {
         oid *current_elements, *cand_elements, *elements;
         oid i, j;
 
         elements_in_result = (BATcount(b_tmp) > 
BATcount(candBAT))?BATcount(candBAT):BATcount(b_tmp);
 
-        if((resBAT = BATnew(TYPE_void, TYPE_oid, elements_in_result, 
TRANSIENT)) == NULL)   \
+        if((resBAT = BATnew(TYPE_void, TYPE_oid, elements_in_result, 
TRANSIENT)) == NULL)
             return NULL;
 
         cand_elements = (oid*)Tloc(candBAT, BUNfirst(candBAT));
@@ -1880,6 +1926,57 @@ BATthetasubselect(BAT *b, BAT *s, const 
                return newempty("BATthetasubselect");
        if (op[0] == '=' && ((op[1] == '=' && op[2] == 0) || op[2] == 0)) {
                /* "=" or "==" */
+               //equality => call simple subselect
+               return BATdimensionSubselect(b, s, val, NULL, 1, 1, 0);
+       }
+       if (op[0] == '!' && op[1] == '=' && op[2] == 0) {
+               /* "!=" (equivalent to "<>") */
+               //not equal to => simple subselect that returns all but the oids
+               //of the qualifying value
+               return BATdimensionSubselect(b, s, val, NULL, 1, 1, 1);
+       }
+       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[1] == '>' && op[2] == 0) {
+                       /* "<>" (equivalent to "!=") */
+                       return BATsubselect(b, s, val, NULL, 1, 1, 1);
+               }
+       }
+       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;
+}
+
+BAT *
+BATdimensionThetasubselect(BAT *b, BAT *s, const void *val, const char *op)
+{
+       const void *nil;
+
+       BATcheck(b, "BATdimensionThetasubselect", NULL);
+       BATcheck(val, "BATdimensionThetasubselect", NULL);
+       BATcheck(op, "BATdimensoinThetasubselect", NULL);
+
+       nil = ATOMnilptr(b->ttype);
+       if (ATOMcmp(b->ttype, val, nil) == 0)
+               return newempty("BATdimensionThetasubselect");
+       if (op[0] == '=' && ((op[1] == '=' && op[2] == 0) || op[2] == 0)) {
+               /* "=" or "==" */
                return BATsubselect(b, s, val, NULL, 1, 1, 0);
        }
        if (op[0] == '!' && op[1] == '=' && op[2] == 0) {
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
@@ -427,6 +427,37 @@ ALGthetasubselect1(bat *result, const ba
 }
 
 str
+ALGdimensionThetasubselect2(bat *result, const bat *bid, const bat *sid, const 
void *val, const char **op)
+{
+       BAT *b, *s = NULL, *bn;
+
+       if ((b = BATdescriptor(*bid)) == NULL) {
+               throw(MAL, "algebra.thetasubselect", RUNTIME_OBJECT_MISSING);
+       }
+       if (sid && *sid != bat_nil && (s = BATdescriptor(*sid)) == NULL) {
+               BBPunfix(b->batCacheid);
+               throw(MAL, "algebra.thetasubselect", RUNTIME_OBJECT_MISSING);
+       }
+       derefStr(b, t, val);
+       bn = BATdimensionThetasubselect(b, s, val, *op);
+       BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
+       if (bn == NULL)
+               throw(MAL, "algebra.subselect", GDK_EXCEPTION);
+       if (!(bn->batDirty&2)) BATsetaccess(bn, BAT_READ);
+       *result = bn->batCacheid;
+       BBPkeepref(bn->batCacheid);
+       return MAL_SUCCEED;
+}
+
+str
+ALGdimensionThetasubselect1(bat *result, const bat *bid, const void *val, 
const char **op)
+{
+       return ALGdimensionThetasubselect2(result, bid, NULL, val, op);
+}
+
+str
 ALGselect1(bat *result, const bat *bid, ptr value)
 {
        BAT *b, *bn = NULL;
diff --git a/monetdb5/modules/kernel/algebra.h 
b/monetdb5/modules/kernel/algebra.h
--- a/monetdb5/modules/kernel/algebra.h
+++ b/monetdb5/modules/kernel/algebra.h
@@ -38,6 +38,8 @@ algebra_export str ALGdimensionSubselect
 algebra_export str ALGdimensionSubselect2(bat *result, const bat *bid, const 
bat *sid, const void *low, const void *high, const bit *li, const bit *hi, 
const bit *anti);
 algebra_export str ALGthetasubselect1(bat *result, const bat *bid, const void 
*val, const char **op);
 algebra_export str ALGthetasubselect2(bat *result, const bat *bid, const bat 
*sid, const void *val, const char **op);
+algebra_export str ALGdimensionThetasubselect1(bat *result, const bat *bid, 
const void *val, const char **op);
+algebra_export str ALGdimensionThetasubselect2(bat *result, const bat *bid, 
const bat *sid, const void *val, const char **op);
 algebra_export str ALGselect1(bat *result, const bat *bid, ptr value);
 algebra_export str ALGselect(bat *result, const bat *bid, ptr low, ptr high);
 algebra_export str ALGselectInclusive(bat *result, const bat *bid, ptr low, 
ptr high, const bit *lin, const bit *rin);
diff --git a/monetdb5/modules/kernel/algebra.mal 
b/monetdb5/modules/kernel/algebra.mal
--- a/monetdb5/modules/kernel/algebra.mal
+++ b/monetdb5/modules/kernel/algebra.mal
@@ -88,14 +88,6 @@ comment "Select all head values of the f
        Note that the output is suitable as second input for this
        function.";
 
-
-command dimension_subselect(b:bat[:oid, :any], low:any, high:any, li:bit, 
hi:bit, anti:bit):bat[:oid,:oid]
-address ALGdimensionSubselect1;
-
-command dimension_subselect(b:bat[:oid,:any], cand:bat[:oid,:oid], low:any, 
high:any, li:bit, hi:bit, anti:bit):bat[:oid,:oid]
-address ALGdimensionSubselect2;
-
-
 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
@@ -113,6 +105,18 @@ comment "Select all head values of the f
        the tail the head value of the input BAT for which the
        relationship holds.  The output BAT is sorted on the tail value.";
 
+command dimension_subselect(b:bat[:oid, :any], low:any, high:any, li:bit, 
hi:bit, anti:bit):bat[:oid,:oid]
+address ALGdimensionSubselect1;
+
+command dimension_subselect(b:bat[:oid,:any], cand:bat[:oid,:oid], low:any, 
high:any, li:bit, hi:bit, anti:bit):bat[:oid,:oid]
+address ALGdimensionSubselect2;
+
+command dimension_thetasubselect(b:bat[:oid,:any], val:any, op:str) 
:bat[:oid,:oid]
+address ALGdimensionThetasubselect1;
+
+command dimension_thetasubselect(b:bat[:oid,:any], s:bat[:oid,:oid], val:any, 
op:str) :bat[:oid,:oid]
+address ALGdimensionThetasubselect2;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to