Changeset: c0d9fdfe16bf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c0d9fdfe16bf
Removed Files:
monetdb5/modules/mal/Tests/ascii_io2.load
Modified Files:
monetdb5/modules/mal/Tests/All
monetdb5/modules/mal/Tests/ascii_io2.mal
monetdb5/modules/mal/Tests/ascii_io2.stable.out
monetdb5/modules/mal/mal_io.c
monetdb5/modules/mal/mal_io.h
monetdb5/modules/mal/mal_io.mal
Branch: default
Log Message:
Fix import/export
The old fashioned import/export routines have been made headless aware.
diffs (truncated from 308 to 300 lines):
diff --git a/monetdb5/modules/mal/Tests/All b/monetdb5/modules/mal/Tests/All
--- a/monetdb5/modules/mal/Tests/All
+++ b/monetdb5/modules/mal/Tests/All
@@ -25,7 +25,7 @@ callstring
callfunction
-#ascii_io2 needs work
+ascii_io2
mat
diff --git a/monetdb5/modules/mal/Tests/ascii_io2.load
b/monetdb5/modules/mal/Tests/ascii_io2.load
deleted file mode 100644
--- a/monetdb5/modules/mal/Tests/ascii_io2.load
+++ /dev/null
@@ -1,19 +0,0 @@
-IA073-000474-B024-230, 0-request
-" "," "
-IA073-000474-B024-231,1-from
- ,
-IA073-000474-B024-232,2-library
-" "," "
-IA073-000474-B024-233,3-subject
- ,
-IA073-000474-B024-234,4-listing
-" "," "
-IA073-000474-B024-235,5-up
- ,
-IA073-000474-B024-236,6-to
-"",""
-IA073-000474-B024-237,7-index
-,
-IA073-000474-B024-238,8-up
-,
-IA073-000474-B024-239,9-to
diff --git a/monetdb5/modules/mal/Tests/ascii_io2.mal
b/monetdb5/modules/mal/Tests/ascii_io2.mal
--- a/monetdb5/modules/mal/Tests/ascii_io2.mal
+++ b/monetdb5/modules/mal/Tests/ascii_io2.mal
@@ -2,33 +2,9 @@ namebat := bat.new(:oid, :str);
bat.append(namebat,"tmpdocs");
bat.append(namebat,"tmpterms");
-sepbat := bat.new(:oid, :str);
-bat.append(sepbat,",");
-bat.append(sepbat,"\n");
+io.printf("#source:%s\n","namebat");
+io.export(namebat, "namebat");
-typebat := bat.new(:oid, :str);
-bat.append(typebat,"str");
-bat.append(typebat,"str");
-
-len := 20;
-targetdir := unix.getenv("TSTTRGDIR");
-barrier correct:= targetdir == "";
- targetdir := unix.getenv("PWD");
-exit correct;
-barrier correct:= targetdir != "";
- targetdir := targetdir + "/";
-exit correct;
-
-datafile := targetdir + "ascii_io2.load";
-io.printf("#source:%s\n",datafile);
-
-idxbat := tablet.load(namebat, sepbat, typebat, datafile, len);
-#io.print(idxbat);
-
-b1:bat[:oid,:str] := algebra.fetch(idxbat,0@0);
-#b1:bat[:oid,:str] := bbp.bind(i1);
-io.print(b1);
-
-b2:bat[:oid,:str] := algebra.fetch(idxbat,1@0);
-#b2:bat[:oid,:str] := bbp.bind(i2);
-io.print(b2);
+z:= bat.new(:oid,:str);
+io.import(z,"namebat");
+io.print(z);
diff --git a/monetdb5/modules/mal/Tests/ascii_io2.stable.out
b/monetdb5/modules/mal/Tests/ascii_io2.stable.out
--- a/monetdb5/modules/mal/Tests/ascii_io2.stable.out
+++ b/monetdb5/modules/mal/Tests/ascii_io2.stable.out
@@ -17,78 +17,19 @@ function user.main():void;
namebat := bat.new(:oid,:str);
bat.append(namebat,"tmpdocs");
bat.append(namebat,"tmpterms");
- sepbat := bat.new(:oid,:str);
- bat.append(sepbat,",");
- bat.append(sepbat,"\n");
- typebat := bat.new(:oid,:str);
- bat.append(typebat,"str");
- bat.append(typebat,"str");
- len := 20;
- targetdir := unix.getenv("TSTTRGDIR");
-barrier correct := calc.==(targetdir,"");
- targetdir := unix.getenv("PWD");
-exit correct;
-barrier correct := calc.!=(targetdir,"");
- targetdir := calc.+(targetdir,"/");
-exit correct;
- datafile := calc.+(targetdir,"ascii_io2.load");
- io.printf("#source:%s\n",datafile);
- idxbat := tablet.load(namebat,sepbat,typebat,datafile,len);
-#io.print(idxbat);
- b1:bat[:oid,:str] := algebra.fetch(idxbat,0@0);
-#b1:bat[:oid,:str] := bbp.bind(i1);
- io.print(b1);
- b2:bat[:oid,:str] := algebra.fetch(idxbat,1@0);
-#b2:bat[:oid,:str] := bbp.bind(i2);
- io.print(b2);
-end main;
-#source:/ufs/mk/monet5/Linux/mTests/src/modules/mal/ascii_io2.load
-#-----------------------------------------#
+ io.printf("#source:%s\n","namebat");
+ io.export(namebat,"namebat");
+ z := bat.new(:oid,:str);
+ io.import(z,"namebat");
+ io.print(z);
+end user.main;
+#source:namebat
+#--------------------------#
# h t # name
# void str # type
-#-----------------------------------------#
-[ 0@0, "IA073-000474-B024-230" ]
-[ 1@0, " " ]
-[ 2@0, "IA073-000474-B024-231" ]
-[ 3@0, "" ]
-[ 4@0, "IA073-000474-B024-232" ]
-[ 5@0, " " ]
-[ 6@0, "IA073-000474-B024-233" ]
-[ 7@0, "" ]
-[ 8@0, "IA073-000474-B024-234" ]
-[ 9@0, " " ]
-[ 10@0, "IA073-000474-B024-235" ]
-[ 11@0, "" ]
-[ 12@0, "IA073-000474-B024-236" ]
-[ 13@0, "" ]
-[ 14@0, "IA073-000474-B024-237" ]
-[ 15@0, "" ]
-[ 16@0, "IA073-000474-B024-238" ]
-[ 17@0, "" ]
-[ 18@0, "IA073-000474-B024-239" ]
-#-------------------------#
-# h t # name
-# void str # type
-#-------------------------#
-[ 0@0, "0-request " ]
-[ 1@0, " " ]
-[ 2@0, "1-from" ]
-[ 3@0, "" ]
-[ 4@0, "2-library" ]
-[ 5@0, " " ]
-[ 6@0, "3-subject" ]
-[ 7@0, "" ]
-[ 8@0, "4-listing" ]
-[ 9@0, " " ]
-[ 10@0, "5-up" ]
-[ 11@0, "" ]
-[ 12@0, "6-to" ]
-[ 13@0, "" ]
-[ 14@0, "7-index" ]
-[ 15@0, "" ]
-[ 16@0, "8-up" ]
-[ 17@0, "" ]
-[ 18@0, "9-to" ]
+#--------------------------#
+[ 0@0, "tmpdocs" ]
+[ 1@0, "tmpterms" ]
# 21:10:47 >
# 21:10:47 > Done.
diff --git a/monetdb5/modules/mal/mal_io.c b/monetdb5/modules/mal/mal_io.c
--- a/monetdb5/modules/mal/mal_io.c
+++ b/monetdb5/modules/mal/mal_io.c
@@ -604,7 +604,7 @@ IOexport(bit *ret, bat *bid, str *fnme)
BBPunfix(b->batCacheid);
throw(MAL, "io.export", RUNTIME_FILE_NOT_FOUND ":%s", *fnme);
}
- BATprintf(s, b);
+ BATprintcolumns(s, 1, &b);
mnstr_close(s);
mnstr_destroy(s);
*ret = TRUE;
@@ -613,32 +613,29 @@ IOexport(bit *ret, bat *bid, str *fnme)
}
/*
- * The import command reads a single BAT from an ASCII file. It assumes
- * a layout compatible with that produced by print or export.
+ * The import command reads a single BAT from an ASCII file produced by export.
*/
-#define COMMA ','
str
-IOimport(bat *ret, bat *bid, str *fnme)
+IOimport(int *ret, bat *bid, str *fnme)
{
BAT *b;
- int (*hconvert) (const char *, int *, ptr *);
int (*tconvert) (const char *, int *, ptr *);
int n;
size_t bufsize = 2048; /* NIELS:tmp change used to be 1024 */
char *base, *cur, *end;
char *buf;
- ptr h = 0, t = 0;
- int lh = 0, lt = 0;
+ ptr t = 0;
+ int lt = 0;
FILE *fp = fopen(*fnme, "r");
char msg[BUFSIZ];
+ (void) ret;
if ((b = BATdescriptor(*bid)) == NULL) {
if (fp)
fclose(fp);
throw(MAL, "io.import", RUNTIME_OBJECT_MISSING);
}
- hconvert = BATatoms[BAThtype(b)].atomFromStr;
tconvert = BATatoms[BATttype(b)].atomFromStr;
/*
* Open the file. Memory map it to minimize buffering problems.
@@ -748,28 +745,6 @@ IOimport(bat *ret, bat *bid, str *fnme)
MT_munmap(base, end - base);
throw(MAL, "io.import", "%s", msg);
}
- n = hconvert(p, &lh, (ptr*)&h);
- if (n <= 0) {
- BBPunfix(b->batCacheid);
- snprintf(msg,sizeof(msg),"error in input %s",buf);
- GDKfree(buf);
- MT_munmap(base, end - base);
- throw(MAL, "io.import", "%s", msg);
- }
- p += n;
-
- for (;*p && *p != COMMA; p++)
- ;
- if (*p)
- for (p++; *p && GDKisspace(*p); p++)
- ;
- if (*p == 0) {
- BBPunfix(b->batCacheid);
- snprintf(msg,sizeof(msg),"error in input %s",buf);
- GDKfree(buf);
- MT_munmap(base, end - base);
- throw(MAL, "io.import", "%s", msg);
- }
n = tconvert(p, <, (ptr*)&t);
if (n <= 0) {
BBPunfix(b->batCacheid);
@@ -779,7 +754,7 @@ IOimport(bat *ret, bat *bid, str *fnme)
throw(MAL, "io.import", "%s", msg);
}
p += n;
- if (BUNins(b, h, t, FALSE) != GDK_SUCCEED) {
+ if (BUNappend(b, t, FALSE) != GDK_SUCCEED) {
BBPunfix(b->batCacheid);
GDKfree(buf);
MT_munmap(base, end - base);
@@ -800,13 +775,11 @@ IOimport(bat *ret, bat *bid, str *fnme)
#endif
}
/* Cleanup and exit. Return the filled BAT. */
- if (h)
- GDKfree(h);
if (t)
GDKfree(t);
GDKfree(buf);
MT_munmap(base, end - base);
- BBPkeepref(*ret= b->batCacheid);
+ BBPunfix(b->batCacheid);
return MAL_SUCCEED;
}
diff --git a/monetdb5/modules/mal/mal_io.h b/monetdb5/modules/mal/mal_io.h
--- a/monetdb5/modules/mal/mal_io.h
+++ b/monetdb5/modules/mal/mal_io.h
@@ -34,7 +34,7 @@ io_export str IOprintf(Client cntxt, Mal
io_export str IOprintfStream(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
io_export str IOtable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
io_export str IOexport(bit *ret, bat *bid, str *fnme);
-io_export str IOimport(bat *ret, bat *bid, str *fnme);
+io_export str IOimport(int *ret, bat *bid, str *fnme);
io_export str io_stdin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
io_export str io_stdout(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
io_export str io_stderr(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
diff --git a/monetdb5/modules/mal/mal_io.mal b/monetdb5/modules/mal/mal_io.mal
--- a/monetdb5/modules/mal/mal_io.mal
+++ b/monetdb5/modules/mal/mal_io.mal
@@ -50,13 +50,13 @@ pattern printf(filep:streams,fmt:str):vo
address IOprintfStream
comment "Select default format ";
-command export(b:bat[:oid,:any_2], filepath:str):bit
+command export(b:bat[:oid,:any_2], filepath:str)
address IOexport
comment "Export a BAT as ASCII to a file. If the 'filepath' is not absolute, it
is put into the $DBPATH directory. Success of failure is indicated.";
-command import(b:bat[:oid,:any_2], filepath:str) :bat[:oid,:any_2]
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list