Changeset: 129094d42aa3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=129094d42aa3
Modified Files:
        monetdb5/optimizer/opt_prelude.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_statement.h
        sql/server/rel_dump.c
        sql/server/rel_dump.h
        sql/server/rel_optimizer.c
        sql/server/rel_rel.c
Branch: graph0
Log Message:

MIL Codegen - WIP


diffs (truncated from 336 to 300 lines):

diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -94,6 +94,8 @@ str getRef;
 str getTraceRef;
 str generatorRef;
 str grabRef;
+str graphRef;
+str graph_makeRef;
 str groupRef;
 str subgroupRef;
 str subgroupdoneRef;
@@ -326,6 +328,8 @@ void optimizerInit(void)
        getTraceRef = putName("getTrace");
        generatorRef = putName("generator");
        grabRef = putName("grab");
+       graphRef = putName("graph");
+       graph_makeRef = putName("gmake");
        groupRef = putName("group");
        subgroupRef = putName("subgroup");
        subgroupdoneRef= putName("subgroupdone");
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4553,10 +4553,81 @@ rel2bin_ddl(mvc *sql, sql_rel *rel, list
 static stmt *
 rel2bin_spfw(mvc *sql, sql_rel *rel, list *refs)
 {
-       printf("[Codegen] Input relation: %s\n", rel_to_str(sql, rel));
-
-       // for the time being, just ignore spfw and generate the code for the 
upper table
-       return subrel_bin(sql, rel->l, refs);
+       stmt *edges = NULL, *spfw = NULL, *graph = NULL;
+       stmt *left = NULL, right = NULL;
+       stmt *c = NULL, *g = NULL, *groups = NULL, *smpl = NULL;
+       stmt *D = NULL;
+       stmt *p0 = NULL, *p1 = NULL;
+       list *l = NULL;
+       stmt *e_from = NULL, *e_to = NULL, *q_from = NULL, *q_to = NULL;
+       node *n = NULL;
+
+       // materialize the input relations
+       left = subrel_bin(sql->sa, rel->l, refs);
+       if(!left) return NULL;
+       (void) right;
+       edges = subrel_bin(sql->sa, rel->r, refs);
+       if(!edges) return NULL;
+
+       // refer to the columns
+       assert(rel->exps->cnt == 4 && "Expected four columns as input (ftb)"); 
// TODO weights missing
+       n = rel->exps->h;
+       q_from = exp_bin(sql->sa, n->data, left, NULL, NULL, NULL, NULL, NULL);
+       n = n->next;
+       q_to = exp_bin(sql->sa, n->data, left, NULL, NULL, NULL, NULL, NULL);
+       n = n->next;
+       e_from = exp_bin(sql->sa, n->data, edges, NULL, NULL, NULL, NULL, NULL);
+       n = n->next;
+       e_to = exp_bin(sql->sa, n->data, edges, NULL, NULL, NULL, NULL, NULL);
+
+       // create the graph
+       // this is, like, super fun!
+       l = sa_list(sql->sa);
+       list_append(l, e_from);
+       list_append(l, e_to);
+       c = stmt_concat(sql->sa, l);
+       g = stmt_group(sql->sa, c, NULL, NULL, NULL);
+       groups = stmt_result(sql->sa, g, 0);
+       smpl = stmt_result(sql->sa, g, 1);
+       e_from = stmt_mkpartition(sql->sa, groups, 0, 2);
+       e_to = stmt_mkpartition(sql->sa, groups, 1, 2);
+       graph = stmt_mkgraph(sql->sa, e_from, e_to);
+
+       // map the values in qfrom, qto into vertex IDs
+       D = stmt_project(sql->sa, smpl, c); // domain
+
+       // make the operator
+       spfw = stmt_spfw(sql->sa, left, graph);
+
+
+
+//     spfw->op4.lval = sa_list(sql->sa);
+//     for(node* n = rel->exps->h; n; n = n->next){
+//             list_append(spfw->op4.lval, exp_bin(sql, n->data, left, edges, 
NULL, NULL, NULL, NULL));
+//     }
+//
+//     // input columns (for debug reasons)
+//     do { // damn c
+//             int i = 0;
+//             for(node* n = left->op4.lval->h; n; n = n->next, i++){
+//                     stmt* s = n->data;
+//                     printf("[%d] %s %s, with f: %s %s, type: %d, tbl: 
%p\n", i, s->tname, s->cname, table_name(sql->sa, s), column_name(sql->sa, s), 
s->type, s->op4.tval);
+//             }
+//     } while(0);
+//
+//     // apply the filter
+//     r = stmt_result(sql->sa, spfw, 0);
+//     l = sa_list(sql->sa);
+//     for(node *n = left->op4.lval->h; n; n = n->next) {
+//             stmt *col = n->data;
+//
+//             if (col->nrcols == 0) /* constant */
+//                     col = stmt_const(sql->sa, r, col);
+//             else
+//                     col = stmt_project(sql->sa, r, col);
+//             list_append(l, col);
+//     }
+//     return stmt_list(sql->sa, l);
 }
 
 static stmt *
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -2771,6 +2771,37 @@ static int
                        if (q == NULL)
                                return -1;
                } break;
+               case st_mkgraph: {
+
+               } break;
+               case st_spfw: {
+                       stmt *qfrom = NULL, *qto = NULL, *efrom = NULL, *eto = 
NULL;
+                       int left = -1, edges = -1;
+                       node* n = NULL;
+
+                       left = _dumpstmt(sql, mb, s->op1);
+                       if(left < 0)
+                               return -1;
+
+                       edges = _dumpstmt(sql, mb, s->op2);
+                       if(edges < 0)
+                               return -1;
+
+                       // retrieve the columns
+                       n = s->op4.lval->h;
+                       qfrom = n->data;
+                       n = n->next;
+                       qto = n->data;
+                       n = n->next;
+                       efrom = n->data;
+                       n = n->next;
+                       eto = n->data;
+
+                       (void) qfrom;
+                       (void) qto;
+                       (void) efrom;
+                       (void) eto;
+               } break;
                }
                if (mb->errors)
                        return -1;
diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -120,6 +120,9 @@ st_type2string(st_type type)
                ST(control_end);
                ST(return);
                ST(assign);
+
+               ST(mkgraph);
+               ST(spfw);
        default:
                return "unknown";       /* just needed for broken compilers ! */
        }
@@ -320,6 +323,8 @@ stmt_deps(list *dep_list, stmt *s, int d
 
                        case st_uselect:
                        case st_uselect2:
+
+                       case st_spfw:
                                if (s->op1)
                                        push(s->op1);
                                if (s->op2)
@@ -1361,6 +1366,7 @@ const char *
        case st_tdiff:
        case st_tinter:
        case st_convert:
+       case st_spfw:
                return column_name(sa, st->op1);
        case st_Nop:
        {
@@ -1432,6 +1438,7 @@ const char *
        case st_tdiff:
        case st_tinter:
        case st_aggr:
+       case st_spfw:
                return table_name(sa, st->op1);
 
        case st_table_clear:
@@ -1489,6 +1496,7 @@ schema_name(sql_allocator *sa, stmt *st)
        case st_convert:
        case st_Nop:
        case st_aggr:
+       case st_spfw:
                return schema_name(sa, st->op1);
        case st_alias:
                /* there are no schema aliases, ie look into the base column */
@@ -1593,6 +1601,51 @@ stmt_assign(sql_allocator *sa, const cha
 }
 
 stmt *
+stmt_concat(sql_allocator *sa, list* l)
+{
+       stmt *s = stmt_create(sa, st_concat);
+       s->op4.lval = l;
+       s->nr = 1;
+       return s;
+}
+
+stmt *
+stmt_mkgraph(sql_allocator *sa, stmt* from, stmt* to)
+{
+       stmt *s = stmt_create(sa, st_mkgraph);
+       s->op1 = from;
+       s->op2 = to;
+       s->nrcols = 3; // 4 with the weights
+       return s;
+}
+
+stmt *
+stmt_mkpartition(sql_allocator *sa, stmt* st, int partno, int num_partitions)
+{
+       stmt *s = stmt_create(sa, st_mkpartition);
+       list *l = sa_list(sa);
+       s->op1 = st;
+       list_append(l, (void*) partno);
+       list_append(l, (void*) num_partitions);
+       s->op4 = l;
+       s->nrcols = 1;
+       return s;
+}
+
+stmt *
+stmt_spfw(sql_allocator *sa, stmt* l, stmt* edges)
+{
+       stmt *s = stmt_create(sa, st_spfw);
+       s->op1 = l;
+       s->op2 = edges;
+
+       // strong suspects these are the output cols of the operator
+       s->nrcols = 2;
+
+       return s;
+}
+
+stmt *
 const_column(sql_allocator *sa, stmt *val)
 {
        sql_subtype *ct = tail_type(val);
diff --git a/sql/backends/monet5/sql_statement.h 
b/sql/backends/monet5/sql_statement.h
--- a/sql/backends/monet5/sql_statement.h
+++ b/sql/backends/monet5/sql_statement.h
@@ -94,7 +94,13 @@ typedef enum stmt_type {
        st_cond,
        st_control_end,
        st_return,
-       st_assign
+       st_assign,
+
+       // these are new kids in the town
+       st_concat,
+       st_mkgraph,
+       st_mkpartition,
+       st_spfw,
 } st_type;
 
 /* flag to indicate anti join/select */
@@ -240,6 +246,10 @@ extern stmt *stmt_if(sql_allocator *sa, 
 extern stmt *stmt_return(sql_allocator *sa, stmt *val, int 
nr_of_declared_tables);
 extern stmt *stmt_assign(sql_allocator *sa, const char *varname, stmt *val, 
int level);
 
+extern stmt *stmt_concat(sql_allocator *sa, list *l);
+extern stmt *stmt_mkgraph(sql_allocator *sa, stmt *from, stmt *to); // + 
weights
+extern stmt *stmt_spfw(sql_allocator *sa, stmt* l, stmt* edges);
+
 extern sql_subtype *tail_type(stmt *st);
 extern int stmt_has_null(stmt *s);
 
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
@@ -1360,3 +1360,18 @@ rel_to_str(mvc *sql, sql_rel *rel)
        mnstr_destroy(s);
        return res;
 }
+
+str
+exp_to_str(mvc *sql, sql_exp *exp)
+{
+       buffer *b;
+       stream *s = buffer_wastream(b = buffer_create(1024), "exp_dump");
+       char *res = NULL;
+
+       exp_print(sql, s, exp, 0, /*comma = */ 0, 0);
+       mnstr_printf(s, "\n");
+       res = buffer_get_buf(b);
+       buffer_destroy(b);
+       mnstr_destroy(s);
+       return res;
+}
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to