Changeset: ede777103926 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ede777103926
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        geom/monetdb5/geom.c
        geom/monetdb5/geom.h
        geom/monetdb5/geomBulk.c
Branch: Jul2021
Log Message:

I forgot to add candidate list support for the wkb type conversion


diffs (168 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -5752,7 +5752,7 @@ stdout of test 'MAL-signatures` in direc
 [ "batcalc",   "timestamp",    "pattern batcalc.timestamp(X_0:bat[:timestamp], 
X_1:bat[:oid], X_2:int):bat[:timestamp] ",      "timestamp_2time_timestamp;",   
""      ]
 [ "batcalc",   "uuid", "command batcalc.uuid(X_0:bat[:str], 
X_1:bat[:oid]):bat[:uuid] ",       "UUIDstr2uuid_bulk;",   ""      ]
 [ "batcalc",   "uuid", "command batcalc.uuid(X_0:bat[:uuid], 
X_1:bat[:oid]):bat[:uuid] ",      "UUIDuuid2uuid_bulk;",  ""      ]
-[ "batcalc",   "wkb",  "command batcalc.wkb(X_0:bat[:wkb], X_1:int, 
X_2:int):bat[:wkb] ",      "geom_2_geom_bat;",     ""      ]
+[ "batcalc",   "wkb",  "command batcalc.wkb(X_0:bat[:wkb], X_1:bat[:oid], 
X_2:int, X_3:int):bat[:wkb] ",       "geom_2_geom_bat;",     ""      ]
 [ "batcalc",   "xml",  "command batcalc.xml(X_0:bat[:str]):bat[:xml] ",        
"BATXMLstr2xml;",       ""      ]
 [ "batcalc",   "xor",  "pattern batcalc.xor(X_0:bat[:bit], 
X_1:bat[:bit]):bat[:bit] ", "CMDbatXOR;",   ""      ]
 [ "batcalc",   "xor",  "pattern batcalc.xor(X_0:bat[:bit], X_1:bat[:bit], 
X_2:bat[:oid], X_3:bat[:oid]):bat[:bit] ",   "CMDbatXOR;",   ""      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -8276,7 +8276,7 @@ stdout of test 'MAL-signatures` in direc
 [ "batcalc",   "timestamp",    "pattern batcalc.timestamp(X_0:bat[:timestamp], 
X_1:bat[:oid], X_2:int):bat[:timestamp] ",      "timestamp_2time_timestamp;",   
""      ]
 [ "batcalc",   "uuid", "command batcalc.uuid(X_0:bat[:str], 
X_1:bat[:oid]):bat[:uuid] ",       "UUIDstr2uuid_bulk;",   ""      ]
 [ "batcalc",   "uuid", "command batcalc.uuid(X_0:bat[:uuid], 
X_1:bat[:oid]):bat[:uuid] ",      "UUIDuuid2uuid_bulk;",  ""      ]
-[ "batcalc",   "wkb",  "command batcalc.wkb(X_0:bat[:wkb], X_1:int, 
X_2:int):bat[:wkb] ",      "geom_2_geom_bat;",     ""      ]
+[ "batcalc",   "wkb",  "command batcalc.wkb(X_0:bat[:wkb], X_1:bat[:oid], 
X_2:int, X_3:int):bat[:wkb] ",       "geom_2_geom_bat;",     ""      ]
 [ "batcalc",   "xml",  "command batcalc.xml(X_0:bat[:str]):bat[:xml] ",        
"BATXMLstr2xml;",       ""      ]
 [ "batcalc",   "xor",  "pattern batcalc.xor(X_0:bat[:bit], 
X_1:bat[:bit]):bat[:bit] ", "CMDbatXOR;",   ""      ]
 [ "batcalc",   "xor",  "pattern batcalc.xor(X_0:bat[:bit], X_1:bat[:bit], 
X_2:bat[:oid], X_3:bat[:oid]):bat[:bit] ",   "CMDbatXOR;",   ""      ]
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -6562,7 +6562,7 @@ static mel_func geom_init_funcs[] = {
  command("calc", "mbr", mbrFromMBR, false, "", args(1,2, 
arg("",mbr),arg("v",mbr))),
  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,4, 
batarg("",wkb),batarg("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))),
  { .imp=NULL }
 };
 #include "mal_import.h"
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -236,7 +236,7 @@ geom_export str wkbUnion_bat(bat* outBAT
 
 geom_export str wkbSetSRID_bat(bat* outBAT_id, bat* inBAT_id, int* srid);
 
-geom_export str geom_2_geom_bat(bat* outBAT_id, bat* inBAT_id, int* 
columnType, int* columnSRID);
+geom_export str geom_2_geom_bat(bat* outBAT_id, bat* inBAT_id, bat* cand, int* 
columnType, int* columnSRID);
 
 geom_export str wkbMBR_bat(bat* outBAT_id, bat* inBAT_id);
 
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -17,51 +17,85 @@
 /*******************************/
 
 str
-geom_2_geom_bat(bat *outBAT_id, bat *inBAT_id, int *columnType, int 
*columnSRID)
+geom_2_geom_bat(bat *outBAT_id, bat *inBAT_id, bat *cand, int *columnType, int 
*columnSRID)
 {
-       BAT *outBAT = NULL, *inBAT = NULL;
+       BAT *b = NULL, *s = NULL, *dst = NULL;
+       BATiter bi;
+       str msg = MAL_SUCCEED;
+       struct canditer ci;
+       BUN q = 0;
+       oid off = 0;
+       bool nils = false;
        wkb *inWKB = NULL, *outWKB = NULL;
-       BUN p = 0, q = 0;
-       BATiter inBAT_iter;
 
        //get the descriptor of the BAT
-       if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
-               throw(MAL, "batcalc.wkb", SQLSTATE(38000) 
RUNTIME_OBJECT_MISSING);
+       if ((b = BATdescriptor(*inBAT_id)) == NULL) {
+               msg = createException(MAL, "batcalc.wkb", SQLSTATE(HY005) 
RUNTIME_OBJECT_MISSING);
+               goto bailout;
+       }
+       if (cand && !is_bat_nil(*cand) && (s = BATdescriptor(*cand)) == NULL) {
+               msg = createException(MAL, "batcalc.wkb", SQLSTATE(HY005) 
RUNTIME_OBJECT_MISSING);
+               goto bailout;
        }
-
+       off = b->hseqbase;
+       q = canditer_init(&ci, b, s);
+       bi = bat_iterator(b);
        //create a new BAT, aligned with input BAT
-       if ((outBAT = COLnew(inBAT->hseqbase, ATOMindex("wkb"), 
BATcount(inBAT), TRANSIENT)) == NULL) {
-               BBPunfix(inBAT->batCacheid);
-               throw(MAL, "batcalc.wkb", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       if (!(dst = COLnew(ci.hseq, ATOMindex("wkb"), q, TRANSIENT))) {
+               msg = createException(MAL, "batcalc.wkb", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               goto bailout;
        }
 
-       //iterator over the BAT
-       inBAT_iter = bat_iterator(inBAT);
-       //for (i = 0; i < BATcount(inBAT); i++) {
-       BATloop(inBAT, p, q) {  //iterate over all valid elements
-               str err = NULL;
+       if (ci.tpe == cand_dense) {
+               for (BUN i = 0; i < q; i++) {
+                       oid p = (canditer_next_dense(&ci) - off);
+                       inWKB = (wkb *) BUNtvar(bi, p);
 
-               //if for used --> inWKB = (wkb *) BUNtvar(inBATi, i);
-               inWKB = (wkb *) BUNtvar(inBAT_iter, p);
-               if ((err = geom_2_geom(&outWKB, &inWKB, columnType, 
columnSRID)) != MAL_SUCCEED) {      //check type
-                       BBPunfix(inBAT->batCacheid);
-                       BBPunfix(outBAT->batCacheid);
-                       return err;
+                       if ((msg = geom_2_geom(&outWKB, &inWKB, columnType, 
columnSRID)) != MAL_SUCCEED)        //check type
+                               goto bailout;
+                       if (tfastins_nocheckVAR(dst, i, outWKB, Tsize(dst)) != 
GDK_SUCCEED) {
+                               GDKfree(outWKB);
+                               msg = createException(MAL, "batcalc.wkb", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils |= is_wkb_nil(outWKB);
+                       GDKfree(outWKB);
+                       outWKB = NULL;
                }
-               if (BUNappend(outBAT, outWKB, false) != GDK_SUCCEED) {
-                       BBPunfix(inBAT->batCacheid);
-                       BBPunfix(outBAT->batCacheid);
+       } else {
+               for (BUN i = 0; i < q; i++) {
+                       oid p = (canditer_next(&ci) - off);
+                       inWKB = (wkb *) BUNtvar(bi, p);
+
+                       if ((msg = geom_2_geom(&outWKB, &inWKB, columnType, 
columnSRID)) != MAL_SUCCEED)        //check type
+                               goto bailout;
+                       if (tfastins_nocheckVAR(dst, i, outWKB, Tsize(dst)) != 
GDK_SUCCEED) {
+                               GDKfree(outWKB);
+                               msg = createException(MAL, "batcalc.wkb", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               goto bailout;
+                       }
+                       nils |= is_wkb_nil(outWKB);
                        GDKfree(outWKB);
-                       throw(MAL, "batcalc.wkb", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+                       outWKB = NULL;
                }
-               GDKfree(outWKB);
-               outWKB = NULL;
        }
 
-       BBPunfix(inBAT->batCacheid);
-       BBPkeepref(*outBAT_id = outBAT->batCacheid);
-       return MAL_SUCCEED;
-
+bailout:
+       if (b)
+               BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
+       if (dst && !msg) {
+               BATsetcount(dst, q);
+               dst->tnil = nils;
+               dst->tnonil = !nils;
+               dst->tkey = BATcount(dst) <= 1;
+               dst->tsorted = BATcount(dst) <= 1;
+               dst->trevsorted = BATcount(dst) <= 1;
+               BBPkeepref(*outBAT_id = dst->batCacheid);
+       } else if (dst)
+               BBPreclaim(dst);
+       return msg;
 }
 
 /*create WKB from WKT */
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to