Changeset: c26a27dc94d8 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c26a27dc94d8 Modified Files: geom/monetdb5/geom.c geom/monetdb5/geom.h geom/monetdb5/geomBulk.c Branch: geo-update-dev Log Message:
Geom and GeomBulk cleanup and fixes, added HAVE_RTREE conditions for installation without librtree. diffs (289 lines): diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c --- a/geom/monetdb5/geom.c +++ b/geom/monetdb5/geom.c @@ -113,14 +113,14 @@ wkbCollectAggrSubGroupedCand(bat *outid, //All unions for output BAT if ((unions = GDKzalloc(sizeof(wkb *) * ngrp)) == NULL) { msg = createException(MAL, "geom.Collect", SQLSTATE(HY013) MAL_MALLOC_FAIL); - BBPunfix(out->batCacheid); + BBPreclaim(out); goto free; } //Intermediate array for all the geometries in a group if ((unionGroup = GDKzalloc(sizeof(GEOSGeom) * ci.ncand)) == NULL) { msg = createException(MAL, "geom.Collect", SQLSTATE(HY013) MAL_MALLOC_FAIL); - BBPunfix(out->batCacheid); + BBPreclaim(out); if (unions) GDKfree(unions); goto free; @@ -188,7 +188,6 @@ wkbCollectAggrSubGroupedCand(bat *outid, GDKfree(unionGroup); if (BUNappendmulti(out, unions, ngrp, false) != GDK_SUCCEED) { - //TODO Free out BAT msg = createException(MAL, "geom.Union", SQLSTATE(38000) "BUNappend operation failed"); bat_iterator_end(&bi); if (unions) { @@ -219,6 +218,7 @@ free: BBPunfix(g->batCacheid); if (s) BBPunfix(s->batCacheid); + BBPreclaim(out); return msg; } @@ -228,7 +228,6 @@ wkbCollectAggrSubGrouped(bat *out, const return wkbCollectAggrSubGroupedCand(out, bid, gid, eid, NULL, skip_nils); } -//TODO Use this for the grouped version, just need to separate the groups and then call this one str wkbCollectAggr (wkb **out, const bat *bid) { str msg = MAL_SUCCEED; @@ -3325,7 +3324,6 @@ wkbMakeLine(wkb **out, wkb **geom1WKB, w GEOSCoordSeq_destroy(outCoordSeq); GEOSGeom_destroy(geom1Geometry); GEOSGeom_destroy(geom2Geometry); - return err; } @@ -3513,14 +3511,14 @@ wkbMakeLineAggrSubGroupedCand(bat *outid //Create an array of WKB to hold the results of the MakeLine if ((lines = GDKzalloc(sizeof(wkb *) * ngrp)) == NULL) { msg = createException(MAL, "aggr.MakeLine", SQLSTATE(HY013) MAL_MALLOC_FAIL); - BBPunfix(out->batCacheid); + BBPreclaim(out); goto free; } //Create an array of WKB to hold the points to be made into a line (for one group at a time) if ((lineGroup = GDKzalloc(sizeof(wkb*) * ci.ncand)) == NULL) { msg = createException(MAL, "aggr.MakeLine", SQLSTATE(HY013) MAL_MALLOC_FAIL); - BBPunfix(out->batCacheid); + BBPreclaim(out); goto free; } @@ -3546,7 +3544,6 @@ wkbMakeLineAggrSubGroupedCand(bat *outid msg = wkbMakeLineAggrArray(&lines[lastGrp], lineGroup, position); if (BUNappendmulti(out, lines, ngrp, false) != GDK_SUCCEED) { - //TODO Free out BAT msg = createException(MAL, "geom.Union", SQLSTATE(38000) "BUNappend operation failed"); bat_iterator_end(&bi); goto free; @@ -3569,6 +3566,7 @@ free: BBPunfix(g->batCacheid); if (s) BBPunfix(s->batCacheid); + BBPreclaim(out); return msg; } diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h --- a/geom/monetdb5/geom.h +++ b/geom/monetdb5/geom.h @@ -226,4 +226,7 @@ geom_export str wkbIntersectsSelectRTree geom_export str wkbDWithinJoinRTree(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, bit *nil_matches, lng *estimate); geom_export str wkbDWithinSelectRTree(bat* outid, const bat *bid , const bat *sid, wkb **wkb_const, double *distance, bit *anti); +str wkbDWithinJoinNoIndex(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, bit *nil_matches, lng *estimate); +str wkbDWithinSelectNoIndex(bat* outid, const bat *bid , const bat *sid, wkb **wkb_const, double *distance, bit *anti); + geom_export str mbrIntersects(bit* out, mbr** mbr1, mbr** mbr2); diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c --- a/geom/monetdb5/geomBulk.c +++ b/geom/monetdb5/geomBulk.c @@ -14,9 +14,8 @@ #include "geod.h" #include "geom_atoms.h" -//TODO Is GEOSDistanceWithin(g1,g2,0) the same (performance) as GEOSIntersects(g1,g2)? - /********** Geo Update Start **********/ +#ifdef HAVE_RTREE static str filterSelectRTree(bat* outid, const bat *bid , const bat *sid, GEOSGeom const_geom, mbr *const_mbr, double distance, bit anti, char (*func) (const GEOSGeometry *, const GEOSGeometry *, double), const char *name) { @@ -45,6 +44,13 @@ filterSelectRTree(bat* outid, const bat //Get a candidate list from searching on the rtree with the constant mbr BUN* results_rtree = RTREEsearch(b,(mbr_t*)const_mbr, b->batCount); + if (results_rtree == NULL) { + BBPunfix(b->batCacheid); + if (s) + BBPunfix(s->batCacheid); + BBPreclaim(out); + throw(MAL, name, "RTreesearch failed, returned NULL candidates"); + } //TODO Change literal value of BUN_NONE to BUN_NONE in loop condition //Cycle through rtree candidates @@ -52,9 +58,7 @@ filterSelectRTree(bat* outid, const bat //Then do the actual calculation for the predicate using the GEOS function for (int i = 0; results_rtree[i] != 18446744073709551615U && i < (int) b->batCount; i++) { oid cand = results_rtree[i]; - //If we have a candidate list that is not dense, we need to check if the rtree candidate is also on the original candidate list - //TODO Check w Stefanos if (ci.tpe != cand_dense) { //If the original candidate list does not contain the rtree cand, move on to next one if (!canditer_contains(&ci,cand)) @@ -98,6 +102,7 @@ filterSelectRTree(bat* outid, const bat BBPkeepref(out); return MAL_SUCCEED; } +#endif static str filterSelectNoIndex(bat* outid, const bat *bid , const bat *sid, wkb *wkb_const, double distance, bit anti, char (*func) (const GEOSGeometry *, const GEOSGeometry *, double), const char *name) @@ -180,6 +185,7 @@ filterSelectNoIndex(bat* outid, const ba str wkbIntersectsSelectRTree(bat* outid, const bat *bid , const bat *sid, wkb **wkb_const, bit *anti) { +#ifdef HAVE_RTREE //If there is an RTree on memory or on file, use the RTree method. Otherwise, use the no index version. if (RTREEexists_bid((bat*)bid)) { //Calculate MBR of constant geometry first @@ -200,10 +206,14 @@ wkbIntersectsSelectRTree(bat* outid, con } else return filterSelectNoIndex(outid,bid,sid,*wkb_const,0,*anti,GEOSDistanceWithin,"geom.wkbIntersectsSelectNoIndex"); +#else + return filterSelectNoIndex(outid,bid,sid,*wkb_const,0,*anti,GEOSDistanceWithin,"geom.wkbIntersectsSelectNoIndex"); +#endif } str wkbDWithinSelectRTree(bat* outid, const bat *bid , const bat *sid, wkb **wkb_const, double* distance, bit *anti) { +#ifdef HAVE_RTREE //If there is an RTree on memory or on file, use the RTree method. Otherwise, use the no index version. if (RTREEexists_bid((bat*)bid)) { //Calculate MBR of constant geometry first @@ -222,7 +232,8 @@ wkbDWithinSelectRTree(bat* outid, const //We expand the bounding box to cover the "distance within" area //And use GEOSIntersects with the expanded bounding box - //TODO This expansion is too much + //This expands the box too much + //But better to get more false candidates than not getting a true candidate const_mbr->xmin -=(*distance); const_mbr->ymin -=(*distance); const_mbr->xmax +=(*distance); @@ -232,6 +243,9 @@ wkbDWithinSelectRTree(bat* outid, const } else return filterSelectNoIndex(outid,bid,sid,*wkb_const,*distance,*anti,GEOSDistanceWithin,"geom.wkbDWithinSelectNoIndex"); +#else + return filterSelectNoIndex(outid,bid,sid,*wkb_const,*distance,*anti,GEOSDistanceWithin,"geom.wkbDWithinSelectNoIndex"); +#endif } str @@ -239,6 +253,11 @@ wkbIntersectsSelectNoIndex(bat* outid, c return filterSelectNoIndex(outid,bid,sid,*wkb_const,0,*anti,GEOSDistanceWithin,"geom.wkbIntersectsSelectNoIndex"); } +str +wkbDWithinSelectNoIndex(bat* outid, const bat *bid , const bat *sid, wkb **wkb_const, double *distance, bit *anti) { + return filterSelectNoIndex(outid,bid,sid,*wkb_const,*distance,*anti,GEOSDistanceWithin,"geom.wkbIntersectsSelectNoIndex"); +} + static str filterJoinNoIndex(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, double double_flag, const bat *ls_id, const bat *rs_id, bit nil_matches, lng *estimate, char (*func) (const GEOSGeometry *, const GEOSGeometry *), const char *name) { @@ -389,6 +408,7 @@ free: return msg; } +#ifdef HAVE_RTREE static str filterJoinRTree(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, double double_flag, const bat *ls_id, const bat *rs_id, bit nil_matches, lng *estimate, char (*func) (const GEOSGeometry *, const GEOSGeometry *), const char *name) { (void) lres_id; @@ -404,16 +424,25 @@ filterJoinRTree(bat *lres_id, bat *rres_ (void) name; return MAL_SUCCEED; } +#endif str wkbIntersectsJoinRTree(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, bit *nil_matches, lng *estimate) { +#ifdef HAVE_RTREE return filterJoinRTree(lres_id,rres_id,l_id,r_id,0,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbIntersectsJoinRTree"); +#else + return filterJoinNoIndex(lres_id,rres_id,l_id,r_id,0,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbIntersectsJoinNoIndex"); +#endif } str wkbDWithinJoinRTree(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, bit *nil_matches, lng *estimate) { (void) distance; - return filterJoinRTree(lres_id,rres_id,l_id,r_id,0,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbDWithinJoinRTree"); +#ifdef HAVE_RTREE + return filterJoinRTree(lres_id,rres_id,l_id,r_id,*distance,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbDWithinJoinRTree"); +#else + return filterJoinNoIndex(lres_id,rres_id,l_id,r_id,*distance,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbDWithinJoinNoIndex"); +#endif } str @@ -421,6 +450,11 @@ wkbIntersectsJoinNoIndex(bat *lres_id, b return filterJoinNoIndex(lres_id,rres_id,l_id,r_id,0,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbIntersectsJoinNoIndex"); } +str +wkbDWithinJoinNoIndex(bat *lres_id, bat *rres_id, const bat *l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, bit *nil_matches, lng *estimate) { + return filterJoinNoIndex(lres_id,rres_id,l_id,r_id,*distance,ls_id,rs_id,*nil_matches,estimate,GEOSIntersects,"geom.wkbDWithinJoinNoIndex"); +} + //MBR bulk function //Creates the BAT with MBRs from the input BAT with WKB geometries //Also creates the RTree structure and saves it on the WKB input BAT @@ -467,9 +501,10 @@ wkbMBR_bat(bat *outBAT_id, bat *inBAT_id *outBAT_id = outBAT->batCacheid; +#ifdef HAVE_RTREE //Build RTree index using the mbr's we just calculated, and save it on the wkb BAT BATrtree(inBAT,outBAT); - +#endif BBPkeepref(outBAT); return MAL_SUCCEED; } @@ -484,6 +519,16 @@ wkbTransform_bat(bat *outBAT_id, bat *in str wkbTransform_bat_cand(bat *outBAT_id, bat *inBAT_id, bat *s_id, int *srid_src, int *srid_dst, char **proj4_src_str, char **proj4_dst_str) { +#ifndef HAVE_PROJ + *outBAT_id = NULL; + (void) inBAT_id; + (void) s_id; + (void) srid_src; + (void) srid_dst; + (void) proj4_src_str; + (void) proj4_dst_str; + throw(MAL, "geom.Transform", SQLSTATE(38000) "PROJ library not found"); +#else BAT *outBAT = NULL, *inBAT = NULL, *s = NULL;; BATiter inBAT_iter; str err = MAL_SUCCEED; @@ -607,6 +652,7 @@ wkbTransform_bat_cand(bat *outBAT_id, ba BBPkeepref(outBAT); return MAL_SUCCEED; +#endif } /* ST_DistanceGeographic Bulk function */ @@ -692,6 +738,7 @@ clean: BBPunfix(a->batCacheid); if (b) BBPunfix(b->batCacheid); + BBPunfix(out->batCacheid); return msg; } _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org