Changeset: a8e9c0a2a7db for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8e9c0a2a7db
Added Files:
monetdb5/modules/atoms/nested_table.c
monetdb5/modules/atoms/nested_table.h
monetdb5/modules/atoms/nested_table.mal
sql/scripts/35_nested_table.sql
Modified Files:
gdk/gdk_private.h
monetdb5/mal/mal_listing.c
monetdb5/modules/atoms/Makefile.ag
monetdb5/modules/mal/mal_init.mal
sql/backends/monet5/rel_bin.c
sql/common/sql_types.c
sql/scripts/Makefile.ag
Branch: graph0
Log Message:
Currently a nest of bugs...
diffs (297 lines):
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -155,9 +155,8 @@ void BBPdump(void); /* never called: fo
__attribute__((__visibility__("hidden")));
__hidden Hash *HASHnew(Heap *hp, int tpe, BUN size, BUN mask, BUN count)
__attribute__((__visibility__("hidden")));
-//__hidden gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize)
-// __attribute__((__visibility__("hidden")));
-gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize);
+__hidden gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize)
+ __attribute__((__visibility__("hidden")));
__hidden gdk_return HEAPcopy(Heap *dst, Heap *src)
__attribute__((__visibility__("hidden")));
__hidden int HEAPdelete(Heap *h, const char *o, const char *ext)
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -294,13 +294,13 @@ instruction2str(MalBlkPtr mb, MalStkPtr
case PATcall:
case CMDcall:
case ASSIGNsymbol :
- // is any variable explicit or used
- for (i = 0; i < p->retc; i++)
- if ( !isTmpVar(mb,getArg(p,i)) || isVarUsed(mb,
getArg(p, i)) || isVarUDFtype(mb,getArg(p,i)))
- break;
-
- if (i == p->retc)
- break;
+// // is any variable explicit or used
+// for (i = 0; i < p->retc; i++)
+// if ( !isTmpVar(mb,getArg(p,i)) || isVarUsed(mb,
getArg(p, i)) || isVarUDFtype(mb,getArg(p,i)))
+// break;
+//
+// if (i == p->retc)
+// break;
/* display multi-assignment list */
if (p->retc > 1)
diff --git a/monetdb5/modules/atoms/Makefile.ag
b/monetdb5/modules/atoms/Makefile.ag
--- a/monetdb5/modules/atoms/Makefile.ag
+++ b/monetdb5/modules/atoms/Makefile.ag
@@ -23,7 +23,7 @@ lib_atoms = {
json.c json.h \
mcurl.c \
mtime.c mtime.h \
- nested.c \
+ nested_table.c nested_table.h \
str.c str.h \
streams.c streams.h \
url.c url.h \
@@ -43,7 +43,7 @@ headers_mal = {
json.mal \
mcurl.mal \
mtime.mal \
- nested.mal \
+ nested_table.mal \
streams.mal \
str.mal \
url.mal \
diff --git a/monetdb5/modules/atoms/nested_table.c
b/monetdb5/modules/atoms/nested_table.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/nested_table.c
@@ -0,0 +1,123 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V.
+ */
+
+#include "monetdb_config.h"
+
+#include "mal.h"
+#include "mal_exception.h"
+#include "gdk_bbp.h"
+
+// errors
+#if !defined(NDEBUG) /* debug only */
+#define _CHECK_ERRLINE_EXPAND(LINE) #LINE
+#define _CHECK_ERRLINE(LINE) _CHECK_ERRLINE_EXPAND(LINE)
+#define _CHECK_ERRMSG(EXPR, ERROR) "[" __FILE__ ":" _CHECK_ERRLINE(__LINE__)
"] " ERROR ": `" #EXPR "'"
+#else /* release mode */
+#define _CHECK_ERRMSG(EXPR, ERROR) ERROR
+#endif
+#define CHECK( EXPR, ERROR ) if ( !(EXPR) ) \
+ { rc = createException(MAL, function_name /*__FUNCTION__?*/,
_CHECK_ERRMSG( EXPR, ERROR ) ); goto error; }
+
+// prototypes
+mal_export str NESTEDTABLEnest1_oid(bat*, const bat*, const bat*);
+mal_export str NESTEDTABLEprelude(void*);
+
+// index in the BATatoms table
+int TYPE_nested_table;
+
+// initializer
+str NESTEDTABLEprelude(void* ret) {
+ atomDesc* descriptor = NULL;
+
+ (void) ret;
+ TYPE_nested_table = ATOMindex("nestedtable");
+ descriptor = BATatoms + TYPE_nested_table;
+ descriptor->size = descriptor->align = sizeof(var_t);
+ descriptor->linear = FALSE;
+ return MAL_SUCCEED;
+}
+
+// MAL interface
+mal_export str NESTEDTABLEnest1_oid(bat* id_out, const bat* id_group_mapping,
const bat* id_histogram) {
+ const char* function_name = "nestedtable.nest1";
+ str rc = MAL_SUCCEED;
+ BAT* group_mapping = NULL;
+ oid* __restrict group_mapping_values = NULL;
+ BAT* histogram = NULL;
+ lng* __restrict histogram_values = NULL;
+ BAT* output = NULL;
+ var_t* __restrict output_offsets = NULL;
+ oid* __restrict output_content = NULL;
+ size_t output_sz = 0;
+ oid sum = 0;
+
+ // input arguments
+ CHECK(id_group_mapping != NULL, ILLEGAL_ARGUMENT);
+ group_mapping = BATdescriptor(*id_group_mapping);
+ CHECK(group_mapping != NULL, RUNTIME_OBJECT_MISSING);
+ CHECK(id_histogram != NULL, ILLEGAL_ARGUMENT);
+ histogram = BATdescriptor(*id_histogram);
+ CHECK(histogram != NULL, RUNTIME_OBJECT_MISSING);
+
+ // output
+ assert(group_mapping->hseqbase == 0 && "This implementation is limited
to a single partition");
+ output = COLnew(group_mapping->hseqbase, TYPE_nested_table,
BATcount(histogram), TRANSIENT);
+ CHECK(output != NULL, MAL_MALLOC_FAIL);
+
+ // edge case, the input is empty
+ output_sz = BATcount(histogram);
+ if(output_sz == 0) goto success;
+
+ // compute the offsets
+ histogram_values = (lng*) histogram->T.heap.base;
+ output_offsets = (var_t*) output->T.heap.base;
+ output_offsets[0] = 0;
+ for (size_t i = 1; i < output_sz; i++){
+ sum += histogram_values[i-1] + /* length */ 1;
+ output_offsets[i] = (var_t) sum;
+ }
+ sum += histogram_values[output_sz -1] +1;
+ assert(sum == BATcount(histogram) + BATcount(group_mapping) && "#groups
+ #values != computed sum");
+ output->tvarsized = 1;
+ output->tkey = 1;
+ output->tdense = output->tnodense = 0;
+ output->tsorted = 1;
+ output->trevsorted = output->tnorevsorted = 0;
+ output->tnonil = 1; output->tnil = 0;
+ BATsetcount(output, output_sz);
+
+ // allocate the virtual heap
+ HEAP_initialize(output->tvheap, 0, sum, sizeof(oid));
+ CHECK(output->tvheap != NULL, MAL_MALLOC_FAIL);
+ memset(output->tvheap->base, 0, output->tvheap->size);
+
+ // insert the actual values into the vheap
+ group_mapping_values = (oid*) group_mapping->tvheap->base;
+ output_content = (oid*) output->T.vheap->base;
+ for(size_t i = 0, sz = BATcount(group_mapping); i < sz; i++){
+ oid count = output_offsets[ group_mapping_values[i] ];
+ oid pos = ++output_content[count];
+ output_content[pos] = i;
+ }
+
+success:
+ BBPunfix(group_mapping->batCacheid);
+ BBPunfix(histogram->batCacheid);
+ *id_out = output->batCacheid;
+ BBPkeepref(output->batCacheid);
+
+ return rc;
+error:
+ if(group_mapping) { BBPunfix(group_mapping->batCacheid); }
+ if(histogram) { BBPunfix(histogram->batCacheid); }
+ if(output) { BBPunfix(output->batCacheid); }
+
+// goto success;
+ return rc;
+}
+
diff --git a/monetdb5/modules/atoms/nested_table.h
b/monetdb5/modules/atoms/nested_table.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/nested_table.h
@@ -0,0 +1,24 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V.
+ */
+#ifndef _MONET_NESTED_TABLE_H_
+#define _MONET_NESTED_TABLE_H_
+
+#include "monetdb_config.h"
+#include "mal.h"
+
+
+// index in the array BATatoms
+extern int TYPE_nested_table;
+
+typedef struct {
+ oid count;
+ oid values[FLEXIBLE_ARRAY_MEMBER];
+} nested_table;
+
+
+#endif /* _MONET_NESTED_TABLE_H_ */
diff --git a/monetdb5/modules/atoms/nested_table.mal
b/monetdb5/modules/atoms/nested_table.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/nested_table.mal
@@ -0,0 +1,13 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V.
+
+module nestedtable;
+
+atom nestedtable : oid;
+
+command nest1(group_mapping :bat[:oid], histogram :bat[:lng])
:bat[:nestedtable]
+address NESTEDTABLEnest1_oid
+comment "Create a nested table out of the grouped partitions";
\ No newline at end of file
diff --git a/monetdb5/modules/mal/mal_init.mal
b/monetdb5/modules/mal/mal_init.mal
--- a/monetdb5/modules/mal/mal_init.mal
+++ b/monetdb5/modules/mal/mal_init.mal
@@ -53,6 +53,7 @@ include inet;
include identifier;
include xml;
include batxml;
+include nested_table;
# The hardwired multiplex extensions
include batmmath;
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
@@ -4819,6 +4819,8 @@ output_rel_bin(backend *be, sql_rel *rel
int sqltype = sql->type;
stmt *s = subrel_bin(be, rel, refs);
+ printf("[output_rel_bin] %s\n", mal2str(be->mb, 0, be->mb->stop));
+
if (sqltype == Q_SCHEMA)
sql->type = sqltype; /* reset */
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
@@ -1346,7 +1346,7 @@ sqltypeinit( sql_allocator *sa)
*t++ = sql_create_type(sa, "BLOB", 0, 0, 0, EC_BLOB, "sqlblob");
- *t++ = sql_create_type(sa, "NESTED_TABLE", 0, 0, 0, EC_NESTED_TABLE,
"nested_table");
+ *t++ = sql_create_type(sa, "NESTED_TABLE", 0, 0, 0, EC_NESTED_TABLE,
"nestedtable");
if (geomcatalogfix_get() != NULL) {
// the geom module is loaded
diff --git a/sql/scripts/35_nested_table.sql b/sql/scripts/35_nested_table.sql
new file mode 100644
--- /dev/null
+++ b/sql/scripts/35_nested_table.sql
@@ -0,0 +1,8 @@
+-- This Source Code Form is subject to the terms of the Mozilla Public
+-- License, v. 2.0. If a copy of the MPL was not distributed with this
+-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
+--
+-- Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V.
+
+CREATE AGGREGATE nest (*) RETURNS nested_table EXTERNAL NAME
"nestedtable"."nest1";
+GRANT EXECUTE ON AGGREGATE nest() TO public;
\ No newline at end of file
diff --git a/sql/scripts/Makefile.ag b/sql/scripts/Makefile.ag
--- a/sql/scripts/Makefile.ag
+++ b/sql/scripts/Makefile.ag
@@ -26,7 +26,7 @@ headers_sql = {
25_debug.sql \
26_sysmon.sql \
27_rejects.sql \
- 35_nested.sql \
+ 35_nested_table.sql \
39_analytics.sql \
40_json.sql \
41_md5sum.sql \
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list