Changeset: fd2793b0d353 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fd2793b0d353 Added Files: sql/backends/monet5/UDF/capi/Tests/capi09.sql sql/backends/monet5/UDF/capi/Tests/capi09.stable.err sql/backends/monet5/UDF/capi/Tests/capi09.stable.out Modified Files: sql/backends/monet5/UDF/capi/Tests/All sql/backends/monet5/UDF/capi/Tests/capi10.stable.err sql/backends/monet5/UDF/capi/capi.c Branch: jitudf Log Message:
Support all types by converting them to strings. diffs (truncated from 330 to 300 lines): diff --git a/sql/backends/monet5/UDF/capi/Tests/All b/sql/backends/monet5/UDF/capi/Tests/All --- a/sql/backends/monet5/UDF/capi/Tests/All +++ b/sql/backends/monet5/UDF/capi/Tests/All @@ -8,3 +8,6 @@ capi05 capi06 capi07 capi08 +capi09 +capi10 +capi11 diff --git a/sql/backends/monet5/UDF/capi/Tests/capi09.sql b/sql/backends/monet5/UDF/capi/Tests/capi09.sql new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/UDF/capi/Tests/capi09.sql @@ -0,0 +1,26 @@ + +START TRANSACTION; + +# uuids +# other (unsupported) types are simply converted to/from strings + +CREATE FUNCTION capi12(inp UUID) RETURNS UUID LANGUAGE C { + result->initialize(result, inp.count); + for(size_t i = 0; i < inp.count; i++) { + if (inp.data[i] == inp.null_value) { + result->data[i] = result->null_value; + } else { + result->data[i] = inp.data[i]; + } + } +}; + +CREATE TABLE uuids(d UUID); +INSERT INTO uuids VALUES ('ad887b3d-08f7-c308-7285-354a1857cbc8'), (NULL); + +SELECT capi12(d) FROM uuids; + +DROP FUNCTION capi12; +DROP TABLE uuids; + +ROLLBACK; diff --git a/sql/backends/monet5/UDF/capi/Tests/capi09.stable.err b/sql/backends/monet5/UDF/capi/Tests/capi09.stable.err new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/UDF/capi/Tests/capi09.stable.err @@ -0,0 +1,34 @@ +stderr of test 'capi09` in directory 'sql/backends/monet5/UDF/capi` itself: + + +# 13:29:00 > +# 13:29:00 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=38148" "--set" "mapi_usock=/var/tmp/mtest-81291/.s.monetdb.38148" "--set" "monet_prompt=" "--forcemito" "--dbpath=NONE/var/MonetDB/mTests_sql_backends_monet5_UDF_capi" +# 13:29:00 > + +# builtin opt gdk_dbpath = /Users/myth/opt/var/monetdb5/dbfarm/demo +# builtin opt gdk_debug = 0 +# builtin opt gdk_vmtrim = no +# builtin opt monet_prompt = > +# builtin opt monet_daemon = no +# builtin opt mapi_port = 50000 +# builtin opt mapi_open = false +# builtin opt mapi_autosense = false +# builtin opt sql_optimizer = default_pipe +# builtin opt sql_debug = 0 +# cmdline opt gdk_nr_threads = 0 +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 38148 +# cmdline opt mapi_usock = /var/tmp/mtest-81291/.s.monetdb.38148 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /Users/myth/opt/mTests/sql/backends/monet5/UDF/capi/NONE/var/MonetDB/mTests_sql_backends_monet5_UDF_capi +# cmdline opt gdk_debug = 536870922 + +# 13:29:00 > +# 13:29:00 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-81291" "--port=38148" +# 13:29:00 > + + +# 13:29:01 > +# 13:29:01 > "Done." +# 13:29:01 > + diff --git a/sql/backends/monet5/UDF/capi/Tests/capi09.stable.out b/sql/backends/monet5/UDF/capi/Tests/capi09.stable.out new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/UDF/capi/Tests/capi09.stable.out @@ -0,0 +1,54 @@ +stdout of test 'capi09` in directory 'sql/backends/monet5/UDF/capi` itself: + + +# 13:29:00 > +# 13:29:00 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=38148" "--set" "mapi_usock=/var/tmp/mtest-81291/.s.monetdb.38148" "--set" "monet_prompt=" "--forcemito" "--dbpath=NONE/var/MonetDB/mTests_sql_backends_monet5_UDF_capi" +# 13:29:00 > + +# MonetDB 5 server v11.28.0 +# This is an unreleased version +# Serving database 'mTests_sql_backends_monet5_UDF_capi', using 4 threads +# Compiled for x86_64-apple-darwin15.6.0/64bit with 128bit integers +# Found 8.000 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2017 MonetDB B.V., all rights reserved +# Visit https://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://dhcp-21.eduroam.cwi.nl:38148/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-81291/.s.monetdb.38148 +# MonetDB/SQL module loaded + +Ready. + +# 13:29:00 > +# 13:29:00 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-81291" "--port=38148" +# 13:29:00 > + +#START TRANSACTION; +#CREATE FUNCTION capi12(inp UUID) RETURNS UUID LANGUAGE C { +# result->initialize(result, inp.count); +# for(size_t i = 0; i < inp.count; i++) { +# if (inp.data[i] == inp.null_value) { +# result->data[i] = result->null_value; +# } else { +# result->data[i] = inp.data[i]; +# } +# } +#}; +#CREATE TABLE uuids(d UUID); +#INSERT INTO uuids VALUES ('ad887b3d-08f7-c308-7285-354a1857cbc8'), (NULL); +[ 2 ] +#SELECT capi12(d) FROM uuids; +% sys.L2 # table_name +% L2 # name +% uuid # type +% 0 # length +[ ad887b3d-08f7-c308-7285-354a1857cbc8 ] +[ NULL ] +#DROP FUNCTION capi12; +#DROP TABLE uuids; +#ROLLBACK; + +# 13:29:01 > +# 13:29:01 > "Done." +# 13:29:01 > + diff --git a/sql/backends/monet5/UDF/capi/Tests/capi10.stable.err b/sql/backends/monet5/UDF/capi/Tests/capi10.stable.err --- a/sql/backends/monet5/UDF/capi/Tests/capi10.stable.err +++ b/sql/backends/monet5/UDF/capi/Tests/capi10.stable.err @@ -27,6 +27,9 @@ stderr of test 'capi10` in directory 'sq # 11:25:01 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-24716" "--port=30547" # 11:25:01 > +MAPI = (monetdb) /var/tmp/mtest-81291/.s.monetdb.38148 +QUERY = SELECT capi10(i) FROM blobs; +ERROR = !Attempting to write to the input or triggered a segfault/bus error # 11:25:02 > # 11:25:02 > "Done." diff --git a/sql/backends/monet5/UDF/capi/capi.c b/sql/backends/monet5/UDF/capi/capi.c --- a/sql/backends/monet5/UDF/capi/capi.c +++ b/sql/backends/monet5/UDF/capi/capi.c @@ -1022,9 +1022,37 @@ static str CUDFeval(Client cntxt, MalBlk goto wrapup; } } else { - assert(0); - msg = createException(MAL, "cudf.eval", "Unknown input type"); - goto wrapup; + // unsupported type: convert to string + BATiter li; + BUN p = 0, q = 0; + str mprotect_retval; + GENERATE_BAT_INPUT_BASE(input_bats[index], str); + bat_data->count = BATcount(input_bats[index]); + bat_data->null_value = NULL; + bat_data->data = GDKzalloc(sizeof(char *) * bat_data->count); + if (!bat_data->data) { + msg = createException(MAL, "cudf.eval", MAL_MALLOC_FAIL); + goto wrapup; + } + j = 0; + + li = bat_iterator(input_bats[index]); + BATloop(input_bats[index], p, q) + { + void *t = BUNtail(li, p); + if (BATatoms[bat_type].atomCmp(t, BATatoms[bat_type].atomNull) == 0) { + bat_data->data[j] = NULL; + } else { + char* result = NULL; + int length = 0; + if (BATatoms[bat_type].atomToStr(&result, &length, t) == 0) { + msg = createException(MAL, "cudf.eval", "Failed to convert element to string"); + goto wrapup; + } + bat_data->data[j] = result; + } + j++; + } } } argnode = argnode ? argnode->next : NULL; @@ -1065,9 +1093,8 @@ static str CUDFeval(Client cntxt, MalBlk bat_data->null_value.size = 0; bat_data->null_value.data = NULL; } else { - assert(0); - msg = createException(MAL, "cudf.eval", "Unknown output type"); - goto wrapup; + // unsupported type, convert from string output + GENERATE_BAT_OUTPUT(str); } argnode = argnode ? argnode->next : NULL; } @@ -1144,8 +1171,6 @@ static str CUDFeval(Client cntxt, MalBlk regions = next; } - // FIXME: deal with SQL types - // create the output bats from the returned results for (i = 0; i < (size_t)pci->retc; i++) { int bat_type = getBatType(getArgType(mb, pci, i)); @@ -1274,10 +1299,35 @@ static str CUDFeval(Client cntxt, MalBlk GDKfree(current_blob); } GDKfree(data); - } else { - msg = createException(MAL, "cudf.eval", "Unsupported output type"); - BBPunfix(b->batCacheid); - goto wrapup; + } else { + char **source_base = (char **)data; + int len = 0; + void* element = NULL; + for (j = 0; j < count; j++) { + const char *ptr = source_base[j]; + const void* appended_element; + if (!ptr || strcmp(ptr, str_nil) == 0) { + appended_element = (void*) BATatoms[bat_type].atomNull; + } else { + int len = 0; + if (BATatoms[bat_type].atomFromStr(ptr, &len, &element) == 0) { + msg = createException(MAL, "cudf.eval", "Failed to convert output element from string: %s", ptr); + goto wrapup; + } + appended_element = element; + } + if (BUNappend(b, appended_element, FALSE) != GDK_SUCCEED) { + if (element) { + GDKfree(element); + } + msg = createException(MAL, "cudf.eval", MAL_MALLOC_FAIL); + goto wrapup; + } + } + if (element) { + GDKfree(element); + } + GDKfree(data); } // free the output value right now to prevent the internal data from @@ -1347,6 +1397,32 @@ wrapup: if (inputs) { for (i = 0; i < (size_t)input_count; i++) { if (inputs[i]) { + int bat_type = getBatType(getArgType(mb, pci, i)); + if (bat_type == TYPE_str || + bat_type == TYPE_date || + bat_type == TYPE_daytime || + bat_type == TYPE_timestamp || + bat_type == TYPE_blob || + bat_type == TYPE_sqlblob) { + // have to free input data + void *data = GetTypeData(bat_type, inputs[i]); + if (data) { + GDKfree(data); + } + } else if (bat_type > TYPE_str) { + // this type was converted to individually malloced strings + // we have to free all the individual strings + char **data = (char**) GetTypeData(bat_type, inputs[i]); + size_t count = GetTypeCount(bat_type, inputs[i]); + for(j = 0; j < count; j++) { + if (data[j]) { + GDKfree(data[j]); + } + } + if (data) { + GDKfree(data); + } + } GDKfree(inputs[i]); } } @@ -1414,7 +1490,8 @@ static const char *GetTypeDefinition(int } else if (type == TYPE_blob || type == TYPE_sqlblob) { tpe = "cudf_data_blob"; } else { - assert(0); + // unsupported type: string + tpe = "char*"; } return tpe; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list