Mercurial > hg > MonetDB-extend
changeset 49:0e5e08bd133b
Rename "reverse" function to "revstr" to avoid clash.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Wed, 23 Jun 2021 13:28:54 +0200 (2021-06-23) |
parents | 099ce41179e9 |
children | 3531b398df38 |
files | reverse/Makefile reverse/README.rst reverse/reverse.c |
diffstat | 3 files changed, 40 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/reverse/Makefile Mon Jun 14 09:44:28 2021 +0200 +++ b/reverse/Makefile Wed Jun 23 13:28:54 2021 +0200 @@ -9,10 +9,10 @@ CFLAGS += $(shell pkgconf --cflags monetdb5) LDFLAGS += $(shell pkgconf --libs monetdb5) -all: lib_reverse.so +all: lib_revstr.so -lib_reverse.so: reverse.o - $(CC) -fPIC -DPIC -o lib_reverse.so -shared reverse.o $(LDFLAGS) -Wl,-soname -Wl,lib_reverse.so +lib_revstr.so: reverse.o + $(CC) -fPIC -DPIC -o lib_revstr.so -shared reverse.o $(LDFLAGS) -Wl,-soname -Wl,lib_revstr.so reverse.o: reverse.c $(CC) -fPIC -DPIC $(CFLAGS) -c reverse.c @@ -28,11 +28,11 @@ clean: rm -f README.html README.pdf *.o *.so -install: lib_reverse.so - cp lib_reverse.so $(DESTDIR)$(LIBDIR)/monetdb5 +install: lib_revstr.so + cp lib_revstr.so $(DESTDIR)$(LIBDIR)/monetdb5 uninstall: - rm -f $(DESTDIR)$(LIBDIR)/monetdb5/lib_reverse.so + rm -f $(DESTDIR)$(LIBDIR)/monetdb5/lib_revstr.so tar: MonetDB-reverse-1.2.tar.bz2 MonetDB-reverse-1.2.tar.bz2: README.rst Makefile reverse.c
--- a/reverse/README.rst Mon Jun 14 09:44:28 2021 +0200 +++ b/reverse/README.rst Wed Jun 23 13:28:54 2021 +0200 @@ -32,7 +32,7 @@ .. code-block:: sql - SELECT reverse(strcol) FROM table; + SELECT revstr(strcol) FROM table; where ``table`` is an SQL table with a column called ``strcol`` which is of type ``VARCHAR`` (or any other string type). @@ -45,20 +45,20 @@ .. code-block:: sql - SELECT reverse('string'); + SELECT revstr('string'); The SQL catalog will need to be extended with a definition of the -``reverse`` function as follows: +``revstr`` function as follows: .. code-block:: sql - CREATE FUNCTION reverse(src STRING) RETURNS STRING - EXTERNAL NAME reverse.reverse; + CREATE FUNCTION revstr(src STRING) RETURNS STRING + EXTERNAL NAME revstr.revstr; The statement tells the SQL system that there is a function called -``reverse`` which takes a ``STRING`` argument and produces a +``revstr`` which takes a ``STRING`` argument and produces a ``STRING`` result. The function is implemented using the MAL -interface ``reverse.reverse``. Note that ``STRING`` is equivalent to +interface ``revstr.revstr``. Note that ``STRING`` is equivalent to ``CHARACTER LARGE OBJECT`` or ``CLOB``. This statement will normally be executed once when the database is @@ -69,8 +69,8 @@ .. code-block:: c - static char reverse_sql[] = "CREATE FUNCTION reverse(src STRING)" - " RETURNS STRING EXTERNAL NAME reverse.reverse;"; + static char reverse_sql[] = "CREATE FUNCTION revstr(src STRING)" + " RETURNS STRING EXTERNAL NAME revstr.revstr;"; At the SQL side we don't have to do anything more. @@ -83,9 +83,9 @@ .. code-block:: - module reverse; + module revstr; - command reverse(ra1:str):str + command revstr(ra1:str):str address UDFreverse comment "Reverse a string"; @@ -94,13 +94,13 @@ produces a column as opposed to a function that works on a single value and produces a single value) has the same name but is located in a module with the string ``bat`` prepended. So, the bulk version of -the ``reverse.reverse`` function can also be created: +the ``revstr.revstr`` function can also be created: .. code-block:: - module batreverse; + module batrevstr; - command reverse(b:bat[:str]):bat[:str] + command revstr(b:bat[:str]):bat[:str] address UDFBATreverse comment "Reverse a column of strings"; @@ -110,10 +110,10 @@ .. code-block:: c static mel_func reverse_init_funcs[] = { - command("reverse", "reverse", UDFreverse, false, + command("revstr", "revstr", UDFreverse, false, "Reverse a string", args(1,2, arg("",str),arg("ra1",str))), - command("batreverse", "reverse", UDFBATreverse, false, + command("batrevstr", "revstr", UDFBATreverse, false, "Reverse a BAT of strings", args(1,2, batarg("",str),batarg("b",str))), { .imp=NULL } /* sentinel */ @@ -149,7 +149,7 @@ Now we come to the actual implementation of the feature. -The MAL interfaces of the scalar and bulk versions of the ``reverse`` +The MAL interfaces of the scalar and bulk versions of the ``revstr`` function translates to the following C interfaces: .. code-block:: c @@ -177,7 +177,7 @@ static char *UDFreverse(char **retval, const char **arg) { (void) retval; (void) arg; /* we're not using these */ - throw(MAL, "reverse.reverse", "Not yet implemented"); + throw(MAL, "revstr.revstr", "Not yet implemented"); } MAL commands can return any number of values. These values are @@ -203,7 +203,7 @@ These functions must be located in a dynamically loadable module (``.so`` file on Linux, ``.dll`` on Windows), and this module must -have the name ``lib_reverse.so`` (or ``lib_reverse.dll``). The +have the name ``lib_revstr.so`` (or ``lib_revstr.dll``). The functions are only directly referenced from the ``reverse_init_funcs`` array that we have defined above, so the functions are declared as ``static`` functions. @@ -237,7 +237,7 @@ *retval = GDKmalloc(strlen(*arg) + 1); if (*retval == NULL) - throw(MAL, "reverse.reverse", MAL_MALLOC_FAIL); + throw(MAL, "revstr.revstr", MAL_MALLOC_FAIL); // reverse the string in *arg into *retval return MAL_SUCCEED; @@ -275,7 +275,7 @@ BAT *b; b = BATdescriptor(*arg); if (b == NULL) - throw(MAL, "batreverse.reverse", RUNTIME_OBJECT_MISSING); + throw(MAL, "batrevstr.revstr", RUNTIME_OBJECT_MISSING); When we're done with this BAT, we will need to decrement the physical reference count again. We do that by calling ``BBPunfix``: @@ -463,8 +463,8 @@ #endif LIB_STARTUP_FUNC(init_reverse) { - mal_module("reverse", NULL, reverse_init_funcs); - sql_register("reverse", reverse_sql); + mal_module("revstr", NULL, reverse_init_funcs); + sql_register("revstr", reverse_sql); } The ``LIB_STARTUP_FUNC`` macro is defined in one of the include files.
--- a/reverse/reverse.c Mon Jun 14 09:44:28 2021 +0200 +++ b/reverse/reverse.c Wed Jun 23 13:28:54 2021 +0200 @@ -76,7 +76,7 @@ len = strlen(*arg); *retval = GDKmalloc(len + 1); if (*retval == NULL) - throw(MAL, "reverse.reverse", MAL_MALLOC_FAIL); + throw(MAL, "revstr.revstr", MAL_MALLOC_FAIL); do_reverse(*retval, *arg, len); @@ -100,12 +100,12 @@ dstlen = 1024; dst = GDKmalloc(dstlen); if (dst == NULL) - throw(MAL, "batreverse.reverse", MAL_MALLOC_FAIL); + throw(MAL, "batrevstr.revstr", MAL_MALLOC_FAIL); b = BATdescriptor(*arg); if (b == NULL) { GDKfree(dst); - throw(MAL, "batreverse.reverse", RUNTIME_OBJECT_MISSING); + throw(MAL, "batrevstr.revstr", RUNTIME_OBJECT_MISSING); } /* we should only get called for string BATs */ @@ -116,7 +116,7 @@ if (bn == NULL) { BBPunfix(b->batCacheid); GDKfree(dst); - throw(MAL, "batreverse.reverse", MAL_MALLOC_FAIL); + throw(MAL, "batrevstr.revstr", MAL_MALLOC_FAIL); } /* loop through BAT b; p is index of the entry we're working @@ -161,19 +161,19 @@ GDKfree(dst); BBPunfix(b->batCacheid); BBPunfix(bn->batCacheid); - throw(MAL, "batreverse.reverse", MAL_MALLOC_FAIL); + throw(MAL, "batrevstr.revstr", MAL_MALLOC_FAIL); } #include "mel.h" -static char reverse_sql[] = "CREATE FUNCTION reverse(src STRING)" - " RETURNS STRING EXTERNAL NAME reverse.reverse;"; +static char reverse_sql[] = "CREATE FUNCTION revstr(src STRING)" + " RETURNS STRING EXTERNAL NAME revstr.revstr;"; static mel_func reverse_init_funcs[] = { - command("reverse", "reverse", UDFreverse, false, + command("revstr", "revstr", UDFreverse, false, "Reverse a string", args(1,2, arg("",str),arg("ra1",str))), - command("batreverse", "reverse", UDFBATreverse, false, + command("batrevstr", "revstr", UDFBATreverse, false, "Reverse a BAT of strings", args(1,2, batarg("",str),batarg("b",str))), { .imp=NULL } /* sentinel */ @@ -187,6 +187,6 @@ #endif LIB_STARTUP_FUNC(init_reverse) { - mal_module("reverse", NULL, reverse_init_funcs); - sql_register("reverse", reverse_sql); + mal_module("revstr", NULL, reverse_init_funcs); + sql_register("revstr", reverse_sql); }