Changeset: e161bd7190d9 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e161bd7190d9
Modified Files:
        gdk/gdk_logger.c
        monetdb5/modules/mal/tablet.c
        monetdb5/modules/mal/tablet.h
        monetdb5/optimizer/opt_pushselect.c
        monetdb5/optimizer/opt_support.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_result.h
        sql/server/rel_updates.c
        sql/server/sql_parser.y
        sql/test/BugTracker-2009/Tests/copy_multiple_files.SF-2902320.stable.out
Branch: default
Log Message:

add optional column list (s) in copy into statement

ie copy ... into table_name [ ( list with to be inserted columns ) ]
        from 'file or stdin' [ ( list of columns in the file/stdin ) ]
        using etc.

The second list should match the number of columns in the input file. If
some of the columns are missing in the first list, they will be skipped
during the parsing process.

Column types should match with the to be inserted column type.


diffs (truncated from 582 to 300 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -508,6 +508,7 @@ la_bat_destroy(logger *lg, logaction *la
 #endif
                        BUNdelete(lg->snapshots_bid, p, FALSE);
                        BUNdelete(lg->snapshots_tid, p, FALSE);
+                       /* move to the dirty new part of the snapshots list */
                        BUNappend(lg->snapshots_bid, &bid, FALSE);
                        BUNappend(lg->snapshots_tid, &lg->tid, FALSE);
                }
@@ -622,6 +623,7 @@ la_bat_use(logger *lg, logaction *la)
                assert(BBPfarms[b->T->vheap->farmid].roles & (1 << PERSISTENT));
        }
 #endif
+       /* move to the dirty new part of the snapshots list, new snapshots will 
get flushed to disk */
        BUNappend(lg->snapshots_bid, &b->batCacheid, FALSE);
        BUNappend(lg->snapshots_tid, &lg->tid, FALSE);
        logbat_destroy(b);
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -210,6 +210,8 @@ TABLETcreate_bats(Tablet *as, BUN est)
        char errbuf[42];
 
        for (i = 0; i < as->nr_attrs; i++) {
+               if (fmt[i].skip)
+                       continue;
                fmt[i].c = void_bat_create(fmt[i].adt, est);
                fmt[i].ci = bat_iterator(fmt[i].c);
                if (!fmt[i].c) {
@@ -229,15 +231,20 @@ TABLETcollect(Tablet *as)
 {
        BAT **bats = GDKmalloc(sizeof(BAT *) * as->nr_attrs);
        Column *fmt = as->format;
-       BUN i;
-       BUN cnt = BATcount(fmt[0].c);
+       BUN i, j;
+       BUN cnt = 0;
        char errbuf[42];
 
        if (bats == NULL)
                return NULL;
-       for (i = 0; i < as->nr_attrs; i++) {
-               bats[i] = fmt[i].c;
-               BBPfix(bats[i]->batCacheid);
+       for (i = 0; i < as->nr_attrs && !cnt; i++) 
+               if (!fmt[i].skip)
+                       cnt = BATcount(fmt[i].c);
+       for (i = 0, j = 0; i < as->nr_attrs; i++) {
+               if (fmt[i].skip)
+                       continue;
+               bats[j] = fmt[i].c;
+               BBPfix(bats[j]->batCacheid);
                BATsetaccess(fmt[i].c, BAT_READ);
                BATderiveProps(fmt[i].c, 0);
 
@@ -250,6 +257,7 @@ TABLETcollect(Tablet *as)
                        GDKfree(bats);
                        return NULL;
                }
+               j++;
        }
        return bats;
 }
@@ -259,19 +267,23 @@ TABLETcollect_parts(Tablet *as, BUN offs
 {
        BAT **bats = GDKmalloc(sizeof(BAT *) * as->nr_attrs);
        Column *fmt = as->format;
-       BUN i;
-       BUN cnt = BATcount(fmt[0].c);
+       BUN i, j;
+       BUN cnt = 0;
        char errbuf[42];
 
        if (bats == NULL)
                return NULL;
-       for (i = 0; i < as->nr_attrs; i++) {
-               BAT *b = fmt[i].c;
-               BAT *bv = NULL;
-
+       for (i = 0; i < as->nr_attrs && !cnt; i++) 
+               if (!fmt[i].skip)
+                       cnt = BATcount(fmt[i].c);
+       for (i = 0, j = 0; i < as->nr_attrs; i++) {
+               BAT *b, *bv = NULL;
+               if (fmt[i].skip)
+                       continue;
+               b = fmt[i].c;
                BATsetaccess(b, BAT_READ);
                bv = BATslice(b, (offset>0)?offset-1:0, BATcount(b));
-               bats[i] = bv;
+               bats[j] = bv;
                BATderiveProps(bv, 0);
 
                b->tkey = (offset>0)?FALSE:bv->tkey; 
@@ -287,7 +299,7 @@ TABLETcollect_parts(Tablet *as, BUN offs
 
                if (offset>0) {
                        BBPunfix(bv->batCacheid);
-                       bats[i] = BATslice(b, offset, BATcount(b));
+                       bats[j] = BATslice(b, offset, BATcount(b));
                }
                if (cnt != BATcount(b)) {
                        snprintf(errbuf, sizeof(errbuf), "Error: column " 
BUNFMT "  count " BUNFMT " differs from " BUNFMT "\n", i, BATcount(b), cnt);
@@ -298,6 +310,7 @@ TABLETcollect_parts(Tablet *as, BUN offs
                        GDKfree(bats);
                        return NULL;
                }
+               j++;
        }
        return bats;
 }
@@ -833,7 +846,7 @@ SQLworker_column(READERtask *task, int c
 
        /* watch out for concurrent threads */
        MT_lock_set(&mal_copyLock, "tablet insert value");
-       if (BATcapacity(fmt[col].c) < BATcount(fmt[col].c) + task->next) {
+       if (!fmt[col].skip && BATcapacity(fmt[col].c) < BATcount(fmt[col].c) + 
task->next) {
                if (BATextend(fmt[col].c, BATgrows(fmt[col].c) + task->limit) 
== GDK_FAIL) {
                        MT_lock_set(&errorlock, "SQLworker_column");
                        if (task->as->error == NULL)
@@ -848,7 +861,7 @@ SQLworker_column(READERtask *task, int c
 
        for (i = 0; i < task->next; i++)
                if (task->fields[col][i]) {     /* no errors */
-                       if (SQLinsert_val(&fmt[col], task->fields[col][i], 
task->quote, NULL, &err, col + 1)) {
+                       if (!fmt[col].skip && SQLinsert_val(&fmt[col], 
task->fields[col][i], task->quote, NULL, &err, col + 1)) {
                                assert(err != NULL);
                                MT_lock_set(&mal_copyLock, "tablet insert 
value");
                                if (!task->as->tryall) {
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
@@ -69,6 +69,7 @@ typedef struct Column_t {
        void *(*frstr)(struct Column_t *fmt, int type, const char *s, const 
char *e, char quote);
        void *extra;
        void *data;
+       int skip;                                       /* only skip to the 
next field */
        int len;
        int nillen;
        bit ws;                                         /* if set we need to 
skip white space */
diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -111,6 +111,20 @@ subselect_find_subselect( subselect_t *s
        return -1;
 }
 
+static int
+lastbat_arg(MalBlkPtr mb, InstrPtr p)
+{
+       int i = 0;
+       for (i=p->retc; i<p->argc; i++) {
+               int type = getArgType(mb, p, i);
+               if (!isaBatType(type) && type != TYPE_bat)
+                       break;
+       }
+       if (i < p->argc)
+               return i-1;
+       return 0;
+}
+
 int
 OPTpushselectImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci)
 {
@@ -136,6 +150,7 @@ OPTpushselectImplementation(Client cntxt
 
        /* check for bailout conditions */
        for (i = 1; i < limit; i++) {
+               int lastbat;
                p = old[i];
 
                for (j = 0; j<p->retc; j++) {
@@ -177,8 +192,9 @@ OPTpushselectImplementation(Client cntxt
                                }
                        }
                }
+               lastbat = lastbat_arg(mb, p);
                if (isSubSelect(p) && p->retc == 1 &&
-                  /* no cand list */ getArgType(mb, p, 2) != 
newBatType(TYPE_oid, TYPE_oid)) {
+                  /* no cand list */ getArgType(mb, p, lastbat) != 
newBatType(TYPE_oid, TYPE_oid)) {
                        int i1 = getArg(p, 1), tid = 0;
                        InstrPtr q = old[vars[i1]];
 
@@ -320,10 +336,11 @@ OPTpushselectImplementation(Client cntxt
                        int tid = 0;
 
                        if ((tid = subselect_find_tids(&subselects, getArg(p, 
0))) >= 0) {
-                               if (getArgType(mb, p, 2) == TYPE_bat) /* empty 
candidate list bat_nil */
-                                       getArg(p,2) = tid;
+                               int lastbat = lastbat_arg(mb, p);
+                               if (getArgType(mb, p, lastbat) == TYPE_bat) /* 
empty candidate list bat_nil */
+                                       getArg(p, lastbat) = tid;
                                else
-                                       p = PushArgument(mb, p, tid, 2);
+                                       p = PushArgument(mb, p, tid, lastbat+1);
                                /* make sure to resolve again */
                                p->token = ASSIGNsymbol; 
                                p->typechk = TYPE_UNKNOWN;
@@ -457,6 +474,7 @@ OPTpushselectImplementation(Client cntxt
        pushInstruction(mb,old[0]);
 
        for (i = 1; i < limit; i++) {
+               int lastbat;
                p = old[i];
 
                for (j = 0; j<p->retc; j++) {
@@ -496,8 +514,11 @@ OPTpushselectImplementation(Client cntxt
                 * ni = subselect(ins, C1..)
                 * nu = subselect(uvl, C1..)
                 * s = subdelta(nc, uid, nu, ni);
+                *
+                * doesn't handle Xsubselect(x, .. z, C1.. cases) ie 
multicolumn selects
                 */
-               if (isSubSelect(p) && p->retc == 1) {
+               lastbat = lastbat_arg(mb, p);
+               if (isSubSelect(p) && p->retc == 1 && lastbat == 2) {
                        int var = getArg(p, 1);
                        InstrPtr q = old[vars[var]];
 
diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -862,7 +862,7 @@ int isDiffOp(InstrPtr p){
 }
 
 int isMatJoinOp(InstrPtr p){
-       return (getModuleId(p) == algebraRef &&
+       return (isSubJoin(p) || (getModuleId(p) == algebraRef &&
                 (getFunctionId(p) == crossRef ||
                  getFunctionId(p) == joinRef ||
                  getFunctionId(p) == subjoinRef ||
@@ -870,7 +870,7 @@ int isMatJoinOp(InstrPtr p){
                  getFunctionId(p) == subthetajoinRef ||
                  getFunctionId(p) == subbandjoinRef ||
                  getFunctionId(p) == subrangejoinRef)
-               );
+               ));
 }
 
 int isDelta(InstrPtr p){
@@ -900,8 +900,7 @@ int isSubSelect(InstrPtr p)
        char *func = getFunctionId(p);
        size_t l = func?strlen(func):0;
        
-       return (l >= 9 && getModuleId(p)== algebraRef && 
-               strcmp(func+l-9,"subselect") == 0);
+       return (l >= 9 && strcmp(func+l-9,"subselect") == 0);
 }
 
 int isSubJoin(InstrPtr p)
@@ -909,8 +908,7 @@ int isSubJoin(InstrPtr p)
        char *func = getFunctionId(p);
        size_t l = func?strlen(func):0;
        
-       return (l >= 7 && getModuleId(p)== algebraRef && 
-               strcmp(func+l-7,"subjoin") == 0);
+       return (l >= 7 && strcmp(func+l-7,"subjoin") == 0);
 }
 
 int isFragmentGroup(InstrPtr p){
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
@@ -2791,16 +2791,15 @@ mvc_import_table_wrap(Client cntxt, MalB
        unsigned char *tsep = NULL, *rsep = NULL, *ssep = NULL, *ns = NULL;
        ssize_t len = 0;
        str filename, cs;
-       str *sname = getArgReference_str(stk, pci, pci->retc + 0);
-       str *tname = getArgReference_str(stk, pci, pci->retc + 1);
-       unsigned char **T = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 2);
-       unsigned char **R = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 3);
-       unsigned char **S = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 4);
-       unsigned char **N = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 5);
-       str *fname = getArgReference_str(stk, pci, pci->retc + 6), msg;
-       lng *sz = getArgReference_lng(stk, pci, pci->retc + 7);
-       lng *offset = getArgReference_lng(stk, pci, pci->retc + 8);
-       int *locked = getArgReference_int(stk, pci, pci->retc + 9);
+       sql_table *t = *(sql_table **) getArgReference(stk, pci, pci->retc + 0);
+       unsigned char **T = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 1);
+       unsigned char **R = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 2);
+       unsigned char **S = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 3);
+       unsigned char **N = (unsigned char **) getArgReference_str(stk, pci, 
pci->retc + 4);
+       str *fname = getArgReference_str(stk, pci, pci->retc + 5), msg;
+       lng *sz = getArgReference_lng(stk, pci, pci->retc + 6);
+       lng *offset = getArgReference_lng(stk, pci, pci->retc + 7);
+       int *locked = getArgReference_int(stk, pci, pci->retc + 8);
        bstream *s;
        stream *ss;
        str utf8 = "UTF-8";
@@ -2883,7 +2882,7 @@ mvc_import_table_wrap(Client cntxt, MalB
        fix_windows_newline(ssep);
 #endif
        if (s != NULL) {
-               b = mvc_import_table(cntxt, be->mvc, s, *sname, *tname, (char 
*) tsep, (char *) rsep, (char *) ssep, (char *) ns, *sz, *offset, *locked);
+               b = mvc_import_table(cntxt, be->mvc, s, t, (char *) tsep, (char 
*) rsep, (char *) ssep, (char *) ns, *sz, *offset, *locked);
                bstream_destroy(s);
        }
        GDKfree(filename);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to