Changeset: 751e80b51d1c for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=751e80b51d1c Added Files: sql/backends/monet5/Tests/pyloader07.sql sql/backends/monet5/Tests/pyloader07.stable.err sql/backends/monet5/Tests/pyloader07.stable.out Modified Files: monetdb5/extras/pyapi/connection.c sql/backends/monet5/Tests/All sql/backends/monet5/sql.c sql/backends/monet5/sql.h Branch: pythonloader Log Message:
directly creating output tables for create table from loader diffs (truncated from 373 to 300 lines): diff --git a/monetdb5/extras/pyapi/connection.c b/monetdb5/extras/pyapi/connection.c --- a/monetdb5/extras/pyapi/connection.c +++ b/monetdb5/extras/pyapi/connection.c @@ -244,106 +244,76 @@ str _connection_query(Client cntxt, char return res; } -static str _connection_append_table(Client cntxt, char *sname, char *tname, EmitCol *columns, size_t ncols) { + +str _connection_create_table(Client cntxt, char *sname, char *tname, EmitCol *columns, size_t ncols) { size_t i; - size_t nvar = 6; // variables we need to make up - MalBlkRecord mb; - MalStack* stk = NULL; - InstrRecord* pci = NULL; - str res = MAL_SUCCEED; - VarRecord bat_varrec; - mvc* m = ((backend *) cntxt->sqlcontext)->mvc; + sql_table *t; + sql_schema *s; + mvc *sql = NULL; + str msg = MAL_SUCCEED; - assert(tname != NULL && columns != NULL && ncols > 0); + if ((msg = getSQLContext(cntxt, NULL, &sql, NULL)) != NULL) + return msg; + if ((msg = checkSQLContext(cntxt)) != NULL) + return msg; - // very black MAL magic below - mb.var = GDKmalloc(nvar * sizeof(VarRecord*)); - stk = GDKmalloc(sizeof(MalStack) + nvar * sizeof(ValRecord)); - pci = GDKmalloc(sizeof(InstrRecord) + nvar * sizeof(int)); - assert(mb.var != NULL && stk != NULL && pci != NULL); // cough, cough - bat_varrec.type = TYPE_bat; - for (i = 0; i < nvar; i++) { - pci->argv[i] = i; - } - stk->stk[0].vtype = TYPE_int; - stk->stk[2].val.sval = (str) sname; - stk->stk[2].vtype = TYPE_str; - stk->stk[3].val.sval = (str) tname; - stk->stk[3].vtype = TYPE_str; - stk->stk[4].vtype = TYPE_str; - stk->stk[5].vtype = TYPE_bat; - mb.var[5] = &bat_varrec; - for (i = 0; i < ncols; i++) { - EmitCol col = columns[i]; - stk->stk[4].val.sval = col.name; - stk->stk[5].val.bval = col.b->batCacheid; + /* for some reason we don't have an allocator here so make one */ + sql->sa = sa_create(); - res = (*mvc_append_wrap_ptr)(cntxt, &mb, stk, pci); - if (res != NULL) { - break; + if (!sname) sname = "sys"; + if (!(s = mvc_bind_schema(sql, sname))) { + msg = sql_error(sql, 02, "3F000!CREATE TABLE: no such schema '%s'", sname); + goto cleanup; + } + if (!(t = mvc_create_table(sql, s, tname, tt_table, 0, SQL_DECLARED_TABLE, CA_COMMIT, -1))) { + msg = sql_error(sql, 02, "3F000!CREATE TABLE: could not create table '%s'", tname); + goto cleanup; + } + + for(i = 0; i < ncols; i++) { + BAT *b = columns[i].b; + sql_subtype *tpe = sql_bind_localtype(ATOMname(b->T->type)); + sql_column *col = NULL; + + if (!tpe) { + msg = sql_error(sql, 02, "3F000!CREATE TABLE: could not find type for column"); + goto cleanup; + } + + col = mvc_create_column(sql, t, columns[i].name, tpe); + if (!col) { + msg = sql_error(sql, 02, "3F000!CREATE TABLE: could not create column %s", columns[i].name); + goto cleanup; } } - if (res == MAL_SUCCEED) { - (*sqlcleanup_ptr)(m, 0); + msg = create_table_or_view(sql, sname, t, 0); + if (msg != MAL_SUCCEED) { + goto cleanup; } - GDKfree(mb.var); - GDKfree(stk); - GDKfree(pci); - return res; -} + t = mvc_bind_table(sql, s, tname); + if (!t) { + msg = sql_error(sql, 02, "3F000!CREATE TABLE: could not bind table %s", tname); + goto cleanup; + } + for(i = 0; i < ncols; i++) { + BAT *b = columns[i].b; + sql_column *col = NULL; -static char *BatType_ToSQLType(int type) { - switch (type) { - case TYPE_bit: - case TYPE_bte: return "TINYINT"; - case TYPE_sht: return "SMALLINT"; - case TYPE_int: return "INTEGER"; - case TYPE_lng: return "BIGINT"; - case TYPE_flt: return "FLOAT"; - case TYPE_dbl: return "DOUBLE"; - case TYPE_str: return "STRING"; - case TYPE_hge: return "HUGEINT"; - case TYPE_oid: return "UNKNOWN"; - default: return "UNKNOWN"; - } -} - -str _connection_create_table(Client cntxt, char *sname, char *tname, EmitCol *columns, size_t ncols) { - char *query = NULL; - size_t i; - size_t query_size = 255, query_index = 0; - res_table *res; - str msg = MAL_SUCCEED; - - if (!sname) sname = "sys"; - - // first compute the size of the query - query_size += strlen(sname); - query_size += strlen(tname); - for(i = 0; i < ncols; i++) { - query_size += strlen(columns[i].name) + 20; + col = mvc_bind_column(sql,t, columns[i].name); + if (!col) { + msg = sql_error(sql, 02, "3F000!CREATE TABLE: could not bind column %s", columns[i].name); + goto cleanup; + } + msg = mvc_append_column(sql->session->tr, col, b); + if (msg != MAL_SUCCEED) { + goto cleanup; + } } - query = GDKzalloc(sizeof(char) * query_size); - if (query == NULL) { - return GDKstrdup(MAL_MALLOC_FAIL"query"); - } - - //format the CREATE TABLE query - query_index = snprintf(query, query_size, "create table %s.%s(", sname, tname); - for(i = 0; i < ncols; i++) { - BAT *b = columns[i].b; - query_index += snprintf(query + query_index, query_size, "%s %s%s", columns[i].name, BatType_ToSQLType(b->T->type), i < ncols - 1 ? "," : ");"); - } - - // execute the create table query - msg = _connection_query(cntxt, query, &res); - GDKfree(query); - if (msg != MAL_SUCCEED) { - return msg; - } - // now append the values to the created table - return _connection_append_table(cntxt, sname, tname, columns, ncols); +cleanup: + sa_destroy(sql->sa); + sql->sa = NULL; + return msg; } diff --git a/sql/backends/monet5/Tests/All b/sql/backends/monet5/Tests/All --- a/sql/backends/monet5/Tests/All +++ b/sql/backends/monet5/Tests/All @@ -57,7 +57,7 @@ HAVE_LIBPY?pyloader03 HAVE_LIBPY?pyloader04 HAVE_LIBPY?pyloader05 HAVE_LIBPY?pyloader06 - +HAVE_LIBPY?pyloader07 # should this work? #inlineUDF diff --git a/sql/backends/monet5/Tests/pyloader07.sql b/sql/backends/monet5/Tests/pyloader07.sql new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/Tests/pyloader07.sql @@ -0,0 +1,11 @@ +START TRANSACTION; +CREATE LOADER pyloader07() LANGUAGE PYTHON { + _emit.emit({'s': 33, 't': 42}); + +}; +CREATE TABLE pyloader07table FROM LOADER pyloader07(); + +SELECT * FROM pyloader07table; +DROP TABLE pyloader07table; +DROP LOADER pyloader07; +ROLLBACK; diff --git a/sql/backends/monet5/Tests/pyloader07.stable.err b/sql/backends/monet5/Tests/pyloader07.stable.err new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/Tests/pyloader07.stable.err @@ -0,0 +1,36 @@ +stderr of test 'pyloader07` in directory 'sql/backends/monet5` itself: + + +# 15:06:46 > +# 15:06:46 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=31590" "--set" "mapi_usock=/var/tmp/mtest-46511/.s.monetdb.31590" "--set" "monet_prompt=" "--forcemito" "--dbpath=/tmp/fuckit/var/MonetDB/mTests_sql_backends_monet5" "--set" "embedded_r=yes" "--set" "embedded_py=true" +# 15:06:46 > + +# builtin opt gdk_dbpath = /tmp/fuckit/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 = 31590 +# cmdline opt mapi_usock = /var/tmp/mtest-46511/.s.monetdb.31590 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /tmp/fuckit/var/MonetDB/mTests_sql_backends_monet5 +# cmdline opt embedded_r = yes +# cmdline opt embedded_py = true +# cmdline opt gdk_debug = 536870922 + +# 15:06:46 > +# 15:06:46 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-46511" "--port=31590" +# 15:06:46 > + + +# 15:06:46 > +# 15:06:46 > "Done." +# 15:06:46 > + diff --git a/sql/backends/monet5/Tests/pyloader07.stable.out b/sql/backends/monet5/Tests/pyloader07.stable.out new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/Tests/pyloader07.stable.out @@ -0,0 +1,82 @@ +stdout of test 'pyloader07` in directory 'sql/backends/monet5` itself: + + +# 15:06:46 > +# 15:06:46 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=31590" "--set" "mapi_usock=/var/tmp/mtest-46511/.s.monetdb.31590" "--set" "monet_prompt=" "--forcemito" "--dbpath=/tmp/fuckit/var/MonetDB/mTests_sql_backends_monet5" "--set" "embedded_r=yes" "--set" "embedded_py=true" +# 15:06:46 > + +# MonetDB 5 server v11.24.0 +# This is an unreleased version +# Serving database 'mTests_sql_backends_monet5', using 4 threads +# Compiled for x86_64-apple-darwin15.5.0/64bit with 64bit OIDs and 128bit integers dynamically linked +# Found 16.000 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2016 MonetDB B.V., all rights reserved +# Visit http://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://dakar.da.cwi.nl:31590/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-46511/.s.monetdb.31590 +# MonetDB/SQL module loaded +# MonetDB/Python module loaded +# MonetDB/R module loaded + +Ready. +# SQL catalog created, loading sql scripts once +# loading sql script: 09_like.sql +# loading sql script: 10_math.sql +# loading sql script: 11_times.sql +# loading sql script: 12_url.sql +# loading sql script: 13_date.sql +# loading sql script: 14_inet.sql +# loading sql script: 15_querylog.sql +# loading sql script: 16_tracelog.sql +# loading sql script: 17_temporal.sql +# loading sql script: 18_index.sql +# loading sql script: 20_vacuum.sql +# loading sql script: 21_dependency_functions.sql +# loading sql script: 22_clients.sql +# loading sql script: 23_skyserver.sql +# loading sql script: 24_zorder.sql +# loading sql script: 25_debug.sql +# loading sql script: 26_sysmon.sql +# loading sql script: 27_rejects.sql +# loading sql script: 39_analytics.sql +# loading sql script: 39_analytics_hge.sql +# loading sql script: 40_json.sql +# loading sql script: 40_json_hge.sql +# loading sql script: 41_md5sum.sql +# loading sql script: 45_uuid.sql +# loading sql script: 46_gsl.sql +# loading sql script: 46_profiler.sql +# loading sql script: 51_sys_schema_extension.sql +# loading sql script: 72_fits.sql +# loading sql script: 75_storagemodel.sql +# loading sql script: 80_statistics.sql +# loading sql script: 80_udf.sql +# loading sql script: 80_udf_hge.sql +# loading sql script: 90_generator.sql _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list