Changeset: 8c4253522348 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8c4253522348
Modified Files:
monetdb5/modules/mal/tablet.c
monetdb5/modules/mal/tablet.h
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
sql/include/sql_catalog.h
sql/include/sql_relation.h
sql/server/rel_dump.c
sql/server/rel_multiset.c
sql/storage/bat/res_table.c
sql/test/nested/Tests/array.test
Branch: nestedtypes
Log Message:
(re)implemented the nested output
diffs (truncated from 724 to 300 lines):
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
@@ -231,7 +231,7 @@ output_line(char **buf, size_t *len, cha
ssize_t fill = 0;
for (i = 0; i < nr_attrs; i++) {
- if (fmt[i].c == NULL)
+ if (fmt[i].c == NULL || fmt[i].virt)
continue;
if (id < fmt[i].c->hseqbase
|| id >= fmt[i].c->hseqbase + BATcount(fmt[i].c))
@@ -277,17 +277,22 @@ output_line(char **buf, size_t *len, cha
return 0;
}
+#define MS_VALUE 0
#define MS_ARRAY 2
/* move into sql_result and store in format */
static int
multiset_size( Column *fmt)
{
- int nrattrs = 1 + (fmt->multiset == MS_ARRAY);
- if (fmt[0].composite) {
- nrattrs += fmt[0].composite;
- for (int i = 0; i<fmt[0].composite; i++)
- if (fmt[i+1].multiset)
- nrattrs += multiset_size(fmt+(i+1));
+ int nrattrs = (fmt->multiset==MS_VALUE)?0:(fmt->multiset==MS_ARRAY)?3:2;
+ if (fmt->composite) {
+ if (fmt->virt)
+ nrattrs++;
+ int o = 0;
+ for (int i = 0; i<fmt->composite; i++) {
+ int j = multiset_size(fmt+(o+1));
+ nrattrs += j;
+ o += j;
+ }
} else {
nrattrs ++;
}
@@ -295,18 +300,18 @@ multiset_size( Column *fmt)
}
static inline ssize_t
-output_line_multiset(char **buf, size_t *len, ssize_t fill, char **localbuf,
size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs);
+output_line_complex(char **buf, size_t *len, ssize_t fill, char **localbuf,
size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs, bool inms);
static ssize_t
output_line_composite(char **buf, size_t *len, ssize_t fill, char **localbuf,
size_t *locallen, Column *fmt, stream *fd, BUN nr_attrs, int composite)
{
(void)composite;
(*buf)[fill++] = '(';
- if (!fmt->multiset) {
+ if (fmt->virt) {
fmt++;
nr_attrs--;
}
- if ((fill = output_line_multiset(buf, len, fill, localbuf, locallen,
fmt, fd, nr_attrs)) < 0) {
+ if ((fill = output_line_complex(buf, len, fill, localbuf, locallen,
fmt, fd, nr_attrs, false)) < 0) {
return -1;
}
(*buf)[fill++] = ')';
@@ -329,7 +334,7 @@ output_multiset_value(char **buf, size_t
break;
}
} else {
- if ((fill = output_line_multiset(buf, len, fill,
localbuf, locallen, fmt, fd, nr_attrs)) < 0) {
+ if ((fill = output_line_complex(buf, len, fill,
localbuf, locallen, fmt, fd, nr_attrs, true)) < 0) {
break;
}
}
@@ -339,43 +344,54 @@ output_multiset_value(char **buf, size_t
}
static inline ssize_t
-output_line_multiset(char **buf, size_t *len, ssize_t fill, char **localbuf,
size_t *locallen,
- Column *fmt, stream *fd, BUN nr_attrs)
+output_line_complex(char **buf, size_t *len, ssize_t fill, char **localbuf,
size_t *locallen,
+ Column *fmt, stream *fd, BUN nr_attrs, bool
inms)
{
- BUN i;
+ BUN j;
+ int composite = 0;
- for (i = 0; i < nr_attrs; i++) {
- Column *f = fmt + i;
+ for (j = 0; j < nr_attrs; ) {
+ Column *f = fmt + j;
const char *p;
ssize_t l = 0;
- if (f->c) {
- p = BUNtail(f->ci, f->p);
+ if (f->virt && f->composite > 1) {
+ (*buf)[fill++] = '\'';
+ (*buf)[fill++] = '(';
+ (*buf)[fill] = 0;
+ composite = f->composite;
+ j++;
+ continue;
+ }
+ if (f->multiset && !inms) {
+ int nr_attrs = multiset_size(f);
+ p = BUNtail(fmt[j+nr_attrs].ci,
fmt[j+nr_attrs].p);
- if (p && i && f->multiset) {
- int nr_attrs = multiset_size(f);
- assert(f->c->ttype == TYPE_int);
-
- (*buf)[fill++] = '\'';
+ if (!composite)
+ (*buf)[fill++] = '\'';
(*buf)[fill++] = '{';
(*buf)[fill] = 0;
- fill = output_multiset_value(buf, len, fill,
localbuf, locallen, fmt + i + 1, fd, nr_attrs, f->multiset, f->composite,
*(int*)p);
+ fill = output_multiset_value(buf, len, fill,
localbuf, locallen, fmt + j + 1, fd, nr_attrs-1, f->multiset, f->composite,
*(int*)p);
(*buf)[fill++] = '}';
- (*buf)[fill++] = '\'';
+ if (!composite)
+ (*buf)[fill++] = '\'';
(*buf)[fill] = 0;
- i += nr_attrs;
- f->p++;
- f = fmt + i;
- } else
+ fmt[j+nr_attrs].p++;
+ f = fmt + j + nr_attrs; /* closing bracket */
+ j += nr_attrs + 1;
+ } else if (f->c) {
+ p = BUNtail(f->ci, f->p);
if (!p || ATOMcmp(f->adt, ATOMnilptr(f->adt), p) == 0) {
p = f->nullstr;
l = (ssize_t) strlen(p);
+ j++;
} else {
l = f->tostr(f->extra, localbuf, locallen,
f->adt, p);
if (l < 0)
return -1;
p = *localbuf;
+ j++;
}
if (fill + l + f->seplen >= (ssize_t) * len) {
/* extend the buffer */
@@ -391,9 +407,25 @@ output_line_multiset(char **buf, size_t
fill += l;
f->p++;
}
+ } else
+ j++;
+ if (composite) {
+ composite--;
+ if (composite) {
+ (*buf)[fill++] = ',';
+ (*buf)[fill++] = ' ';
+ (*buf)[fill] = 0;
+ } else {
+ (*buf)[fill++] = ')';
+ (*buf)[fill++] = '\'';
+ (*buf)[fill] = 0;
+ strncpy(*buf + fill, f->sep, f->seplen);
+ fill += f->seplen;
+ }
+ } else {
+ strncpy(*buf + fill, f->sep, f->seplen);
+ fill += f->seplen;
}
- strncpy(*buf + fill, f->sep, f->seplen);
- fill += f->seplen;
}
return fill;
}
@@ -410,6 +442,8 @@ output_line_dense(char **buf, size_t *le
const char *p;
ssize_t l;
+ if (f->virt)
+ continue;
if (f->c) {
p = BUNtail(f->ci, f->p);
@@ -452,6 +486,8 @@ output_line_lookup(char **buf, size_t *l
for (i = 0; i < nr_attrs; i++) {
Column *f = fmt + i;
+ if (f->virt)
+ continue;
if (f->c) {
const void *p = BUNtail(f->ci, id - f->c->hseqbase);
@@ -550,7 +586,7 @@ output_file_default(Tablet *as, BAT *ord
}
static int
-output_multiset(Tablet *as, stream *fd, bstream *in)
+output_complex(Tablet *as, stream *fd, bstream *in)
{
size_t len = BUFSIZ, locallen = BUFSIZ;
ssize_t res = 0;
@@ -568,7 +604,7 @@ output_multiset(Tablet *as, stream *fd,
res = -5; /* "Query aborted" */
break;
}
- if ((res = output_line_multiset(&buf, &len, 0, &localbuf,
&locallen, as->format, fd, as->nr_attrs)) < 0) {
+ if ((res = output_line_complex(&buf, &len, 0, &localbuf,
&locallen, as->format, fd, as->nr_attrs, false)) < 0) {
break;
}
if (fd && mnstr_write(fd, buf, 1, res) != res)
@@ -654,13 +690,13 @@ TABLEToutput_file(Tablet *as, BAT *order
as->nr = maxnr;
}
assert(as->nr != BUN_NONE);
- int multiset = 0;
- for (unsigned int i = 1; i < as->nr_attrs; i++)
- multiset |= as->format[i].multiset;
+ int complex = 0;
+ for (unsigned int i = 1; i < as->nr_attrs && !complex; i++)
+ complex |= (as->format[i].multiset || as->format[i].composite);
- if (multiset) {
+ if (complex) {
assert(!order);
- return output_multiset(as, s, in);
+ return output_complex(as, s, in);
}
base = check_BATs(as);
if (!order || !is_oid_nil(base)) {
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
@@ -43,8 +43,9 @@ typedef struct Column_t {
size_t null_length; /* its length */
unsigned int width; /* actual column width */
unsigned int maxwidth; /* permissible width */
- int multiset; /* multiset */
- int composite; /* 0 no composite type else
number of composite fields */
+ int composite; /* number of composite fields */
+ int multiset; /* type of multiset */
+ bool virt; /* not part of output */
int fieldstart; /* Fixed character field load
positions */
int fieldwidth;
int scale, precision;
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -849,7 +849,7 @@ value_list(backend *be, sql_exp *vals_ex
sql_exp *v = vals->h->data;
if (type_create_result(be, type, attr) < 0)
return NULL;
- int rowcnt = 1, lcnt = 1;
+ int rowcnt = 0, lcnt = 1;
int irc = is_row(v)?0:1;
int lrc = is_row(v)?1:0;
for (node *n = vals->h; n; n = n->next, rowcnt += irc, lcnt +=
lrc) {
@@ -1656,6 +1656,7 @@ is_const_func(sql_subfunc *f, list *attr
static stmt*
exp2bin_multiset(backend *be, sql_exp *fe, stmt *left, stmt *right, stmt *sel)
{
+ assert(0);
return left;
(void)fe;
(void)right;
@@ -2680,6 +2681,7 @@ rel2bin_basetable(backend *be, sql_rel *
stmt *ns = (c == fcol) ? col :
stmt_col(be, c, complex?dels:NULL, dels->partition);
list_append(s->op4.lval, ns);
s->nr = ns->nr;
+ s->multiset = c->type.multiset;
}
} else {
s = (c == fcol) ? col : stmt_col(be, c,
complex?dels:NULL, dels->partition);
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
@@ -1246,17 +1246,34 @@ mvc_export_table_columnar(stream *s, res
}
static int
-complex_type_size(res_col *c)
+output_complex_type(res_col *cols, Column *fmt, int nr_cols, bool ms, bool
composite)
{
- if (c->type.multiset) {
- int res = (c->type.multiset == MS_ARRAY?2:1);
- if (c->type.type->composite)
- res += list_length(c->type.type->d.fields);
- else
- res ++;
- return res;
+ int j = 0;
+ for(int i = 0; i < nr_cols; i++) {
+ res_col *c = cols + j;
+
+ if (c->multiset) {
+ /* c rowid */
+ j += output_complex_type(cols + j + 1, fmt + j + 1,
c->composite?list_length(c->type.type->d.fields):1, true, composite);
+ j++;
+ if (c->multiset == MS_ARRAY)
+ j++;
+ j++;
+ } else if (c->composite) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]