IITDBGroup / gprom

GProM is a middleware that adds support for provenance to database backends.
http://www.cs.iit.edu/%7edbgroup/research/gprom.php
Apache License 2.0
8 stars 5 forks source link

LogicBlox backend - generate LB code (casting) #26

Closed lordpretzel closed 6 years ago

lordpretzel commented 6 years ago

integer values are not casted to strings in string concatenation in move rules. Example,

Q(X) :- R(X,Y). WHY(Q(1)).

is compiled into

_(X,Y) <- _move(X,Y).
_move((((((("REL_" + "R_WON") + "(") + 1) + ",") + V0) + ")"),(((((("EDB_" + "rR_LOST") + "(") + 1) + ",") + V0) + ")")) <- _RR_WON(1,V0).
_move((((("REL_" + "Q_WON") + "(") + 1) + ")"),(((((("RULE_" + "0_LOST") + "(") + 1) + ",") + Y) + ")")) <- _r0_WON(1,Y).
_move((((((("RULE_" + "0_LOST") + "(") + 1) + ",") + Y) + ")"),(((((("GOAL_" + "0_0_WON") + "(") + 1) + ",") + Y) + ")")) <- _r0_WON(1,Y).
_move((((((("GOAL_" + "0_0_WON") + "(") + 1) + ",") + Y) + ")"),(((((("notREL_" + "R_LOST") + "(") + 1) + ",") + Y) + ")")) <- _r0_WON(1,Y).
_move((((((("notREL_" + "R_LOST") + "(") + 1) + ",") + Y) + ")"),(((((("REL_" + "R_WON") + "(") + 1) + ",") + Y) + ")")) <- _r0_WON(1,Y).
_RR_WON_nonlinked(1,V0) <- R(1,V0).
_RQ_WON_nonlinked(1) <- _r0_WON_nonlinked(1,Y).
_RR_WON(1,V1) <- _r0_WON(1,V1),_RR_WON_nonlinked(1,V1).
_r0_WON_nonlinked(1,Y) <- _RR_WON_nonlinked(1,Y).
_r0_WON(1,Y) <- _r0_WON_nonlinked(1,Y).

For instance, in the first move rule the variable V0 is of type int, so logicblox will complain if we do not cast this into a string like this:

_(X,Y) <- _move(X,Y).
_move((((((("REL_" + "R_WON") + "(") + "1") + ",") + int:string:convert[V0]) + ")"),(((((("EDB_" + "rR_LOST") + "(") + "1") + ",") + int:string:convert[V0]) + ")")) <- _RR_WON(1,V0).
_move((((("REL_" + "Q_WON") + "(") + "1") + ")"),(((((("RULE_" + "0_LOST") + "(") + "1") + ",") + int:string:convert[Y]) + ")")) <- _r0_WON(1,Y).
_move((((((("RULE_" + "0_LOST") + "(") + "1") + ",") + int:string:convert[Y]) + ")"),(((((("GOAL_" + "0_0_WON") + "(") + "1") + ",") + int:string:convert[Y]) + ")")) <- _r0_WON(1,Y).
_move((((((("GOAL_" + "0_0_WON") + "(") + "1") + ",") + int:string:convert[Y]) + ")"),(((((("notREL_" + "R_LOST") + "(") + "1") + ",") + int:string:convert[Y]) + ")")) <- _r0_WON(1,Y).
_move((((((("notREL_" + "R_LOST") + "(") + "1") + ",") + int:string:convert[Y]) + ")"),(((((("REL_" + "R_WON") + "(") + "1") + ",") + int:string:convert[Y]) + ")")) <- _r0_WON(1,Y).
_RR_WON_nonlinked(1,V0) <- R(1,V0).
_RQ_WON_nonlinked(1) <- _r0_WON_nonlinked(1,_).
_RR_WON(1,V1) <- _r0_WON(1,V1),_RR_WON_nonlinked(1,V1).
_r0_WON_nonlinked(1,Y) <- _RR_WON_nonlinked(1,Y).
_r0_WON(1,Y) <- _r0_WON_nonlinked(1,Y).

Solution: check data type of variables used in string concatenation and add cast for non-int ones.

lordpretzel commented 6 years ago

added support for that, but data types of DLVars in rules that are generated are not correct which means the problem still exists, e.g., Q(X || Y) :- R(X,Y).

lordpretzel commented 6 years ago

fixed by using translator_dl.c code that sets data types correctly and introduces casts