Changeset: 181c38c2dd09 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=181c38c2dd09
Modified Files:
        geom/monetdb5/geom.c
        geom/monetdb5/geom.mal
        monetdb5/optimizer/opt_geospatial.c
        monetdb5/optimizer/opt_geospatial.h
Branch: geo
Log Message:

MBRfilter filters both BATs


diffs (104 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -2903,7 +2903,11 @@ str wkbContains_bat_bat(int* outBAT_id, 
        return MAL_SUCCEED;
 
 }
-
+/**
+ * It filters the geometries on one BAT with respect to the MBR of the 
geometry in the other BAT.
+ * The BAT with single geometry is the one used to create the filtering 
condition.
+ * If both BATs have more than one geometries, no filtering is performed.
+ **/
 str wkbFilter_bat(int* outBAT_id, int* aBAT_id, int* bBAT_id) {
        BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL;
        wkb *aWKB = NULL, *bWKB = NULL;
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -414,8 +414,8 @@ geom.prelude();
 
 module batgeom;
 
-command MBRfilter{unsafe}(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:wkb] 
address wkbFilter_bat
-comment "Filters the points in the second bat according to the MBR of the 
first bat. First bat shoud contain only one geometry in order for the filtering 
to be possible.";
+command MBRfilter{unsafe}(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) 
(aFiltered:bat[:oid,:wkb], bFiltered:bat[:oid,:wkb]) address wkbFilter_bat
+comment "Filters the points in the bats according to the MBR of the other bat. 
The BAT with more that one geometries is the one filtered";
 #command point(x:bat[:oid,:dbl],y:bat[:oid,:dbl]) :bat[:oid,:wkb]
 #address wkbcreatepoint_bat
 #comment "Construct a point-BAT from two geometry-BATs";
diff --git a/monetdb5/optimizer/opt_geospatial.c 
b/monetdb5/optimizer/opt_geospatial.c
--- a/monetdb5/optimizer/opt_geospatial.c
+++ b/monetdb5/optimizer/opt_geospatial.c
@@ -10,7 +10,7 @@ int OPTgeospatialImplementation(Client c
        InstrPtr *oldInstrPtr = mb->stmt; //pointer to the first instruction
        int slimit = mb->ssize; //what is this?
        InstrPtr newInstrPtr;
-       int newInstrReturnValue;
+       int aBATreturnId, bBATreturnId;
 
        (void) pci;
        (void) stk;     
@@ -21,7 +21,7 @@ int OPTgeospatialImplementation(Client c
                return 0;
        
 
-       //iterate over the instructions and put them back in the stach
+       //iterate over the instructions
        for(i=0; i<nextFreeSlot; i++) {
 
                //chech the module and function name
@@ -30,20 +30,25 @@ int OPTgeospatialImplementation(Client c
 
                                //create the new instruction
                                newInstrPtr = newStmt(mb, "batgeom", 
"MBRfilter");
-                               //create the return variable of the new 
instruction
-                               newInstrReturnValue = newVariable(mb, 
GDKstrdup("result"), newBatType(TYPE_oid, getArgType(mb,oldInstrPtr[i],2)));
+                               //create the return variables of the new 
instruction
+                               aBATreturnId = newVariable(mb, 
GDKstrdup("aBAT_filtered"), newBatType(TYPE_oid, 
getArgType(mb,oldInstrPtr[i],1)));
+                               bBATreturnId = newVariable(mb, 
GDKstrdup("bBAT_filtered"), newBatType(TYPE_oid, 
getArgType(mb,oldInstrPtr[i],2)));
                                //set the return and input arguments of the new 
instruction
-                               setReturnArgument(newInstrPtr, 
newInstrReturnValue);
+                               setReturnArgument(newInstrPtr, aBATreturnId); 
//set the first return argument
+                               newInstrPtr = pushReturn(mb, newInstrPtr, 
bBATreturnId); //push a second return argument
                                newInstrPtr = pushArgument(mb, newInstrPtr, 
getArg(oldInstrPtr[i],1));
                                newInstrPtr = pushArgument(mb, newInstrPtr, 
getArg(oldInstrPtr[i],2));
-                       
-                               //replace the second argument of the contains 
function with the results of the new instruction (the filtered results) 
+
+                               //replace the arguments of the contains 
function with the results of the new instructions (the filtered results) 
+                               delArgument(oldInstrPtr[i], 1);
                                delArgument(oldInstrPtr[i], 2);
                                pushInstruction(mb, oldInstrPtr[i]);
-                               setArgument(mb, oldInstrPtr[i], 2, 
newInstrReturnValue);
+                               setArgument(mb, oldInstrPtr[i], 1, 
aBATreturnId);
+                               setArgument(mb, oldInstrPtr[i], 2, 
bBATreturnId);
                                
-                               actions++;
-                       }
+                               actions+=3; //three changes
+                       } else //put back all other instructions from batgeom
+                               pushInstruction(mb, oldInstrPtr[i]);
                } else //put all other instructions back
                        pushInstruction(mb, oldInstrPtr[i]);
        }
diff --git a/monetdb5/optimizer/opt_geospatial.h 
b/monetdb5/optimizer/opt_geospatial.h
--- a/monetdb5/optimizer/opt_geospatial.h
+++ b/monetdb5/optimizer/opt_geospatial.h
@@ -17,13 +17,10 @@
  * All Rights Reserved.
  */
 
-#ifndef _OPT_GEOM_
-#define _OPT_GEOM_
-#include "opt_prelude.h"
+#ifndef _OPT_GEOSPATIAL_
+#define _OPT_GEOSPATIAL_
 #include "opt_support.h"
 #include "mal_interpreter.h"
-#include "mal_instruction.h"
-#include "mal_function.h"
 
 opt_export int OPTgeospatialImplementation(Client cntxt, MalBlkPtr mb, 
MalStkPtr stk, InstrPtr pci);
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to