Changeset: 3c28c82f22d6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3c28c82f22d6
Modified Files:
        gdk/gdk.h
        gdk/gdk_sketch.c
        sql/backends/monet5/sql_statistics.c
Branch: pp_hashjoin
Log Message:

Handle failure of getting seed for sketches. Skip it but indicate error.


diffs (85 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1434,7 +1434,7 @@ gdk_export void STRMPdestroy(BAT *b);
 gdk_export bool BAThasstrimps(BAT *b);
 gdk_export gdk_return BATsetstrimps(BAT *b);
 
-gdk_export void sketch_populate(BAT* n, BATiter *ni, struct canditer *nci, 
uint8_t cnting_sketch[BUCKETS][CLZ_BUCKETS]);
+gdk_export int sketch_populate(BAT* n, BATiter *ni, struct canditer *nci, 
uint8_t cnting_sketch[BUCKETS][CLZ_BUCKETS]);
 /* gdk_export void sketch_merge(BAT* b, BAT* n); */
 gdk_export double sketch_estimate(uint8_t cnt_sketch[BUCKETS][CLZ_BUCKETS]);
 gdk_export double bat_guess_uniques(BAT *b, BATiter *bi, struct canditer *bci);
diff --git a/gdk/gdk_sketch.c b/gdk/gdk_sketch.c
--- a/gdk/gdk_sketch.c
+++ b/gdk/gdk_sketch.c
@@ -79,7 +79,7 @@ sketch_estimate(uint8_t cnt_sketch[BUCKE
        return alpha * (double)BUCKETS * BUCKETS / z;
 }
 
-void
+int
 sketch_populate(BAT* b, BATiter *bi, struct canditer *bci,
                uint8_t cnting_sketch[BUCKETS][CLZ_BUCKETS])
 {
@@ -121,7 +121,9 @@ sketch_populate(BAT* b, BATiter *bi, str
                                hash = XXH64(ptr, strlen(ptr), HLLSEED);
                        break;
                default:
-                       return;
+                       /* TRC_ERROR(ACCELERATOR, "Type not supported for 
counting sketches." */
+                       /*        "Aborting count distinct estimation."); */
+                       return -1;
                }
                bucket = hash & BITS_MASK;
                hash |= BITS_MASK;
@@ -132,11 +134,16 @@ sketch_populate(BAT* b, BATiter *bi, str
                } else {
                        uint8_t k = cnting_sketch[bucket][clz] - 128;
                        uint64_t rng;
-                       if (getentropy(&rng, sizeof(rng)) == 0 &&
-                          (rng & ((1ULL << k) - 1)) == 0)
+                       if (getentropy(&rng, sizeof(rng)) != 0) {
+                               /* TRC_ERROR(ACCELERATOR, "Failed to generate 
sketch seed." */
+                               /*        "Aborting count distinct 
estimation."); */
+                               return -1;
+                       }
+                       if ((rng & ((1ULL << k) - 1)) == 0)
                                cnting_sketch[bucket][clz]++;
                }
        }
+       return 0;
 }
 
 /* void */
@@ -155,14 +162,15 @@ double
 bat_guess_uniques(BAT *b, BATiter *bi, struct canditer *bci)
 {
        uint8_t cnting_sketch[BUCKETS][CLZ_BUCKETS] = {0};
+       double unique_guess = -1;
 
        BATiter nbi = bi ? *bi : bat_iterator(b);
        struct canditer nbci;
        if (bci == NULL)
                canditer_init(&nbci, b, NULL);
 
-       sketch_populate(b, &nbi, &nbci, cnting_sketch);
-       double unique_guess = sketch_estimate(cnting_sketch);
+       if (sketch_populate(b, &nbi, &nbci, cnting_sketch) == 0)
+               unique_guess = sketch_estimate(cnting_sketch);
 
        if (bi == NULL)
                bat_iterator_end(&nbi);
diff --git a/sql/backends/monet5/sql_statistics.c 
b/sql/backends/monet5/sql_statistics.c
--- a/sql/backends/monet5/sql_statistics.c
+++ b/sql/backends/monet5/sql_statistics.c
@@ -213,7 +213,8 @@ sql_analyze(Client cntxt, MalBlkPtr mb, 
                                        GDKfree(mx);
                                        BBPunfix(b->batCacheid);
 
-                                       store->storage_api.set_stats_col(tr, c, 
&unique_est, NULL, NULL);
+                                       if (unique_est > 0)
+                                               
store->storage_api.set_stats_col(tr, c, &unique_est, NULL, NULL);
                                }
                        }
                }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to