Changeset: ed9c9e15c398 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ed9c9e15c398
Modified Files:
        clients/mapilib/mapi.c
        sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:

now shipping all of lineitem


diffs (228 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4001,6 +4001,11 @@ static char* mapi_convert_int(struct Map
        return (char*) col->write_buf;
 }
 
+static char* mapi_convert_lng(struct MapiColumn *col) {
+       sprintf(col->write_buf, "%lld", *((lng*) col->buffer_ptr));
+       return (char*) col->write_buf;
+}
+
 static char* mapi_convert_smallint(struct MapiColumn *col) {
        sprintf(col->write_buf, "%hd", *((short*) col->buffer_ptr));
        return (char*) col->write_buf;
@@ -4011,6 +4016,11 @@ static char* mapi_convert_tinyint(struct
        return (char*) col->write_buf;
 }
 
+static char* mapi_convert_double(struct MapiColumn *col) {
+       sprintf(col->write_buf, "%g", *((double*) col->buffer_ptr));
+       return (char*) col->write_buf;
+}
+
 static char* mapi_convert_boolean(struct MapiColumn *col) {
        if (*((signed char*) col->buffer_ptr) == 1) {
                return "true";
@@ -4020,6 +4030,86 @@ static char* mapi_convert_boolean(struct
        }
 }
 
+
+/* apologies for now */
+typedef int date;
+int date_nil = -1;
+
+static int
+leapyears(int year)
+{
+       /* count the 4-fold years that passed since jan-1-0 */
+       int y4 = year / 4;
+
+       /* count the 100-fold years */
+       int y100 = year / 100;
+
+       /* count the 400-fold years */
+       int y400 = year / 400;
+
+       return y4 + y400 - y100 + (year >= 0);  /* may be negative */
+}
+
+#define leapyear(y)            ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 
== 0))
+
+#define YEARDAYS(y)            (leapyear(y) ? 366 : 365)
+
+static int CUMDAYS[13] = {
+       0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
+};
+static int CUMLEAPDAYS[13] = {
+       0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366
+};
+
+
+static char*
+mapi_convert_date(struct MapiColumn *col){
+       int day, month, year;
+
+       date n = *((date*) col->buffer_ptr);
+
+       if (n == date_nil) {
+               return "NULL";
+       }
+       year = n / 365;
+       day = (n - year * 365) - leapyears(year >= 0 ? year - 1 : year);
+       if (n < 0) {
+               year--;
+               while (day >= 0) {
+                       year++;
+                       day -= YEARDAYS(year);
+               }
+               day = YEARDAYS(year) + day;
+       } else {
+               while (day < 0) {
+                       year--;
+                       day += YEARDAYS(year);
+               }
+       }
+
+       day++;
+       if (leapyear(year)) {
+               for (month = day / 31 == 0 ? 1 : day / 31; month <= 12; month++)
+                       if (day > CUMLEAPDAYS[month - 1] && day <= 
CUMLEAPDAYS[month]) {
+                               break;
+                       }
+               day -= CUMLEAPDAYS[month - 1];
+       } else {
+               for (month = day / 31 == 0 ? 1 : day / 31; month <= 12; month++)
+                       if (day > CUMDAYS[month - 1] && day <= CUMDAYS[month]) {
+                               break;
+                       }
+               day -= CUMDAYS[month - 1];
+       }
+
+       sprintf(col->write_buf, "%04d-%02d-%02d", year, month, day);
+
+       return col->write_buf;
+}
+
+
+/* end of apologies */
+
 static char* mapi_convert_unknown(struct MapiColumn *col) {
        (void) col;
        return "<unknown>";
@@ -4117,6 +4207,14 @@ read_into_cache(MapiHdl hdl, int lookahe
                                        result->fields[i].converter = 
(mapi_converter) mapi_convert_tinyint;
                                } else if (strcasecmp(type_sql_name, "boolean") 
== 0) {
                                        result->fields[i].converter = 
(mapi_converter) mapi_convert_boolean;
+                               } else if (strcasecmp(type_sql_name, "decimal") 
== 0) {
+                                       result->fields[i].converter = 
(mapi_converter) mapi_convert_double;
+                               } else if (strcasecmp(type_sql_name, "double") 
== 0) {
+                                       result->fields[i].converter = 
(mapi_converter) mapi_convert_double;
+                               } else if (strcasecmp(type_sql_name, "date") == 
0) {
+                                       result->fields[i].converter = 
(mapi_converter) mapi_convert_date;
+                               } else if (strcasecmp(type_sql_name, "bigint") 
== 0) {
+                                       result->fields[i].converter = 
(mapi_converter) mapi_convert_lng;
                                } else {
                                        result->fields[i].converter = 
(mapi_converter) mapi_convert_unknown;
                                        // TODO: complain
@@ -5382,7 +5480,7 @@ mapi_fetch_row(MapiHdl hdl)
                        }
                        bs2_resetbuf(hdl->mid->from);
 
-                       fprintf(stderr, "nrows=%llu\n", nrows);
+//                     fprintf(stderr, "nrows=%llu\n", nrows);
                        buf = (char*) bs2_getbuf(hdl->mid->from) + sizeof(lng);
 
                        // iterate over cols
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -1870,6 +1870,7 @@ static int mvc_export_resultset_prot10(r
        size_t srow = 0;
        lng *var_col_len;
        BATiter *iterators;
+       lng fixed_lengths = 0;
 
        iterators = GDKmalloc(sizeof(BATiter) * t->nr_cols);
        var_col_len = GDKmalloc(sizeof(lng) * t->nr_cols);
@@ -1900,8 +1901,47 @@ static int mvc_export_resultset_prot10(r
                int typelen = ATOMsize(mtype);
                iterators[i] = bat_iterator(BATdescriptor(c->b));
 
+               if (strcasecmp(c->type.type->sqlname, "decimal") == 0) {
+                       str res = MAL_SUCCEED;
+               int bat_type = ATOMstorage(iterators[i].b->ttype);
+               int hpos = c->type.scale; //this value isn't right, it's always 
3. todo: find the right scale value (i.e. where the decimal point is)
+               bat result = 0;
+               //decimal values can be stored in various numeric fields, so 
check the numeric field and convert the one it's actually stored in
+               switch(bat_type)
+               {
+                   case TYPE_bte:
+                       res = batbte_dec2_dbl(&result, &hpos, 
&iterators[i].b->batCacheid);
+                       break;
+                   case TYPE_sht:
+                       res = batsht_dec2_dbl(&result, &hpos, 
&iterators[i].b->batCacheid);
+                       break;
+                   case TYPE_int:
+                       res = batint_dec2_dbl(&result, &hpos, 
&iterators[i].b->batCacheid);
+                       break;
+                   case TYPE_lng:
+                       res = batlng_dec2_dbl(&result, &hpos, 
&iterators[i].b->batCacheid);
+                       break;
+       #ifdef HAVE_HGE
+                   case TYPE_hge:
+                       res = bathge_dec2_dbl(&result, &hpos, 
&iterators[i].b->batCacheid);
+                       break;
+       #endif
+                   default:
+                       return -1;
+               }
+               if (res == MAL_SUCCEED) {
+                       typelen = sizeof(dbl);
+                       BBPunfix(iterators[i].b->batCacheid);
+                   iterators[i].b = BATdescriptor(result);
+               } else {
+                       return -1;
+               }
+               }
+
                if (ATOMvarsized(mtype)) {
                        typelen = -1;
+               } else {
+                       fixed_lengths += typelen;
                }
 
                if (!mnstr_writeLng(s, (lng)(strlen(c->tn) + strlen(c->name) + 
strlen(c->type.type->sqlname) + sizeof(int) + 3)) ||
@@ -1923,7 +1963,7 @@ static int mvc_export_resultset_prot10(r
 
                // FIXME: this can be skipped if there are no variable-length 
types in the result set
                while (row < (size_t) count) {
-                       size_t rowsize = 0;
+                       size_t rowsize = fixed_lengths;
                        for (i = 0; i < (size_t) t->nr_cols; i++) {
                                res_col *c = t->cols + i;
                                int mtype = c->type.type->localtype;
@@ -1933,8 +1973,6 @@ static int mvc_export_resultset_prot10(r
                                        assert(mtype == TYPE_str);
                                        rowsize += slen;
                                        var_col_len[i] += slen;
-                               } else {
-                                       rowsize += ATOMsize(mtype);
                                }
                        }
                        if (bytes_left < rowsize) break;
@@ -1974,7 +2012,11 @@ static int mvc_export_resultset_prot10(r
                                        }
                                }
                        } else {
-                               if (mnstr_write(s, Tloc(iterators[i].b, srow), 
ATOMsize(mtype), row - srow) != (ssize_t) (row - srow)) {
+                               int atom_size = ATOMsize(mtype);
+                               if (strcasecmp(c->type.type->sqlname, 
"decimal") == 0) {
+                                       atom_size = sizeof(dbl);
+                               }
+                               if (mnstr_write(s, Tloc(iterators[i].b, srow), 
atom_size, row - srow) != (ssize_t) (row - srow)) {
                                        return -1;
                                }
                        }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to