Changeset: 769cc2e46a29 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=769cc2e46a29
Modified Files:
        clients/R/Tests/copy_into_fwf.R
        common/stream/stream.c
        common/stream/stream.h
        sql/backends/monet5/sql.c
        sql/server/rel_updates.c
Branch: fixed-width-format
Log Message:

Some cleanup before merge. Niels?


diffs (90 lines):

diff --git a/clients/R/Tests/copy_into_fwf.R b/clients/R/Tests/copy_into_fwf.R
--- a/clients/R/Tests/copy_into_fwf.R
+++ b/clients/R/Tests/copy_into_fwf.R
@@ -23,7 +23,8 @@ if (dbExistsTable(con, "mtcars")) dbRemo
 dbBegin(con)
 dbSendQuery(con, "CREATE TABLE mtcars (mpg DOUBLE PRECISION, cyl DOUBLE 
PRECISION, disp DOUBLE PRECISION, hp DOUBLE PRECISION, drat DOUBLE PRECISION, 
wt DOUBLE PRECISION, qsec DOUBLE PRECISION, vs DOUBLE PRECISION, am DOUBLE 
PRECISION, gear DOUBLE PRECISION, carb DOUBLE PRECISION)")
 
-res <- dbSendQuery(con, paste0("COPY INTO mtcars FROM '", tf, "' FWF (4, 2, 6, 
4, 5, 6, 6, 2, 2, 2, 2)"))
+# delimiters are ineffective for fwf import just set them to make sure they 
dont break stuff
+res <- dbSendQuery(con, paste0("COPY OFFSET 1 INTO mtcars FROM '", tf, "' 
USING DELIMITERS 'a','b','c' NULL AS '' FWF (4, 2, 6, 4, 5, 6, 6, 2, 2, 2, 2)"))
 
 print(dbReadTable(con, "mtcars"))
 
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -4674,11 +4674,7 @@ stream * stream_blackhole_create (void)
 
 
 /* fixed-width format streams */
-
-#define STREAM_FWF_NAME "fwf"
-#define STREAM_FWF_FIELD_SEP '|'
-#define STREAM_FWF_ESCAPE '\\'
-#define STREAM_FWF_RECORD_SEP '\n'
+#define STREAM_FWF_NAME "fwf_ftw"
 
 typedef struct {
        stream *s;
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -87,6 +87,12 @@ typedef __int128_t hge;
 #define ST_READ  0
 #define ST_WRITE 1
 
+/* fwf gets turned into a csv with these parameters */
+#define STREAM_FWF_FIELD_SEP '|'
+#define STREAM_FWF_ESCAPE '\\'
+#define STREAM_FWF_RECORD_SEP '\n'
+#define STREAM_FWF_FILLER ' '
+
 typedef struct stream stream;
 
 /* some os specific initialization */
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
@@ -3501,17 +3501,26 @@ mvc_import_table_wrap(Client cntxt, MalB
                        }
                        widths = malloc(sizeof(size_t) * ncol);
                        if (!widths) {
-                               // TODO: free other stuff
+                               mnstr_destroy(ss);
+                               GDKfree(tsep);
+                               GDKfree(rsep);
+                               GDKfree(ssep);
+                               GDKfree(ns);
                                throw(MAL, "sql.copy_from", MAL_MALLOC_FAIL);
                        }
                        for (i = 0; i < width_len; i++) {
-                               if (fixed_widths[i] == '|') {
+                               if (fixed_widths[i] == STREAM_FWF_FIELD_SEP) {
                                        fixed_widths[i] = '\0';
                                        widths[current_width_entry++] = 
(size_t) atoll(val_start);
                                        val_start = fixed_widths + i + 1;
                                }
                        }
-                       ss = stream_fwf_create(ss, ncol, widths, ' ');
+                       /* overwrite other delimiters to the ones the FWF 
stream uses */
+                       sprintf((char*) tsep, "%c", STREAM_FWF_FIELD_SEP);
+                       sprintf((char*) rsep, "%c", STREAM_FWF_RECORD_SEP);
+                       sprintf((char*) ssep, "");
+
+                       ss = stream_fwf_create(ss, ncol, widths, 
STREAM_FWF_FILLER);
                }
 #if SIZEOF_VOID_P == 4
                s = bstream_create(ss, 0x20000);
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
@@ -1167,7 +1167,7 @@ rel_import(mvc *sql, sql_table *t, char 
                }
                char* fwf_string_cur = fwf_string;
                for (dn = fwf_widths->h; dn; dn = dn->next) {
-                       fwf_string_cur += sprintf(fwf_string_cur, LLFMT"|", 
dn->data.l_val);
+                       fwf_string_cur += sprintf(fwf_string_cur, LLFMT"%c", 
dn->data.l_val, STREAM_FWF_FIELD_SEP);
                        ncol++;
                }
                if(list_length(f->res) != ncol) {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to