Changeset: 55c595a00ec5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=55c595a00ec5
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        clients/Tests/exports.stable.out
        gdk/gdk_join.c
        gdk/gdk_select.c
        monetdb5/ChangeLog
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/kernel/algebra.h
        monetdb5/modules/kernel/algebra.mal
Branch: default
Log Message:

BATjoin and BATleftjoin now optionally don't produce the right output.


diffs (truncated from 1094 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -555,7 +555,9 @@ stdout of test 'MAL-signatures` in direc
 [ "algebra",   "ilikeselect",  "command algebra.ilikeselect(b:bat[:str], 
cand:bat[:oid], pat:str, esc:str, anti:bit):bat[:oid] ",      
"PCRElikeselect1;",     ""      ]
 [ "algebra",   "ilikeselect",  "command algebra.ilikeselect(b:bat[:str], 
cand:bat[:oid], pat:str, anti:bit):bat[:oid] ",       "PCRElikeselect4;",     
""      ]
 [ "algebra",   "intersect",    "command algebra.intersect(l:bat[:any_1], 
r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, 
estimate:lng):bat[:oid] ",        "ALGintersect;",        "Intersection of l 
and r with candidate lists (i.e. half of semi-join)" ]
+[ "algebra",   "join", "command algebra.join(l:bat[:any_1], r:bat[:any_1], 
sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng):bat[:oid] ",     
"ALGjoin1;",    "Join; only produce left output"        ]
 [ "algebra",   "join", "command algebra.join(l:bat[:any_1], r:bat[:any_1], 
sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) (X_0:bat[:oid], 
X_1:bat[:oid]) ",        "ALGjoin;",     "Join"  ]
+[ "algebra",   "leftjoin",     "command algebra.leftjoin(l:bat[:any_1], 
r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, 
estimate:lng):bat[:oid] ", "ALGleftjoin1;",        "Left join with candidate 
lists; only produce left output"      ]
 [ "algebra",   "leftjoin",     "command algebra.leftjoin(l:bat[:any_1], 
r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) 
(X_0:bat[:oid], X_1:bat[:oid]) ",    "ALGleftjoin;", "Left join with candidate 
lists"        ]
 [ "algebra",   "like", "command algebra.like(s:str, pat:str):bit ",    
"PCRElike2;",   ""      ]
 [ "algebra",   "like", "command algebra.like(s:str, pat:str, esc:str):bit ",   
"PCRElike3;",   ""      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -659,7 +659,9 @@ stdout of test 'MAL-signatures` in direc
 [ "algebra",   "ilikeselect",  "command algebra.ilikeselect(b:bat[:str], 
cand:bat[:oid], pat:str, esc:str, anti:bit):bat[:oid] ",      
"PCRElikeselect1;",     ""      ]
 [ "algebra",   "ilikeselect",  "command algebra.ilikeselect(b:bat[:str], 
cand:bat[:oid], pat:str, anti:bit):bat[:oid] ",       "PCRElikeselect4;",     
""      ]
 [ "algebra",   "intersect",    "command algebra.intersect(l:bat[:any_1], 
r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, 
estimate:lng):bat[:oid] ",        "ALGintersect;",        "Intersection of l 
and r with candidate lists (i.e. half of semi-join)" ]
+[ "algebra",   "join", "command algebra.join(l:bat[:any_1], r:bat[:any_1], 
sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng):bat[:oid] ",     
"ALGjoin1;",    "Join; only produce left output"        ]
 [ "algebra",   "join", "command algebra.join(l:bat[:any_1], r:bat[:any_1], 
sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) (X_0:bat[:oid], 
X_1:bat[:oid]) ",        "ALGjoin;",     "Join"  ]
+[ "algebra",   "leftjoin",     "command algebra.leftjoin(l:bat[:any_1], 
r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, 
estimate:lng):bat[:oid] ", "ALGleftjoin1;",        "Left join with candidate 
lists; only produce left output"      ]
 [ "algebra",   "leftjoin",     "command algebra.leftjoin(l:bat[:any_1], 
r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) 
(X_0:bat[:oid], X_1:bat[:oid]) ",    "ALGleftjoin;", "Left join with candidate 
lists"        ]
 [ "algebra",   "like", "command algebra.like(s:str, pat:str):bit ",    
"PCRElike2;",   ""      ]
 [ "algebra",   "like", "command algebra.like(s:str, pat:str, esc:str):bit ",   
"PCRElike3;",   ""      ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -728,7 +728,9 @@ str ALGfirstn(Client cntxt, MalBlkPtr mb
 str ALGgroupby(bat *res, const bat *gids, const bat *cnts);
 str ALGintersect(bat *r1, const bat *lid, const bat *rid, const bat *slid, 
const bat *srid, const bit *nil_matches, const lng *estimate);
 str ALGjoin(bat *r1, bat *r2, const bat *l, const bat *r, const bat *sl, const 
bat *sr, const bit *nil_matches, const lng *estimate);
+str ALGjoin1(bat *r1, const bat *l, const bat *r, const bat *sl, const bat 
*sr, const bit *nil_matches, const lng *estimate);
 str ALGleftjoin(bat *r1, bat *r2, const bat *l, const bat *r, const bat *sl, 
const bat *sr, const bit *nil_matches, const lng *estimate);
+str ALGleftjoin1(bat *r1, const bat *l, const bat *r, const bat *sl, const bat 
*sr, const bit *nil_matches, const lng *estimate);
 str ALGmaxany(ptr result, const bat *bid);
 str ALGmaxany_skipnil(ptr result, const bat *bid, const bit *skipnil);
 str ALGminany(ptr result, const bat *bid);
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -111,6 +111,9 @@ joininitresults(BAT **r1p, BAT **r2p, BU
        BAT *r1, *r2;
        BUN maxsize, size;
 
+       /* if nil_on_miss is set, we really need a right output */
+       assert(!nil_on_miss || r2p != NULL);
+
        lkey |= lcnt <= 1;
        rkey |= rcnt <= 1;
 
@@ -329,13 +332,19 @@ selectjoin(BAT **r1p, BAT **r2p, BAT *l,
                               "selectjoin", t0);
        }
        BAT *r1 = COLnew(0, TYPE_oid, lci->ncand * BATcount(bn), TRANSIENT);
-       BAT *r2 = COLnew(0, TYPE_oid, lci->ncand * BATcount(bn), TRANSIENT);
-       if (r1 == NULL || r2 == NULL) {
+       if (r1 == NULL) {
                BBPunfix(bn->batCacheid);
-               BBPreclaim(r1);
-               BBPreclaim(r2);
                return GDK_FAIL;
        }
+       BAT *r2 = NULL;
+       if (r2p) {
+               r2 = COLnew(0, TYPE_oid, lci->ncand * BATcount(bn), TRANSIENT);
+               if (r2 == NULL) {
+                       BBPunfix(bn->batCacheid);
+                       BBPreclaim(r1);
+                       return GDK_FAIL;
+               }
+       }
 
        r1->tsorted = true;
        r1->trevsorted = lci->ncand == 1;
@@ -343,44 +352,56 @@ selectjoin(BAT **r1p, BAT **r2p, BAT *l,
        r1->tkey = BATcount(bn) == 1;
        r1->tnil = false;
        r1->tnonil = true;
-       r2->tsorted = lci->ncand == 1 || BATcount(bn) == 1;
-       r2->trevsorted = BATcount(bn) == 1;
-       r2->tseqbase = lci->ncand == 1 && BATtdense(bn) ? bn->tseqbase : 
oid_nil;
-       r2->tkey = lci->ncand == 1;
-       r2->tnil = false;
-       r2->tnonil = true;
+       if (r2) {
+               r2->tsorted = lci->ncand == 1 || BATcount(bn) == 1;
+               r2->trevsorted = BATcount(bn) == 1;
+               r2->tseqbase = lci->ncand == 1 && BATtdense(bn) ? bn->tseqbase 
: oid_nil;
+               r2->tkey = lci->ncand == 1;
+               r2->tnil = false;
+               r2->tnonil = true;
+       }
        if (BATtdense(bn)) {
                oid *o1p = (oid *) Tloc(r1, 0);
-               oid *o2p = (oid *) Tloc(r2, 0);
+               oid *o2p = r2 ? (oid *) Tloc(r2, 0) : NULL;
                oid bno = bn->tseqbase;
-               BUN q = BATcount(bn);
+               BUN p, q = BATcount(bn);
 
                do {
-                       for (BUN p = 0; p < q; p++) {
+                       for (p = 0; p < q; p++) {
                                *o1p++ = o;
-                               *o2p++ = bno + p;
+                       }
+                       if (o2p) {
+                               for (p = 0; p < q; p++) {
+                                       *o2p++ = bno + p;
+                               }
                        }
                        o = canditer_next(lci);
                } while (!is_oid_nil(o));
        } else {
                oid *o1p = (oid *) Tloc(r1, 0);
-               oid *o2p = (oid *) Tloc(r2, 0);
+               oid *o2p = r2 ? (oid *) Tloc(r2, 0) : NULL;
                const oid *bnp = (const oid *) Tloc(bn, 0);
-               BUN q = BATcount(bn);
+               BUN p, q = BATcount(bn);
 
                do {
-                       for (BUN p = 0; p < q; p++) {
+                       for (p = 0; p < q; p++) {
                                *o1p++ = o;
-                               *o2p++ = bnp[p];
+                       }
+                       if (o2p) {
+                               for (p = 0; p < q; p++) {
+                                       *o2p++ = bnp[p];
+                               }
                        }
                        o = canditer_next(lci);
                } while (!is_oid_nil(o));
        }
        BATsetcount(r1, lci->ncand * BATcount(bn));
-       BATsetcount(r2, lci->ncand * BATcount(bn));
+       *r1p = r1;
+       if (r2p) {
+               BATsetcount(r2, lci->ncand * BATcount(bn));
+               *r2p = r2;
+       }
        BBPunfix(bn->batCacheid);
-       *r1p = r1;
-       *r2p = r2;
        ALGODEBUG fprintf(stderr, "#%s: %s(l=" ALGOBATFMT ","
                          "r=" ALGOBATFMT ",sl=" ALGOOPTBATFMT ","
                          "sr=" ALGOOPTBATFMT ",nil_matches=%d)%s %s "
@@ -933,8 +954,10 @@ mergejoin_int(BAT **r1p, BAT **r2p, BAT 
                        /* value occurs multiple times in l, so entry
                         * in r will be repeated multiple times: hence
                         * r2 is not key and not dense */
-                       r2->tkey = false;
-                       r2->tseqbase = oid_nil;
+                       if (r2) {
+                               r2->tkey = false;
+                               r2->tseqbase = oid_nil;
+                       }
                        /* multiple different values will be inserted
                         * in r1 (always in order), so not reverse
                         * ordered anymore */
@@ -949,13 +972,17 @@ mergejoin_int(BAT **r1p, BAT **r2p, BAT 
                        /* multiple different values will be inserted
                         * in r2 (in order), so not reverse ordered
                         * anymore */
-                       r2->trevsorted = false;
-                       if (nl > 1) {
-                               /* multiple values in l match multiple
-                                * values in r, so an ordered sequence
-                                * will be inserted multiple times in
-                                * r2, so r2 is not ordered anymore */
-                               r2->tsorted = false;
+                       if (r2) {
+                               r2->trevsorted = false;
+                               if (nl > 1) {
+                                       /* multiple values in l match
+                                        * multiple values in r, so an
+                                        * ordered sequence will be
+                                        * inserted multiple times in
+                                        * r2, so r2 is not ordered
+                                        * anymore */
+                                       r2->tsorted = false;
+                               }
                        }
                }
                if (BATcount(r1) > 0) {
@@ -963,14 +990,17 @@ mergejoin_int(BAT **r1p, BAT **r2p, BAT 
                         * r1, so r1 is not reverse ordered anymore */
                        r1->trevsorted = false;
                        /* a new higher value will be added to r2 */
-                       r2->trevsorted = false;
+                       if (r2) {
+                               r2->trevsorted = false;
+                       }
                        if (BATtdense(r1) &&
                            ((oid *) r1->theap.base)[r1->batCount - 1] + 1 != 
l->hseqbase + lstart - nl) {
                                r1->tseqbase = oid_nil;
                        }
                }
 
-               if (BATcount(r2) > 0 &&
+               if (r2 &&
+                   BATcount(r2) > 0 &&
                    BATtdense(r2) &&
                    ((oid *) r2->theap.base)[r2->batCount - 1] + 1 != 
r->hseqbase + rstart - nr) {
                        r2->tseqbase = oid_nil;
@@ -980,28 +1010,37 @@ mergejoin_int(BAT **r1p, BAT **r2p, BAT 
                lv = l->hseqbase + lstart - nl;
                for (i = 0; i < nl; i++) {
                        BUN j;
-                       oid rv;
 
-                       rv = r->hseqbase + rstart - nr;
                        for (j = 0; j < nr; j++) {
                                APPEND(r1, lv);
-                               APPEND(r2, rv);
-                               rv++;
+                       }
+                       if (r2) {
+                               oid rv = r->hseqbase + rstart - nr;
+
+                               for (j = 0; j < nr; j++) {
+                                       APPEND(r2, rv);
+                                       rv++;
+                               }
                        }
                        lv++;
                }
        }
        /* also set other bits of heap to correct value to indicate size */
        BATsetcount(r1, BATcount(r1));
-       BATsetcount(r2, BATcount(r2));
-       assert(BATcount(r1) == BATcount(r2));
+       if (r2) {
+               BATsetcount(r2, BATcount(r2));
+               assert(BATcount(r1) == BATcount(r2));
+       }
        if (BATcount(r1) > 0) {
                if (BATtdense(r1))
                        r1->tseqbase = ((oid *) r1->theap.base)[0];
-               if (BATtdense(r2))
+               if (r2 && BATtdense(r2))
                        r2->tseqbase = ((oid *) r2->theap.base)[0];
        } else {
-               r1->tseqbase = r2->tseqbase = 0;
+               r1->tseqbase = 0;
+               if (r2) {
+                       r2->tseqbase = 0;
+               }
        }
        ALGODEBUG fprintf(stderr, "#%s: %s(l=" ALGOBATFMT ","
                          "r=" ALGOBATFMT ","
@@ -1214,8 +1253,10 @@ mergejoin_lng(BAT **r1p, BAT **r2p, BAT 
                        /* value occurs multiple times in l, so entry
                         * in r will be repeated multiple times: hence
                         * r2 is not key and not dense */
-                       r2->tkey = false;
-                       r2->tseqbase = oid_nil;
+                       if (r2) {
+                               r2->tkey = false;
+                               r2->tseqbase = oid_nil;
+                       }
                        /* multiple different values will be inserted
                         * in r1 (always in order), so not reverse
                         * ordered anymore */
@@ -1230,13 +1271,17 @@ mergejoin_lng(BAT **r1p, BAT **r2p, BAT 
                        /* multiple different values will be inserted
                         * in r2 (in order), so not reverse ordered
                         * anymore */
-                       r2->trevsorted = false;
-                       if (nl > 1) {
-                               /* multiple values in l match multiple
-                                * values in r, so an ordered sequence
-                                * will be inserted multiple times in
-                                * r2, so r2 is not ordered anymore */
-                               r2->tsorted = false;
+                       if (r2) {
+                               r2->trevsorted = false;
+                               if (nl > 1) {
+                                       /* multiple values in l match
+                                        * multiple values in r, so an
+                                        * ordered sequence will be
+                                        * inserted multiple times in
+                                        * r2, so r2 is not ordered
+                                        * anymore */
+                                       r2->tsorted = false;
+                               }
                        }
                }
                if (BATcount(r1) > 0) {
@@ -1244,14 +1289,17 @@ mergejoin_lng(BAT **r1p, BAT **r2p, BAT 
                         * r1, so r1 is not reverse ordered anymore */
                        r1->trevsorted = false;
                        /* a new higher value will be added to r2 */
-                       r2->trevsorted = false;
+                       if (r2) {
+                               r2->trevsorted = false;
+                       }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to