Changeset: c02778d25f57 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c02778d25f57
Modified Files:
        monetdb5/extras/jaql/json.c
Branch: Oct2012
Log Message:

unwrap: allow empty input

people (me) can write queries that yield in an empty set, in which case,
we shouldn't abort, but just return that empty set


diffs (32 lines):

diff --git a/monetdb5/extras/jaql/json.c b/monetdb5/extras/jaql/json.c
--- a/monetdb5/extras/jaql/json.c
+++ b/monetdb5/extras/jaql/json.c
@@ -1408,7 +1408,27 @@ JSONunwrap(Client cntxt, MalBlkPtr mb, M
        b = BATselect(BATmirror(jb.array), BUNhead(bi, p), NULL);
        b = BATsemijoin(jb.kind, b);
        bi = bat_iterator(b);
-       assert(BATcount(b) != 0);
+
+       if (BATcount(b) == 0) {
+               /* input empty, return empty result */
+               unloadbats();
+               switch (tpe->vtype) {
+                       case TYPE_str:
+                               r = BATnew(TYPE_oid, TYPE_str, 0);
+                               break;
+                       case TYPE_dbl:
+                               r = BATnew(TYPE_oid, TYPE_dbl, 0);
+                               break;
+                       case TYPE_lng:
+                               r = BATnew(TYPE_oid, TYPE_lng, 0);
+                               break;
+                       default:
+                               assert(0); /* should not happen, checked above 
*/
+               }
+               BBPkeepref(r->batCacheid);
+               *ret = r->batCacheid;
+               return MAL_SUCCEED;
+       }
 
        /* special case for when the argument is a single array */
        c = BATantiuselect_(b, "a", NULL, TRUE, TRUE);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to