Changeset: c112a375769e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c112a375769e
Modified Files:
clients/Tests/MAL-signatures.stable.out
sql/backends/monet5/sql.mx
sql/benchmarks/tpch/Tests/11-explain.stable.out
Branch: default
Log Message:
added bat versions of sql.round() to get iterator-free TPCH MAL plans
Checked in on default branch, because this adds new MAL signatures.
If desired, transplant to Feb2013 should work fine (patch tested
with changeset 59b033398063), expect conflicts with
sql/benchmarks/tpch/Tests/11-explain.stable.out that can be resolved
by re-approving that output.
diffs (truncated from 578 to 300 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
@@ -2908,10 +2908,34 @@ command batsql.alpha(dec:bat[:oid,:dbl],
address SQLbat_alpha_cst;
comment BAT implementation of astronomy alpha function
+command batsql.dec_round(v:bat[:oid,:lng],r:lng):bat[:oid,:lng]
+address lng_bat_dec_round_wrap;
+comment round off the value v to nearests multiple of r
+
+command batsql.dec_round(v:bat[:oid,:int],r:int):bat[:oid,:int]
+address int_bat_dec_round_wrap;
+comment round off the value v to nearests multiple of r
+
+command batsql.dec_round(v:bat[:oid,:sht],r:sht):bat[:oid,:sht]
+address sht_bat_dec_round_wrap;
+comment round off the value v to nearests multiple of r
+
+command batsql.dec_round(v:bat[:oid,:bte],r:bte):bat[:oid,:bte]
+address bte_bat_dec_round_wrap;
+comment round off the value v to nearests multiple of r
+
pattern batsql.next_value(sname:bat[:oid,:str],sequence:str):bat[:oid,:lng]
address mvc_bat_next_value;
comment return the next value of the sequence
+command batsql.round(v:bat[:oid,:dbl],r:bte):bat[:oid,:dbl]
+address dbl_bat_round_wrap;
+comment round off the floating point v to r digits behind the dot (if r < 0,
before the dot)
+
+command batsql.round(v:bat[:oid,:flt],r:bte):bat[:oid,:flt]
+address flt_bat_round_wrap;
+comment round off the floating point v to r digits behind the dot (if r < 0,
before the dot)
+
command batgeom.point(x:bat[:oid,:dbl],y:bat[:oid,:dbl]):bat[:oid,:wkb]
address wkbcreatepoint_bat;
comment Construct a point-BAT from two geometry-BATs
@@ -42062,10 +42086,18 @@ command sql.dense_rank_grp(b:bat[:oid,:a
address sql_dense_rank_grp;
comment return the densely ranked groups
+command sql.dec_round(v:bat[:oid,:dbl],r:dbl):bat[:oid,:dbl]
+address dbl_bat_dec_round_wrap;
+comment round off the value v to nearests multiple of r
+
command sql.dec_round(v:dbl,r:dbl):dbl
address dbl_dec_round_wrap;
comment round off the value v to nearests multiple of r
+command sql.dec_round(v:bat[:oid,:flt],r:flt):bat[:oid,:flt]
+address flt_bat_dec_round_wrap;
+comment round off the value v to nearests multiple of r
+
command sql.dec_round(v:flt,r:flt):flt
address flt_dec_round_wrap;
comment round off the value v to nearests multiple of r
@@ -42298,18 +42330,34 @@ command sql.round(v:flt,r:bte):flt
address flt_round_wrap;
comment round off the floating point v to r digits behind the dot (if r < 0,
before the dot)
+command sql.round(v:bat[:oid,:lng],d:int,s:int,r:bte):bat[:oid,:lng]
+address lng_bat_round_wrap;
+comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+
command sql.round(v:lng,d:int,s:int,r:bte):lng
address lng_round_wrap;
comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+command sql.round(v:bat[:oid,:int],d:int,s:int,r:bte):bat[:oid,:int]
+address int_bat_round_wrap;
+comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+
command sql.round(v:int,d:int,s:int,r:bte):int
address int_round_wrap;
comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+command sql.round(v:bat[:oid,:sht],d:int,s:int,r:bte):bat[:oid,:sht]
+address sht_bat_round_wrap;
+comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+
command sql.round(v:sht,d:int,s:int,r:bte):sht
address sht_round_wrap;
comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+command sql.round(v:bat[:oid,:bte],d:int,s:int,r:bte):bat[:oid,:bte]
+address bte_bat_round_wrap;
+comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
+
command sql.round(v:bte,d:int,s:int,r:bte):bte
address bte_round_wrap;
comment round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -662,10 +662,18 @@ command sql.dec_round( v:@1, r:@1 ) :@1
address @1_dec_round_wrap
comment "round off the value v to nearests multiple of r";
+command batsql.dec_round( v:bat[:oid,:@1], r:@1 ) :bat[:oid,:@1]
+address @1_bat_dec_round_wrap
+comment "round off the value v to nearests multiple of r";
+
command sql.round( v:@1, d:int, s:int, r:bte) :@1
address @1_round_wrap
comment "round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)";
+command sql.round( v:bat[:oid,:@1], d:int, s:int, r:bte) :bat[:oid,:@1]
+address @1_bat_round_wrap
+comment "round off the decimal v(d,s) to r digits behind the dot (if r < 0,
before the dot)";
+
command calc.second_interval( sc:int, v:@1, ek:int, sk:int ) :lng
address @1_dec2second_interval
comment "cast @1 decimal to a second_interval";
@@ -682,10 +690,18 @@ command sql.dec_round( v:@1, r:@1 ) :@1
address @1_dec_round_wrap
comment "round off the value v to nearests multiple of r";
+command sql.dec_round( v:bat[:oid,:@1], r:@1 ) :bat[:oid,:@1]
+address @1_bat_dec_round_wrap
+comment "round off the value v to nearests multiple of r";
+
command sql.round( v:@1, r:bte) :@1
address @1_round_wrap
comment "round off the floating point v to r digits behind the dot (if r < 0,
before the dot)";
+command batsql.round( v:bat[:oid,:@1], r:bte) :bat[:oid,:@1]
+address @1_bat_round_wrap
+comment "round off the floating point v to r digits behind the dot (if r < 0,
before the dot)";
+
command sql.ms_trunc( v:@1, r:int) :@1
address @1_trunc_wrap
comment "truncate the floating point v to r digits behind the dot (if r < 0,
before the dot)";
@@ -1429,7 +1445,9 @@ sql5_export str BATSQLidentity(bat *rid,
sql5_export str PBATSQLidentity(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
@= round_export
sql5_export str @1_dec_round_wrap( @1 *res, @1 *v, @1 *r );
+sql5_export str @1_bat_dec_round_wrap( bat *res, bat *v, @1 *r );
sql5_export str @1_round_wrap( @1 *res, @1 *v, int *d, int *s, bte *r );
+sql5_export str @1_bat_round_wrap( bat *res, bat *v, int *d, int *s, bte *r );
sql5_export str str_2dec_@1( @1 *res, str *val, int *d, int *sc );
sql5_export str str_2num_@1( @1 *res, str *v, int *len );
sql5_export str batstr_2dec_@1( int *res, int *val, int *d, int *sc );
@@ -1475,7 +1493,9 @@ sql5_export str SQLstr_cast(Client cntxt
sql5_export str SQLbatstr_cast(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
@= fround_export
sql5_export str @1_dec_round_wrap( @1 *res, @1 *v, @1 *r );
+sql5_export str @1_bat_dec_round_wrap( bat *res, bat *v, @1 *r );
sql5_export str @1_round_wrap( @1 *res, @1 *v, bte *r );
+sql5_export str @1_bat_round_wrap( bat *res, bat *v, bte *r );
sql5_export str @1_trunc_wrap( @1 *res, @1 *v, int *r );
@
@h
@@ -4604,61 +4624,169 @@ lng scales[20] = {
* SQL-99 are shown below. At some point they also should be
* moved to module code base.
*/
+
+@= round_wrappers
+static inline @1 @2
+{
+ /* shortcut nil */
+ if (v == @1_nil) {
+ return @1_nil;
+ } else {
+ return @5;
+ }
+}
+
+str @3
+{
+ /* basic sanity checks */
+ assert(res && v && r @8);
+
+ *res = @6;
+ return MAL_SUCCEED;
+}
+
+str @4
+{
+ BAT *res, *v;
+ @1 *src, *dst;
+ BUN i, cnt;
+ bit nonil; /* TRUE: we know there are no NIL (NULL) values */
+ bit nil; /* TRUE: we know there is at least one NIL (NULL) value */
+
+ /* basic sanity checks */
+ assert(_res && _v && r @8);
+
+ /* get argument BAT descriptor */
+ if ((v = BATdescriptor(*_v)) == NULL)
+ throw(MAL, "round", RUNTIME_OBJECT_MISSING);
+
+ /* more sanity checks */
+ if (!BAThdense(v)) {
+ BBPreleaseref(v->batCacheid);
+ throw(MAL, "round", "argument 1 must have a dense head");
+ }
+ if (v->ttype != TYPE_@1) {
+ BBPreleaseref(v->batCacheid);
+ throw(MAL, "round", "argument 1 must have a @1 tail");
+ }
+ cnt = BATcount(v);
+
+ /* allocate result BAT */
+ res = BATnew(TYPE_void, TYPE_@1, cnt);
+ if (res == NULL) {
+ BBPreleaseref(v->batCacheid);
+ throw(MAL, "round", MAL_MALLOC_FAIL);
+ }
+
+ /* access columns as arrays */
+ src = (@1*) Tloc(v, BUNfirst(v));
+ dst = (@1*) Tloc(res, BUNfirst(res));
+
+ nil = FALSE;
+ nonil = TRUE;
+ if (v->T->nonil == TRUE) {
+ for (i = 0; i < cnt; i++)
+ dst[i] = @7;
+ } else {
+ for (i = 0; i < cnt; i++) {
+ if (src[i] == @1_nil) {
+ nil = TRUE;
+ nonil = FALSE;
+ dst[i] = @1_nil;
+ } else {
+ dst[i] = @7;
+ }
+ }
+ }
+
+ /* set result BAT properties */
+ BATsetcount(res, cnt);
+ /* result head is aligned with agument head */
+ ALIGNsetH(res, v);
+ /* hard to predict correct tail properties in general */
+ res->T->nonil = nonil;
+ res->T->nil = nil;
+ res->tdense = FALSE;
+ res->tsorted = v->tsorted;
+ BATkey(BATmirror(res), FALSE);
+
+ /* release argument BAT descriptors */
+ BBPreleaseref(v->batCacheid);
+
+ /* keep result */
+ BBPkeepref(*_res = res->batCacheid);
+
+ return MAL_SUCCEED;
+}
+@
+
@= round
-str
-@1_dec_round_wrap( @1 *res, @1 *v, @1 *r )
-{
- @1 val = *v;
- @1 add = *r;
-
- /* shortcut nil */
- if (*v == @1_nil) {
- *res = @1_nil;
- return NULL;
- }
-
- add >>=1;
- if (val < 0)
+static inline @1
+@1_dec_round_body_nonil( @1 v, @1 r )
+{
+ @1 add = r >> 1;
+
+ assert(v != @1_nil);
+
+ if (v < 0)
add = -add;
- val += add;
- val /= *r;
- *res = val;
- return NULL;
-}
-
-str
-@1_round_wrap( @1 *res, @1 *v, int *d, int *s, bte *r )
-{
- /* shortcut nil */
- if (*v == @1_nil) {
- *res = @1_nil;
- } else if (-*r > *d) {
- *res = 0;
- } else if (*r > 0 && *r < *s) {
- int dff = *s - *r;
+ v += add;
+ return v / r;
+}
+
+@:round_wrappers(@1, \
+ @1_dec_round_body ( @1 v, @1 r ), \
+ @1_dec_round_wrap ( @1 *res, @1 *v, @1 *r ), \
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list