Mercurial > hg > MonetDB-extend
changeset 37:e5d2d0c9b7b3
build libraries and included mal/sql in the library startup functions
author | Niels Nes <niels@cwi.nl> |
---|---|
date | Tue, 15 Dec 2020 14:13:55 +0100 (2020-12-15) |
parents | f100f14c0d0a |
children | d3a47663cb28 |
files | CMakeLists.txt README.md monetdbe/example1.c regexp/CMakeLists.txt regexp/regexp.c reverse/CMakeLists.txt reverse/reverse.c |
diffstat | 7 files changed, 74 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Tue Jun 16 10:11:57 2020 +0200 +++ b/CMakeLists.txt Tue Dec 15 14:13:55 2020 +0100 @@ -12,12 +12,17 @@ set(C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 99) +include(GNUInstallDirs) + set(CMAKE_MODULE_PATH + "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_SOURCE_DIR}/cmake/Modules" CACHE INTERNAL "Location of custom CMake modules.") +include(monetdb-functions) + find_package(MonetDB CONFIG REQUIRED) find_package(PCRE)
--- a/README.md Tue Jun 16 10:11:57 2020 +0200 +++ b/README.md Tue Dec 15 14:13:55 2020 +0100 @@ -4,7 +4,7 @@ ``` mkdir build && cd build -CMAKE_PREFIX_PATH=/tmp/monetdb/include/cmake/ cmake -DCMAKE_BUILD_TYPE=Release ~/hg/monetdb-extend/ +cmake CMAKE_PREFIX_PATH=/tmp/monetdb/include/cmake/ -DCMAKE_BUILD_TYPE=Release ~/hg/monetdb-extend/ cmake --build . ```
--- a/monetdbe/example1.c Tue Jun 16 10:11:57 2020 +0200 +++ b/monetdbe/example1.c Tue Dec 15 14:13:55 2020 +0100 @@ -20,9 +20,9 @@ monetdbe_database mdbe = NULL; monetdbe_result* result = NULL; - // first argument is a string for the db directory or NULL for in-memory mode - if ((err = monetdbe_open(&mdbe, NULL, NULL)) != NULL) - error(err) + // second argument is a string for the db directory or NULL for in-memory mode + if (monetdbe_open(&mdbe, NULL, NULL)) + error("Failed to open database") if ((err = monetdbe_query(mdbe, "CREATE TABLE test (x integer, y string)", NULL, NULL)) != NULL) error(err) if ((err = monetdbe_query(mdbe, "INSERT INTO test VALUES (42, 'Hello'), (NULL, 'World')", NULL, NULL)) != NULL) @@ -48,7 +48,7 @@ } case monetdbe_str: { monetdbe_column_str * col = (monetdbe_column_str *) rcol; - if (col->is_null(col->data[r])) { + if (col->is_null(col->data+r)) { printf("NULL"); } else { printf("%s", (char*) col->data[r]); @@ -69,7 +69,7 @@ if ((err = monetdbe_cleanup_result(mdbe, result)) != NULL) error(err) - if ((err = monetdbe_close(mdbe)) != NULL) - error(err) + if (monetdbe_close(mdbe)) + error("Failed to close database") return 0; }
--- a/regexp/CMakeLists.txt Tue Jun 16 10:11:57 2020 +0200 +++ b/regexp/CMakeLists.txt Tue Dec 15 14:13:55 2020 +0100 @@ -28,9 +28,12 @@ DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5/autoload) -install(FILES - 81_regexp.sql - DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5/createdb) +install(TARGETS + regexp + RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5) add_custom_command(OUTPUT README.html COMMAND "rst2html" "-d" "${CMAKE_SOURCE_DIR}/README.rst" "README.html")
--- a/regexp/regexp.c Tue Jun 16 10:11:57 2020 +0200 +++ b/regexp/regexp.c Tue Dec 15 14:13:55 2020 +0100 @@ -678,3 +678,31 @@ return do_join(lres, rres, *lid, *rid, *flags, *sl, *sr, *nil_matches, *estimate); } + +#include "mel.h" + +static char regexp_sql[] = "CREATE FILTER FUNCTION rematch(val STRING, pat STRING) EXTERNAL NAME regexp.rematch; CREATE FILTER FUNCTION rematch(val STRING, pat STRING, flags STRING) EXTERNAL NAME regexp.rematch;"; + +static mel_func regexp_init_funcs[] = { + command("regexp", "rematch", regexpmatch, false, "Return true when the value 'val' matches the regular expression 'pat'", args(1,3, arg("",bit),arg("val",str),arg("pat",str))), + command("regexp", "rematchselect", regexpmatchselect, false, "Return the list of matches in 'val' that match the regular expression 'pat'", args(1,5, batarg("",oid),batarg("val",str),batarg("cand",oid),arg("pat",str),arg("anti",bit))), + command("regexp", "rematchjoin", regexpmatchjoin, false, "Return the matching pairs from the 'val' and 'pat' columns", args(2,8, batarg("lr",oid),batarg("rr",oid),batarg("val",str),batarg("pat",str),batarg("sl",oid),batarg("sr",oid),arg("nil_matches",bit),arg("estimate",lng))), + command("regexp", "rematch", regexpmatchf, false, "Return true when the value 'val' matches the regular expression 'pat'", args(1,4, arg("",bit),arg("val",str),arg("pat",str),arg("flags",str))), + command("regexp", "rematchselect", regexpmatchfselect, false, "Return the list of matches in 'val' that match the regular expression 'pat'", args(1,6, batarg("",oid),batarg("val",str),batarg("s",oid),arg("pat",str),arg("flags",str),arg("anti",bit))), + command("regexp", "rematchjoin", regexpmatchfjoin, false, "Return the matching pairs from the 'val' and 'pat'\ncolumns", args(2,9, batarg("lr",oid),batarg("rr",oid),batarg("val",str),batarg("pat",str),arg("flags",str),batarg("sl",oid),batarg("sr",oid),arg("nil_matches",bit),arg("estimate",lng))), + command("batregexp", "rematch", regexpmatchbulk, false, "Return a BAT with true for match and false for no match", args(1,3, batarg("",bit),batarg("val",str),arg("pat",str))), + command("batregexp", "rematch", regexpmatchfbulk, false, "Return a BAT with true for match and false for no match", args(1,4, batarg("",bit),batarg("val",str),arg("pat",str),arg("flags",str))), + { .imp=NULL } +}; + +#include "mal_import.h" +#include "sql_import.h" +#ifdef _MSC_VER +#undef read +#pragma section(".CRT$XCU",read) +#endif +LIB_STARTUP_FUNC(init_regexp) +{ + mal_module("regexp", NULL, regexp_init_funcs); + sql_register("regexp", regexp_sql); +}
--- a/reverse/CMakeLists.txt Tue Jun 16 10:11:57 2020 +0200 +++ b/reverse/CMakeLists.txt Tue Dec 15 14:13:55 2020 +0100 @@ -27,9 +27,12 @@ DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5/autoload) -install(FILES - 80_regexp.sql - DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5/createdb) +install(TARGETS + reverse + RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5) add_custom_command(OUTPUT README.html COMMAND "rst2html" "-d" "${CMAKE_SOURCE_DIR}/README.rst" "README.html")
--- a/reverse/reverse.c Tue Jun 16 10:11:57 2020 +0200 +++ b/reverse/reverse.c Tue Dec 15 14:13:55 2020 +0100 @@ -172,3 +172,25 @@ BBPunfix(bn->batCacheid); throw(MAL, "batreverse.reverse", MAL_MALLOC_FAIL); } + +#include "mel.h" + +static char reverse_sql[] = "CREATE FUNCTION reverse(src STRING) RETURNS STRING EXTERNAL NAME reverse.reverse;"; + +static mel_func reverse_init_funcs[] = { + command("reverse", "reverse", UDFreverse, false, "Reverse a string", args(1,2, arg("",str),arg("ra1",str))), + command("batreverse", "reverse", UDFBATreverse, false, "Reverse a BAT of strings", args(1,2, batarg("",str),batarg("b",str))), + { .imp=NULL } +}; + +#include "mal_import.h" +#include "sql_import.h" +#ifdef _MSC_VER +#undef read +#pragma section(".CRT$XCU",read) +#endif +LIB_STARTUP_FUNC(init_reverse) +{ + mal_module("reverse", NULL, reverse_init_funcs); + sql_register("reverse", reverse_sql); +}