Changeset: 398a24a90f65 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=398a24a90f65
Added Files:
geom/monetdb5/geom_upgrade.c
Modified Files:
gdk/gdk_logger.c
gdk/gdk_logger.h
geom/monetdb5/Makefile.ag
geom/monetdb5/geom.c
geom/monetdb5/geom.h
sql/backends/monet5/sql_upgrades.c
sql/storage/bat/bat_logger.c
Branch: geo
Log Message:
Moved all upgrade code to the geom module
diffs (truncated from 9311 to 300 lines):
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -127,6 +127,9 @@ log_find(BAT *b, BAT *d, int val)
return BUN_NONE;
}
+static geomcatalogfix_fptr geomcatalogfix = NULL;
+static geomsqlfix_fptr geomsqlfix = NULL;
+
static void
logbat_destroy(BAT *b)
{
@@ -2807,3 +2810,28 @@ logger_find_bat(logger *lg, const char *
}
return 0;
}
+
+void
+geomcatalogfix_set(geomcatalogfix_fptr f)
+{
+ geomcatalogfix = f;
+}
+
+geomcatalogfix_fptr
+geomcatalogfix_get(void)
+{
+ return geomcatalogfix;
+}
+
+void
+geomsqlfix_set(geomsqlfix_fptr f)
+{
+ geomsqlfix = f;
+}
+
+geomsqlfix_fptr
+geomsqlfix_get(void)
+{
+ return geomsqlfix;
+}
+
diff --git a/gdk/gdk_logger.h b/gdk/gdk_logger.h
--- a/gdk/gdk_logger.h
+++ b/gdk/gdk_logger.h
@@ -139,4 +139,12 @@ gdk_export log_bid logger_add_bat(logger
gdk_export void logger_del_bat(logger *lg, log_bid bid);
gdk_export log_bid logger_find_bat(logger *lg, const char *name);
+typedef int (*geomcatalogfix_fptr)(void*,int,int);
+gdk_export void geomcatalogfix_set(geomcatalogfix_fptr);
+gdk_export geomcatalogfix_fptr geomcatalogfix_get(void);
+
+typedef str (*geomsqlfix_fptr)(void);
+gdk_export void geomsqlfix_set(geomsqlfix_fptr);
+gdk_export geomsqlfix_fptr geomsqlfix_get(void);
+
#endif /*_LOGGER_H_*/
diff --git a/geom/monetdb5/Makefile.ag b/geom/monetdb5/Makefile.ag
--- a/geom/monetdb5/Makefile.ag
+++ b/geom/monetdb5/Makefile.ag
@@ -10,12 +10,16 @@ INCLUDES = ../lib \
../../common/stream \
../../common/options \
../../monetdb5/mal \
+ ../../sql/include \
+ ../../sql/common \
+ ../../sql/storage \
+ ../../sql/storage/bat \
$(GEOS_INCS) $(PROJ_INCS)
lib__geom = {
MODULE
DIR = libdir/monetdb5
- SOURCES = geom.h geom.c geomBulk.c
+ SOURCES = geom.h geom.c geomBulk.c geom_upgrade.c
LIBS = ../lib/libgeom \
../../gdk/libbat \
../../common/stream/libstream \
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -1852,6 +1852,9 @@ str geom_prelude(void *ret) {
(void) ret;
libgeom_init();
TYPE_mbr = malAtomSize(sizeof(mbr), sizeof(oid), "mbr");
+ geomcatalogfix_set(geom_catalog_upgrade);
+ geomsqlfix_set(geom_sql_upgrade);
+
return MAL_SUCCEED;
}
@@ -5679,3 +5682,4 @@ wkbContains_point(bit *out, wkb **a, dbl
*out = TRUE;
return MAL_SUCCEED;
}
+
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -25,6 +25,8 @@
#include <math.h>
#include <time.h>
+#include <gdk_logger.h>
+
#ifdef WIN32
#ifndef LIBGEOM
#define geom_export extern __declspec(dllimport)
@@ -289,3 +291,6 @@ geom_export str wkbMBR_bat(bat* outBAT_i
geom_export str wkbCoordinateFromWKB_bat(bat *outBAT_id, bat *inBAT_id, int*
coordinateIdx);
geom_export str wkbCoordinateFromMBR_bat(bat *outBAT_id, bat *inBAT_id, int*
coordinateIdx);
+
+geom_export int geom_catalog_upgrade(void*,int,int);
+geom_export str geom_sql_upgrade(void);
diff --git a/geom/monetdb5/geom_upgrade.c b/geom/monetdb5/geom_upgrade.c
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/geom_upgrade.c
@@ -0,0 +1,4574 @@
+/*
+ * 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.
+ */
+
+/*
+ * @a Kostis Kyzirakos, Foteini Alvanaki
+ */
+
+
+#include <geom.h>
+
+typedef struct list_element {
+ BAT *ob;
+ BAT *nb;
+ char *n;
+} list_element;
+
+typedef struct ulist {
+ size_t capacity;
+ size_t count;
+ list_element *elements;
+} ulist;
+
+static ulist*
+list_init(size_t capacity)
+{
+ ulist *l;
+ if ((l = GDKmalloc(sizeof(ulist))) == NULL)
+ return NULL;
+ l->capacity = capacity;
+ l->count = 0;
+ if ((l->elements = GDKmalloc(capacity*sizeof(list_element))) == NULL) {
+ GDKfree(l);
+ return NULL;
+ }
+ return l;
+}
+
+static char*
+list_delete(ulist* ul)
+{
+ size_t i;
+ for (i = 0; i < ul->count; i++)
+ GDKfree(ul->elements[i].n);
+ GDKfree(ul->elements);
+ GDKfree(ul);
+ return true;
+}
+
+static char*
+list_extend(ulist **ul)
+{
+ ulist* nl;
+ if ((nl = list_init((*ul)->capacity*2)) == NULL )
+ return NULL;
+ memcpy(nl->elements, (*ul)->elements,
sizeof(list_element)*(*ul)->count);
+ nl->count = (*ul)->count;
+ GDKfree((*ul)->elements);
+ GDKfree(*ul);
+ *ul = nl;
+ return true;
+}
+
+static char*
+list_add(ulist **ul, BAT *ob, BAT *nb, char *n)
+{
+ char *nn;
+ if ((nn = GDKmalloc(sizeof(char)*strlen(n))) == NULL)
+ return NULL;
+ strcpy(nn, n);
+ if ((*ul)->count == (*ul)->capacity)
+ if (!list_extend(ul))
+ return NULL;
+ (*ul)->elements[(*ul)->count].ob = ob;
+ (*ul)->elements[(*ul)->count].nb = nb;
+ (*ul)->elements[(*ul)->count].n = nn;
+ (*ul)->count++;
+ return true;
+}
+
+static char *
+mkLower(char *s)
+{
+ char *r = s;
+
+ while (*s) {
+ *s = (char) tolower(*s);
+ s++;
+ }
+ return r;
+}
+
+static char *
+toLower(const char *s)
+{
+ char *r = GDKstrdup((char*)s);
+
+ return r ? mkLower(r) : NULL;
+}
+
+static char *
+N( char *buf, char *pre, char *schema, char *post)
+{
+ if (pre)
+ snprintf(buf, 64, "%s_%s_%s", pre, schema, post);
+ else
+ snprintf(buf, 64, "%s_%s", schema, post);
+ return buf;
+}
+
+int
+geom_catalog_upgrade(void *lg, int EC_GEOM, int EC_EXTERNAL)
+{
+ /* Do the updates needed for the new geom module */
+ BAT *ct, *cnt, *cd, *cnd, *cs, *cns, *cn, *ctid, *ti, *tn, *ts, *si,
*sn, *g;
+ BATiter cti, cdi, csi, cni, ctidi, tsi, tni, sni, gi;
+ char *s = "sys", n[64];
+ BUN p,q;
+ char *nt[] = {"types_id", "types_systemname", "types_sqlname",
"types_digits", "types_scale", "types_radix", "types_eclass",
"types_schema_id"};
+ unsigned char ntt[] = {TYPE_int, TYPE_str, TYPE_str, TYPE_int,
TYPE_int, TYPE_int, TYPE_int, TYPE_int};
+ char *nf[] = {"functions_id", "functions_name", "functions_func",
"functions_mod", "functions_language", "functions_type",
"functions_side_effect", "functions_varres", "functions_vararg",
"functions_schema_id"};
+ unsigned char nft[] = {TYPE_int, TYPE_str, TYPE_str, TYPE_str,
TYPE_int, TYPE_int, TYPE_bit, TYPE_bit, TYPE_bit, TYPE_int};
+ BAT *tt[8], *ttn[8], *ff[10], *ffn[10];
+ BATiter tti[8], ffi[10];
+ int val, maxid, i;
+ size_t ii;
+ bit bval;
+ ulist *ul = list_init(32);
+
+ /* Update the catalog to use the new geometry types */
+ ct = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type")));
+ cti = bat_iterator(ct);
+ cd = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type_digits")));
+ cdi = bat_iterator(cd);
+ cs = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type_scale")));
+ csi = bat_iterator(cs);
+ cn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_name")));
+ cni = bat_iterator(cn);
+ ctid = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_table_id")));
+ ctidi = bat_iterator(ctid);
+ ti = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_id")));
+ tn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_name")));
+ tni = bat_iterator(tn);
+ ts = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_schema_id")));
+ tsi = bat_iterator(ts);
+ si = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"schemas_id")));
+ sn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"schemas_name")));
+ sni = bat_iterator(sn);
+
+ cnt = BATnew(TYPE_void, TYPE_str, BATcount(ct), PERSISTENT);
+ cnd = BATnew(TYPE_void, TYPE_int, BATcount(cd), PERSISTENT);
+ cns = BATnew(TYPE_void, TYPE_int, BATcount(cs), PERSISTENT);
+
+ if (!cnt || !cnd || !cns || !ct || !cd || !cs ||
+ !cn || !ctid || !ti || !tn || !ts || !si || !sn)
+ return 0;
+ BATseqbase(cnt, ct->hseqbase);
+ BATseqbase(cnd, cd->hseqbase);
+ BATseqbase(cns, cs->hseqbase);
+
+ for(p=BUNfirst(ct), q=BUNlast(ct); p<q; p++) {
+ bool isGeom = false;
+ char *type = BUNtail(cti, p);
+ int digits = *(int*)BUNtail(cdi, p);
+ int scale = *(int*)BUNtail(csi, p);
+ char* colname = BUNtail(cni, p);
+
+ if (strcmp(toLower(type), "point") == 0) {
+ type = "geometry";
+ isGeom = true;
+ digits = wkbPoint;
+ scale = 0; // in the past we did not save the srid
+ } else if (strcmp(toLower(type), "linestring") == 0) {
+ type = "geometry";
+ isGeom = true;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list