[prev in list] [next in list] [prev in thread] [next in thread] 

List:       monetdb-checkins
Subject:    MonetDB: default - Merge with mangled.
From:       Aris_Koning <commits+aris.koning=monetdbsolutions.com () monetdb ! o
Date:       2022-01-31 10:52:49
Message-ID: hg.d9c0306a548f.1643626369.5907838980758977560 () dev ! monetdb ! org
[Download RAW message or body]

Changeset: d9c0306a548f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d9c0306a548f
Branch: default
Log Message:

Merge with mangled.


diffs (truncated from 202958 to 300 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -2587,7 +2587,7 @@ doFile(Mapi mid, stream *fp, bool useins
 							continue;
 						}
 
-						/*
+						/* get all object names in current schema
 						 * | LINE            | SCHEMA FILTER | NAME FILTER                   |
 						 * |-----------------+---------------+-------------------------------|
 						 * | ""              | yes           | -                             |
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
@@ -539,7 +539,7 @@ static str CUDFeval(Client cntxt, MalBlk
 		sqlfun = *(sql_func **)getArgReference_ptr(stk, pci, pci->retc);
 	}
 
-	funcname = sqlfun ? sqlfun->base.name : "yet_another_c_function";
+	funcname = sqlfun ? sqlfun->sql_name : "yet_another_c_function";
 
 	args = (str *)GDKzalloc(sizeof(str) * pci->argc);
 	output_names = (str *)GDKzalloc(sizeof(str) * pci->argc);
diff --git a/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_01.test \
                b/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_01.test
--- a/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_01.test
+++ b/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_01.test
@@ -86,7 +86,7 @@ DROP LOADER myfunc2
 statement ok
 DROP LOADER myfunc3
 
-query ITTTIIIIIIII rowsort
+query ITTTIIIIIIIIT rowsort
 SELECT * FROM functions WHERE name='myfunc'
 ----
 
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
@@ -1256,13 +1256,13 @@ exp_bin(backend *be, sql_exp *e, stmt *l
 		}
 		assert(!e->r);
 		if (strcmp(mod, "") == 0 && strcmp(fimp, "") == 0) {
-			if (strcmp(f->func->base.name, "star") == 0)
+			if (strcmp(f->func->sql_name, "star") == 0)
 				return left->op4.lval->h->data;
-			if (strcmp(f->func->base.name, "case") == 0)
+			if (strcmp(f->func->sql_name, "case") == 0)
 				return exp2bin_case(be, e, left, right, sel, depth);
-			if (strcmp(f->func->base.name, "casewhen") == 0)
+			if (strcmp(f->func->sql_name, "casewhen") == 0)
 				return exp2bin_casewhen(be, e, left, right, sel, depth);
-			if (strcmp(f->func->base.name, "coalesce") == 0)
+			if (strcmp(f->func->sql_name, "coalesce") == 0)
 				return exp2bin_coalesce(be, e, left, right, sel, depth);
 		}
 		if (!list_empty(exps)) {
@@ -1281,7 +1281,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
 				else if (f->func->type == F_ANALYTIC && es->nrcols == 0) {
 					if (en == exps->h && left->nrcols)
 						es = stmt_const(be, bin_find_smallest_column(be, left), es); /* ensure the \
                first argument is a column */
-					if (!f->func->s && !strcmp(f->func->base.name, "window_bound")
+					if (!f->func->s && !strcmp(f->func->sql_name, "window_bound")
 						&& exps->h->next && list_length(f->func->ops) == 6 && en == exps->h->next && \
left->nrcols)  es = stmt_const(be, bin_find_smallest_column(be, left), es);
 				}
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -930,7 +930,7 @@ drop_func(mvc *sql, char *sname, char *n
 			sql_func *func = (sql_func*)b;
 
 			if (!action && mvc_check_dependency(sql, func->base.id, !IS_PROC(func) ? \
                FUNC_DEPENDENCY : PROC_DEPENDENCY, NULL))
-				throw(SQL,"sql.drop_func", SQLSTATE(42000) "DROP %s: there are database objects \
dependent on %s %s;", F, fn, func->base.name); +				throw(SQL,"sql.drop_func", \
SQLSTATE(42000) "DROP %s: there are database objects dependent on %s %s;", F, fn, \
func->sql_name);  res = mvc_drop_func(sql, s, func, action);
 		}
 	} else if (fid == -2) { /* if exists option */
@@ -944,7 +944,7 @@ drop_func(mvc *sql, char *sname, char *n
 
 				if (!action && mvc_check_dependency(sql, func->base.id, !IS_PROC(func) ? \
FUNC_DEPENDENCY : PROC_DEPENDENCY, list_func)) {  list_destroy(list_func);
-					throw(SQL,"sql.drop_func", SQLSTATE(42000) "DROP %s: there are database objects \
dependent on %s %s;", F, fn, func->base.name); +					throw(SQL,"sql.drop_func", \
SQLSTATE(42000) "DROP %s: there are database objects dependent on %s %s;", F, fn, \
func->sql_name);  }
 			}
 		res = mvc_drop_all_func(sql, s, list_func, action);
@@ -1003,7 +1003,7 @@ create_func(mvc *sql, char *sname, char 
 			sql_func *sff = sf->func;
 
 			if (!sff->s || sff->system)
-				throw(SQL,"sql.create_func", SQLSTATE(42000) "%s %s: not allowed to replace \
system %s %s;", base, F, fn, sff->base.name); +				throw(SQL,"sql.create_func", \
SQLSTATE(42000) "%s %s: not allowed to replace system %s %s;", base, F, fn, \
sff->sql_name);  
 			/* if all function parameters are the same, return */
 			if (sff->lang == f->lang && sff->type == f->type &&
@@ -1014,7 +1014,7 @@ create_func(mvc *sql, char *sname, char 
 				return MAL_SUCCEED;
 
 			if (mvc_check_dependency(sql, sff->base.id, !IS_PROC(sff) ? FUNC_DEPENDENCY : \
                PROC_DEPENDENCY, NULL))
-				throw(SQL,"sql.create_func", SQLSTATE(42000) "%s %s: there are database objects \
dependent on %s %s;", base, F, fn, sff->base.name); +				throw(SQL,"sql.create_func", \
SQLSTATE(42000) "%s %s: there are database objects dependent on %s %s;", base, F, fn, \
sff->sql_name);  switch (mvc_drop_func(sql, s, sff, 0)) {
 				case -1:
 					throw(SQL,"sql.create_func", SQLSTATE(HY013) MAL_MALLOC_FAIL);
@@ -1029,7 +1029,7 @@ create_func(mvc *sql, char *sname, char 
 			sql->errstr[0] = '\0';
 		}
 	}
-	switch (mvc_create_func(&nf, sql, NULL, s, f->base.name, f->ops, f->res, f->type, \
f->lang, f->mod, f->imp, f->query, f->varres, f->vararg, f->system, f->side_effect)) \
{ +	switch (mvc_create_func(&nf, sql, NULL, s, f->sql_name, f->ops, f->res, f->type, \
f->lang, f->mod, f->imp, f->query, f->varres, f->vararg, f->system, f->side_effect)) \
{  case -1:
 			throw(SQL,"sql.create_func", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 		case -2:
diff --git a/sql/backends/monet5/sql_gencode.c b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -1160,12 +1160,12 @@ backend_create_mal_func(mvc *m, sql_func
 	if (!(fimp = mal_function_find_implementation_address(m, f)))
 		return -1;
 	if (!backend_resolve_function(&clientid, f, fimp, &new_side_effect)) {
-		(void) sql_error(m, 10, SQLSTATE(3F000) "MAL external name %s.%s not bound \
(%s.%s)", f->mod, fimp, f->s->base.name, f->base.name); +		(void) sql_error(m, 10, \
SQLSTATE(3F000) "MAL external name %s.%s not bound (%s.%s)", f->mod, fimp, \
f->s->base.name, f->sql_name);  return -1;
 	}
 	if (old_side_effect != new_side_effect) {
 		(void) sql_error(m, 10, SQLSTATE(42000) "Side-effect value from the SQL %s %s.%s \
                doesn't match the MAL definition %s.%s\n"
-						 "Either re-create the %s, or fix the MAL definition and restart the \
database", fn, f->s->base.name, f->base.name, f->mod, fimp, fn); +						 "Either \
re-create the %s, or fix the MAL definition and restart the database", fn, \
f->s->base.name, f->sql_name, f->mod, fimp, fn);  return -1;
 	}
 	MT_lock_set(&sql_gencodeLock);
@@ -1212,11 +1212,11 @@ backend_create_sql_func(backend *be, sql
 
 #ifndef NDEBUG
 	/* for debug builds we keep the SQL function name in the MAL function name to make \
                it easy to debug */
-	if (strlen(f->base.name) + 21 >= IDLENGTH) { /* 20 bits for u64 number + '%' */
-		(void) sql_error(m, 10, SQLSTATE(42000) "MAL function name '%s' too large for the \
backend", f->base.name); +	if (strlen(f->sql_name) + 21 >= IDLENGTH) { /* 20 bits for \
u64 number + '%' */ +		(void) sql_error(m, 10, SQLSTATE(42000) "MAL function name \
'%s' too large for the backend", f->sql_name);  return -1;
 	}
-	(void) snprintf(befname, IDLENGTH, "%%" LLFMT "%s", \
store_function_counter(m->store), f->base.name); +	(void) snprintf(befname, IDLENGTH, \
"%%" LLFMT "%s", store_function_counter(m->store), f->sql_name);  #else
 	(void) snprintf(befname, IDLENGTH, "f_" LLFMT, store_function_counter(m->store));
 #endif
diff --git a/sql/backends/monet5/sql_statement.c \
                b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -1627,7 +1627,7 @@ range_join_convertable(stmt *s, stmt **b
 		h = s->op3->op1->op4.lval->t->data;
 	}
 
-	if (((ls = (l && strcmp(s->op2->op4.funcval->func->base.name, "sql_sub") == 0 && \
l->nrcols == 0)) || (hs = (h && strcmp(s->op3->op4.funcval->func->base.name, \
"sql_add") == 0 && h->nrcols == 0))) && (ls || hs) && bl == bh) { +	if (((ls = (l && \
strcmp(s->op2->op4.funcval->func->sql_name, "sql_sub") == 0 && l->nrcols == 0)) || \
(hs = (h && strcmp(s->op3->op4.funcval->func->sql_name, "sql_add") == 0 && h->nrcols \
                == 0))) && (ls || hs) && bl == bh) {
 		*base = bl;
 		*L = l;
 		*H = h;
@@ -3360,7 +3360,7 @@ stmt_Nop(backend *be, stmt *ops, stmt *s
 
 		nrcols = e1->nrcols>e2->nrcols ? e1->nrcols:e2->nrcols;
 		/* nullif(e1,e2) -> ifthenelse(e1==e2),NULL,e1) */
-		if (strcmp(f->func->base.name, "nullif") == 0) {
+		if (strcmp(f->func->sql_name, "nullif") == 0) {
 			const char *mod = (!nrcols)?calcRef:batcalcRef;
 			sql_subtype *t = tail_type(e1);
 			int tt = t->type->localtype;
@@ -3936,7 +3936,7 @@ const char *
 	case st_aggr:
 	{
 		const char *cn = column_name(sa, st->op1);
-		return func_name(sa, st->op4.funcval->func->base.name, cn);
+		return func_name(sa, st->op4.funcval->func->sql_name, cn);
 	}
 	case st_alias:
 		if (st->op3)
diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -77,8 +77,8 @@ sql_fix_system_tables(Client c, mvc *sql
 		pos += snprintf(buf + pos, bufsize - pos,
 				"insert into sys.functions values"
 				" (%d, '%s', '%s', '%s',"
-				" %d, %d, %s, %s, %s, %d, %s, %s);\n",
-				func->base.id, func->base.name,
+				" %d, %d, %s, %s, %s, %d, %s, %s, '%s');\n",
+				func->base.id, func->sql_name,
 				sql_func_imp(func), sql_func_mod(func), (int) FUNC_LANG_INT,
 				(int) func->type,
 				boolnames[func->side_effect],
@@ -86,7 +86,8 @@ sql_fix_system_tables(Client c, mvc *sql
 				boolnames[func->vararg],
 				func->s ? func->s->base.id : s->base.id,
 				boolnames[func->system],
-				boolnames[func->semantics]);
+				boolnames[func->semantics],
+				func->base.name);
 		if (func->res) {
 			for (m = func->res->h; m; m = m->next, number++) {
 				arg = m->data;
@@ -4649,6 +4650,230 @@ sql_update_jan2022(Client c, mvc *sql, c
 	return err;		/* usually MAL_SUCCEED */
 }
 
+static str
+sql_update_default(Client c, mvc *sql, const char *prev_schema, bool *systabfixed)
+{
+	size_t bufsize = 65536, pos = 0;
+	char *buf = NULL, *err = NULL;
+	res_table *output;
+
+	if ((buf = GDKmalloc(bufsize)) == NULL)
+		throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+
+	pos += snprintf(buf + pos, bufsize - pos,
+			"select c.id from schemas s, tables t, columns c, functions f, dependencies d \n"
+			"where s.id = t.schema_id and t.id = c.table_id and d.id = c.id and d.depend_id = \
f.id and f.name = 'describe_function' and s.name = 'sys' and t.name = 'functions' and \
c.name = 'mangled_name';\n"); +	err = SQLstatementIntern(c, buf, "update", 1, 0, \
&output); +	if (err) {
+		GDKfree(buf);
+		return err;
+	}
+	BAT* b = BATdescriptor(output->cols[0].b);
+	if (b) {
+		if (BATcount(b)) {
+			assert(BATcount(b) == 1);
+			BBPunfix(b->batCacheid);
+			/* nothing to do */
+			GDKfree(buf);
+			res_table_destroy(output);
+			return NULL;
+		}
+		BBPunfix(b->batCacheid);
+	}
+	else {
+		res_table_destroy(output);
+		throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+	}
+
+	res_table_destroy(output);
+
+	if (!*systabfixed && (err = sql_fix_system_tables(c, sql, prev_schema)) != NULL)
+		return err;
+	*systabfixed = true;
+
+	pos = snprintf(buf, bufsize, "SET SCHEMA \"sys\";\n");
+
+	sql_schema *s = mvc_bind_schema(sql, "sys");
+	sql_table* t = NULL;
+
+	t = mvc_bind_table(sql, s, "describe_privileges");
+	t->system = 0;
+	t = mvc_bind_table(sql, s, "dump_comments");
+	t->system = 0;
+	t = mvc_bind_table(sql, s, "describe_comments");
+	t->system = 0;
+	t = mvc_bind_table(sql, s, "fully_qualified_functions");
+	t->system = 0;
+
+	pos += snprintf(buf + pos, bufsize - pos,
+				"UPDATE sys.functions SET system = false WHERE schema_id = 2000 AND name in \
('dump_database', 'describe_function');" +				"UPDATE sys._tables SET system = false \
WHERE schema_id = 2000 AND name in ('describe_privileges', 'dump_comments', \
'describe_comments', 'fully_qualified_functions');" +				"DROP VIEW \
sys.describe_privileges;\n" +				"DROP FUNCTION sys.dump_database(BOOLEAN);\n"
+				"DROP VIEW sys.dump_comments;\n"
+				"DROP VIEW sys.describe_comments;\n"
+				"DROP VIEW sys.fully_qualified_functions;\n"
+				"DROP FUNCTION sys.describe_function(STRING, STRING);\n"
+				"CREATE FUNCTION sys.describe_function(schemaName string, functionName \
string)\n" +				"	RETURNS TABLE(id integer, name string, type string, language \
string, remark string)\n" +				"BEGIN\n"
+				"	RETURN SELECT f.id, f.name, ft.function_type_keyword, fl.language_keyword, \
c.remark\n" +				"		FROM sys.functions f\n"
+				"		JOIN sys.schemas s ON f.schema_id = s.id\n"
+				"		JOIN sys.function_types ft ON f.type = ft.function_type_id\n"
+				"		LEFT OUTER JOIN sys.function_languages fl ON f.language = fl.language_id\n"
+				"		LEFT OUTER JOIN sys.comments c ON f.id = c.id\n"
+				"		WHERE f.name=functionName AND s.name = schemaName;\n"
+				"END;\n"
+				"CREATE VIEW sys.fully_qualified_functions AS\n"
+				"	WITH fqn(id, tpe, sig, num) AS\n"
+				"	(\n"
+				"		SELECT\n"
+				"			f.id,\n"
+				"			ft.function_type_keyword,\n"
+				"			CASE WHEN a.type IS NULL THEN\n"
+				"				sys.fqn(s.name, f.name) || '()'\n"
+				"			ELSE\n"
+				"				sys.fqn(s.name, f.name) || '(' || group_concat(sys.describe_type(a.type, \
a.type_digits, a.type_scale), ',') OVER (PARTITION BY f.id ORDER BY a.number)  || \
')'\n" +				"			END,\n"
+				"			a.number\n"
+				"		FROM sys.schemas s, sys.function_types ft, sys.functions f LEFT JOIN sys.args \
a ON f.id = a.func_id\n" +				"		WHERE s.id= f.schema_id AND f.type = \
ft.function_type_id\n" +				"	)\n"
+				"	SELECT\n"
+				"		fqn1.id id,\n"
+				"		fqn1.tpe tpe,\n"
+				"		fqn1.sig nme\n"
+				"	FROM\n"
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic