Changeset: 7d58e725c06a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7d58e725c06a
Modified Files:
        geom/monetdb5/grid.c
        geom/sql/Tests/grid.sql
        geom/sql/Tests/grid.stable.out
Branch: grid
Log Message:

2D grid produces correct results


diffs (truncated from 697 to 300 lines):

diff --git a/geom/monetdb5/grid.c b/geom/monetdb5/grid.c
--- a/geom/monetdb5/grid.c
+++ b/geom/monetdb5/grid.c
@@ -35,24 +35,24 @@ do {                                    
        max = res + add;                            \
 } while (0)
 
-#define GRIDextend(g1, g2, cellR, cellS, r1, r2, msg)                          
    \
-do {                                                                           
    \
-/* make space to cater for the worst case where all points qualify */          
    \
-BUN maxSize = BATcount((r1)) +                                                 
    \
-              ((g1)->dir[(cellR)+1]-(g1)->dir[(cellR)])*                       
    \
-              ((g2)->dir[(cellS)+1]-(g2)->dir[(cellS)]);                       
    \
-       if (maxSize > GDK_oid_max) {                                            
       \
-                       (msg) = createException(MAL,"grid.distance","overflow 
of head value"); \
-                       goto distancejoin_fail;                                 
               \
-       }                                                                       
       \
-       while (maxSize > BATcapacity((r1))) {                                   
       \
-               if ((BATextend((r1), BATgrows((r1))) != GDK_SUCCEED) ||         
           \
-                       (BATextend((r2), BATgrows((r2))) != GDK_SUCCEED)) {     
               \
-                       (msg) = createException(MAL, "grid.distance",           
               \
-                                       "could not extend BATs for storing the 
join results");         \
-                       goto distancejoin_fail;                                 
               \
-               }                                                               
           \
-       }                                                                       
       \
+#define GRIDextend(g1, g2, cellR, cellS, r1, r2, msg)                          
   \
+do {                                                                           
   \
+/* make space to cater for the worst case where all points qualify */          
   \
+BUN maxSize = BATcount((r1)) +                                                 
   \
+              ((g1)->dir[(cellR)+1]-(g1)->dir[(cellR)])*                       
   \
+              ((g2)->dir[(cellS)+1]-(g2)->dir[(cellS)]);                       
   \
+       if (maxSize > GDK_oid_max) {                                            
      \
+                       (msg) = createException(MAL,"grid.distance","overflow 
of head value");\
+                       goto distancejoin_fail;                                 
              \
+       }                                                                       
      \
+       while (maxSize > BATcapacity((r1))) {                                   
      \
+               if ((BATextend((r1), BATgrows((r1))) != GDK_SUCCEED) ||         
          \
+                       (BATextend((r2), BATgrows((r2))) != GDK_SUCCEED)) {     
              \
+                       (msg) = createException(MAL, "grid.distance",           
              \
+                                       "could not extend BATs for storing the 
join results");        \
+                       goto distancejoin_fail;                                 
              \
+               }                                                               
          \
+       }                                                                       
      \
 } while (0)
 
 #define GRIDdist(r1Vals, oid1, seq1, r1b, x1v, y1v,                            
   \
@@ -82,12 +82,13 @@ do {                                    
        m = (g1)->dir[(cellR)];                                                 
      \
        if (GRIDcount(g1, cellR) > 16) {                                        
      \
                /* compare points of R in cellR with points of S in cellS */    
          \
-               for (m = (g1)->dir[(cellR)]; m < (g1)->dir[(cellR)+1]-16; 
m+=16) {        \
+               for (; m < (g1)->dir[(cellR)+1]-16; m+=16) {        \
                        for (oid n = (g2)->dir[(cellS)]; n < 
(g2)->dir[(cellS)+1]; n++) {     \
-                               oid oid2 = n;                                   
                  \
+                               oid oid2 = (g2)->oids[n];                       
                  \
                                lng x2v = (x2Vals)[oid2];                       
                  \
                                lng y2v = (y2Vals)[oid2];                       
                  \
-                               for(oid oid1 = m; oid1 < m+16; oid1++) {        
                  \
+                               for(oid o1 = m; o1 < m+16; o1++) {              
                  \
+                                       oid oid1 = (g1)->oids[o1];              
                      \
                                        lng x1v = (x1Vals)[oid1];               
                      \
                                        lng y1v = (y1Vals)[oid1];               
                      \
                                        GRIDdist(r1Vals, oid1, seq1, r1b, x1v, 
y1v,                   \
@@ -97,11 +98,11 @@ do {                                    
                }                                                               
          \
        }                                                                       
      \
        for (; m < (g1)->dir[(cellR)+1]; m++) {                                 
      \
-               oid oid1 = m;                                                   
          \
+               oid oid1 = (g1)->oids[m];                                       
          \
                lng x1v = (x1Vals)[oid1];                                       
          \
                lng y1v = (y1Vals)[oid1];                                       
          \
                for (oid n = (g2)->dir[(cellS)]; n < (g2)->dir[(cellS)+1]; n++) 
{         \
-                       oid oid2 = n;                                           
              \
+                       oid oid2 = (g2)->oids[n];                               
              \
                        lng x2v = (x2Vals)[oid2];                               
              \
                        lng y2v = (y2Vals)[oid2];                               
              \
                        GRIDdist(r1Vals, oid1, seq1, r1b, x1v, y1v,             
              \
@@ -144,7 +145,6 @@ countSetBits(uint64_t *resBitvector, siz
 
        return num;
 }
-
 #if 0
 static void
 grid_print(Grid * g)
@@ -183,6 +183,17 @@ grid_print(Grid * g)
        for (size_t i = 0; i < g->cellsX; i++)
                fprintf(stderr, "%*zu|", m, i);
        fprintf(stderr, "\n");
+
+       fprintf(stderr, "- Directory\n[");
+       for (size_t i = 0; i <= g->cellsNum; i++)
+               fprintf(stderr, "%zu,",g->dir[i]);
+       fprintf(stderr, "\r]\n");
+       fprintf(stderr, "- Directory\n");
+       for (size_t i = 0; i < g->cellsNum; i++)
+               if (g->dir[i] != g->dir[i+1])
+                       fprintf(stderr, "[%zu] %zu,", i, g->dir[i]);
+       fprintf(stderr, "\r\n");
+
        fprintf(stderr, "- OIDs\n[");
        for (size_t i = 0; i < g->dir[g->cellsNum]; i++) {
                fprintf(stderr, "%zu,", g->oids[i]);
@@ -406,6 +417,11 @@ grid_create_mbr(Grid * g, BAT *bx, BAT *
 
        g->cellsPerAxis = 0;
 
+#if 0
+#ifndef NDEBUG
+       grid_print(g);
+#endif
+#endif
        return MAL_SUCCEED;
 }
 
@@ -910,11 +926,11 @@ GRIDdistancesubjoin(bat *res1, bat * res
                        size_t R[] = {min,            min,              min,   
min, min+1, min+g1->cellsX, min+g1->cellsX+1};
                        size_t S[] = {min+g1->cellsX, min+g1->cellsX+1, min+1, 
min, min,   min,            min             };
                        for (size_t k = 0; k < 7; k++) {
-                               if (GRIDcount(g1,R[k]) > GRIDcount(g2,S[k])) {
+//                             if (GRIDcount(g1,R[k]) > GRIDcount(g2,S[k])) {
                                        GRIDcmp(x1Vals, y1Vals, g1, x2Vals, 
y2Vals, g2, R[k], S[k], r1, r2, seq1, seq2, msg);
-                               } else {
-                                       GRIDcmp(x2Vals, y2Vals, g2, x1Vals, 
y1Vals, g1, S[k], R[k], r2, r1, seq2, seq1, msg);
-                               }
+//                             } else {
+//                                     GRIDcmp(x2Vals, y2Vals, g2, x1Vals, 
y1Vals, g1, S[k], R[k], r2, r1, seq2, seq1, msg);
+//                             }
                        }
                }
        }
diff --git a/geom/sql/Tests/grid.sql b/geom/sql/Tests/grid.sql
--- a/geom/sql/Tests/grid.sql
+++ b/geom/sql/Tests/grid.sql
@@ -10,10 +10,28 @@ SELECT * FROM points1 p1 WHERE [p1.x, p1
 SELECT * FROM points2 p2 WHERE [p2.x, p2.y] distance [150,150, 5] ORDER BY 
p2.x, p2.y;
 
 -- join
-SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, p2.y,  
1] ORDER BY p1.x, p1.y;
-SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y,1.5] ORDER BY p1.x, p1.y;
-SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, p2.y, 
31] ORDER BY p1.x, p1.y;
-SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y,500] ORDER BY p1.x, p1.y;
+SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, p2.y,  
1] ORDER BY p1.x, p1.y, p2.x, p2.y;
+SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y,1.5] ORDER BY p1.x, p1.y, p2.x, p2.y;
+SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, p2.y, 
31] ORDER BY p1.x, p1.y, p2.x, p2.y;
+SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y,500] ORDER BY p1.x, p1.y, p2.x, p2.y;
+
+INSERT INTO points1 VALUES ( 95,95), ( 95, 96), ( 96, 96), ( 97, 97), ( 98, 
97);
+INSERT INTO points1 VALUES ( 95,99), ( 99,102), (101,100), (102,100), 
(101,101);
+INSERT INTO points1 VALUES (101,99), (100, 97), (102, 99), (103, 99), 
(101,102);
+INSERT INTO points1 VALUES (103,98), (103, 96), (101,103), (101, 99), 
(102,102);
+
+INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+
+-- expecting 21*21 results     
+SELECT COUNT(*) FROM points1 p1 WHERE [p1.x, p1.y] distance [100, 100, 15];
+SELECT COUNT(*) FROM points2 p2 WHERE [p2.x, p2.y] distance [100, 100, 15];
+SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, p2.y, 
15] ORDER BY p1.x, p1.y, p2.x, p2.y;
+SELECT COUNT(*) FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y, 15];
+SELECT COUNT(*) FROM points1 p1, points2 p2 WHERE 
(p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) <= 15*15;
+
 
 DROP TABLE points1;
 DROP TABLE points2;
diff --git a/geom/sql/Tests/grid.stable.out b/geom/sql/Tests/grid.stable.out
--- a/geom/sql/Tests/grid.stable.out
+++ b/geom/sql/Tests/grid.stable.out
@@ -112,27 +112,516 @@ Ready.
 [ 100, 100,    99,     101     ]
 [ 100, 150,    101,    180     ]
 [ 150, 150,    149,    149     ]
-#SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y,500] ORDER BY p1.x, p1.y;
+[ 150, 150,    149,    151     ]
+#SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, 
p2.y,500] ORDER BY p1.x, p1.y, p2.x, p2.y;
 % sys.p1,      sys.p1, sys.p2, sys.p2 # table_name
 % x,   y,      x,      y # name
 % bigint,      bigint, bigint, bigint # type
 % 3,   3,      3,      3 # length
 [ 100, 100,    99,     101     ]
-[ 100, 100,    149,    151     ]
 [ 100, 100,    101,    180     ]
 [ 100, 100,    149,    149     ]
+[ 100, 100,    149,    151     ]
+[ 100, 150,    99,     101     ]
+[ 100, 150,    101,    180     ]
+[ 100, 150,    149,    149     ]
 [ 100, 150,    149,    151     ]
-[ 100, 150,    99,     101     ]
-[ 100, 150,    149,    149     ]
-[ 100, 150,    101,    180     ]
+[ 150, 100,    99,     101     ]
+[ 150, 100,    101,    180     ]
+[ 150, 100,    149,    149     ]
 [ 150, 100,    149,    151     ]
-[ 150, 100,    99,     101     ]
-[ 150, 100,    149,    149     ]
-[ 150, 100,    101,    180     ]
-[ 150, 150,    149,    151     ]
+[ 150, 150,    99,     101     ]
 [ 150, 150,    101,    180     ]
 [ 150, 150,    149,    149     ]
-[ 150, 150,    99,     101     ]
+[ 150, 150,    149,    151     ]
+#INSERT INTO points1 VALUES ( 95,95), ( 95, 96), ( 96, 96), ( 97, 97), ( 98, 
97);
+[ 5    ]
+#INSERT INTO points1 VALUES ( 95,99), ( 99,102), (101,100), (102,100), 
(101,101);
+[ 5    ]
+#INSERT INTO points1 VALUES (101,99), (100, 97), (102, 99), (103, 99), 
(101,102);
+[ 5    ]
+#INSERT INTO points1 VALUES (103,98), (103, 96), (101,103), (101, 99), 
(102,102);
+[ 5    ]
+#INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+[ 5    ]
+#INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+[ 5    ]
+#INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+[ 5    ]
+#INSERT INTO points2 VALUES ( 99,99), (101, 97), (103, 98), (102, 97), 
(102,102);
+[ 5    ]
+#SELECT COUNT(*) FROM points1 p1 WHERE [p1.x, p1.y] distance [100, 100, 15];
+% sys.L1 # table_name
+% L1 # name
+% wrd # type
+% 2 # length
+[ 21   ]
+#SELECT COUNT(*) FROM points2 p2 WHERE [p2.x, p2.y] distance [100, 100, 15];
+% sys.L1 # table_name
+% L1 # name
+% wrd # type
+% 2 # length
+[ 21   ]
+#SELECT * FROM points1 p1, points2 p2 WHERE [p1.x, p1.y] distance [p2.x, p2.y, 
15] ORDER BY p1.x, p1.y, p2.x, p2.y;
+% sys.p1,      sys.p1, sys.p2, sys.p2 # table_name
+% x,   y,      x,      y # name
+% bigint,      bigint, bigint, bigint # type
+% 3,   3,      3,      3 # length
+[ 95,  95,     99,     99      ]
+[ 95,  95,     99,     99      ]
+[ 95,  95,     99,     99      ]
+[ 95,  95,     99,     99      ]
+[ 95,  95,     99,     101     ]
+[ 95,  95,     101,    97      ]
+[ 95,  95,     101,    97      ]
+[ 95,  95,     101,    97      ]
+[ 95,  95,     101,    97      ]
+[ 95,  95,     102,    97      ]
+[ 95,  95,     102,    97      ]
+[ 95,  95,     102,    97      ]
+[ 95,  95,     102,    97      ]
+[ 95,  95,     102,    102     ]
+[ 95,  95,     102,    102     ]
+[ 95,  95,     102,    102     ]
+[ 95,  95,     102,    102     ]
+[ 95,  95,     103,    98      ]
+[ 95,  95,     103,    98      ]
+[ 95,  95,     103,    98      ]
+[ 95,  95,     103,    98      ]
+[ 95,  96,     99,     99      ]
+[ 95,  96,     99,     99      ]
+[ 95,  96,     99,     99      ]
+[ 95,  96,     99,     99      ]
+[ 95,  96,     99,     101     ]
+[ 95,  96,     101,    97      ]
+[ 95,  96,     101,    97      ]
+[ 95,  96,     101,    97      ]
+[ 95,  96,     101,    97      ]
+[ 95,  96,     102,    97      ]
+[ 95,  96,     102,    97      ]
+[ 95,  96,     102,    97      ]
+[ 95,  96,     102,    97      ]
+[ 95,  96,     102,    102     ]
+[ 95,  96,     102,    102     ]
+[ 95,  96,     102,    102     ]
+[ 95,  96,     102,    102     ]
+[ 95,  96,     103,    98      ]
+[ 95,  96,     103,    98      ]
+[ 95,  96,     103,    98      ]
+[ 95,  96,     103,    98      ]
+[ 95,  99,     99,     99      ]
+[ 95,  99,     99,     99      ]
+[ 95,  99,     99,     99      ]
+[ 95,  99,     99,     99      ]
+[ 95,  99,     99,     101     ]
+[ 95,  99,     101,    97      ]
+[ 95,  99,     101,    97      ]
+[ 95,  99,     101,    97      ]
+[ 95,  99,     101,    97      ]
+[ 95,  99,     102,    97      ]
+[ 95,  99,     102,    97      ]
+[ 95,  99,     102,    97      ]
+[ 95,  99,     102,    97      ]
+[ 95,  99,     102,    102     ]
+[ 95,  99,     102,    102     ]
+[ 95,  99,     102,    102     ]
+[ 95,  99,     102,    102     ]
+[ 95,  99,     103,    98      ]
+[ 95,  99,     103,    98      ]
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to