Changeset: cc2c07ed53cc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/cc2c07ed53cc
Modified Files:
monetdb5/optimizer/opt_dict.c
sql/backends/monet5/dict.c
sql/backends/monet5/dict.h
sql/backends/monet5/sql.c
Branch: dict
Log Message:
handle all selects.
added dict.convert (:bat[:oid]) :bat[bte], etc
to handle offsets > 127
don't clean same bat twice
diffs (106 lines):
diff --git a/monetdb5/optimizer/opt_dict.c b/monetdb5/optimizer/opt_dict.c
--- a/monetdb5/optimizer/opt_dict.c
+++ b/monetdb5/optimizer/opt_dict.c
@@ -101,10 +101,10 @@ OPTdictImplementation(Client cntxt, MalB
pushInstruction(mb,r);
done = 1;
break;
- } else if (getModuleId(p) == algebraRef &&
getFunctionId(p) == selectRef) {
+ } else if (isSelect(p)) {
/* pos = select(col, cand, l, h, ...)
with col = dict.decompress(o,u)
* tp = select(u, nil, l, h, ...)
- * tp2 = bte/sht/int(tp)
+ * tp2 = batcalc.bte/sht/int(tp)
* pos = intersect(o, tp2, cand, nil) */
int cand = getArg(p, j+1);
@@ -115,10 +115,9 @@ OPTdictImplementation(Client cntxt, MalB
pushInstruction(mb,r);
int tpe = getVarType(mb, varisdict[k]);
- InstrPtr s = newInstructionArgs(mb,
batcalcRef, putName(ATOMname(getBatType(tpe))), 3);
+ InstrPtr s = newInstructionArgs(mb,
dictRef, putName("convert"), 3);
getArg(s, 0) = newTmpVariable(mb, tpe);
addArgument(mb, s, getArg(r, 0));
- s = pushNil(mb, s, TYPE_bat);
pushInstruction(mb,s);
InstrPtr t = newInstructionArgs(mb,
algebraRef, intersectRef, 5);
diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -128,7 +128,7 @@ DICTdecompress(Client cntxt, MalBlkPtr m
BAT *u = BATdescriptor(U);
if (!o || !u) {
bat_destroy(o);
- bat_destroy(o);
+ bat_destroy(u);
throw(SQL, "sql.dict_compress", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
BAT *b = COLnew(0, u->ttype, BATcount(o), TRANSIENT);
@@ -176,3 +176,43 @@ DICTdecompress(Client cntxt, MalBlkPtr m
bat_destroy(u);
return MAL_SUCCEED;
}
+
+str
+DICTconvert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ /* convert candidates into bte,sht,int offsets */
+ (void)cntxt;
+ bat *r = getArgReference_bat(stk, pci, 0);
+ bat O = *getArgReference_bat(stk, pci, 1);
+ int rt = getBatType(getArgType(mb, pci, 0));
+
+ BAT *o = BATdescriptor(O);
+ if (!o)
+ throw(SQL, "sql.dict_compress", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+
+ BAT *b = COLnew(0, rt, BATcount(o), TRANSIENT);
+ BATiter oi = bat_iterator(o);
+
+ BUN p, q;
+ if (rt == TYPE_bte) {
+ unsigned char *rp = Tloc(b, 0);
+ oid *op = Tloc(o, 0);
+ BATloop(o, p, q) {
+ rp[p] = op[p];
+ }
+ } else if (rt == TYPE_sht) {
+ unsigned short *rp = Tloc(b, 0);
+ oid *op = Tloc(o, 0);
+ BATloop(o, p, q) {
+ rp[p] = op[p];
+ }
+ } else {
+ assert(0);
+ }
+ bat_iterator_end(&oi);
+ BATsetcount(b, BATcount(o));
+ /* TODO correct props and set min/max offset */
+ BBPkeepref(*r = b->batCacheid);
+ bat_destroy(o);
+ return MAL_SUCCEED;
+}
diff --git a/sql/backends/monet5/dict.h b/sql/backends/monet5/dict.h
--- a/sql/backends/monet5/dict.h
+++ b/sql/backends/monet5/dict.h
@@ -6,6 +6,7 @@
extern str DICTcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
extern str DICTdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
+extern str DICTconvert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
#endif /* _DICT_H */
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -5170,6 +5170,7 @@ static mel_func sql_init_funcs[] = {
pattern("sql", "copy_rejects_clear", COPYrejects_clear, true, "", noargs),
pattern("dict", "compress", DICTcompress, false, "compress a sql column",
args(0, 3, arg("schema", str), arg("table", str), arg("column", str))),
pattern("dict", "decompress", DICTdecompress, false, "decompress a dictionary
compressed (sub)column", args(1, 3, batargany("", 1), batargany("o", 0),
batargany("u", 1))),
+ pattern("dict", "convert", DICTconvert, false, "convert candidate list into
compressed offsets", args(1, 2, batargany("", 1), batargany("o", 0))),
command("calc", "dec_round", bte_dec_round_wrap, false, "round off the value
v to nearests multiple of r", args(1,3, arg("",bte),arg("v",bte),arg("r",bte))),
pattern("batcalc", "dec_round", bte_bat_dec_round_wrap, false, "round off the
value v to nearests multiple of r", args(1,3,
batarg("",bte),batarg("v",bte),arg("r",bte))),
pattern("batcalc", "dec_round", bte_bat_dec_round_wrap, false, "round off the
value v to nearests multiple of r", args(1,4,
batarg("",bte),batarg("v",bte),arg("r",bte),batarg("s",oid))),
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list