Changeset: 3dec46b01b6e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3dec46b01b6e
Modified Files:
        
Branch: default
Log Message:

Merge with default


diffs (truncated from 385 to 300 lines):

diff --git a/clients/python/monetdb/mapi2.py b/clients/python/monetdb/mapi2.py
--- a/clients/python/monetdb/mapi2.py
+++ b/clients/python/monetdb/mapi2.py
@@ -237,7 +237,7 @@
         while count > 0:
             try:
                 recv = self.socket.recv(bytes, flags)
-                logging.debug("II: package size: %i payload: %s" % (len(recv), 
recv))
+                logger.debug("II: package size: %i payload: %s" % (len(recv), 
recv))
             except socket.error, error:
                 raise OperationalError(error[1])
             count -= len(recv)
diff --git a/clients/python/monetdb/mapi3.py b/clients/python/monetdb/mapi3.py
--- a/clients/python/monetdb/mapi3.py
+++ b/clients/python/monetdb/mapi3.py
@@ -238,7 +238,7 @@
         while count > 0:
             try:
                 recv = self.socket.recv(bytes, flags)
-                logging.debug("II: package size: %i payload: %s" % (len(recv), 
recv))
+                logger.debug("II: package size: %i payload: %s" % (len(recv), 
recv))
             except socket.error as error:
                 raise OperationalError(error[1])
             count -= len(recv)
diff --git a/gdk/gdk_bbp.mx b/gdk/gdk_bbp.mx
--- a/gdk/gdk_bbp.mx
+++ b/gdk/gdk_bbp.mx
@@ -902,8 +902,8 @@
                        if (BBPsize >= BBPlimit)
                                BBPextend(BATMARGIN, FALSE);
                }
-               if (src == 0)
-                       assert(BBP[bid].cache == NULL); /* no duplicates in 
BBP.dir */
+               if (src == 0 && BBP[bid].cache != NULL)
+                       GDKfatal("BBPinit: duplicate entry in BBP.dir.");
                bs = GDKzalloc(sizeof(BATstore));
                if (bs == NULL)
                        GDKfatal("BBPinit: cannot allocate memory for 
BATstore.");
@@ -1155,16 +1155,20 @@
 @-
 In a distributed version of MonetDB, it would be nice to easily share the BATs
 with other server instances. Although concurrency control issues should be 
handled
-with care, it can avoid excessive communiction costs. The BBPimportEntry 
creates
-a BATdescriptor using symbolic links to its source. Presummably this would lead
-to a transparant behavior.
+with care, it can avoid excessive communication costs. The BBPimportEntry 
creates
+a BATdescriptor using symbolic links to its source. Presumably this would lead
+to a transparent behavior.
 @= linkHeap
-       lstat(@3, &st);
+       if (lstat(@3, &st) < 0) {
+               GDKerror("BBPimportEntry: file '%s' does not exist.\n", @3);
+               BBPdestroy(bn);
+               return 0;
+       }
        GDKfilepath(path, BATDIR, BBP_physical(bn->batCacheid), "@4");
        GDKcreatedir(path);
        IODEBUG mnstr_printf(GDKerr, "#symlink %s ->%s\n", @3, path);
        if (symlink(@3, path) < 0) {
-               GDKerror("attach.bind:cannot link '%s' -> '%s'\n", path, @3);
+               GDKerror("BBPimportEntry: cannot link '%s' -> '%s'\n", path, 
@3);
                BBPdestroy(bn);
                return 0;
        }
@@ -1174,15 +1178,23 @@
                GDKfree(bn->@1->@2.filename);
                bn->@1->@2.filename = 0;
        }
-       HEAPload(&bn->@1->@2, BBP_physical(bn->batCacheid), "@4", TRUE);
+       if (HEAPload(&bn->@1->@2, BBP_physical(bn->batCacheid), "@4", TRUE) < 
0) {
+               GDKerror("BBPimportEntry: cannot read heap file '%s'\n", @3);
+               BBPdestroy(bn);
+               return 0;
+       }
 
 @= linkvHeap
-       lstat(@2, &st);
+       if (lstat(@2, &st) < 0) {
+               GDKerror("BBPimportEntry: file '%s' does not exist.\n", @2);
+               BBPdestroy(bn);
+               return 0;
+       }
        GDKfilepath(path, BATDIR, BBP_physical(bn->batCacheid), "@3");
        GDKcreatedir(path);
        IODEBUG mnstr_printf(GDKerr, "#symlink %s ->%s\n", @2, path);
        if (symlink(@2, path) < 0) {
-               GDKerror("attach.bind:cannot link '%s' -> '%s'\n", path, @2);
+               GDKerror("BBPimportEntry: cannot link '%s' -> '%s'\n", path, 
@2);
                BBPdestroy(bn);
                return 0;
        }
@@ -1195,7 +1207,11 @@
                GDKfree(bn->@1->vheap->filename);
                bn->@1->vheap->filename = 0;
        }
-       HEAPload(bn->@1->vheap, BBP_physical(bn->batCacheid), "@3", TRUE);
+       if (HEAPload(bn->@1->vheap, BBP_physical(bn->batCacheid), "@3", TRUE) < 
0) {
+               GDKerror("BBPimportEntry: cannot read heap file '%s'\n", @2);
+               BBPdestroy(bn);
+               return 0;
+       }
 
 @c
 bat
@@ -1221,6 +1237,10 @@
        int BBPlimit;
 
        IODEBUG mnstr_printf(GDKerr,"#importEntry %s\n",nme);
+       if (strlen(nme) >= sizeof(bbpdir)) {
+               GDKerror("BBPimportEntry: file name too long\n");
+               return 0;
+       }
        strcpy(bbpdir,nme);
        s= strstr(bbpdir,BATDIR);
        if (s == 0)
diff --git a/monetdb5/modules/mal/remote.mx b/monetdb5/modules/mal/remote.mx
--- a/monetdb5/modules/mal/remote.mx
+++ b/monetdb5/modules/mal/remote.mx
@@ -1205,7 +1205,7 @@
 str RMTbincopyto(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        int bid = *(int *)getArgReference(stk, pci, 1);
-       BAT *b = BBPquickdesc(bid, FALSE);
+       BAT *b = BBPquickdesc(ABS(bid), FALSE);
        char sendhead = 0;
        char sendtheap = 0;
        oid Hseqbase = 0;
@@ -1354,8 +1354,15 @@
        /* the BAT we will return */
        b = BATnew(bb.Htype, bb.Ttype, bb.size);
        b->hseqbase = bb.Hseqbase;
-       if (bb.Ttype == TYPE_void)
+       if (bb.Ttype == TYPE_void) {
                b->tseqbase = bb.Tseqbase;
+               b->tdense = 1;
+               b->tkey = 1;
+       }
+       if (bb.Htype == TYPE_void) {
+               b->hdense = 1;
+               b->hkey = 1;
+       }
        b->batCount = bb.size;
 
        /* for strings, the width may not match, fix it to match what we
@@ -1382,6 +1389,8 @@
                mnstr_printf(GDKout, "!MALexception:remote.bincopyfrom: 
expected flush, got: %c", tmp);
        }
 
+       BATpropcheck(b, BATPROPS_ALL);
+
        *ret = b;
        return(MAL_SUCCEED);
 }
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -1688,6 +1688,55 @@
 }
 
 static sql_exp *
+sql_div_fixup( mvc *sql, sql_exp *e, sql_exp *cond, int lr )
+{
+       list *args = e->l;
+       sql_exp *le = args->h->data, *o;
+       sql_exp *re = args->h->next->data;
+       sql_subfunc *ifthen;
+
+       /* if (cond) then val else const */
+       args = new_exp_list(sql->sa);
+       append(args, cond);
+       if (!lr)
+               append(args, re);
+       o = exp_atom_wrd(sql->sa, 1);
+       append(args, exp_convert(sql->sa, o, exp_subtype(o), exp_subtype(re)));
+       if (lr)
+               append(args, re);
+       ifthen = find_func(sql, "ifthenelse", args);
+       assert(ifthen);
+       re = exp_op(sql->sa, args, ifthen);
+
+       return exp_binop(sql->sa, le, re, e->f);
+}
+
+static list *
+exps_case_fixup( mvc *sql, list *exps, sql_exp *cond, int lr )
+{
+       node *n;
+
+       if (exps) {
+               list *nexps = new_exp_list(sql->sa);
+               for( n = exps->h; n; n = n->next) {
+                       sql_exp *e = n->data;
+                       if (e->type == e_func && e->l && !is_rank_op(e) ) {
+                               sql_subfunc *f = e->f;
+
+                               if (!f->func->s && !strcmp(f->func->base.name, 
"sql_div")) 
+                                       e = sql_div_fixup(sql, e, cond, lr);
+                               else 
+                                       e->l = exps_case_fixup(sql, e->l, cond, 
lr);
+
+                       }
+                       append(nexps, e);
+               }
+               return nexps;
+       }
+       return exps;
+}
+
+static sql_exp *
 exp_case_fixup( mvc *sql, sql_exp *e )
 {
        /* only functions need fix up */
@@ -1713,46 +1762,19 @@
                        sql_exp *a2 = args->h->next->next->data; 
                        sql_subfunc *a1f = a1->f;
                        sql_subfunc *a2f = a2->f;
-                       sql_subfunc *ifthen;
-
-                       /* TODO we should find the div recursively ! */
 
                        /* rewrite right hands of div */
                        if (a1->type == e_func && !a1f->func->s && 
                             !strcmp(a1f->func->base.name, "sql_div")) {
-                               list *args = a1->l;
-                               sql_exp *le = args->h->data, *o;
-                               sql_exp *re = args->h->next->data;
-
-                               /* if (cond) then val else const */
-                               args = new_exp_list(sql->sa);
-                               append(args, cond);
-                               append(args, re);
-                               o = exp_atom_wrd(sql->sa, 1);
-                               append(args, exp_convert(sql->sa, o, 
exp_subtype(o), exp_subtype(re)));
-                               ifthen = find_func(sql, "ifthenelse", args);
-                               assert(ifthen);
-                               re = exp_op(sql->sa, args, ifthen);
-
-                               a1 = exp_binop(sql->sa, le, re, a1->f);
+                               a1 = sql_div_fixup(sql, a1, cond, 0);
+                       } else if (a1->type == e_func && a1->l) { 
+                               a1->l = exps_case_fixup(sql, a1->l, cond, 0); 
                        }
                        if  (a2->type == e_func && !a2f->func->s && 
                             !strcmp(a2f->func->base.name, "sql_div")) { 
-                               list *args = a2->l;
-                               sql_exp *le = args->h->data, *o;
-                               sql_exp *re = args->h->next->data;
-
-                               /* if (cond) then const else val */
-                               args = new_exp_list(sql->sa);
-                               append(args, cond);
-                               o = exp_atom_wrd(sql->sa, 1);
-                               append(args, exp_convert(sql->sa, o, 
exp_subtype(o), exp_subtype(re)));
-                               append(args, re);
-                               ifthen = find_func(sql, "ifthenelse", args);
-                               assert(ifthen);
-                               re = exp_op(sql->sa, args, ifthen);
-
-                               a2 = exp_binop(sql->sa, le, re, a2->f);
+                               a2 = sql_div_fixup(sql, a2, cond, 1);
+                       } else if (a2->type == e_func && a2->l) { 
+                               a2->l = exps_case_fixup(sql, a2->l, cond, 1); 
                        }
                        nne = exp_op3(sql->sa, cond, a1, a2, ne->f);
                        exp_setname(sql->sa, nne, ne->rname, ne->name );
diff --git a/sql/storage/restrict/restrict_storage.c 
b/sql/storage/restrict/restrict_storage.c
--- a/sql/storage/restrict/restrict_storage.c
+++ b/sql/storage/restrict/restrict_storage.c
@@ -946,6 +946,7 @@
 
        sf->count_col = (count_col_fptr)&count_col;
        sf->count_idx = (count_idx_fptr)&count_idx;
+       sf->sorted_col = (sorted_col_fptr)&sorted_col;
 
        sf->create_col = (create_col_fptr)&create_col;
        sf->create_idx = (create_idx_fptr)&create_idx;
diff --git a/sql/test/BugTracker-2011/Tests/All 
b/sql/test/BugTracker-2011/Tests/All
--- a/sql/test/BugTracker-2011/Tests/All
+++ b/sql/test/BugTracker-2011/Tests/All
@@ -1,3 +1,4 @@
+aggregate-in-subquery.Bug-2739
 correlated-update.Bug-2771
 double_erange.Bug-2774
 view_avg_incorrect_result.Bug-2790
diff --git a/sql/test/BugTracker-2011/Tests/aggregate-in-subquery.Bug-2739.sql 
b/sql/test/BugTracker-2011/Tests/aggregate-in-subquery.Bug-2739.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2011/Tests/aggregate-in-subquery.Bug-2739.sql
@@ -0,0 +1,4 @@
+create table bug2739 (val int);
+insert into bug2739 values (1), (2);
+select avg(val - (select avg(val) from bug2739)) from bug2739;
+drop table bug2739;
diff --git 
a/sql/test/BugTracker-2011/Tests/aggregate-in-subquery.Bug-2739.stable.err 
b/sql/test/BugTracker-2011/Tests/aggregate-in-subquery.Bug-2739.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2011/Tests/aggregate-in-subquery.Bug-2739.stable.err
@@ -0,0 +1,39 @@
+stderr of test 'aggregate-in-subquery.Bug-2739` in directory 
'test/BugTracker-2011` itself:
+
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to