Changeset: 220733c8ae40 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=220733c8ae40
Added Files:
        sql/backends/monet5/UDF/80_ssdb.mal
        sql/backends/monet5/UDF/80_ssdb.sql
        sql/backends/monet5/UDF/ssdb.c
        sql/backends/monet5/UDF/ssdb.h
        sql/backends/monet5/UDF/ssdb.mal
Modified Files:
        sql/backends/monet5/UDF/Makefile.ag
Branch: ssdb2
Log Message:

merged from the (first) ssdb branch


diffs (truncated from 1931 to 300 lines):

diff --git a/sql/backends/monet5/UDF/80_ssdb.mal 
b/sql/backends/monet5/UDF/80_ssdb.mal
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/80_ssdb.mal
@@ -0,0 +1,20 @@
+# 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-2012 MonetDB B.V.
+# All Rights Reserved.
+
+# This announces the SSDB module to the MAL interpreter
+
+include ssdb;
diff --git a/sql/backends/monet5/UDF/80_ssdb.sql 
b/sql/backends/monet5/UDF/80_ssdb.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/80_ssdb.sql
@@ -0,0 +1,76 @@
+/*
+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-2012 MonetDB B.V.
+All Rights Reserved.
+*/
+
+-- This file defines the signatures of the UDFs needed to run the SS-DB
+--   benchmark on MonetDB
+
+-- Cooks one pixels value (tin_pixs.val) for each image in the input table
+--   'tin_pixs' according to the description in the SS-DB paper.
+-- tin: name of the input table for image pixel values, with columns
+--             (imageid int, x int, y int, val int)
+-- tout_obs: name of the output table for observations, with columns
+--             (obsid INT, imageid INT, time INT, cyclem INT, averageDist REAL,
+--              pixelSum BIGINT, centerx INT, centery INT,
+--              boxxstart INT, boxystart INT, boxxend INT, boxyend INT)
+-- tout_plg: name of the output table for polygons, with columns
+--             (obsid INT, ord INT, x INT, y INT)
+-- width: width of all images, assuming they are the same
+-- height: height of all images, assuming they are the same
+CREATE PROCEDURE cooking (tin CHAR(128), tout_obs CHAR(128), tout_plg 
CHAR(128), imgsize INT)
+EXTERNAL NAME ssdb.cooking;
+
+-- Cooks observations from the input table
+--   'tin' according to the description in the SS-DB paper.
+-- tin: name of the input table for image pixel values, with columns
+--             (l_obsid int, l_time int, l_centerx int, l_centery int, r_obsid 
int, r_time int, r_centerx int, r_centery int)
+-- tout_grp: name of the output table for groups, with columns
+--             (obsgroupid INT, center_traj_x INT, center_traj_y INT, fromtime 
INT, totime INT)
+-- tout_obs: name of the output table for groups-observations, with columns
+--             (obsgroupid INT, obsid INT)
+--observations: total number of observations-1
+CREATE PROCEDURE grouping (tin CHAR(128), tout_grp CHAR(128), tout_obs 
CHAR(128), observations INT)
+EXTERNAL NAME ssdb.grouping;
+
+-- Determines for each polygon in the input table 'tin' if it intersects with
+--   the bounding box by [(xstart, ystart), (xstart+xlen, ystart+ylen)
+-- The ID of the intersecting polygons are stored in the output table 'tout'
+-- tin: name of the input table, with columns (obsid int, ord int, x int, y 
int)
+-- tout: name of the output table, with columns (obsid int)
+CREATE PROCEDURE intersects (
+       tin CHAR(128), tout CHAR(128), xstart INT, ystart INT, xlen INT, ylen 
INT)
+EXTERNAL NAME ssdb.intersects;
+
+-- Regrid each image in the input table 'tin' according to the definition of 
Q3.
+-- tin: name of the input table, with columns (imageid int, x int, y int, val 
int)
+-- tout: name of the output table, with columns (imageid int, x int, y int, 
avgval real)
+CREATE PROCEDURE regrid (tin CHAR(128), tout CHAR(128))
+EXTERNAL NAME ssdb.regrid;
+
+-- Group the pixels in the input table 'tin' into tiles and return the centers
+--   (x,y) and the number of observations, i.e., cnt, in those tiles, where
+--   cnt > $threshold
+-- See for more information the definition of Q6.
+-- tin: name of the input table, with columns (x int, y int), i.e., the
+--   center{x,y} of all observations.
+-- tout: name of the output table, with columns (x int, y int, cnt int), i.e.,
+--   the center{x,y} of the tiles and the density
+CREATE PROCEDURE density (
+       tin CHAR(128), tout CHAR(128), x2 INT, u2 INT, y2 INT, v2 INT, tilesize 
INT, threshold INT)
+EXTERNAL NAME ssdb.density;
+
diff --git a/sql/backends/monet5/UDF/Makefile.ag 
b/sql/backends/monet5/UDF/Makefile.ag
--- a/sql/backends/monet5/UDF/Makefile.ag
+++ b/sql/backends/monet5/UDF/Makefile.ag
@@ -38,22 +38,30 @@ lib__udf = {
                   ../../../../gdk/libbat
 }
 
+lib__ssdb = {
+       MODULE
+       DIR = libdir/monetdb5
+       SOURCES = ssdb.c ssdb.h
+       LIBS = ../../../../monetdb5/tools/libmonetdb5 \
+                  ../../../../gdk/libbat
+}
+
 headers_mal = {
        HEADERS = mal
        DIR = libdir/monetdb5
-       SOURCES = udf.mal
+       SOURCES = udf.mal ssdb.mal
 }
 
 headers_sql = {
        HEADERS = sql
        DIR = libdir/monetdb5/createdb
-       SOURCES = 80_udf.sql
+       SOURCES = 80_udf.sql 80_ssdb.sql
 }
 
 headers_autoload = {
        HEADERS = mal
        DIR = libdir/monetdb5/autoload
-       SOURCES = 80_udf.mal
+       SOURCES = 80_udf.mal 80_ssdb.mal
 }
 
 EXTRA_DIST_DIR = Tests
diff --git a/sql/backends/monet5/UDF/ssdb.c b/sql/backends/monet5/UDF/ssdb.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/ssdb.c
@@ -0,0 +1,1665 @@
+/*
+ * 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-2012 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/* monetdb_config.h must be the first include in each .c file */
+#include "monetdb_config.h"
+#include "sql.h"
+#include "sql_semantic.h"
+#include "ssdb.h"
+
+#define IS_SAME_POINT(p, q) ((p).x == (q).x && (p).y == (q).y)
+#define IS_LESS_POINT(p, q) ((p).y < (q).y || ((p).y == (q).y && (p).x < 
(q).x))
+#define APPEND_POINT(obspix, xnew, ynew) \
+{ \
+       (obspix).pnt[(obspix).cnt].x = (xnew); \
+       (obspix).pnt[(obspix).cnt].y = (ynew); \
+       (obspix).cnt++; \
+}
+
+#define _MIN(a, b) ((a) < (b) ? (a) : (b))
+#define _MAX(a, b) ((a) > (b) ? (a) : (b))
+
+/* for curve-tracing */
+/* Lookup table for polygoniser to make the direction logic simpler */
+point DIRECTIONS[] = { /* for curve-tracing */
+       { 0, -1},  /* [ 0] */
+       { 1, -1},  /* [ 1] */
+       { 1,  0},  /* [ 2] */
+       { 1,  1},  /* [ 3] */
+       { 0,  1},  /* [ 4] */
+       {-1,  1},  /* [ 5] */
+       {-1,  0},  /* [ 6] */
+       {-1, -1},  /* [ 7] */
+       { 0, -1},  /* [ 8] */
+       { 1, -1},  /* [ 9] */
+       { 1,  0},  /* [10] */
+       { 1,  1},  /* [11] */
+       { 0,  1},  /* [12] */
+       {-1,  1},  /* [13] */
+       {-1,  0},  /* [14] */
+       {-1, -1},  /* [15] */
+       { 0,  0}}; /* [16], safety values */
+
+static sql_table *
+_bind_table(mvc *sql, char *sname, char *tname)
+{
+       sql_table *t = NULL;
+       
+       if (sname)
+               t = mvc_bind_table(sql, mvc_bind_schema(sql, sname), tname);
+       if (!t)
+               mvc_bind_table(sql, cur_schema(sql), tname);
+       if (!t) 
+               t = mvc_bind_table(sql, mvc_bind_schema(sql, "sys"), tname);
+       if (!t)
+               t = mvc_bind_table(sql, tmp_schema(sql), tname);
+
+       return t;
+}
+
+static BAT *
+_bind_bat(mvc *sql, sql_table *t, char *cname, int localtype, int access)
+{
+       BAT *b = NULL;
+       sql_column *c = mvc_bind_column(sql, t, cname);
+
+       if (c)
+               b = store_funcs.bind_col(sql->session->tr, c, access);
+       if (b && (b->ttype != localtype))
+               return sql_error(sql, 02, "_bind_bat(): column '%s.%s' has type 
%d, expedted %d", t->base.name, cname, b->ttype, localtype);
+       return b;
+}
+
+static str
+_append_bat(mvc *sql, sql_table *t, char *cname, BAT *b)
+{
+       sql_column *c = mvc_bind_column(sql, t, cname);
+
+       if (!c)
+               return sql_message("42S22!_append_bat(): no such column 
'%s.%s'", t->base.name, cname);
+       store_funcs.append_col(sql->session->tr, c, b, TYPE_bat);
+       return NULL;
+}
+
+static obs_pixels *
+_obs_pix_expand(obs_pixels *op_ptr)
+{
+       void *ptr;
+       unsigned int newcap = op_ptr->cap * 2;
+
+       if (!(ptr = GDKrealloc(op_ptr->pnt, newcap * sizeof(point))))
+               return NULL;
+       op_ptr->pnt = (point *) ptr;
+       op_ptr->cap = newcap;
+       return op_ptr;
+}
+
+/* binary search of 'key' in 'pnts' */
+static int
+_find_point(point *pnts, point *key, int imin, int imax)
+{
+       int imid;
+
+       /* if the array of points is empty, return not found */
+       if (imax < imin)
+               return -1;
+
+       /* avoid possible overflow */
+       imid = (int) (((long long)imin + (long long) imax) / 2);
+       if (IS_SAME_POINT(pnts[imid], *key))
+               return imid;
+       else if (IS_LESS_POINT(*key, pnts[imid])) /* key is in lower subset */
+               return _find_point(pnts, key, imin, imid-1);
+       else /* key is in upper subset */
+               return _find_point(pnts, key, imid+1, imax);
+       return -1; /* quite the compiler */
+}
+
+/* find the next pixel and next direction */
+static void
+_choose_next(obs_pixels *pix, unsigned int cur_pix, unsigned int cur_dir, 
unsigned int *next_pix, unsigned int *next_dir)
+{
+       int leftTurn = 1, idx = 0, nxt = -1;
+       point prosp;
+
+       /* Compensate for diagonals: okay to turn 90 degrees left for them. */
+       if ((DIRECTIONS[cur_dir].x * DIRECTIONS[cur_dir].x +
+                DIRECTIONS[cur_dir].y * DIRECTIONS[cur_dir].y) == 2) { /* 
diagonal? */
+               leftTurn = 2;
+       }
+       /* Seek to current direction. */
+       for (idx = leftTurn; !IS_SAME_POINT(DIRECTIONS[idx], 
DIRECTIONS[cur_dir]); ++idx);
+       /* Then back-off two: while tracing, we can at most turn left 90deg */
+       idx -= leftTurn;
+
+       do {
+               prosp.x = pix->pnt[cur_pix].x + DIRECTIONS[idx].x;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to