Changeset: 85080e30793f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=85080e30793f
Added Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql_bat2time.c
        sql/backends/monet5/sql_cast.c
        sql/backends/monet5/sql_cast.h
        sql/backends/monet5/sql_cast.sh
        sql/backends/monet5/sql_fround.c
        sql/backends/monet5/sql_rdf.c
        sql/backends/monet5/sql_round.c
Removed Files:
        sql/backends/monet5/sql.mx
Modified Files:
        sql/backends/monet5/Makefile.ag
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_octopus.mal
        sql/backends/monet5/sql_rank.mal
Branch: default
Log Message:

Ditching the sql.mx file
A major breakdown of the sql.mx files into a bunch of .c .h and .mal files.
Further reshuffling to get better functional cohesion might be applied.


diffs (truncated from 27378 to 300 lines):

diff --git a/sql/backends/monet5/Makefile.ag b/sql/backends/monet5/Makefile.ag
--- a/sql/backends/monet5/Makefile.ag
+++ b/sql/backends/monet5/Makefile.ag
@@ -36,7 +36,7 @@ lib__sql = {
        MODULE
        DIR = libdir/monetdb5
        SOURCES = \
-               sql.mx \
+               sql.c sql.h \
                mal_backend.c mal_backend.h \
                sql_user.c sql_user.h \
                sql_scenario.c sql_scenario.h \
@@ -46,7 +46,9 @@ lib__sql = {
                sql_gencode.c sql_gencode.h \
                sql_optimizer.c sql_optimizer.h \
                sql_result.c sql_result.h \
-               sql_readline.c sql_readline.h 
+               sql_readline.c sql_readline.h \
+               sql_cast.c sql_cast.h \
+               sql_round.c sql_bat2time.c sql_fround.c sql_rdf.c
        LIBS = ../../server/libsqlserver \
                   ../../storage/libstore \
                   ../../storage/bat/libbatstore \
@@ -96,7 +98,9 @@ lib__sql = {
 headers_mal = {
        HEADERS = mal
        DIR = libdir/monetdb5
-       SOURCES = sql.mx sql_aggr_bte.mal  sql_aggr_flt.mal  sql_aggr_int.mal  
sql_aggr_lng.mal  sql_aggr_sht.mal  sql_aggr_wrd.mal  sql_decimal.mal  
sql_inspect.mal  sql.mal  sql_octopus.mal  sql_rank.mal  sql_rdf.mal  
sql_sort.mal
+       SOURCES = sql_aggr_bte.mal  sql_aggr_flt.mal  sql_aggr_int.mal  
sql_aggr_lng.mal \
+               sql_aggr_sht.mal  sql_aggr_wrd.mal  sql_decimal.mal  
sql_inspect.mal \
+               sql_rank.mal  sql_rdf.mal  sql_sort.mal sql.mal sql_octopus.mal
 }
 
 headers_autoload = {
@@ -105,5 +109,9 @@ headers_autoload = {
        SOURCES = 40_sql.mal
 }
 
-EXTRA_DIST = 40_sql.mal
+EXTRA_DIST = 40_sql.mal \
+       sql_aggr_bte.mal  sql_aggr_flt.mal  sql_aggr_int.mal  sql_aggr_lng.mal \
+       sql_aggr_sht.mal  sql_aggr_wrd.mal  sql_decimal.mal  sql_inspect.mal \
+       sql_rank.mal  sql_rdf.mal  sql_sort.mal sql.mal sql_octopus.mal
+
 EXTRA_DIST_DIR = Tests
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/sql.c
@@ -0,0 +1,4555 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ * 
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * 
+ * The Original Code is the MonetDB Database System.
+ * 
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+*/
+
+/*
+ * authors M Kersten, N Nes
+ * SQL support implementation
+ * This module contains the wrappers around the SQL
+ * multi-version-catalog and support routines copied
+ * from the Version 4 code base.
+ */
+#include "monetdb_config.h"
+#include "sql.h"
+#include "sql_result.h"
+#include "sql_gencode.h"
+#include <sql_storage.h>
+#include <sql_scenario.h>
+#include <store_sequence.h>
+#include <sql_optimizer.h>
+#include <sql_datetime.h>
+#include <rel_optimizer.h>
+#include <rel_distribute.h>
+#include <rel_select.h>
+#include <rel_exp.h>
+#include <rel_dump.h>
+#include <rel_bin.h>
+#include <bbp.h>
+#include <cluster.h>
+#include <opt_dictionary.h>
+#include <opt_pipes.h>
+#include "clients.h"
+#ifdef HAVE_RAPTOR
+# include <rdf.h>
+#endif
+#include "mal_instruction.h"
+
+/* Windows doesn't have round or trunc, but it does have floor and ceil */
+#ifndef HAVE_ROUND
+static inline double
+round(double val)
+{
+       /* round to nearest integer, away from zero */
+       if (val < 0)
+               return -floor(-val + 0.5);
+       else
+               return floor(val + 0.5);
+}
+#endif
+
+#ifndef HAVE_TRUNC
+static inline double
+trunc(double val)
+{
+       /* round to integer, towards zero */
+       if (val < 0)
+               return ceil(val);
+       else
+               return floor(val);
+}
+#endif
+
+static int
+rel_is_table( sql_rel *rel )
+{
+       if (!rel || is_base(rel->op))
+               return 1;
+       return 0;
+}
+
+static int
+exp_is_point_select( sql_exp * e) 
+{
+       if (!e)
+               return 1;
+       if (e->type == e_cmp && !e->f && e->flag == (int)cmp_equal) {
+               sql_exp *r = e->r;
+
+               if (r->card <= CARD_AGGR) 
+                       return 1;
+       }
+       return 0;
+}
+
+static int
+rel_is_point_query( sql_rel *rel)
+{
+       int is_point = 0;
+
+       if (!rel)
+               return 1;
+       if (is_project(rel->op))
+               return rel_is_point_query(rel->l);
+       if (is_select(rel->op) && rel_is_table(rel->l) && rel->exps) {
+/*
+               node *n;
+               is_point = 1;
+               for (n=rel->exps->h; n && is_point; n = n->next) {
+                       if (!exp_is_point_select(n->data))
+                               is_point = 0;
+               }
+*/
+               is_point = 0;
+               /* just one point expression makes this a point query */
+               if (rel->exps->h)
+                       if (exp_is_point_select(rel->exps->h->data))
+                               is_point = 1;
+       }
+       return is_point;
+}
+
+static int
+rel_need_distinct_query( sql_rel *rel)
+{
+       int need_distinct = 0;
+
+       while (!need_distinct && rel && is_project(rel->op) && 
!is_groupby(rel->op))
+               rel = rel->l;
+       if (!need_distinct && rel && is_groupby(rel->op) && rel->exps) {
+               node *n, *m;
+               for (n=rel->exps->h; n && !need_distinct; n = n->next) {
+                       sql_exp *e = n->data;
+                       if (e->type == e_aggr) {
+                               list *l = e->l;
+
+                               if (l) for(m = l->h; m && !need_distinct; m = 
m->next){
+                                       sql_exp *a = m->data;
+       
+                                       if (need_distinct(a))
+                                               need_distinct = 1;
+                               }
+                       }
+               }
+       }
+       return need_distinct;
+}
+
+
+sql_rel *
+sql_symbol2relation(mvc *c, symbol *sym)
+{
+       sql_rel *r;
+
+       r = rel_semantic(c, sym);
+       if (!r) 
+               return NULL;
+       if (r) {
+               r = rel_optimizer(c, r);
+               r = rel_distribute(c, r);
+               if (rel_is_point_query(r) || rel_need_distinct_query(r))
+                       c->point_query = 1;
+       }
+       return r;
+}
+
+stmt *
+sql_relation2stmt(mvc *c, sql_rel *r)
+{
+       stmt *s = NULL;
+
+       if (!r) {
+               return NULL;
+       } else {
+               if (c->emode == m_plan) {
+                       rel_print(c, r, 0);
+               } else {
+                       s = output_rel_bin(c, r);
+               }
+       }
+       return s;
+}
+
+/*
+ * After the SQL statement has been executed, its data structures
+ * should be garbage collected. For successful actions we have to finish
+ * the transaction as well, e.g. commit or rollback.
+ */
+int
+sqlcleanup(mvc *c, int err)
+{
+       sql_destroy_params(c);
+       sql_destroy_args(c);
+
+       if ((c->emod & mod_locked) == mod_locked) {
+               /* here we should commit the transaction */
+               if (!err) {
+                       sql_trans_commit(c->session->tr);
+                       /* write changes to disk */
+                       sql_trans_end(c->session);
+                       store_apply_deltas();
+                       sql_trans_begin(c->session);
+               }
+               store_unlock();
+               c->emod = 0;
+       }
+       /* some statements dynamically disable caching */
+       c->sym = NULL;
+       if (c->sa) 
+               c->sa = sa_reset(c->sa);
+       if (err > 0)
+               c->session->status = -err;
+       if (err < 0)
+               c->session->status = err;
+       c->label = 0;
+       c->point_query = 0;
+       scanner_query_processed(&(c->scanner));
+       return err;
+}
+
+/*
+ * The internal administration of the SQL compilation and execution state
+ * is administered by a state descriptor accessible in each phase.
+ * Failure to find the state descriptor aborts the session.
+ */
+
+str
+checkSQLContext(Client cntxt)
+{
+       backend *be;
+
+       if (cntxt == NULL)
+               throw(SQL, "mvc", "No client record");
+       if (cntxt->sqlcontext == NULL)
+               throw(SQL, "mvc", "SQL module not initialized");
+       be = (backend *) cntxt->sqlcontext;
+       if (be->mvc == NULL)
+               throw(SQL, "mvc", "SQL module not initialized, mvc struct 
missing");
+       return MAL_SUCCEED;
+}
+
+str 
+getSQLContext(Client cntxt, MalBlkPtr mb, mvc **c, backend **b)
+{
+       backend *be;
+       (void) mb;
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to