Changeset: 98a41b22d000 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=98a41b22d000
Modified Files:
        sql/server/rel_dump.c
        sql/server/rel_dump.h
        sql/server/rel_exp.c
        sql/server/rel_graph.c
        sql/server/rel_graph.h
        sql/server/rel_select.c
Branch: graph0
Log Message:

Reintroduce the semantic for the shortest path


diffs (truncated from 439 to 300 lines):

diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -64,8 +64,6 @@ cmp_print(mvc *sql, stream *fout, int cm
        mnstr_printf(fout, " %s ", r);
 }
 
-static void exps_print(mvc *sql, stream *fout, list *exps, int depth, int 
alias, int brackets);
-
 static void
 exp_print(mvc *sql, stream *fout, sql_exp *e, int depth, int comma, int alias) 
 {
@@ -237,7 +235,7 @@ exp_print(mvc *sql, stream *fout, sql_ex
                mnstr_printf(fout, ", ");
 }
 
-static void
+void
 exps_print(mvc *sql, stream *fout, list *exps, int depth, int alias, int 
brackets) 
 {
        node *en;
@@ -547,6 +545,9 @@ rel_print_(mvc *sql, stream  *fout, sql_
                exps_print(sql, fout, graph_ptr->efrom, depth, 1, 0);
                mnstr_printf(fout, ", dst:");
                exps_print(sql, fout, graph_ptr->eto, depth, 1, 0);
+               print_indent(sql, fout, depth, decorate);
+               mnstr_printf(fout, "shortest paths: ");
+               exps_print(sql, fout, graph_ptr->spfw, depth, 1, 1);
        }   break;
        default:
                assert(0);
diff --git a/sql/server/rel_dump.h b/sql/server/rel_dump.h
--- a/sql/server/rel_dump.h
+++ b/sql/server/rel_dump.h
@@ -14,6 +14,7 @@
 
 extern void rel_print_(mvc *sql, stream  *fout, sql_rel *rel, int depth, list 
*refs, int decorate);
 extern void rel_print_refs(mvc *sql, stream* fout, sql_rel *rel, int depth, 
list *refs, int decorate);
+extern void exps_print(mvc *sql, stream *fout, list *exps, int depth, int 
alias, int brackets);
 extern const char *op2string(operator_type op);
 
 extern sql_rel *rel_read(mvc *sql, char *ra, int *pos, list *refs);
diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -984,7 +984,8 @@ exp_match_exp( sql_exp *e1, sql_exp *e2)
                                return 1;
                        break;
                case e_graph:
-                       assert(0 && "Not implemented yet");
+                       assert(0 && "This should not be necessary");
+                       return exp_match_exp(e1->l, e2->l) && 
exp_match_exp(e1->r, e2->r);
                default:
                        break;
                }
diff --git a/sql/server/rel_graph.c b/sql/server/rel_graph.c
--- a/sql/server/rel_graph.c
+++ b/sql/server/rel_graph.c
@@ -36,6 +36,22 @@ rel2str1( mvc *sql, sql_rel *rel)
 }
 
 
+str
+exps2str(mvc *sql, list *exps ){
+       buffer *b;
+       stream *s = buffer_wastream(b = buffer_create(1024), "rel_dump");
+
+       char *res = NULL;
+
+       exps_print(sql, s, exps, 0, /*alias=*/ 1, /*brackets=*/0);
+       mnstr_printf(s, "\n");
+       res = buffer_get_buf(b);
+       buffer_destroy(b);
+       mnstr_destroy(s);
+       return res;
+}
+
+
 sql_rel* rel_graph_reaches(mvc *sql, sql_rel *rel, symbol *sq, int context){
        // TODO handle edge components defined with multiple attributes
        // this needs changes in the parser to accept list of columns & scalars
@@ -150,155 +166,193 @@ sql_rel* rel_graph_reaches(mvc *sql, sql
  *                                                                           *
  *****************************************************************************/
 
-//static bool error_reported(mvc* sql){ return (sql->session->status < 0); }
-//
-//static sql_exp* bindg_ret(mvc *sql, sql_exp* bind1, sql_exp* bind2){
-//        if (error_reported(sql)){ // an error already occurred
-//                return NULL;
-//        } else if(bind1 && bind2){
-//                return sql_error(sql, ERR_AMBIGUOUS, "Ambiguous expression 
for CHEAPEST SUM: %s, %s", exp_name(bind1), exp_name(bind2));
-//        } else if(bind1){
-//                return bind1;
-//        } else {
-//                return bind2; // either if it has a value or it is null */
-//        }
-//}
+static bool error_reported(mvc* sql){ return (sql->session->status < 0); }
+
+static sql_exp* bind_cheapest_sum_return(mvc *sql, sql_exp* bind1, sql_exp* 
bind2){
+       if (error_reported(sql)){ // an error already occurred
+               return NULL;
+       } else if(bind1 && bind2){
+               return sql_error(sql, ERR_AMBIGUOUS, "Ambiguous expression for 
CHEAPEST SUM: %s, %s", exp_name(bind1), exp_name(bind2));
+       } else if(bind1){
+               return bind1;
+       } else {
+               return bind2; // either if it has a value or it is null */
+       }
+}
 //
 //static sql_exp* bindg_filter_graph(mvc *sql, sql_exp *exp, dlist 
*parse_tree){
-//        const char* table_ref = NULL; // the table referred (optional)
-//        symbol* expr_weight = NULL; // the expression inside CHEAPEST SUM ( 
... );
-//        graph_join* g = NULL;
-//        sql_exp* e = NULL;
-//        exp_kind exp_kind_value = {type_value, card_column, TRUE};
+//     const char* table_ref = NULL; // the table referred (optional)
+//     symbol* expr_weight = NULL; // the expression inside CHEAPEST SUM ( ... 
);
+//     graph_join* g = NULL;
+//     sql_exp* e = NULL;
+//     exp_kind exp_kind_value = {type_value, card_column, TRUE};
 //
-//        assert(exp && "Expected an expression");
-//        assert(exp->type == e_cmp && get_cmp(exp) == cmp_filter_graph && 
"Expected a graph filter exp~");
-//        assert(parse_tree && "The input argument parse_tree is NULL");
-//        assert(parse_tree->cnt == 2 && "Expected two nodes in the root of 
the parse tree");
+//     assert(exp && "Expected an expression");
+//     assert(exp->type == e_cmp && get_cmp(exp) == cmp_filter_graph && 
"Expected a graph filter exp~");
+//     assert(parse_tree && "The input argument parse_tree is NULL");
+//     assert(parse_tree->cnt == 2 && "Expected two nodes in the root of the 
parse tree");
 //
-//        g = exp->f;
+//     g = exp->f;
 //
-//        table_ref = parse_tree->h->data.sval;
-//        expr_weight = parse_tree->h->next->data.sym;
+//     table_ref = parse_tree->h->data.sval;
+//     expr_weight = parse_tree->h->next->data.sym;
 //
-//        if (table_ref){ // use the table name to refer to the edge table
-//                const char* tname = rel_name(g->edges);
+//     if (table_ref){ // use the table name to refer to the edge table
+//             const char* tname = rel_name(g->edges);
 //
-//                // TODO shall we consider the schema as well?
-//                assert(tname != NULL);
-//                if(strcmp(tname, table_ref) == 0){
-//                        // force the binding against this relation
-//                        e = rel_value_exp(sql, &(g->edges), expr_weight, 
sql_sel, exp_kind_value);
-//                        if(!e){ return sql_error(sql, 02, "Cannot bind the 
cheapest sum expression in the subquery `%s'", tname); }
-//                }
-//        } else { // table name not given
-//                // try to bind the expression a la `best effort'
-//                e = rel_value_exp(sql, &(g->edges), expr_weight, sql_sel, 
exp_kind_value);
-//        }
+//             // TODO shall we consider the schema as well?
+//             assert(tname != NULL);
+//             if(strcmp(tname, table_ref) == 0){
+//                     // force the binding against this relation
+//                     e = rel_value_exp(sql, &(g->edges), expr_weight, 
sql_sel, exp_kind_value);
+//                     if(!e){ return sql_error(sql, 02, "Cannot bind the 
cheapest sum expression in the subquery `%s'", tname); }
+//             }
+//     } else { // table name not given
+//             // try to bind the expression a la `best effort'
+//             e = rel_value_exp(sql, &(g->edges), expr_weight, sql_sel, 
exp_kind_value);
+//     }
 //
-//        // did we bind our parse tree?
-//        if(e){
-//                if(g->cost){ // existing limitation, an expression has 
already been bound
-//                        return sql_error(sql, 02, "TODO: At the moment you 
cannot bind multiple CHEAPEST SUM expression against the same join");
-//                }
+//     // did we bind our parse tree?
+//     if(e){
+//             if(g->cost){ // existing limitation, an expression has already 
been bound
+//                     return sql_error(sql, 02, "TODO: At the moment you 
cannot bind multiple CHEAPEST SUM expression against the same join");
+//             }
 //
-//                // found it!
-//                g->cost = exp_label(sql->sa, e, ++sql->label);
-//                return g->cost;
+//             // found it!
+//             g->cost = exp_label(sql->sa, e, ++sql->label);
+//             return g->cost;
 //
-//        } else { // no, we didn't bind it
-//                return NULL;
-//        }
+//     } else { // no, we didn't bind it
+//             return NULL;
+//     }
 //}
 //
 //static sql_exp* bindg_exp(mvc *sql, sql_exp *exp, dlist *parse_tree){
-//        if(exp->type == e_cmp && get_cmp(exp) == cmp_filter_graph){
-//                // ok this is a graph join
-//                return bindg_filter_graph(sql, exp, parse_tree);
-//        } else {
-//                // this is not a graph join, move along
-//                return NULL;
-//        }
+//     if(exp->type == e_cmp && get_cmp(exp) == cmp_filter_graph){
+//             // ok this is a graph join
+//             return bindg_filter_graph(sql, exp, parse_tree);
+//     } else {
+//             // this is not a graph join, move along
+//             return NULL;
+//     }
 //}
 //// DEBUG ONLY -- copy & paste from sql_gencode.c + decorate = TRUE
-
+//
 //static sql_exp* bindg_exps(mvc *sql, list *exps, dlist *parse_tree){
-//        sql_exp *result = NULL;
+//     sql_exp *result = NULL;
 //
-//        // edge case
-//        if(!exps || error_reported(sql)) return NULL;
+//     // edge case
+//     if(!exps || error_reported(sql)) return NULL;
 //
-//        for(node* n = exps->h; n; n = n->next){
-//                sql_exp *bound = bindg_exp(sql, n->data, parse_tree);
-//                result = bindg_ret(sql, result, bound);
-//                if(error_reported(sql)) return NULL; // ERROR! => stop 
processing
-//        }
+//     for(node* n = exps->h; n; n = n->next){
+//             sql_exp *bound = bindg_exp(sql, n->data, parse_tree);
+//             result = bind_cheapest_sum_return(sql, result, bound);
+//             if(error_reported(sql)) return NULL; // ERROR! => stop 
processing
+//     }
 //
-//        return result;
-//}
-//
-//static sql_exp* bindg_rel(mvc *sql, sql_rel* relation, dlist *parse_tree){
-//        // edge case
-//        if(!relation || error_reported(sql)) return NULL;
-//
-//        switch(relation->op){
-//        case op_full:
-//        case op_left:
-//        case op_right:
-//        case op_semi:
-//                assert("I haven't thought about these cases yet");
-//                break;
-//        case op_join: {
-//                sql_exp *exp1 = NULL, *exp2 = NULL, *exp3 = NULL, *ret = 
NULL;
-//
-//                exp1 = bindg_rel(sql, relation->l, parse_tree);
-//                exp2 = bindg_rel(sql, relation->r, parse_tree);
-//                ret = bindg_ret(sql, exp1, exp2);
-//                exp3 = bindg_exps(sql, relation->exps, parse_tree);
-//                return bindg_ret(sql, ret, exp3);
-//        } break;
-//        case op_select: {
-//                sql_exp* exp1 = bindg_exps(sql, relation->exps, parse_tree);
-//                sql_exp* exp2 = bindg_rel(sql, relation->l, parse_tree);
-//                return bindg_ret(sql, exp1, exp2);
-//        } break;
-//        case op_groupby:
-//                // move up in the tree
-//                return bindg_rel(sql, relation->l, parse_tree);
-//        default:
-//                return NULL;
-//        }
-//
-//        return NULL; // silent the warning
-//}
-//
-//sql_exp* rel_graph_cheapest_sum(mvc *sql, sql_rel **rel, symbol *sym, int 
context){
-//        sql_exp* exp_bound = NULL;
-//        sql_exp* result = NULL;
-//
-//        assert(sym->data.lval != NULL && "CHEAPEST SUM: empty parse tree");
-//
-//        // Check the context is the SELECT clause
-//        if(context != sql_sel){
-//                return sql_error(sql, 02, "CHEAPEST SUM is only allowed 
inside the SELECT clause");
-//        }
-//
-//        // Find the relation where the sub the expression binds to
-//        assert(is_project((*rel)->op) && "Unexpected relation type");
-//        exp_bound = bindg_rel(sql, (*rel)->l, sym->data.lval);
-//        if(!exp_bound){ return NULL; }
-//
-//        // Create the new column
-//        result = exp_column(sql->sa, NULL, exp_bound->name, 
exp_subtype(exp_bound), (*rel)->card, /* has_nil = */ FALSE, /* is_intern = */ 
FALSE);
-//        return result;
+//     return result;
 //}
 
+static sql_exp* bind_cheapest_sum_graph(mvc *sql, sql_graph *graph, dlist 
*parse_tree){
+       const char* table_ref = NULL; // the table referred (optional)
+       symbol* expr_weight = NULL; // the expression inside CHEAPEST SUM ( ... 
);
+       sql_rel* edges = NULL; // the table expression representing the edges
+       sql_exp* e = NULL; // the final result
+       exp_kind exp_kind_value = {type_value, card_column, TRUE}; // 
rel_value_exp parameters
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to