Changeset: a25ff473dbde for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a25ff473dbde
Added Files:
        sql/backends/monet5/sql_copyinto_int_tmpl.h
Modified Files:
        sql/backends/monet5/CMakeLists.txt
        sql/backends/monet5/sql_copyinto.c
Branch: directappend
Log Message:

Add specialized loaders for integer columns


diffs (192 lines):

diff --git a/sql/backends/monet5/CMakeLists.txt 
b/sql/backends/monet5/CMakeLists.txt
--- a/sql/backends/monet5/CMakeLists.txt
+++ b/sql/backends/monet5/CMakeLists.txt
@@ -147,7 +147,7 @@ target_sources(sql
   sql_orderidx.c sql_orderidx.h
   sql_strimps.c sql_strimps.h
   sql_time.c
-  sql_copyinto.c sql_copyinto.h sql_copyinto_dec_tmpl.h
+  sql_copyinto.c sql_copyinto.h sql_copyinto_int_tmpl.h sql_copyinto_dec_tmpl.h
   sql_bincopyfrom.c
   wlr.c wlr.h
   sql_datetrunc.c
diff --git a/sql/backends/monet5/sql_copyinto.c 
b/sql/backends/monet5/sql_copyinto.c
--- a/sql/backends/monet5/sql_copyinto.c
+++ b/sql/backends/monet5/sql_copyinto.c
@@ -981,6 +981,34 @@ SQLworker_onebyone_column(READERtask *ta
 }
 
 #define TMPL_TYPE bte
+#define TMPL_FUNC_NAME integer_bte_frstr
+#define TMPL_BULK_FUNC_NAME bulk_convert_bte
+#include "sql_copyinto_int_tmpl.h"
+
+#define TMPL_TYPE sht
+#define TMPL_FUNC_NAME integer_sht_frstr
+#define TMPL_BULK_FUNC_NAME bulk_convert_sht
+#include "sql_copyinto_int_tmpl.h"
+
+#define TMPL_TYPE int
+#define TMPL_FUNC_NAME integer_int_frstr
+#define TMPL_BULK_FUNC_NAME bulk_convert_int
+#include "sql_copyinto_int_tmpl.h"
+
+#define TMPL_TYPE lng
+#define TMPL_FUNC_NAME integer_lng_frstr
+#define TMPL_BULK_FUNC_NAME bulk_convert_lng
+#include "sql_copyinto_int_tmpl.h"
+
+#ifdef HAVE_HGE
+#define TMPL_TYPE hge
+#define TMPL_FUNC_NAME integer_hge_frstr
+#define TMPL_BULK_FUNC_NAME bulk_convert_hge
+#include "sql_copyinto_int_tmpl.h"
+#endif
+
+
+#define TMPL_TYPE bte
 #define TMPL_FUNC_NAME dec_bte_frstr
 #define TMPL_BULK_FUNC_NAME bulk_convert_bte_dec
 #include "sql_copyinto_dec_tmpl.h"
@@ -1050,7 +1078,31 @@ SQLworker_fixedwidth_column(READERtask *
        }
 
        ConversionResult res;
-       if (c->column->type.type->eclass == EC_DEC) {
+       sql_class eclass = c->column->type.type->eclass;
+       if (eclass == EC_NUM && c->adt == TYPE_bte) {
+               switch (c->adt) {
+                       case TYPE_bte:
+                               res = bulk_convert_bte(task, c, col, count, 
width);
+                               break;
+                       case TYPE_sht:
+                               res = bulk_convert_sht(task, c, col, count, 
width);
+                               break;
+                       case TYPE_int:
+                               res = bulk_convert_int(task, c, col, count, 
width);
+                               break;
+                       case TYPE_lng:
+                               res = bulk_convert_lng(task, c, col, count, 
width);
+                               break;
+#ifdef HAVE_HGE
+                       case TYPE_hge:
+                               res = bulk_convert_hge(task, c, col, count, 
width);
+                               break;
+#endif
+                       default:
+                               assert(0 && "unexpected column type for 
decimal");
+                               return ConversionFailed;
+               }
+       } else if (eclass == EC_DEC) {
                switch (c->adt) {
                        case TYPE_bte:
                                res = bulk_convert_bte_dec(task, c, col, count, 
width, t->digits, t->scale);
@@ -1064,9 +1116,11 @@ SQLworker_fixedwidth_column(READERtask *
                        case TYPE_lng:
                                res = bulk_convert_lng_dec(task, c, col, count, 
width, t->digits, t->scale);
                                break;
+#ifdef HAVE_HGE
                        case TYPE_hge:
                                res = bulk_convert_hge_dec(task, c, col, count, 
width, t->digits, t->scale);
                                break;
+#endif
                        default:
                                assert(0 && "unexpected column type for 
decimal");
                                return ConversionFailed;
diff --git a/sql/backends/monet5/sql_copyinto_int_tmpl.h 
b/sql/backends/monet5/sql_copyinto_int_tmpl.h
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/sql_copyinto_int_tmpl.h
@@ -0,0 +1,92 @@
+
+#ifndef TMPL_TYPE
+#error "only include sql_copyinto_int_tmpl.h with TMPL_TYPE defined"
+#endif
+#ifndef TMPL_FUNC_NAME
+#error "only include sql_copyinto_int_tmpl.h with TMPL_FUNC_NAME defined"
+#endif
+#ifndef TMPL_BULK_FUNC_NAME
+#error "only include sql_copyinto_int_tmpl.h with TMPL_BULK_FUNC_NAME defined"
+#endif
+
+static inline ConversionResult
+TMPL_FUNC_NAME(const char *s, TMPL_TYPE *dst)
+{
+       bool pos = true;
+       TMPL_TYPE acc = 0;
+
+       while(isspace((unsigned char) *s))
+               s++;
+
+       if (*s == '-') {
+               pos = false;
+               s++;
+       } else if (*s == '+') {
+               s++;
+       }
+
+       while (isdigit((unsigned char) *s)) {
+               // int is safe because of promotion rules
+               int digit = *s - '0';
+               TMPL_TYPE new_acc = 10 * acc + digit;
+               if (new_acc < acc) {
+                       // overflow
+                       return ConversionFailed;
+               }
+               acc = new_acc;
+               s++;
+       }
+
+       if (*s == '.') {
+               s++;
+               while (*s == '0')
+                       s++;
+       }
+
+       while (isspace((unsigned char) *s))
+               s++;
+
+       if (*s != '\0')
+               return ConversionFailed;
+
+       if (pos)
+               *dst = acc;
+       else
+               *dst = -acc;
+
+       return ConversionOk;
+}
+
+
+static ConversionResult
+TMPL_BULK_FUNC_NAME(READERtask *task, Column *c, int col, int count, size_t 
width)
+{
+       TMPL_TYPE *cursor = task->primary.data;
+       assert(sizeof(TMPL_TYPE) == width); (void)width;
+       ConversionResult res = ConversionOk;
+       for (int i = 0; i < count; i++) {
+               char *unescaped = NULL;
+               res = prepare_conversion(task, c, col, i, &unescaped);
+               if (res == ConversionOk) {
+                       res = TMPL_FUNC_NAME(unescaped, cursor);
+                       assert(res != ConversionNull);
+                       if (res != ConversionOk) {
+                               res = report_conversion_failed(task, c, i, col 
+ 1, unescaped);
+                       }
+               }
+               if (res != ConversionOk) {
+                       set_nil(c, cursor);
+               }
+               if (res == ConversionFailed) {
+                       return res;
+               }
+               cursor++;
+       }
+       return res;
+}
+
+
+
+#undef TMPL_TYPE
+#undef TMPL_FUNC_NAME
+#undef TMPL_BULK_FUNC_NAME
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to