Changeset: f5004e7118b8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f5004e7118b8
Modified Files:
        monetdb5/modules/mal/mal_weld.c
        monetdb5/modules/mal/mal_weld.h
        sql/backends/monet5/rel_weld.c
Branch: rel-weld
Log Message:

rel_weld handle scale mismatch in e_convert


diffs (77 lines):

diff --git a/monetdb5/modules/mal/mal_weld.c b/monetdb5/modules/mal/mal_weld.c
--- a/monetdb5/modules/mal/mal_weld.c
+++ b/monetdb5/modules/mal/mal_weld.c
@@ -68,6 +68,25 @@ str getWeldType(int type) {
                return NULL;
 }
 
+str getWeldTypeSuffix(int type) {
+       if (type == TYPE_bte)
+               return "c";
+       if (type == TYPE_sht)
+               return "si";
+       else if (type == TYPE_int)
+               return "";
+       else if (type == TYPE_lng)
+               return "L";
+       else if (type == TYPE_flt)
+               return "f";
+       else if (type == TYPE_dbl)
+               return "";
+       else if (ATOMstorage(type) != type)
+               return getWeldType(ATOMstorage(type));
+       else
+               return NULL;
+}
+
 static str getWeldUTypeFromWidth(int width) {
        if (width == 1)
                return "u8";
diff --git a/monetdb5/modules/mal/mal_weld.h b/monetdb5/modules/mal/mal_weld.h
--- a/monetdb5/modules/mal/mal_weld.h
+++ b/monetdb5/modules/mal/mal_weld.h
@@ -17,6 +17,7 @@
 mal_export void dumpWeldProgram(str program, FILE *f);
 mal_export void getOrSetStructMember(char **addr, int type, const void *value, 
int op);
 mal_export str getWeldType(int type);
+mal_export str getWeldTypeSuffix(int type);
 mal_export str WeldRun(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
 
 #endif
diff --git a/sql/backends/monet5/rel_weld.c b/sql/backends/monet5/rel_weld.c
--- a/sql/backends/monet5/rel_weld.c
+++ b/sql/backends/monet5/rel_weld.c
@@ -273,13 +273,32 @@ exp_to_weld(backend *be, weld_state *wst
        }
        switch (exp->type) {
        case e_convert: {
-               str conv_to = getWeldType(exp->tpe.type->localtype);
+               sql_subtype *from = ((list*)exp->r)->h->data;
+               sql_subtype *to = ((list*)exp->r)->h->next->data;
+               str conv_to = getWeldType(to->type->localtype);
                if (strcmp(conv_to, "vec[i8]") == 0) {
                        /* Do nothing */
                        exp_to_weld(be, wstate, exp->l);
                } else {
                        wprintf(wstate, "%s(", conv_to);
                        exp_to_weld(be, wstate, exp->l);
+                       int scale_diff = to->scale - from->scale;
+                       if (scale_diff != 0) {
+                               if (scale_diff < 0) {
+                                       wprintf(wstate, " / 1");
+                                       scale_diff = -scale_diff;
+                               } else {
+                                       wprintf(wstate, " * 1");
+                               }
+                               while (scale_diff--) {
+                                       wprintf(wstate, "0");
+                               }
+                               str conv_from = 
getWeldType(from->type->localtype);
+                               if (strcmp(conv_from, "f32") == 0 || 
strcmp(conv_from, "f64") == 0) {
+                                       wprintf(wstate, ".0");
+                               }
+                               wprintf(wstate, "%s", 
getWeldTypeSuffix(from->type->localtype));
+                       }
                        wprintf(wstate, ")");
                }
                break;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to