Changeset: 98a35cf459a6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=98a35cf459a6
Added Files:
        sql/backends/monet5/sql_cast_impl_down_from_flt.h
        sql/backends/monet5/sql_cast_impl_down_from_int.h
        sql/backends/monet5/sql_cast_impl_up_to_flt.h
        sql/backends/monet5/sql_cast_impl_up_to_int.h
Modified Files:
        sql/backends/monet5/Makefile.ag
        sql/backends/monet5/sql_cast.c
Branch: Jan2014
Log Message:

sql_cast.c: use C include files for type-expansion


diffs (truncated from 12479 to 300 lines):

diff --git a/sql/backends/monet5/Makefile.ag b/sql/backends/monet5/Makefile.ag
--- a/sql/backends/monet5/Makefile.ag
+++ b/sql/backends/monet5/Makefile.ag
@@ -48,6 +48,10 @@ lib__sql = {
                sql_result.c sql_result.h \
                sql_readline.c sql_readline.h \
                sql_cast.c sql_cast.h \
+               sql_cast_impl_down_from_flt.h \
+               sql_cast_impl_down_from_int.h \
+               sql_cast_impl_up_to_flt.h \
+               sql_cast_impl_up_to_int.h \
                sql_round.c sql_bat2time.c sql_fround.c sql_rdf.c
        LIBS = ../../server/libsqlserver \
                   ../../storage/libstore \
diff --git a/sql/backends/monet5/sql_cast.c b/sql/backends/monet5/sql_cast.c
--- a/sql/backends/monet5/sql_cast.c
+++ b/sql/backends/monet5/sql_cast.c
@@ -544,11042 +544,281 @@ SQLbatstr_cast(Client cntxt, MalBlkPtr m
        return msg;
 }
 
-str
-bte_2_bte(bte *res, bte *v)
-{
-       /* shortcut nil */
-       if (*v == bte_nil) {
-               *res = bte_nil;
-               return (MAL_SUCCEED);
-       }
+/* sql_cast_impl_up_to_int */
 
-       /* since the bte type is bigger than or equal to the bte type, it will
-          always fit */
-       *res = (bte) *v;
-       return (MAL_SUCCEED);
-}
+#define TP1 bte
+#define TP2 bte
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-str
-batbte_2_bte(int *res, int *bid)
-{
-       BAT *b, *bn;
-       bte *p, *q;
-       bte *o;
+#define TP1 bte
+#define TP2 sht
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "batcalc.bte_2_bte", "Cannot access descriptor");
-       }
-       bn = BATnew(TYPE_void, TYPE_bte, BATcount(b));
-       if (bn == NULL) {
-               BBPreleaseref(b->batCacheid);
-               throw(SQL, "sql.bte_2_bte", MAL_MALLOC_FAIL);
-       }
-       bn->hsorted = b->hsorted;
-       bn->hrevsorted = b->hrevsorted;
-       BATseqbase(bn, b->hseqbase);
-       o = (bte *) Tloc(bn, BUNfirst(bn));
-       p = (bte *) Tloc(b, BUNfirst(b));
-       q = (bte *) Tloc(b, BUNlast(b));
-       bn->T->nonil = 1;
-       if (b->T->nonil) {
-               for (; p < q; p++, o++)
-                       *o = (bte) *p;
-       } else {
-               for (; p < q; p++, o++)
-                       if (*p == bte_nil) {
-                               *o = bte_nil;
-                               bn->T->nonil = FALSE;
-                       } else
-                               *o = (bte) *p;
-       }
-       BATsetcount(bn, BATcount(b));
-       bn->hrevsorted = bn->batCount <= 1;
-       bn->tsorted = 0;
-       bn->trevsorted = 0;
-       BATkey(BATmirror(bn), FALSE);
+#define TP1 sht
+#define TP2 sht
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       if (!(bn->batDirty & 2))
-               bn = BATsetaccess(bn, BAT_READ);
+#define TP1 bte
+#define TP2 int
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       if (b->htype != bn->htype) {
-               BAT *r = VIEWcreate(b, bn);
+#define TP1 sht
+#define TP2 int
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-               BBPkeepref(*res = r->batCacheid);
-               BBPreleaseref(bn->batCacheid);
-               BBPreleaseref(b->batCacheid);
-               return MAL_SUCCEED;
-       }
-       BBPkeepref(*res = bn->batCacheid);
-       BBPreleaseref(b->batCacheid);
-       return MAL_SUCCEED;
-}
+#define TP1 int
+#define TP2 int
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-str
-bte_dec2_bte(bte *res, int *s1, bte *v)
-{
-       int scale = *s1;
-       bte r, h = (*v < 0) ? -5 : 5;
+#define TP1 bte
+#define TP2 wrd
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       /* shortcut nil */
-       if (*v == bte_nil) {
-               *res = bte_nil;
-               return (MAL_SUCCEED);
-       }
+#define TP1 sht
+#define TP2 wrd
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       /* since the bte type is bigger than or equal to the bte type, it will
-          always fit */
-       r = (bte) *v;
-       if (scale)
-               r = (bte) ((r + h * scales[scale - 1]) / scales[scale]);
-       *res = r;
-       return (MAL_SUCCEED);
-}
+#define TP1 int
+#define TP2 wrd
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-str
-bte_dec2dec_bte(bte *res, int *S1, bte *v, int *d2, int *S2)
-{
-       int p = *d2, inlen = 1;
-       bte cpyval = *v;
-       int s1 = *S1, s2 = *S2;
-       bte r, h = (*v < 0) ? -5 : 5;
+#define TP1 wrd
+#define TP2 wrd
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       /* shortcut nil */
-       if (*v == bte_nil) {
-               *res = bte_nil;
-               return (MAL_SUCCEED);
-       }
+#define TP1 bte
+#define TP2 lng
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       /* count the number of digits in the input */
-       while (cpyval /= 10)
-               inlen++;
+#define TP1 sht
+#define TP2 lng
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       /* rounding is allowed */
-       inlen += (s2 - s1);
-       if (p && inlen > p) {
-               throw(SQL, "convert", "22003!too many digits (%d > %d)", inlen, 
p);
-       }
+#define TP1 int
+#define TP2 lng
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-       /* since the bte type is bigger than or equal to the bte type, it will
-          always fit */
-       r = (bte) *v;
-       if (s2 > s1)
-               r *= (bte) scales[s2 - s1];
-       else if (s2 != s1)
-               r = (bte) ((r + h * scales[s1 - s2 - 1]) / scales[s1 - s2]);
-       *res = r;
-       return (MAL_SUCCEED);
-}
+#define TP1 wrd
+#define TP2 lng
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-str
-bte_num2dec_bte(bte *res, bte *v, int *d2, int *s2)
-{
-       int zero = 0;
-       return bte_dec2dec_bte(res, &zero, v, d2, s2);
-}
+#define TP1 lng
+#define TP2 lng
+#include "sql_cast_impl_up_to_int.h"
+#undef TP2
+#undef TP1
 
-str
-batbte_dec2_bte(int *res, int *s1, int *bid)
-{
-       BAT *b, *bn;
-       bte *p, *q;
-       char *msg = NULL;
-       int scale = *s1;
-       bte *o;
+/* sql_cast_impl_down_from_flt */
 
-       if ((b = BATdescriptor(*bid)) == NULL) {
-               throw(SQL, "batcalc.bte_dec2_bte", "Cannot access descriptor");
-       }
-       bn = BATnew(TYPE_void, TYPE_bte, BATcount(b));
-       if (bn == NULL) {
-               BBPreleaseref(b->batCacheid);
-               throw(SQL, "sql.dec2_bte", MAL_MALLOC_FAIL);
-       }
-       bn->hsorted = b->hsorted;
-       bn->hrevsorted = b->hrevsorted;
-       BATseqbase(bn, b->hseqbase);
-       o = (bte *) Tloc(bn, BUNfirst(bn));
-       p = (bte *) Tloc(b, BUNfirst(b));
-       q = (bte *) Tloc(b, BUNlast(b));
-       bn->T->nonil = 1;
-       if (b->T->nonil) {
-               if (scale)
-                       for (; p < q; p++, o++)
-                               *o = (bte) ((*p + (*p < 0 ? -5 : 5) * 
scales[scale - 1]) / scales[scale]);
-               else
-                       for (; p < q; p++, o++)
-                               *o = (bte) (*p);
-       } else {
-               for (; p < q; p++, o++) {
-                       if (*p == bte_nil) {
-                               *o = bte_nil;
-                               bn->T->nonil = FALSE;
-                       } else if (scale) {
-                               *o = (bte) ((*p + (*p < 0 ? -5 : 5) * 
scales[scale - 1]) / scales[scale]);
-                       } else {
-                               *o = (bte) (*p);
-                       }
-               }
-       }
-       BATsetcount(bn, BATcount(b));
-       bn->hrevsorted = bn->batCount <= 1;
-       bn->tsorted = 0;
-       bn->trevsorted = 0;
-       BATkey(BATmirror(bn), FALSE);
+#define TP1 flt
+#define TP2 bte
+#include "sql_cast_impl_down_from_flt.h"
+#undef TP2
+#undef TP1
 
-       if (!(bn->batDirty & 2))
-               bn = BATsetaccess(bn, BAT_READ);
+#define TP1 flt
+#define TP2 sht
+#include "sql_cast_impl_down_from_flt.h"
+#undef TP2
+#undef TP1
 
-       if (b->htype != bn->htype) {
-               BAT *r = VIEWcreate(b, bn);
+#define TP1 flt
+#define TP2 int
+#include "sql_cast_impl_down_from_flt.h"
+#undef TP2
+#undef TP1
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to