Changeset: 6b605785c8a8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6b605785c8a8
Modified Files:
        monetdb5/modules/mal/tablet.h
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_result.h
        sql/common/sql_types.c
        sql/server/rel_updates.c
Branch: default
Log Message:

Implement DECIMAL DELIMITERS clause


diffs (220 lines):

diff --git a/monetdb5/modules/mal/tablet.h b/monetdb5/modules/mal/tablet.h
--- a/monetdb5/modules/mal/tablet.h
+++ b/monetdb5/modules/mal/tablet.h
@@ -30,6 +30,7 @@ typedef struct Column_t {
        const char *name;                       /* column title */
        const char *sep;
        const char *rsep;
+       char decsep;
        int seplen;
        const char *type;
        int adt;                                        /* type index */
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3112,6 +3112,7 @@ mvc_import_table_wrap(Client cntxt, MalB
        const char *fixed_widths = *getArgReference_str(stk, pci, pci->retc + 
9);
        int onclient = *getArgReference_int(stk, pci, pci->retc + 10);
        bool escape = *getArgReference_int(stk, pci, pci->retc + 11);
+       const char *decsep = *getArgReference_str(stk, pci, pci->retc + 12);
        str msg = MAL_SUCCEED;
        bstream *s = NULL;
        stream *ss;
@@ -3132,7 +3133,7 @@ mvc_import_table_wrap(Client cntxt, MalB
        if (strNil(fname))
                fname = NULL;
        if (fname == NULL) {
-               msg = mvc_import_table(cntxt, &b, be->mvc, be->mvc->scanner.rs, 
t, tsep, rsep, ssep, ns, sz, offset, besteffort, true, escape);
+               msg = mvc_import_table(cntxt, &b, be->mvc, be->mvc->scanner.rs, 
t, tsep, rsep, ssep, ns, sz, offset, besteffort, true, escape, decsep);
        } else {
                if (onclient) {
                        ss = mapi_request_upload(fname, false, 
be->mvc->scanner.rs, be->mvc->scanner.ws);
@@ -3190,7 +3191,7 @@ mvc_import_table_wrap(Client cntxt, MalB
                        close_stream(ss);
                        throw(MAL, "sql.copy_from", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
-               msg = mvc_import_table(cntxt, &b, be->mvc, s, t, tsep, rsep, 
ssep, ns, sz, offset, besteffort, false, escape);
+               msg = mvc_import_table(cntxt, &b, be->mvc, s, t, tsep, rsep, 
ssep, ns, sz, offset, besteffort, false, escape, decsep);
                // This also closes ss:
                bstream_destroy(s);
        }
@@ -5288,7 +5289,7 @@ static mel_func sql_init_funcs[] = {
  pattern("sql", "export_bin_column", mvc_bin_export_column_wrap, true, "export 
column as binary", args(1, 5, arg("", lng), batargany("col", 1), 
arg("byteswap", bit), arg("filename", str), arg("onclient", int))),
  pattern("sql", "export_bin_column", mvc_bin_export_column_wrap, true, "export 
column as binary", args(1, 5, arg("", lng), argany("val", 1), arg("byteswap", 
bit), arg("filename", str), arg("onclient", int))),
  pattern("sql", "affectedRows", mvc_affected_rows_wrap, true, "export the 
number of affected rows by the current query", args(1,3, 
arg("",int),arg("mvc",int),arg("nr",lng))),
- pattern("sql", "copy_from", mvc_import_table_wrap, true, "Import a table from 
bstream s with the \ngiven tuple and seperators (sep/rsep)", args(1,13, 
batvarargany("",0),arg("t",ptr),arg("sep",str),arg("rsep",str),arg("ssep",str),arg("ns",str),arg("fname",str),arg("nr",lng),arg("offset",lng),arg("best",int),arg("fwf",str),arg("onclient",int),arg("escape",int))),
+ pattern("sql", "copy_from", mvc_import_table_wrap, true, "Import a table from 
bstream s with the \ngiven tuple and seperators (sep/rsep)", args(1,14, 
batvarargany("",0),arg("t",ptr),arg("sep",str),arg("rsep",str),arg("ssep",str),arg("ns",str),arg("fname",str),arg("nr",lng),arg("offset",lng),arg("best",int),arg("fwf",str),arg("onclient",int),arg("escape",int),arg("decsep",str))),
  //we use bat.single now
  //pattern("sql", "single", CMDBATsingle, false, "", args(1,2, 
batargany("",2),argany("x",2))),
  pattern("sql", "importColumn", mvc_bin_import_column_wrap, false, "Import a 
column from the given file", args(2, 8, batargany("", 0),arg("", oid), 
arg("method",str),arg("width",int),arg("bswap",bit),arg("path",str),arg("onclient",int),arg("nrows",oid))),
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
@@ -317,7 +317,7 @@ bat_max_length(hge, hge)
                } else if (*s == '+'){                                          
                                        \
                        s++;                                                    
                                                        \
                }                                                               
                                                                \
-               for (i = 0; *s && *s != '.' && ((res == 0 && *s == '0') || i < 
t->digits - t->scale); s++) { \
+               for (i = 0; *s && *s != c->decsep && ((res == 0 && *s == '0') 
|| i < t->digits - t->scale); s++) { \
                        if (!isdigit((unsigned char) *s))                       
                                \
                                break;                                          
                                                        \
                        res *= 10;                                              
                                                        \
@@ -325,7 +325,7 @@ bat_max_length(hge, hge)
                        if (res)                                                
                                                        \
                                i++;                                            
                                                        \
                }                                                               
                                                                \
-               if (*s == '.') {                                                
                                                \
+               if (*s == c->decsep) {                                          
                                                \
                        s++;                                                    
                                                        \
                        while (*s && isdigit((unsigned char) *s) && scale > 0) 
{        \
                                res *= 10;                                      
                                                        \
@@ -356,6 +356,8 @@ bat_max_length(hge, hge)
 static void *
 dec_frstr(Column *c, int type, const char *s)
 {
+       assert(c->decsep != '\0');
+
        /* support dec map to bte, sht, int and lng */
        if( strcmp(s,"nil")== 0)
                return NULL;
@@ -532,7 +534,7 @@ has_whitespace(const char *s)
 }
 
 str
-mvc_import_table(Client cntxt, BAT ***bats, mvc *m, bstream *bs, sql_table *t, 
const char *sep, const char *rsep, const char *ssep, const char *ns, lng sz, 
lng offset, int best, bool from_stdin, bool escape)
+mvc_import_table(Client cntxt, BAT ***bats, mvc *m, bstream *bs, sql_table *t, 
const char *sep, const char *rsep, const char *ssep, const char *ns, lng sz, 
lng offset, int best, bool from_stdin, bool escape, const char *decsep)
 {
        int i = 0, j;
        node *n;
@@ -581,6 +583,7 @@ mvc_import_table(Client cntxt, BAT ***ba
                        fmt[i].sep = (n->next) ? sep : rsep;
                        fmt[i].rsep = rsep;
                        fmt[i].seplen = _strlen(fmt[i].sep);
+                       fmt[i].decsep = '\0',
                        fmt[i].type = sql_subtype_string(m->ta, &col->type);
                        fmt[i].adt = ATOMindex(col->type.type->impl);
                        fmt[i].tostr = &_ASCIIadt_toStr;
@@ -607,9 +610,11 @@ mvc_import_table(Client cntxt, BAT ***ba
                        if (col->type.type->eclass == EC_DEC) {
                                fmt[i].tostr = &dec_tostr;
                                fmt[i].frstr = &dec_frstr;
+                               fmt[i].decsep = decsep[0];  // apply DECIMAL 
DELIMITERS clause
                        } else if (col->type.type->eclass == EC_SEC) {
                                fmt[i].tostr = &dec_tostr;
                                fmt[i].frstr = &sec_frstr;
+                               fmt[i].decsep = '.';  // not sure if it should 
be affected by DECIMAL DELIMITERS clause
                        }
                        fmt[i].size = ATOMsize(fmt[i].adt);
                }
diff --git a/sql/backends/monet5/sql_result.h b/sql/backends/monet5/sql_result.h
--- a/sql/backends/monet5/sql_result.h
+++ b/sql/backends/monet5/sql_result.h
@@ -31,7 +31,7 @@ extern int mvc_export_bin_chunk(backend 
 
 extern int mvc_export_prepare(backend *b, stream *s);
 
-extern str mvc_import_table(Client cntxt, BAT ***bats, mvc *c, bstream *s, 
sql_table *t, const char *sep, const char *rsep, const char *ssep, const char 
*ns, lng nr, lng offset, int best, bool from_stdin, bool escape);
+extern str mvc_import_table(Client cntxt, BAT ***bats, mvc *c, bstream *s, 
sql_table *t, const char *sep, const char *rsep, const char *ssep, const char 
*ns, lng nr, lng offset, int best, bool from_stdin, bool escape, const char 
*decsep);
 sql5_export int mvc_result_table(backend *be, oid query_id, int nr_cols, 
mapi_query_t type);
 
 sql5_export int mvc_result_column(backend *be, const char *tn, const char 
*name, const char *typename, int digits, int scale, BAT *b);
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -1663,8 +1663,8 @@ sqltypeinit( sql_allocator *sa)
        sql_create_func(sa, "character_length", "str", "length", FALSE, FALSE, 
SCALE_NONE, 0, INT, 1, STR);
        sql_create_func(sa, "octet_length", "str", "nbytes", FALSE, FALSE, 
SCALE_NONE, 0, INT, 1, STR);
 
-       /* copyfrom fname (arg 12) */
-       f = sql_create_union(sa, "copyfrom", "sql", "copy_from", TRUE, 
SCALE_FIX, 0, TABLE, 12, PTR, STR, STR, STR, STR, STR, LNG, LNG, INT, STR, INT, 
INT);
+       /* copyfrom fname (arg 13) */
+       f = sql_create_union(sa, "copyfrom", "sql", "copy_from", TRUE, 
SCALE_FIX, 0, TABLE, 13, PTR, STR, STR, STR, STR, STR, LNG, LNG, INT, STR, INT, 
INT, STR);
        f->varres = 1;
 
        /* bincopyfrom */
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1493,25 +1493,25 @@ table_column_names_and_defaults(sql_allo
 }
 
 static sql_rel *
-rel_import(mvc *sql, sql_table *t, const char *tsep, const char *rsep, const 
char *ssep, const char *ns, const char *filename, lng nr, lng offset, int 
best_effort, dlist *fwf_widths, int onclient, int escape)
+rel_import(mvc *sql, sql_table *t, const char *tsep, const char *rsep, const 
char *ssep, const char *ns, const char *filename, lng nr, lng offset, int 
best_effort, dlist *fwf_widths, int onclient, int escape, const char* decsep)
 {
        sql_rel *res;
        list *exps, *args;
        node *n;
        sql_subtype tpe;
        sql_exp *import;
-       sql_subfunc *f = sql_find_func(sql, "sys", "copyfrom", 12, F_UNION, 
true, NULL);
+       sql_subfunc *f = sql_find_func(sql, "sys", "copyfrom", 13, F_UNION, 
true, NULL);
        char *fwf_string = NULL;
 
        assert(f); /* we do expect copyfrom to be there */
        f->res = table_column_types(sql->sa, t);
        sql_find_subtype(&tpe, "varchar", 0, 0);
-       args = append( append( append( append( append( new_exp_list(sql->sa),
-               exp_atom_ptr(sql->sa, t)),
-               exp_atom_str(sql->sa, tsep, &tpe)),
-               exp_atom_str(sql->sa, rsep, &tpe)),
-               exp_atom_str(sql->sa, ssep, &tpe)),
-               exp_atom_str(sql->sa, ns, &tpe));
+       args = new_exp_list(sql->sa);
+       append(args, exp_atom_ptr(sql->sa, t));
+       append(args, exp_atom_str(sql->sa, tsep, &tpe));
+       append(args, exp_atom_str(sql->sa, rsep, &tpe));
+       append(args, exp_atom_str(sql->sa, ssep, &tpe));
+       append(args, exp_atom_str(sql->sa, ns, &tpe));
 
        if (fwf_widths && dlist_length(fwf_widths) > 0) {
                dnode *dn;
@@ -1529,20 +1529,16 @@ rel_import(mvc *sql, sql_table *t, const
                *fwf_string_cur = '\0';
        }
 
-       append( args, exp_atom_str(sql->sa, filename, &tpe));
-       import = exp_op(sql->sa,
-                                       append(
-                                               append(
-                                                       append(
-                                                               append(
-                                                                       append(
-                                                                               
append(args,
-                                                                               
           exp_atom_lng(sql->sa, nr)),
-                                                                               
exp_atom_lng(sql->sa, offset)),
-                                                                       
exp_atom_int(sql->sa, best_effort)),
-                                                               
exp_atom_str(sql->sa, fwf_string, &tpe)),
-                                                       exp_atom_int(sql->sa, 
onclient)),
-                                               exp_atom_int(sql->sa, escape)), 
f);
+       append(args, exp_atom_str(sql->sa, filename, &tpe));
+       append(args, exp_atom_lng(sql->sa, nr));
+       append(args, exp_atom_lng(sql->sa, offset));
+       append(args, exp_atom_int(sql->sa, best_effort));
+       append(args, exp_atom_str(sql->sa, fwf_string, &tpe));
+       append(args, exp_atom_int(sql->sa, onclient));
+       append(args, exp_atom_int(sql->sa, escape));
+       append(args, exp_atom_str(sql->sa, decsep, &tpe));
+
+       import = exp_op(sql->sa, args, f);
 
        exps = new_exp_list(sql->sa);
        for (n = ol_first_node(t->columns); n; n = n->next) {
@@ -1679,7 +1675,7 @@ copyfrom(sql_query *query, dlist *qname,
                                return NULL;
                        }
 
-                       nrel = rel_import(sql, nt, tsep, rsep, ssep, ns, fname, 
nr, offset, best_effort, fwf_widths, onclient, escape);
+                       nrel = rel_import(sql, nt, tsep, rsep, ssep, ns, fname, 
nr, offset, best_effort, fwf_widths, onclient, escape, decsep);
 
                        if (!rel)
                                rel = nrel;
@@ -1692,7 +1688,7 @@ copyfrom(sql_query *query, dlist *qname,
                }
        } else {
                assert(onclient == 0);
-               rel = rel_import(sql, nt, tsep, rsep, ssep, ns, NULL, nr, 
offset, best_effort, NULL, onclient, escape);
+               rel = rel_import(sql, nt, tsep, rsep, ssep, ns, NULL, nr, 
offset, best_effort, NULL, onclient, escape, decsep);
        }
        if (headers) {
                dnode *n;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to