Changeset: d8f365b3ce54 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d8f365b3ce54
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
monetdb5/modules/mal/01_batcalc.mal
monetdb5/modules/mal/batcalc.c
Branch: Jul2015
Log Message:
Implemented batcalc.ifthenelse with non-BAT first (conditional) argument.
diffs (211 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
@@ -24708,6 +24708,18 @@ pattern batcalc.ifthenelse(b:bat[:oid,:b
address CMDifthen;
comment If-then-else operation to assemble a conditional result
+pattern
batcalc.ifthenelse(v:bit,b1:bat[:oid,:any_1],v2:any_1):bat[:oid,:any_1]
+address CMDifthen;
+comment If-then-else operation to assemble a conditional result
+
+pattern
batcalc.ifthenelse(v:bit,v1:any_1,b2:bat[:oid,:any_1]):bat[:oid,:any_1]
+address CMDifthen;
+comment If-then-else operation to assemble a conditional result
+
+pattern
batcalc.ifthenelse(v:bit,b1:bat[:oid,:any_1],b2:bat[:oid,:any_1]):bat[:oid,:any_1]
+address CMDifthen;
+comment If-then-else operation to assemble a conditional result
+
pattern batcalc.int_noerror(b:bat[:oid,:str],s:bat[:oid,:oid]):bat[:oid,:int]
address CMDconvert_int;
comment cast from str to int with candidates list
diff --git a/clients/Tests/MAL-signatures.stable.out.int128
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -31937,6 +31937,18 @@ pattern batcalc.ifthenelse(b:bat[:oid,:b
address CMDifthen;
comment If-then-else operation to assemble a conditional result
+pattern
batcalc.ifthenelse(v:bit,b1:bat[:oid,:any_1],v2:any_1):bat[:oid,:any_1]
+address CMDifthen;
+comment If-then-else operation to assemble a conditional result
+
+pattern
batcalc.ifthenelse(v:bit,v1:any_1,b2:bat[:oid,:any_1]):bat[:oid,:any_1]
+address CMDifthen;
+comment If-then-else operation to assemble a conditional result
+
+pattern
batcalc.ifthenelse(v:bit,b1:bat[:oid,:any_1],b2:bat[:oid,:any_1]):bat[:oid,:any_1]
+address CMDifthen;
+comment If-then-else operation to assemble a conditional result
+
pattern batcalc.int_noerror(b:bat[:oid,:str],s:bat[:oid,:oid]):bat[:oid,:int]
address CMDconvert_int;
comment cast from str to int with candidates list
diff --git a/monetdb5/modules/mal/01_batcalc.mal
b/monetdb5/modules/mal/01_batcalc.mal
--- a/monetdb5/modules/mal/01_batcalc.mal
+++ b/monetdb5/modules/mal/01_batcalc.mal
@@ -21075,6 +21075,18 @@ pattern str_noerror(b:bat[:oid,:str],s:b
address CMDconvert_str
comment "cast from str to str with candidates list";
+pattern ifthenelse(v:bit, b1:bat[:oid,:any_1], b2:bat[:oid,:any_1])
:bat[:oid,:any_1]
+address CMDifthen
+comment "If-then-else operation to assemble a conditional result";
+
+pattern ifthenelse(v:bit, v1:any_1, b2:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address CMDifthen
+comment "If-then-else operation to assemble a conditional result";
+
+pattern ifthenelse(v:bit, b1:bat[:oid,:any_1], v2:any_1) :bat[:oid,:any_1]
+address CMDifthen
+comment "If-then-else operation to assemble a conditional result";
+
pattern ifthenelse(b:bat[:oid,:bit], v1:any_1, v2:any_1) :bat[:oid,:any_1]
address CMDifthen
comment "If-then-else operation to assemble a conditional result";
diff --git a/monetdb5/modules/mal/batcalc.c b/monetdb5/modules/mal/batcalc.c
--- a/monetdb5/modules/mal/batcalc.c
+++ b/monetdb5/modules/mal/batcalc.c
@@ -1293,66 +1293,106 @@ batcalc_export str CMDifthen(Client cntx
str
CMDifthen(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- BAT *b, *b1, *b2, *bn;
- int tp1, tp2;
+ BAT *b = NULL, *b1 = NULL, *b2 = NULL, *bn;
+ int tp0, tp1, tp2;
bat *ret;
+ BUN cnt = BUN_NONE;
(void) cntxt;
(void) mb;
+ if (pci->argc != 4)
+ throw(MAL, "batcalc.ifthen", "Operation not supported.");
+
ret = getArgReference_bat(stk, pci, 0);
- b = BATdescriptor(* getArgReference_bat(stk, pci, 1));
- if (b == NULL)
- throw(MAL, "batcalc.ifthenelse", RUNTIME_OBJECT_MISSING);
- assert(BAThdense(b));
-
+ tp0 = stk->stk[getArg(pci, 1)].vtype;
tp1 = stk->stk[getArg(pci, 2)].vtype;
+ tp2 = stk->stk[getArg(pci, 3)].vtype;
+ if (tp0 == TYPE_bat || isaBatType(tp0)) {
+ b = BATdescriptor(* getArgReference_bat(stk, pci, 1));
+ if (b == NULL)
+ throw(MAL, "batcalc.ifthenelse",
RUNTIME_OBJECT_MISSING);
+ assert(BAThdense(b));
+ cnt = BATcount(b);
+ }
if (tp1 == TYPE_bat || isaBatType(tp1)) {
b1 = BATdescriptor(* getArgReference_bat(stk, pci, 2));
if (b1 == NULL) {
- BBPunfix(b->batCacheid);
+ if (b)
+ BBPunfix(b->batCacheid);
throw(MAL, "batcalc.ifthenelse",
RUNTIME_OBJECT_MISSING);
}
assert(BAThdense(b1));
- if (pci->argc == 4) {
- tp2 = stk->stk[getArg(pci, 3)].vtype;
- if (tp2 == TYPE_bat || isaBatType(tp2)) {
- b2 = BATdescriptor(* getArgReference_bat(stk,
pci, 3));
- if (b2 == NULL) {
- BBPunfix(b->batCacheid);
- BBPunfix(b1->batCacheid);
- throw(MAL, "batcalc.ifthenelse",
RUNTIME_OBJECT_MISSING);
- }
- assert(BAThdense(b2));
+ if (cnt == BUN_NONE)
+ cnt = BATcount(b1);
+ else if (BATcount(b1) != cnt) {
+ BBPunfix(b->batCacheid);
+ throw(MAL, "batcalc.ifthenelse", ILLEGAL_ARGUMENT);
+ }
+ }
+ if (tp2 == TYPE_bat || isaBatType(tp2)) {
+ b2 = BATdescriptor(* getArgReference_bat(stk, pci, 3));
+ if (b2 == NULL) {
+ if (b)
+ BBPunfix(b->batCacheid);
+ if (b1)
+ BBPunfix(b1->batCacheid);
+ throw(MAL, "batcalc.ifthenelse",
RUNTIME_OBJECT_MISSING);
+ }
+ assert(BAThdense(b2));
+ if (cnt == BUN_NONE)
+ cnt = BATcount(b2);
+ else if (BATcount(b2) != cnt) {
+ if (b)
+ BBPunfix(b->batCacheid);
+ if (b1)
+ BBPunfix(b1->batCacheid);
+ throw(MAL, "batcalc.ifthenelse", ILLEGAL_ARGUMENT);
+ }
+ }
+ if (b == NULL && b1 == NULL && b2 == NULL) {
+ /* at least one BAT required */
+ throw(MAL, "batcalc.ifthenelse", ILLEGAL_ARGUMENT);
+ }
+ if (b != NULL) {
+ if (b1 != NULL) {
+ if (b2 != NULL) {
bn = BATcalcifthenelse(b, b1, b2);
- BBPunfix(b2->batCacheid);
} else {
bn = BATcalcifthenelsecst(b, b1,
&stk->stk[getArg(pci, 3)]);
}
} else {
- throw(MAL, "batcalc.ifthen", "Operation not
supported.");
- }
- BBPunfix(b1->batCacheid);
- } else {
- if (pci->argc == 4) {
- tp2 = stk->stk[getArg(pci, 3)].vtype;
- if (tp2 == TYPE_bat || isaBatType(tp2)) {
- b2 = BATdescriptor(* getArgReference_bat(stk,
pci, 3));
- if (b2 == NULL) {
- BBPunfix(b->batCacheid);
- throw(MAL, "batcalc.ifthenelse",
RUNTIME_OBJECT_MISSING);
- }
- assert(BAThdense(b2));
+ if (b2 != NULL) {
bn = BATcalcifthencstelse(b,
&stk->stk[getArg(pci, 2)], b2);
- BBPunfix(b2->batCacheid);
} else {
bn = BATcalcifthencstelsecst(b,
&stk->stk[getArg(pci, 2)], &stk->stk[getArg(pci, 3)]);
}
+ }
+ } else {
+ bit v = *getArgReference_bit(stk, pci, 1);
+ if (v == bit_nil) {
+ if (b1 != NULL)
+ bn = BATconst(b1, b1->ttype,
ATOMnilptr(b1->ttype), TRANSIENT);
+ else
+ bn = BATconst(b2, b2->ttype,
ATOMnilptr(b2->ttype), TRANSIENT);
+ } else if (v) {
+ if (b1 != NULL)
+ bn = BATcopy(b1, TYPE_void, b1->ttype, 0,
TRANSIENT);
+ else
+ bn = BATconst(b2, b2->ttype,
getArgReference(stk, pci, 2), TRANSIENT);
} else {
- throw(MAL, "batcalc.ifthen", "Operation not
supported.");
+ if (b2 != NULL)
+ bn = BATcopy(b2, TYPE_void, b2->ttype, 0,
TRANSIENT);
+ else
+ bn = BATconst(b1, b1->ttype,
getArgReference(stk, pci, 3), TRANSIENT);
}
}
- BBPunfix(b->batCacheid);
+ if (b)
+ BBPunfix(b->batCacheid);
+ if (b1)
+ BBPunfix(b1->batCacheid);
+ if (b2)
+ BBPunfix(b2->batCacheid);
if (bn == NULL) {
return mythrow(MAL, "batcalc.ifthenelse", OPERATION_FAILED);
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list