Changeset: f59b78c78ebe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f59b78c78ebe
Modified Files:
        monetdb5/modules/mal/sample.c
        monetdb5/modules/mal/sample.h
        monetdb5/modules/mal/sample.mal
        sql/server/rel_select.c
        sql/server/sql_parser.y
Branch: default
Log Message:

Adding the option of a percentage for sampling.

If after the SAMPLE clause a double number between 0.0 and 1.0 follows,
then it is intepreted as percentage and the sample will be of the size
of that percentage.


diffs (83 lines):

diff --git a/monetdb5/modules/mal/sample.c b/monetdb5/modules/mal/sample.c
--- a/monetdb5/modules/mal/sample.c
+++ b/monetdb5/modules/mal/sample.c
@@ -151,3 +151,23 @@ SAMPLEuniform(bat *r, bat *b, ptr s) {
        throw(MAL, "sample.uniform", OPERATION_FAILED "bunfastins");
 }
 
+sample_export str
+SAMPLEuniform_dbl(bat *r, bat *b, ptr p) {
+       BAT *bb;
+       double pr = *(double *)p;
+       wrd s;
+
+       if ( pr < 0.0 || pr > 1.0 ) {
+               throw(MAL, "sample.uniform", ILLEGAL_ARGUMENT " p should be 
between 0 and 1.0" );
+       } else if (pr == 0) {/* special case */
+               s = 0;
+               return SAMPLEuniform(r, b, (ptr)&s);
+       }
+
+       if ((bb = BATdescriptor(*b)) == NULL) {
+               throw(MAL, "sample.uniform", INTERNAL_BAT_ACCESS);
+       }
+       s = (wrd) (pr*(double)BATcount(bb));
+       BBPunfix(bb->batCacheid);
+       return SAMPLEuniform(r, b, (ptr) &s);
+}
diff --git a/monetdb5/modules/mal/sample.h b/monetdb5/modules/mal/sample.h
--- a/monetdb5/modules/mal/sample.h
+++ b/monetdb5/modules/mal/sample.h
@@ -43,4 +43,7 @@
 sample_export str
 SAMPLEuniform(bat *r, bat *b, ptr s);
 
+sample_export str
+SAMPLEuniform_dbl(bat *r, bat *b, ptr p);
+
 #endif
diff --git a/monetdb5/modules/mal/sample.mal b/monetdb5/modules/mal/sample.mal
--- a/monetdb5/modules/mal/sample.mal
+++ b/monetdb5/modules/mal/sample.mal
@@ -26,3 +26,7 @@ module sample;
 command uniform(b:bat[:oid,:any],s:wrd):bat[:oid,:any]
 address SAMPLEuniform
 comment "Returns a uniform sample of size s"
+
+command uniform(b:bat[:oid,:any],p:dbl):bat[:oid,:any]
+address SAMPLEuniform_dbl
+comment "Returns a uniform sample of size = (p x count(b)), where 0 <= p <= 
1.0"
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -4787,10 +4787,9 @@ rel_select_exp(mvc *sql, sql_rel *rel, s
        }
 
        if (sn->sample) {
-               sql_subtype *wrd = sql_bind_localtype("wrd");
                list *exps = new_exp_list(sql->sa);
                sql_exp *o = rel_value_exp( sql, NULL, sn->sample, 0, ek);
-               if (!o || !(o=rel_check_type(sql, wrd, o, type_equal)))
+               if (!o)
                        return NULL;
                append(exps, o);
                rel = rel_sample(sql->sa, rel, exps);
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -3141,9 +3141,13 @@ opt_offset:
 
 opt_sample:
        /* empty */     { $$ = NULL; }
- |  SAMPLE poswrd      { 
+ |  SAMPLE poswrd      {
                          sql_subtype *t = sql_bind_localtype("wrd");
-                         $$ = _newAtomNode( atom_int(SA, t, (lng)$2)); 
+                         $$ = _newAtomNode( atom_int(SA, t, (lng)$2));
+                       }
+ |  SAMPLE INTNUM      {
+                         sql_subtype *t = sql_bind_localtype("dbl");
+                         $$ = _newAtomNode( atom_float(SA, t, 
strtod($2,NULL)));
                        }
  |  SAMPLE param       { $$ = $2; }
  ;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to