Changeset: 25dff8591156 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=25dff8591156
Added Files:
        sql/server/rel_graph.c
        sql/server/rel_graph.h
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/include/sql_relation.h
        sql/server/Makefile.ag
        sql/server/rel_dump.c
        sql/server/rel_select.c
        sql/server/sql_parser.y
        sql/server/sql_scan.c
Branch: graph0
Log Message:

Semantic analysis for the graph operator

Starting to convert the parse tree into a relop


diffs (truncated from 357 to 300 lines):

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
@@ -1338,6 +1338,7 @@ rel2bin_args( mvc *sql, sql_rel *rel, li
        case op_left: 
        case op_right: 
        case op_full: 
+       case op_spfw:
 
        case op_apply: 
        case op_semi: 
@@ -1345,7 +1346,7 @@ rel2bin_args( mvc *sql, sql_rel *rel, li
 
        case op_union: 
        case op_inter: 
-       case op_except: 
+       case op_except:
                args = rel2bin_args(sql, rel->l, args);
                args = rel2bin_args(sql, rel->r, args);
                break;
@@ -4637,6 +4638,9 @@ subrel_bin(mvc *sql, sql_rel *rel, list 
        case op_ddl:
                s = rel2bin_ddl(sql, rel, refs);
                break;
+       case op_spfw:
+               // todo
+               return NULL;
        }
        if (s && rel_is_ref(rel)) {
                list_append(refs, rel);
diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h
--- a/sql/include/sql_relation.h
+++ b/sql/include/sql_relation.h
@@ -156,6 +156,7 @@ typedef enum operator_type {
        op_groupby,     
        op_topn,
        op_sample,
+       op_spfw,
        op_insert,      /* insert(l=table, r insert expressions) */ 
        op_update,      /* update(l=table, r update expressions) */
        op_delete       /* delete(l=table, r delete expression) */
diff --git a/sql/server/Makefile.ag b/sql/server/Makefile.ag
--- a/sql/server/Makefile.ag
+++ b/sql/server/Makefile.ag
@@ -49,10 +49,11 @@ lib_sqlserver = {
                rel_psm.c \
                rel_xml.c \
                rel_dump.c \
+               rel_graph.c \
                rel_dump.h rel_exp.h rel_rel.h \
                rel_optimizer.h rel_partition.h rel_distribute.h rel_prop.h 
rel_schema.h rel_select.h \
                rel_semantic.h rel_sequence.h rel_trans.h \
-               rel_updates.h rel_psm.h rel_xml.h sql_atom.h sql_datetime.h \
+               rel_updates.h rel_psm.h rel_xml.h rel_graph.h sql_atom.h 
sql_datetime.h \
                sql_decimal.h sql_env.h sql_mvc.h sql_parser.h \
                sql_privileges.h sql_qc.h sql_scan.h \
                sql_semantic.h sql_symbol.h
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
@@ -283,6 +283,8 @@ op2string(operator_type op)
                return "topn";
        case op_sample:
                return "sample";
+       case op_spfw:
+               return "spfw";
        case op_insert: 
        case op_update: 
        case op_delete: 
@@ -384,6 +386,7 @@ rel_print_(mvc *sql, stream  *fout, sql_
        case op_union: 
        case op_inter: 
        case op_except: 
+       case op_spfw:
                r = "join";
                if (rel->op == op_left)
                        r = "left outer join";
@@ -414,6 +417,8 @@ rel_print_(mvc *sql, stream  *fout, sql_
                        r = "except";
                else if (!rel->exps && rel->op == op_join)
                        r = "crossproduct";
+               else if(rel->op == op_spfw)
+                       r = "spfw";
                print_indent(sql, fout, depth, decorate);
                if (need_distinct(rel))
                        mnstr_printf(fout, "distinct ");
diff --git a/sql/server/rel_graph.c b/sql/server/rel_graph.c
new file mode 100644
--- /dev/null
+++ b/sql/server/rel_graph.c
@@ -0,0 +1,111 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
+ */
+
+#include "monetdb_config.h"
+#include "rel_graph.h"
+
+#include <assert.h>
+
+#include "rel_dump.h"
+#include "rel_exp.h"
+#include "rel_rel.h"
+#include "rel_select.h"
+
+// copied and pasted from codegen
+static str
+rel2str( mvc *sql, sql_rel *rel)
+{
+       buffer *b;
+       stream *s = buffer_wastream(b = buffer_create(1024), "rel_dump");
+       list *refs = sa_list(sql->sa);
+       char *res = NULL;
+
+       rel_print_refs(sql, s, rel, 0, refs, 0);
+       rel_print_(sql, s, rel, 0, refs, 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){
+       str dump = NULL;
+       dnode* lstoperands = NULL; // temp to navigate over the operands
+       symbol* sym_qfrom = NULL; // the `from' column in the ast
+       symbol* sym_qto = NULL; // the `to' column in the ast
+       sql_exp* qfrom = NULL; // reference to the `from' column
+       sql_exp* qto = NULL; // reference to the `to' column
+       exp_kind dummy = {0}; // dummy param, required by rel_value_exp
+       symbol* sym_edges_tbl = NULL; // the table edges in the ast
+       sql_rel* tbl_edges = NULL; // the edges table
+       symbol* sym_edges_from = NULL; // reference to the `edges from' column 
in the ast
+       symbol* sym_edges_to = NULL; // ref to the `edges to' column in the ast
+       sql_exp* efrom = NULL; // ref to the edges column `from'
+       sql_exp* eto= NULL; // ref to the edges column `to'
+       sql_subtype* exptype = NULL; // the expression type for all columns
+       sql_rel* result = NULL; // final output operator
+
+       assert(sq->token == SQL_GRAPH_REACHES && "Invalid label in the AST, 
expected SQL_GRAPH_REACHES");
+
+       // let's see what we have got so far
+       dump = rel2str(sql, rel);
+       printf("Input relation: %s\n", dump);
+
+       lstoperands = sq->data.lval->h;
+       sym_qfrom = lstoperands->data.sym; // first operand symbol( dlist( 
table, column ) )
+       lstoperands = lstoperands->next; // move next
+       sym_qto = lstoperands->data.sym; // second operand symbol( dlist( 
table, column ) )
+
+       qfrom = rel_value_exp(sql, &rel, sym_qfrom, sql_where, dummy);
+       if(!qfrom) return NULL; // cannot refer to qfrom
+       qto = rel_value_exp(sql, &rel, sym_qto, sql_where, dummy);
+       if(!qto) return NULL; // cannot refer to qto
+
+       // assume for the time being qfrom and qto come from the same table
+       // if they are not properly joined => result explosion!
+
+       // edges table
+       lstoperands = lstoperands->next;
+       sym_edges_tbl = lstoperands->data.sym;
+       tbl_edges = table_ref(sql, NULL, sym_edges_tbl, /* lateral = */ 0);
+       if(!tbl_edges) return NULL; // error
+
+       // find the columns in tbl_edges
+       lstoperands = lstoperands->next;
+       sym_edges_from = lstoperands->data.sym;
+       efrom = rel_value_exp(sql, &tbl_edges, sym_edges_from, sql_where, 
dummy);
+       if(!efrom) return NULL; // error
+       lstoperands = lstoperands->next;
+       sym_edges_to = lstoperands->data.sym;
+       eto = rel_value_exp(sql, &tbl_edges, sym_edges_to, sql_where, dummy);
+       if(!eto) return NULL; // error
+
+       // check the types match
+       exptype = exp_subtype(efrom);
+       if(subtype_cmp(exptype, exp_subtype(eto)) < 0){
+               return sql_error(sql, 03, "Types for the edge columns `%s' and 
`%s' do not match", efrom->name, eto->name);
+       }
+       qfrom = rel_check_type(sql, exptype, qfrom, type_equal);
+       if(!qfrom) return NULL; // cannot convert qfrom into the same type of 
efrom
+       qto = rel_check_type(sql, exptype, qto, type_equal);
+       if(!qto) return NULL; // cannot convert qto into the same type of eto
+
+       // build the new operator graphjoin operator
+       result = rel_create(sql->sa);
+       result->l = rel;
+       result->r = tbl_edges;
+       result->op = op_spfw;
+       result->exps = NULL; // TODO: TO BE DONE!
+       result->card = rel->card;
+       result->nrcols = rel->nrcols;
+       result->processed = 1; // *to be checked *
+
+       return rel;
+}
diff --git a/sql/server/rel_graph.h b/sql/server/rel_graph.h
new file mode 100644
--- /dev/null
+++ b/sql/server/rel_graph.h
@@ -0,0 +1,17 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
+ */
+
+#ifndef _REL_GRAPH_H_
+#define _REL_GRAPH_H_
+
+#include "rel_semantic.h"
+#include "sql_semantic.h"
+
+sql_rel* rel_graph_reaches(mvc *sql, sql_rel *rel, symbol *sq);
+
+#endif /* _REL_GRAPH_H_ */
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -21,6 +21,7 @@
 #include "rel_schema.h"
 #include "rel_remote.h"
 #include "rel_sequence.h"
+#include "rel_graph.h"
 #ifdef HAVE_HGE
 #include "mal.h"               /* for have_hge */
 #endif
@@ -2753,6 +2754,8 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
        case SQL_EXCEPT:
        case SQL_INTERSECT:
                return rel_setquery(sql, rel, sc);
+       case SQL_GRAPH_REACHES:
+               return rel_graph_reaches(sql, rel, sc);
        default: {
                sql_exp *re, *le = rel_value_exp(sql, &rel, sc, f, ek);
 
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -7,6 +7,7 @@
  */
 
 %{
+// #define YYDEBUG 1
 #include "monetdb_config.h"
 #include <sql_mem.h>
 #include "sql_parser.h"
@@ -119,9 +120,9 @@ UTF8_strlen(const char *val)
 }
 %{
 extern int sqllex( YYSTYPE *yylval, void *m );
-/* enable to activate debugging support
+/* enable to activate debugging support*/
 int yydebug=1;
-*/
+//*/
 %}
 
        /* symbolic tokens */
@@ -297,6 +298,8 @@ int yydebug=1;
        XML_primary
        opt_comma_string_value_expression
        graph_reaches_exp
+       graph_reaches_column_def
+       graph_reaches_edges_table
 
 %type <type>
        data_type
@@ -555,7 +558,7 @@ int yydebug=1;
 %token FILTER
 
 /* GRAPH tokens */
-%token REACHES
+%token REACHES EDGE
 
 /* operators */
 %left UNION EXCEPT INTERSECT CORRESPONDING UNIONJOIN
@@ -3303,6 +3306,7 @@ predicate:
  |  existence_test
  |  filter_exp
  |  scalar_exp
+ |  graph_reaches_exp
  ;
 
 pred_exp:
@@ -3324,7 +3328,6 @@ pred_exp:
                  else
                        $$ = _symbol_create_symbol(SQL_NOT, $2); }
  |   predicate { $$ = $1; }
- |   graph_reaches_exp /* Disable NOT */
  ;
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to