Changeset: ba3a72cd7bd3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ba3a72cd7bd3
Modified Files:
sql/backends/monet5/sql_rank.c
sql/server/rel_optimizer.c
sql/test/analytics/Tests/analytics01.stable.out
Branch: default
Log Message:
Merge with Nov2019
diffs (truncated from 367 to 300 lines):
diff --git a/sql/backends/monet5/sql_rank.c b/sql/backends/monet5/sql_rank.c
--- a/sql/backends/monet5/sql_rank.c
+++ b/sql/backends/monet5/sql_rank.c
@@ -558,57 +558,90 @@ SQLcume_dist(Client cntxt, MalBlkPtr mb,
(void)cntxt;
if (isaBatType(getArgType(mb, pci, 1))) {
bat *res = getArgReference_bat(stk, pci, 0);
- BAT *b = BATdescriptor(*getArgReference_bat(stk, pci, 1)), *p,
*r;
- BUN cnt;
- int j;
- dbl *rb, *rp, *end, cnt_cast;
- bit *np;
+ BAT *b = BATdescriptor(*getArgReference_bat(stk, pci, 1)), *p,
*o, *r;
+ BUN ncnt, j = 0;
+ bit *np, *no, *bo1, *bo2, *end;
+ dbl *rb, *rp, cnt_cast, nres;
if (!b)
throw(SQL, "sql.cume_dist", SQLSTATE(HY005) "Cannot
access column descriptor");
- cnt = BATcount(b);
- cnt_cast = (dbl) cnt;
- voidresultBAT(r, TYPE_dbl, cnt, b, "sql.cume_dist");
+ voidresultBAT(r, TYPE_dbl, BATcount(b), b, "sql.cume_dist");
rb = rp = (dbl*)Tloc(r, 0);
- end = rp + cnt;
if (isaBatType(getArgType(mb, pci, 2))) {
if (isaBatType(getArgType(mb, pci, 3))) {
p = BATdescriptor(*getArgReference_bat(stk,
pci, 2));
- if (!p) {
+ o = BATdescriptor(*getArgReference_bat(stk,
pci, 3));
+ if (!p || !o) {
BBPunfix(b->batCacheid);
+ if (p) BBPunfix(p->batCacheid);
+ if (o) BBPunfix(o->batCacheid);
throw(SQL, "sql.cume_dist",
SQLSTATE(HY005) "Cannot access column descriptor");
}
np = (bit*)Tloc(p, 0);
- for(j=0; rp<end; j++, np++, rp++) {
+ end = np + BATcount(p);
+ bo1 = bo2 = no = (bit*)Tloc(o, 0);
+
+ for (; np<end; np++, no++) {
if (*np) {
- for(; rb<rp; rb++)
- *rb = j / cnt_cast;
+ ncnt = no - bo2;
+ cnt_cast = (dbl) ncnt;
+ for (; bo2<no; bo2++) {
+ if (*bo2) {
+ j += (bo2 -
bo1);
+ nres = j /
cnt_cast;
+ for (; bo1 <
bo2; bo1++, rb++)
+ *rb =
nres;
+ }
+ }
+ for (; bo1 < bo2; bo1++, rb++)
+ *rb = 1;
}
}
- for(; rb<rp; rb++)
+ ncnt = no - bo2;
+ cnt_cast = (dbl) ncnt;
+ for (; bo2<no; bo2++) {
+ if (*bo2) {
+ j += (bo2 - bo1);
+ nres = j / cnt_cast;
+ for (; bo1 < bo2; bo1++, rb++)
+ *rb = nres;
+ }
+ }
+ for (; bo1 < bo2; bo1++, rb++)
*rb = 1;
} else { /* single value, ie no ordering */
- p = BATdescriptor(*getArgReference_bat(stk,
pci, 2));
- if (!p) {
+ rp = rb + BATcount(b);
+ for (; rb<rp; rb++)
+ *rb = 1;
+ }
+ } else { /* single value, ie no partitions */
+ if (isaBatType(getArgType(mb, pci, 3))) {
+ o = BATdescriptor(*getArgReference_bat(stk,
pci, 3));
+ if (!o) {
BBPunfix(b->batCacheid);
throw(SQL, "sql.cume_dist",
SQLSTATE(HY005) "Cannot access column descriptor");
}
- np = (bit*)Tloc(p, 0);
- for(j=0; rp<end; j++, np++, rp++) {
- if (*np) {
- for(; rb<rp; rb++)
- *rb = j / cnt_cast;
+ bo1 = bo2 = (bit*)Tloc(o, 0);
+ no = bo1 + BATcount(b);
+ cnt_cast = (dbl) BATcount(b);
+ for (; bo2<no; bo2++) {
+ if (*bo2) {
+ j += (bo2 - bo1);
+ nres = j / cnt_cast;
+ for (; bo1 < bo2; bo1++, rb++)
+ *rb = nres;
}
}
- for(; rb<rp; rb++)
+ for (; bo1 < bo2; bo1++, rb++)
*rb = 1;
- BBPunfix(p->batCacheid);
+ BBPunfix(o->batCacheid);
+ } else { /* single value, ie no ordering */
+ rp = rb + BATcount(b);
+ for (; rb<rp; rb++)
+ *rb = 1;
}
- } else {
- for(; rp<end; rp++)
- *rp = 1;
}
- BATsetcount(r, cnt);
+ BATsetcount(r, BATcount(b));
BBPunfix(b->batCacheid);
BBPkeepref(*res = r->batCacheid);
} else {
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -940,7 +940,6 @@ order_joins(mvc *sql, list *rels, list *
fnd = 1; // not really, but this bails
out
continue;
}
-
list_remove_data(rels, r);
append(n_rels, r);
diff --git a/sql/test/analytics/Tests/analytics01.stable.out
b/sql/test/analytics/Tests/analytics01.stable.out
--- a/sql/test/analytics/Tests/analytics01.stable.out
+++ b/sql/test/analytics/Tests/analytics01.stable.out
@@ -182,21 +182,51 @@ stdout of test 'analytics01` in director
% %4 # name
% double # type
% 24 # length
-[ 0.2 ]
-[ 0.2 ]
-[ 0.3 ]
-[ 0.5 ]
-[ 0.5 ]
-[ 0.6 ]
-[ 0.7 ]
-[ 0.8 ]
-[ 0.9 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
[ 1 ]
#select cume_dist() over (partition by aa order by aa asc) from analytics;
% sys.%4 # table_name
% %4 # name
% double # type
% 24 # length
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+#select cume_dist() over (partition by aa order by aa desc) from analytics;
+% sys.%4 # table_name
+% %4 # name
+% double # type
+% 24 # length
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+#select cume_dist() over (order by aa) from analytics;
+% sys.%4 # table_name
+% %4 # name
+% double # type
+% 24 # length
[ 0.2 ]
[ 0.2 ]
[ 0.3 ]
@@ -207,49 +237,19 @@ stdout of test 'analytics01` in director
[ 0.8 ]
[ 0.9 ]
[ 1 ]
-#select cume_dist() over (partition by aa order by aa desc) from analytics;
-% sys.%4 # table_name
-% %4 # name
-% double # type
-% 24 # length
-[ 0.2 ]
-[ 0.2 ]
-[ 0.3 ]
-[ 0.4 ]
-[ 0.5 ]
-[ 0.6 ]
-[ 0.7 ]
-[ 0.9 ]
-[ 0.9 ]
-[ 1 ]
-#select cume_dist() over (order by aa) from analytics;
-% sys.%4 # table_name
-% %4 # name
-% double # type
-% 24 # length
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
#select cume_dist() over (order by aa desc) from analytics;
% sys.%4 # table_name
% %4 # name
% double # type
% 24 # length
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
-[ 1 ]
+[ 0.1 ]
+[ 0.2 ]
+[ 0.3 ]
+[ 0.4 ]
+[ 0.5 ]
+[ 0.7 ]
+[ 0.7 ]
+[ 0.8 ]
[ 1 ]
[ 1 ]
#select cume_dist() over (partition by bb) from analytics;
@@ -257,6 +257,51 @@ stdout of test 'analytics01` in director
% %4 # name
% double # type
% 24 # length
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+#select cume_dist() over (partition by bb order by bb asc) from analytics;
+% sys.%4 # table_name
+% %4 # name
+% double # type
+% 24 # length
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+#select cume_dist() over (partition by bb order by bb desc) from analytics;
+% sys.%4 # table_name
+% %4 # name
+% double # type
+% 24 # length
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+[ 1 ]
+#select cume_dist() over (order by bb) from analytics;
+% sys.%4 # table_name
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list