Changeset: 2db68096ac73 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2db68096ac73
Modified Files:
        geom/monetdb5/geom.c
        sql/backends/monet5/vaults/shp/shp.c
Branch: geo-update
Log Message:

Fixed a merge


diffs (246 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -4184,6 +4184,7 @@ str wkbMakeLineAggr(wkb **outWKB, bat *i
        aWKB = (wkb *)BUNtvar(inBAT_iter, 0);
        if (BATcount(inBAT) == 1)
        {
+               bat_iterator_end(&inBAT_iter);
                err = wkbFromWKB(outWKB, &aWKB);
                BBPunfix(inBAT->batCacheid);
                if (err)
@@ -4208,6 +4209,7 @@ str wkbMakeLineAggr(wkb **outWKB, bat *i
                GDKfree(aWKB);
        }
 
+       bat_iterator_end(&inBAT_iter);
        BBPunfix(inBAT->batCacheid);
 
        return err;
@@ -5206,10 +5208,10 @@ str wkbUnionAggr(wkb **outWKB, const bat
 
        //iterator over the BATs
        inBAT_iter = bat_iterator(inBAT);
-
        aWKB = (wkb *)BUNtvar(inBAT_iter, 0);
        if (BATcount(inBAT) == 1)
        {
+               bat_iterator_end(&inBAT_iter);
                err = wkbFromWKB(outWKB, &aWKB);
                BBPunfix(inBAT->batCacheid);
                if (err)
@@ -5232,11 +5234,13 @@ str wkbUnionAggr(wkb **outWKB, const bat
                GDKfree(aWKB);
        }
 
+       bat_iterator_end(&inBAT_iter);
        BBPunfix(inBAT->batCacheid);
 
        return err;
 }
 
+//TODO This is very slow. Is it because of the constant wkbToGEOS and 
GEOSToWkb transformations?
 static str wkbUnionAggrSubGroupedCand(bat *outid, const bat *bid, const bat 
*gid, const bat *eid, const bat *sid, const bit *skip_nils)
 {
        BAT *b = NULL, *g = NULL, *e = NULL, *s = NULL, *out = NULL;
@@ -5261,15 +5265,15 @@ static str wkbUnionAggrSubGroupedCand(ba
                msg = createException(MAL, "geom.Union", 
RUNTIME_OBJECT_MISSING);
                return msg;
        }
-       bi = bat_iterator(b);
 
        //Fill in the values of the group aggregate operation
        if ((err = BATgroupaggrinit(b, g, e, s, &min, &max, &ngrp, &ci, 
&ncand)) != NULL)
        {
                msg = createException(MAL, "geom.Union", "%s", err);
-               BBPunfix(b->batCacheid);
-               return msg;
-       }
+               goto free;
+       }
+
+       //TODO Add check if the ngrp/ncand is 0, or the GDKzalloc below will 
crash mserver
 
        //Create a new BAT column of wkb type, with lenght equal to the number 
of groups
        if ((out = COLnew(min, ATOMindex("wkb"), ngrp, TRANSIENT)) == NULL)
@@ -5278,6 +5282,7 @@ static str wkbUnionAggrSubGroupedCand(ba
                goto free;
        }
 
+       bi = bat_iterator(b);
        //Allocate space for the intermediate unions of wkb's
        if ((unions = GDKzalloc(sizeof(wkb *) * ngrp)) == NULL)
        {
@@ -5299,11 +5304,18 @@ static str wkbUnionAggrSubGroupedCand(ba
                oid grp = gids ? gids[p] : g ? min + (oid)p : 0;
 
 #ifndef NDEBUG
-               char *geomSTR;
+               /*char *geomSTR;
                wkbAsText(&geomSTR, &inWKB, NULL);
                printf("Row %zu: %s\n", i, geomSTR);
                fflush(stdout);
-               GDKfree(geomSTR);
+               GDKfree(geomSTR);*/
+               if (i % 100 == 0) {
+                       printf("Processed %zu records, on group %zu\n", i,grp);
+                       time_t t = time(NULL);
+                       struct tm tm = *localtime(&t);
+                       printf("%d-%02d-%02d %02d:%02d:%02d\n\n", tm.tm_year + 
1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
+                       fflush(stdout);
+               }
 #endif
 
                if (unions[grp] == NULL)
@@ -5355,7 +5367,8 @@ free:
                BBPunfix(e->batCacheid);
        if (s)
                BBPunfix(s->batCacheid);
-       if (unions) {
+       if (unions)
+       {
                for (BUN i = 0; i < ngrp; i++)
                        GDKfree(unions[i]);
                GDKfree(unions);
@@ -6349,7 +6362,7 @@ wkbPUT(BAT *b, var_t *bun, const void *V
 
        *bun = HEAP_malloc(b, wkb_size(val->len));
        base = b->tvheap->base;
-       if (*bun)
+       if (*bun != (var_t) -1)
        {
                memcpy(&base[*bun], val, wkb_size(val->len));
                b->tvheap->dirty = true;
@@ -6843,7 +6856,7 @@ wkbaPUT(BAT *b, var_t *bun, const void *
 
        *bun = HEAP_malloc(b, wkba_size(val->itemsNum));
        base = b->tvheap->base;
-       if (*bun)
+       if (*bun != (var_t) -1)
        {
                memcpy(&base[*bun], val, wkba_size(val->itemsNum));
                b->tvheap->dirty = true;
@@ -6919,8 +6932,10 @@ pnpoly(int *out, int nvert, dbl *vx, dbl
        }
 
        /*Iterate over the Point BATs and determine if they are in Polygon 
represented by vertex BATs */
-       px = (dbl *)Tloc(bpx, 0);
-       py = (dbl *)Tloc(bpy, 0);
+       BATiter bpxi = bat_iterator(bpx);
+       BATiter bpyi = bat_iterator(bpy);
+       px = (dbl *) bpxi.base;
+       py = (dbl *) bpyi.base;
 
        nv = nvert - 1;
        cnt = BATcount(bpx);
@@ -6946,6 +6961,8 @@ pnpoly(int *out, int nvert, dbl *vx, dbl
                *cs++ = wn & 1;
        }
 
+       bat_iterator_end(&bpxi);
+       bat_iterator_end(&bpyi);
        bo->tsorted = bo->trevsorted = false;
        bo->tkey = false;
        BATsetcount(bo, cnt);
@@ -6992,8 +7009,10 @@ pnpolyWithHoles(bat *out, int nvert, dbl
        }
 
        /*Iterate over the Point BATs and determine if they are in Polygon 
represented by vertex BATs */
-       px = (dbl *)Tloc(bpx, 0);
-       py = (dbl *)Tloc(bpy, 0);
+       BATiter bpxi = bat_iterator(bpx);
+       BATiter bpyi = bat_iterator(bpy);
+       px = (dbl *) bpxi.base;
+       py = (dbl *) bpyi.base;
        cnt = BATcount(bpx);
        cs = (bit *)Tloc(bo, 0);
        for (i = 0; i < cnt; i++)
@@ -7049,6 +7068,8 @@ pnpolyWithHoles(bat *out, int nvert, dbl
                }
                *cs++ = wn & 1;
        }
+       bat_iterator_end(&bpxi);
+       bat_iterator_end(&bpyi);
        bo->tsorted = bo->trevsorted = false;
        bo->tkey = false;
        BATsetcount(bo, cnt);
@@ -7798,9 +7819,8 @@ static mel_func geom_init_funcs[] = {
        command("calc", "wkb", wkbFromWKB, false, "It is called when adding a 
new geometry column to an existing table", args(1, 2, arg("", wkb), arg("v", 
wkb))),
        command("calc", "wkb", geom_2_geom, false, "Called when inserting 
values to a table in order to check if the inserted geometries are of the same 
type and srid required by the column definition", args(1, 4, arg("", wkb), 
arg("geo", wkb), arg("columnType", int), arg("columnSRID", int))),
        command("batcalc", "wkb", geom_2_geom_bat, false, "Called when 
inserting values to a table in order to check if the inserted geometries are of 
the same type and srid required by the column definition", args(1, 5, 
batarg("", wkb), batarg("geo", wkb), batarg("s", oid), arg("columnType", int), 
arg("columnSRID", int))),
-       command("batcalc", "wkb", wkbFromText_bat_cand, false, "", args(1,5, 
batarg("",wkb),batarg("wkt",str),batarg("s",oid),arg("srid",int),arg("type",int))),
-       {.imp = NULL}
-};
+       command("batcalc", "wkb", wkbFromText_bat_cand, false, "", args(1, 5, 
batarg("", wkb), batarg("wkt", str), batarg("s", oid), arg("srid", int), 
arg("type", int))),
+       {.imp = NULL}};
 #include "mal_import.h"
 #ifdef _MSC_VER
 #undef read
diff --git a/sql/backends/monet5/vaults/shp/shp.c 
b/sql/backends/monet5/vaults/shp/shp.c
--- a/sql/backends/monet5/vaults/shp/shp.c
+++ b/sql/backends/monet5/vaults/shp/shp.c
@@ -209,12 +209,12 @@ str createSHPtable(Client cntxt, str sch
 
        //Concat the schema name with the table name
        size_t schemaTableSize = strlen(schemaname) + strlen(tablename) + 3;
-       char* schemaTable = GDKmalloc(schemaTableSize);
-       snprintf(schemaTable,schemaTableSize-1,"%s.%s",schemaname,tablename);
-       
+       char *schemaTable = GDKmalloc(schemaTableSize);
+       snprintf(schemaTable, schemaTableSize - 1, "%s.%s", schemaname, 
tablename);
+
        //Build the CREATE TABLE command
        snprintf(buf, size, CRTTBL, schemaTable, temp_buf);
-       
+
        msg = SQLstatementIntern(cntxt, buf, "shp.load", TRUE, FALSE, NULL);
 
        GDKfree(buf);
@@ -235,6 +235,8 @@ str loadSHPtable(mvc *m, sql_schema *sch
        char *nameToLowerCase = NULL;
        int i;
 
+       BUN offset;
+       BAT *pos = NULL;
        sqlstore *store;
 
        /* SHP-level descriptor */
@@ -403,13 +405,12 @@ str loadSHPtable(mvc *m, sql_schema *sch
        }
        /* finalise the BATs */
        store = m->session->tr->store;
-       BUN offset;
-       BAT *pos = NULL;
-       if (store->storage_api.claim_tab(m->session->tr, data_table, 
BATcount(colsBAT[0]), &offset, &pos) != LOG_OK) {
+       if (store->storage_api.claim_tab(m->session->tr, data_table, 
BATcount(colsBAT[0]), &offset, &pos) != LOG_OK)
+       {
                msg = createException(MAL, "shp.load", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                goto unfree;
        }
-               
+
        for (i = 0; i < colsNum; i++)
        {
                if (store->storage_api.append_col(m->session->tr, cols[i], 
offset, pos, colsBAT[i], BATcount(colsBAT[i]), TYPE_bat) != LOG_OK)
@@ -459,9 +460,10 @@ str SHPload(Client cntxt, MalBlkPtr mb, 
        GDALWSimpleFieldDef *field_definitions;
        GDALWSpatialInfo spatial_info;
 
-       if (!(sch = mvc_bind_schema(m, schemaname))) {
+       if (!(sch = mvc_bind_schema(m, schemaname)))
+       {
                /* Can't find schema */
-               return createException(MAL, "shp.load", SQLSTATE(38000) "Schema 
%s missing\n",schemaname);
+               return createException(MAL, "shp.load", SQLSTATE(38000) "Schema 
%s missing\n", schemaname);
        }
 
        if ((tablename != NULL) && (tablename[0] == '\0'))
@@ -469,7 +471,7 @@ str SHPload(Client cntxt, MalBlkPtr mb, 
                /* Output table name is NULL */
                return createException(MAL, "shp.load", SQLSTATE(38000) 
"Missing output table name %s\n", tablename);
        }
-               
+
        if ((shp_conn_ptr = GDALWConnect((char *)filename)) == NULL)
        {
                /* Can't find shapefile */
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to