Changeset: 641334538f5a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=641334538f5a
Modified Files:
        monetdb5/extras/jaql/Tests/plan01.stable.out
        monetdb5/extras/jaql/jaql.c
Branch: jacqueline
Log Message:

transform: check array expansion usage

we cannot deduce names from array refs, and we cannot assign multiple
values to a single pair-value

check for these and generate appropriate errors for them


diffs (65 lines):

diff --git a/monetdb5/extras/jaql/Tests/plan01.stable.out 
b/monetdb5/extras/jaql/Tests/plan01.stable.out
--- a/monetdb5/extras/jaql/Tests/plan01.stable.out
+++ b/monetdb5/extras/jaql/Tests/plan01.stable.out
@@ -23,7 +23,8 @@ function user.main():void;
 end main;
 a as $ -> transform: { "a": $.j } 
 a as $ -> transform: { "a": $.j[1] } 
-a as $ -> transform: { "a": $.j[*].k } 
+!transform: cannot perform array expansion in a pair value (needs to be single 
value)
+
 
 # 16:07:49 >  
 # 16:07:49 >  "Done."
diff --git a/monetdb5/extras/jaql/jaql.c b/monetdb5/extras/jaql/jaql.c
--- a/monetdb5/extras/jaql/jaql.c
+++ b/monetdb5/extras/jaql/jaql.c
@@ -642,13 +642,12 @@ tree *
 make_pair(char *name, tree *val)
 {
        tree *res = GDKzalloc(sizeof(tree));
+       tree *w;
 
        assert(val != NULL);
        assert(name != NULL || val->type == j_var);
 
        if (name == NULL) {
-               tree *w;
-
                if (val->tval1 == NULL) {
                        /* we can't do arithmetic with these */
                        res->type = j_error;
@@ -658,11 +657,31 @@ make_pair(char *name, tree *val)
                }
 
                /* find last var in val */
-               for (w = val; w->tval1 != NULL; w = w->tval1)
-                       ;
+               for (w = val; w->tval1 != NULL; w = w->tval1) {
+                       if (w->tval2 != NULL && w->tval1 == NULL) {
+                               /* array as last, doesn't have a name */
+                               res->type = j_error;
+                               res->sval = GDKstrdup("transform: cannot deduce 
pair name "
+                                               "from array member(s)");
+                               freetree(val);
+                               return res;
+                       }
+               }
                name = GDKstrdup(w->sval);
        }
 
+       for (w = val; w->tval1 != NULL; w = w->tval1) {
+               if (w->tval2 != NULL && w->tval2->nval == -1) {
+                       /* expansion is impossible here */
+                       res->type = j_error;
+                       res->sval = GDKstrdup("transform: cannot perform array 
expansion "
+                                       "in a pair value (needs to be single 
value)");
+                       freetree(val);
+                       GDKfree(name);
+                       return res;
+               }
+       }
+
        res->type = j_pair;
        res->tval1 = val;
        res->sval = name;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to