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

materialise dimension before output


diffs (truncated from 427 to 300 lines):

diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1927,13 +1927,13 @@ BATthetasubselect(BAT *b, BAT *s, const 
        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);
+               return BATsubselect(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);
+               return BATsubselect(b, s, val, NULL, 1, 1, 1);
        }
        if (op[0] == '<') {
                if (op[1] == 0) {
@@ -1977,11 +1977,11 @@ BATdimensionThetasubselect(BAT *b, BAT *
                return newempty("BATdimensionThetasubselect");
        if (op[0] == '=' && ((op[1] == '=' && op[2] == 0) || op[2] == 0)) {
                /* "=" or "==" */
-               return BATsubselect(b, s, val, NULL, 1, 1, 0);
+               return BATdimensionSubselect(b, s, val, NULL, 1, 1, 0);
        }
        if (op[0] == '!' && op[1] == '=' && op[2] == 0) {
                /* "!=" (equivalent to "<>") */
-               return BATsubselect(b, s, val, NULL, 1, 1, 1);
+               return BATdimensionSubselect(b, s, val, NULL, 1, 1, 1);
        }
        if (op[0] == '<') {
                if (op[1] == 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
@@ -413,7 +413,7 @@ ALGthetasubselect2(bat *result, const ba
        if (s)
                BBPunfix(s->batCacheid);
        if (bn == NULL)
-               throw(MAL, "algebra.subselect", GDK_EXCEPTION);
+               throw(MAL, "algebra.thetasubselect", GDK_EXCEPTION);
        if (!(bn->batDirty&2)) BATsetaccess(bn, BAT_READ);
        *result = bn->batCacheid;
        BBPkeepref(bn->batCacheid);
@@ -432,11 +432,11 @@ ALGdimensionThetasubselect2(bat *result,
        BAT *b, *s = NULL, *bn;
 
        if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(MAL, "algebra.thetasubselect", RUNTIME_OBJECT_MISSING);
+               throw(MAL, "algebra.dimension_thetasubselect", 
RUNTIME_OBJECT_MISSING);
        }
        if (sid && *sid != bat_nil && (s = BATdescriptor(*sid)) == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "algebra.thetasubselect", RUNTIME_OBJECT_MISSING);
+               throw(MAL, "algebra.dimension_thetasubselect", 
RUNTIME_OBJECT_MISSING);
        }
        derefStr(b, t, val);
        bn = BATdimensionThetasubselect(b, s, val, *op);
@@ -444,7 +444,7 @@ ALGdimensionThetasubselect2(bat *result,
        if (s)
                BBPunfix(s->batCacheid);
        if (bn == NULL)
-               throw(MAL, "algebra.subselect", GDK_EXCEPTION);
+               throw(MAL, "algebra.dimension_thetasubselect", GDK_EXCEPTION);
        if (!(bn->batDirty&2)) BATsetaccess(bn, BAT_READ);
        *result = bn->batCacheid;
        BBPkeepref(bn->batCacheid);
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
@@ -117,7 +117,6 @@ address ALGdimensionThetasubselect1;
 command dimension_thetasubselect(b:bat[:oid,:any], s:bat[:oid,:oid], val:any, 
op:str) :bat[:oid,:oid]
 address ALGdimensionThetasubselect2;
 
-
 command select(b:bat[:oid,:any_2], low:any_2, high:any_2):bat[:oid,:any_2]
 address ALGselect
 comment "Select all BUNs that have tail values: {v| low <= v <= high}.
diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -45,6 +45,7 @@ str binddbatRef;
 str bindidxRef;
 str bindRef;
 str createDimRef;
+str materialiseDimRef;
 str bpmRef;
 str bstreamRef;
 str calcRef;
@@ -298,6 +299,7 @@ void optimizerInit(void)
        bindidxRef = putName("bind_idxbat",11);
        bindRef = putName("bind",4);
        createDimRef = putName("create_dimension",16);
+       materialiseDimRef = putName("materialise_dimension",21);
        bpmRef = putName("bpm",3);
        bstreamRef = putName("bstream",7);
        calcRef = putName("calc",4);
diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h
--- a/monetdb5/optimizer/opt_prelude.h
+++ b/monetdb5/optimizer/opt_prelude.h
@@ -43,6 +43,7 @@ opt_export  str binddbatRef;
 opt_export  str bindidxRef;
 opt_export  str bindRef;
 opt_export  str createDimRef;
+opt_export  str materialiseDimRef;
 opt_export  str bpmRef;
 opt_export  str bstreamRef;
 opt_export  str calcRef;
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -2252,7 +2252,9 @@ rel2bin_project( mvc *sql, sql_rel *rel,
                        s = const_column(sql->sa, s);
                else if (sub && sub->nrcols >= 1 && s->nrcols == 0)
                        s = stmt_const(sql->sa, bin_first_column(sql->sa, sub), 
s);
-                       
+       
+               if(exp->type == e_dimension)
+                       s = stmt_materialise(sql->sa, s);       
                s = stmt_rename(sql, rel, exp, s);
                column_name(sql->sa, s); /* save column name */
                list_append(pl, s);
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -1786,7 +1786,7 @@ mvc_create_dimension_bat(mvc *m, char *s
        if (dim == NULL)
                return NULL;
        
-#define materialiseDim(TPE, min, step, max)                     \
+#define createDim(TPE, min, step, max)                     \
     do {                                \
                        TPE /*it,*/ *elements = NULL; \
                        long repeat1, repeat2, i, j; \
@@ -1794,7 +1794,6 @@ mvc_create_dimension_bat(mvc *m, char *s
                        repeat1 = dim->lvl1_repeatsNum; \
                        repeat2 = dim->lvl2_repeatsNum; \
 \
-/*             if((b = BATnew(TYPE_void, TYPE_##TPE, t->cellsNum, TRANSIENT)) 
== NULL)*/   \
                        if((b = BATnew(TYPE_void, TYPE_##TPE, 
repeat1+repeat2+1, TRANSIENT)) == NULL) \
                        return NULL;                   \
 \
@@ -1811,15 +1810,6 @@ mvc_create_dimension_bat(mvc *m, char *s
 \
                        *elements = step; \
 \
-                       /*for(j=0; j<repeat2; j++) { \
-                       for(it = min ; it <= max ; it += step) { \
-                       for(i=0; i<repeat1; i++) { \
-                               *elements = (TPE) it; \
-                               elements++; \
-                       } \
-                       } \
-               } */\
-\
                b->tsorted = 0;              \
                b->trevsorted = 0;           \
     } while (0)
@@ -1830,27 +1820,27 @@ mvc_create_dimension_bat(mvc *m, char *s
 
        switch (dim->type.type->localtype) {
        case TYPE_bte:
-           materialiseDim(bte, dim->min->data.val.btval, 
dim->step->data.val.btval, dim->max->data.val.btval);
+           createDim(bte, dim->min->data.val.btval, dim->step->data.val.btval, 
dim->max->data.val.btval);
                break;
        case TYPE_sht:
-               materialiseDim(sht, dim->min->data.val.shval, 
dim->step->data.val.shval, dim->max->data.val.shval);
+               createDim(sht, dim->min->data.val.shval, 
dim->step->data.val.shval, dim->max->data.val.shval);
                break;
        case TYPE_int:
-               materialiseDim(int, dim->min->data.val.ival, 
dim->step->data.val.ival, dim->max->data.val.ival);
+               createDim(int, dim->min->data.val.ival, 
dim->step->data.val.ival, dim->max->data.val.ival);
                break;
        case TYPE_lng:
-               materialiseDim(lng, dim->min->data.val.lval, 
dim->step->data.val.lval, dim->max->data.val.lval);
+               createDim(lng, dim->min->data.val.lval, 
dim->step->data.val.lval, dim->max->data.val.lval);
                break;
 #ifdef HAVE_HGE
        case TYPE_hge:
-               materialiseDim(hge, dim->min->data.val.hval, 
dim->step->data.val.hval, dim->max->data.val.hval);
+               createDim(hge, dim->min->data.val.hval, 
dim->step->data.val.hval, dim->max->data.val.hval);
                break;
 #endif
                case TYPE_flt:
-               materialiseDim(flt, dim->min->data.val.fval, 
dim->step->data.val.fval, dim->max->data.val.fval);
+               createDim(flt, dim->min->data.val.fval, 
dim->step->data.val.fval, dim->max->data.val.fval);
                break;
        case TYPE_dbl:
-               materialiseDim(dbl, dim->min->data.val.dval, 
dim->step->data.val.dval, dim->max->data.val.dval);
+               createDim(dbl, dim->min->data.val.dval, 
dim->step->data.val.dval, dim->max->data.val.dval);
                break;
        case TYPE_str:
                        fprintf(stderr, "mvc_create_dimension_bat: str 
dimension needs special handling\n");
@@ -2231,6 +2221,115 @@ mvc_create_dimension_bat_wrap(Client cnt
        throw(SQL, "sql.create_dimension", "unable to find %s(%s)", *tname, 
*dname);
 }
 
+str materialiseDimension(bat* res, bat* in) {
+       BAT *dimensionBAT, *resBAT;
+       int tpe;
+
+       if ((dimensionBAT = BATdescriptor(*in)) == NULL) {
+               throw(MAL, "sql.materialise_dimension", RUNTIME_OBJECT_MISSING);
+       }
+
+       tpe = ATOMtype(dimensionBAT->ttype);
+
+
+#define materialise(TPE) \
+    do { \
+        /*find the min, max, step in the dimension*/ \
+        long repeat1, repeat2, elementsNum; \
+        TPE min, max, step; \
+        oid i, j; \
+        TPE *el_in, *el_out, el; \
+\
+        el_in = (TPE*)Tloc(dimensionBAT, BUNfirst(dimensionBAT)); \
+        min = el_in[0]; \
+        step = el_in[BATcount(dimensionBAT)-1]; \
+\
+        repeat1 = 1; \
+        for(i=1; i<BATcount(dimensionBAT); i++) { \
+            if(min == el_in[i]) \
+                repeat1++; \
+            else { \
+                max = el_in[i]; \
+                break; \
+            } \
+        } \
+\
+               repeat2 = 1; \
+        for(; i<BATcount(dimensionBAT); i++) { \
+            if(max == el_in[i]) \
+                repeat2++; \
+            else { \
+                break; \
+            } \
+        } \
+fprintf(stderr, "materialise repeat1 = %ld\n", repeat1); \
+fprintf(stderr, "materialise repeat2 = %ld\n", repeat2); \
+\
+        elementsNum = floor((max-min)/step) + 1; \
+fprintf(stderr, "materialise elementsNum = %ld\n", elementsNum); \
+\
+               if((resBAT = BATnew(TYPE_void, TYPE_##TPE, 
repeat1*elementsNum*repeat2, TRANSIENT)) == NULL) \
+               throw(MAL, "sql.materialise_dimension", "Unable to create 
output BAT"); \
+\
+               el_out = (TPE*)Tloc(resBAT, BUNfirst(resBAT)); \
+               for(j=0; j<(unsigned long)repeat2; j++) { \
+                       for(el=min; el<=max; el+=step) { \
+                               for(i=0; i<(unsigned long)repeat1; i++) { \
+                                       *el_out = el; \
+                                       el_out++; \
+                               } \
+                       } \
+               } \
+\
+        BATseqbase(resBAT,0); \
+        BATsetcount(resBAT, repeat1*elementsNum*repeat2);                  \
+\
+    } while(0)
+
+       
+    switch (tpe) {
+    case TYPE_bte:
+        materialise(bte);
+        break;
+    case TYPE_sht:
+        materialise(sht);
+        break;
+    case TYPE_int:
+        materialise(int);
+        break;
+    case TYPE_flt:
+        materialise(flt);
+        break;
+    case TYPE_dbl:
+        materialise(dbl);
+        break;
+    case TYPE_lng:
+        materialise(lng);
+        break;
+#ifdef HAVE_HGE
+    case TYPE_hge:
+        materialise(hge);
+        break;
+#endif
+    case TYPE_oid:
+#if SIZEOF_OID == SIZEOF_INT
+        materialise(int);
+#else
+        materialise(lng);
+#endif
+        break;
+    default:
+        fprintf(stderr, "BATdimensionProject: dimension type not handled\n");
+        return NULL;
+       }
+       
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to