Changeset: b0cf7fed6ddc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b0cf7fed6ddc
Modified Files:
        monetdb5/extras/jaql/Tests/plan00.stable.out
        monetdb5/extras/jaql/jaql.c
        monetdb5/extras/jaql/jaql.h
        monetdb5/extras/jaql/jaqlgencode.c
        monetdb5/extras/jaql/parser/jaql.y
Branch: jacqueline
Log Message:

jaql: simplify predicate handling by eliminating j_cmpnd

It's not necessary to have a special type for compounds of predicates,
code generation has to recursively dump them anyway, just like with
arithmetic.


diffs (177 lines):

diff --git a/monetdb5/extras/jaql/Tests/plan00.stable.out 
b/monetdb5/extras/jaql/Tests/plan00.stable.out
--- a/monetdb5/extras/jaql/Tests/plan00.stable.out
+++ b/monetdb5/extras/jaql/Tests/plan00.stable.out
@@ -37,11 +37,11 @@ function user.main():void;
     jaql.x("plan [1,2,3] -> transform ($ * 2.0) / 4;");
 end main;
 B => A 
-test as $ -> filter: $.mgr == true => <result> 
-test as emp -> filter: emp.mgr == true => <result> 
-e as $ -> filter: ( $.mgr == true || $.income > 30000 ) => <result> 
+test as $ -> filter: ( $.mgr == true ) => <result> 
+test as emp -> filter: ( emp.mgr == true ) => <result> 
+e as $ -> filter: ( ( $.mgr == true ) || ( $.income > 30000 ) ) => <result> 
 [ {id:1, dept:1, income:12000},{id:2, dept:1, income:13000} ] => emps 
-[ {id:1, dept:1, income:12000},{id:2, dept:1, income:13000} ] as $ -> filter: 
$.dept == 1 => <result> 
+[ {id:1, dept:1, income:12000},{id:2, dept:1, income:13000} ] as $ -> filter: 
( $.dept == 1 ) => <result> 
 [ [3,65,8,72], [5,98,2,65] ] as arr -> expand: arr => <result> 
 [ {"name":"Jon Doe", "movie_ids":[3,65,8,72]}, {"name":"Jane 
Dean","movie_ids":[5,98,2]} ] as $ -> expand: $.movie_ids => <result> 
 A as $ -> expand: $ as $ -> transform: ( $ * 2 ) 
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
@@ -289,49 +289,33 @@ make_jaql_top(long long int num)
        return res;
 }
 
-/* create predicate, chaining onto the previous predicate ppred,
- * applying a comparison (AND/OR/NOT currently) with the next predicate
- * pred */
+/* create predicate between left and right which can be predicates on
+ * their own, or variables and values */
 tree *
-make_cpred(tree *ppred, tree *comp, tree *pred)
+make_pred(tree *l, tree *comp, tree *r)
 {
        tree *res;
 
-       assert(comp == NULL || comp->type == j_comp);
-       assert(pred != NULL && (pred->type == j_pred || pred->type == j_cmpnd));
+       /* shortcut to optimize non-not constructions */
+       if (comp == NULL && l == NULL)
+               return r;
 
-       /* shortcut to optimize non-not constructions */
-       if (comp == NULL && ppred == NULL)
-               return pred;
-
-       /* optimise the case where comp is _NOT, and pred is a variable to
+       /* optimise the case where comp is _NOT, and r is a variable to
         * rewrite its comp to _NEQUALS */
-       if (comp->nval == _NOT && pred->type == j_pred &&
-                       pred->tval2->nval == _EQUALS)
+       if (comp->nval == _NOT && r->type == j_pred &&
+                       r->tval2->nval == _EQUALS)
        {
-               pred->tval2->nval = _NEQUAL;
-               return pred;
+               r->tval2->nval = _NEQUAL;
+               freetree(l);
+               freetree(comp);
+               return r;
        }
 
        res = GDKzalloc(sizeof(tree));
-       res->type = j_cmpnd;
-       res->tval1 = ppred;
+       res->type = j_pred;
+       res->tval1 = l;
        res->tval2 = comp;
-       res->tval3 = pred;
-
-       return res;
-}
-
-/* create predicate of simple form that compares an identifier to a
- * value */
-tree *
-make_pred(tree *var, tree *comp, tree *value)
-{
-       tree *res = GDKzalloc(sizeof(tree));
-       res->type = j_pred;
-       res->tval1 = var;
-       res->tval2 = comp;
-       res->tval3 = value;
+       res->tval3 = r;
 
        return res;
 }
@@ -753,23 +737,6 @@ printtree(tree *t, int level, char op)
                                        printf("-> top: %lld ", t->nval);
                                }
                                break;
-                       case j_cmpnd:
-                               if (op) {
-                                       printf("j_cmpnd( ");
-                                       printtree(t->tval1, level + step, op);
-                                       printf(", ");
-                                       printtree(t->tval2, level + step, op);
-                                       printf(", ");
-                                       printtree(t->tval3, level + step, op);
-                                       printf(") ");
-                               } else {
-                                       printf("( ");
-                                       printtree(t->tval1, level + step, op);
-                                       printtree(t->tval2, level + step, op);
-                                       printtree(t->tval3, level + step, op);
-                                       printf(") ");
-                               }
-                               break;
                        case j_comp:
                        case j_op:
                                switch (t->cval) {
@@ -824,9 +791,11 @@ printtree(tree *t, int level, char op)
                                        printtree(t->tval3, level + step, op);
                                        printf(") ");
                                } else {
+                                       printf("( ");
                                        printtree(t->tval1, level + step, op);
                                        printtree(t->tval2, level + step, op);
                                        printtree(t->tval3, level + step, op);
+                                       printf(") ");
                                }
                                break;
                        case j_operation:
diff --git a/monetdb5/extras/jaql/jaql.h b/monetdb5/extras/jaql/jaql.h
--- a/monetdb5/extras/jaql/jaql.h
+++ b/monetdb5/extras/jaql/jaql.h
@@ -66,7 +66,6 @@ enum treetype {
        j_expand,
        j_sort,
        j_top,
-       j_cmpnd,
        j_comp,
        j_op,
        j_operation,
@@ -120,7 +119,6 @@ tree *make_jaql_transform(tree *var, tre
 tree *make_jaql_expand(tree *var, tree *expr);
 tree *make_jaql_sort(tree *var, tree *expr);
 tree *make_jaql_top(long long int num);
-tree *make_cpred(tree *ppred, tree *comp, tree *pred);
 tree *make_pred(tree *var, tree *comp, tree *value);
 tree *make_sort_arg(tree *var, char asc);
 tree *append_sort_arg(tree *osarg, tree *nsarg);
diff --git a/monetdb5/extras/jaql/jaqlgencode.c 
b/monetdb5/extras/jaql/jaqlgencode.c
--- a/monetdb5/extras/jaql/jaqlgencode.c
+++ b/monetdb5/extras/jaql/jaqlgencode.c
@@ -1964,7 +1964,6 @@ dumptree(jc *j, MalBlkPtr mb, tree *t)
                                j5 = getArg(q, 0);
                                pushInstruction(mb, q);
                                break;
-                       case j_cmpnd:
                        case j_comp:
                        case j_pred:
                                break;
diff --git a/monetdb5/extras/jaql/parser/jaql.y 
b/monetdb5/extras/jaql/parser/jaql.y
--- a/monetdb5/extras/jaql/parser/jaql.y
+++ b/monetdb5/extras/jaql/parser/jaql.y
@@ -158,15 +158,15 @@ ident: _IDENT   {$$ = $1;}
 
 predicates: predicate        {$$ = $1;}
                  | opt_not '(' predicates and_or predicate ')' 
-                             {$$ = make_cpred(NULL, $1, make_cpred($3, $4, 
$5));}
+                             {$$ = make_pred(NULL, $1, make_pred($3, $4, $5));}
                  | predicates and_or predicate
-                             {$$ = make_cpred($1, $2, $3);}
+                             {$$ = make_pred($1, $2, $3);}
                  ;
 
 predicate: opt_not variable
-                      {$$ = make_cpred(NULL, $1, make_pred($2, 
make_comp(j_equals), make_bool(1)));}
+                      {$$ = make_pred(NULL, $1, make_pred($2, 
make_comp(j_equals), make_bool(1)));}
                 | opt_not variable comparison value
-                      {$$ = make_cpred(NULL, $1, make_pred($2, $3, $4));}
+                      {$$ = make_pred(NULL, $1, make_pred($2, $3, $4));}
                 ;
 
 variable: ident                 {$$ = make_varname($1);}
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to