Changeset: 599c4ed8e37d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=599c4ed8e37d
Modified Files:
        monetdb5/mal/mal_linker.mx
        sql/backends/monet5/sql.mx
        sql/backends/monet5/sql_optimizer.mx
        sql/backends/monet5/sql_scenario.mx
Branch: default
Log Message:

Merged from Mar2011


diffs (truncated from 391 to 300 lines):

diff --git a/monetdb5/extras/sphinx/sphinx.mx b/monetdb5/extras/sphinx/sphinx.mx
--- a/monetdb5/extras/sphinx/sphinx.mx
+++ b/monetdb5/extras/sphinx/sphinx.mx
@@ -19,7 +19,7 @@
 
 @f sphinx
 @a S.A.M.M. de Konink
-@v 0.1
+@v 0.2
 @* The Sphinx module
 The Sphinx module implements an external full text search engine returning a
 list of identifiers based on a query string and an index to search upon.
@@ -27,17 +27,35 @@
 @mal
 module sphinx;
 
-command search(q:str) :bat[:int,:lng]
-address SPHINXsearch
-comment "Searches the query on all indices";
+command searchIndexLimit(q:str, i:str, l:int) :bat[:oid,:lng]
+address SPHINXsearchIndexLimit
+comment "Search the query on the specified index, with limit";
 
-command searchIndex(q:str, i:str) :bat[:oid,:lng]
-address SPHINXsearchIndex
-comment "Search the query on the specified indices";
+function search(q:str) :bat[:oid,:lng];
+       ret := searchIndexLimit(q, "*", 20);
+       return ret;
+end search;
 
-pattern sphinx_searchIndex(q:str, i:str) :bat[:str,:bat]
-address SPHINXsearchIndexWrap
-comment "Searches the query on all indices";
+function searchIndex(q:str, i:str) :bat[:oid,:lng];
+       ret := searchIndexLimit(q, i, 20);
+       return ret;
+end searchIndex;
+
+
+pattern sphinx_searchIndexLimit(q:str, i:str, l:int) :bat[:str,:bat]
+address SPHINXsearchIndexLimitWrap
+comment "Search the query on the specified index, with limit";
+
+function sphinx_search(q:str) :bat[:str,:bat];
+       ret := sphinx_searchIndexLimit(q, "*", 20);
+       return ret;
+end sphinx_search;
+
+function sphinx_searchIndex(q:str, i:str) :bat[:str,:bat];
+       ret := sphinx_searchIndexLimit(q, i, 20);
+       return ret;
+end sphinx_searchIndex;
+
 
 @h
 #ifndef SPHINX_H
@@ -59,9 +77,7 @@
 #define sphinx_export extern
 #endif
 
-sphinx_export str SPHINXsearch(int *ret, str *query);
-sphinx_export str SPHINXsearchIndex(int *ret, str *query, str *index);
-sphinx_export str SPHINXsearchIndexWrap(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
+sphinx_export str SPHINXsearchIndexLimitWrap(Client cntxt, MalBlkPtr mb, 
MalStkPtr stk, InstrPtr pci);
 
 #endif /* SPHINX_H */
 
@@ -73,11 +89,11 @@
 #include "mal_exception.h"
 #include <sphinxclient.h>
 
-/* COMMAND "SPHINXsearchIndex": Search the query on the specified indices
- * SIGNATURE: SPHINXsearchIndex(str, str) : bat[oid,lng]; */
+/* COMMAND "SPHINXsearchIndexLimit": Search the query on the specified 
indices, with limit
+ * SIGNATURE: SPHINXsearchIndexLimit(str, str, int) : bat[oid,lng]; */
 str
-sphinx_searchIndex(BAT **ret, /* put pointer to BAT[oid,int] record here. */
-                   str query, str index)
+sphinx_searchIndexLimit(BAT **ret, /* put pointer to BAT[oid,int] record here. 
*/
+                        str query, str index, int limit)
 {
        int i;
        BAT *bn;
@@ -87,7 +103,9 @@
 
        client = sphinx_create ( SPH_TRUE );
        if (client == NULL)
-               throw(MAL, "sphinx.searchIndex", "Cannot create Sphinx object");
+               throw(MAL, "sphinx.searchIndexLimit", "Cannot create Sphinx 
object");
+
+       sphinx_set_limits ( client, 0, limit, limit, 0 );
 
        res = sphinx_query ( client, query, index, NULL );
        if (!res || (res && res->num_matches == 0)) {
@@ -113,10 +131,10 @@
 }
 
 str
-SPHINXsearchIndex(int *ret, str *query, str *index)
+SPHINXsearchIndexLimit(int *ret, str *query, str *index, int *limit)
 {
        BAT *b = NULL;
-       str msg = sphinx_searchIndex(&b, *query, *index);
+       str msg = sphinx_searchIndexLimit(&b, *query, *index, *limit);
 
        if (!b)
                throw(MAL, "sphinx.searchIndex", "Cannot create Sphinx object");
@@ -125,26 +143,20 @@
        return msg;
 }
 
+/* str sphinx_searchIndexLimit(int *ret, str *query, str *index, int *limit); 
*/
 str
-SPHINXsearch(int *ret, str *query)
-{
-       str index = "*";
-       return SPHINXsearchIndex(ret, query, &index);
-}
-
-/* str sphinx_searchIndex(int *ret, str *query, str *index); */
-str
-SPHINXsearchIndexWrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+SPHINXsearchIndexLimitWrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
        bat ret;
        BAT *t;
        int *r = (int *) getArgReference(stk, pci, 0);
        str *query = (str *) getArgReference(stk, pci, 1);
        str *index = (str *) getArgReference(stk, pci, 2);
+       int *limit = (int *) getArgReference(stk, pci, 3);
 
        (void) cntxt;
        (void) mb;
-       SPHINXsearchIndex(&ret, query, index);
+       SPHINXsearchIndexLimit(&ret, query, index, limit);
 
        t = BATnew(TYPE_str, TYPE_bat, 1);
        BUNins(t, "id", &ret, FALSE);
diff --git a/monetdb5/mal/mal_linker.mx b/monetdb5/mal/mal_linker.mx
--- a/monetdb5/mal/mal_linker.mx
+++ b/monetdb5/mal/mal_linker.mx
@@ -66,7 +66,6 @@
 mal_export MALfcn getAddress(str filename, str modnme, str fcnname,int silent);
 mal_export char *MSP_locate_script(const char *mod_name);
 mal_export char *MSP_locate_sqlscript(const char *mod_name, bit recurse);
-mal_export char *MSP_locate_file(const char *mod_name);
 mal_export str loadLibrary(str modulename, int flag);
 mal_export void unloadLibraries(void);
 mal_export void initLibraries(void);
@@ -221,39 +220,84 @@
        int mode = RTLD_NOW | RTLD_GLOBAL;
        char nme[MAXPATHLEN];
        void *handle = NULL;
-       str fullname, s;
+       str s;
        int idx;
        const char *errmsg;
+       char *mod_path = GDKgetenv("monet_mod_path");
+
+       /* AIX requires RTLD_MEMBER to load a module that is a member of an
+        * archive.  */
+#ifdef RTLD_MEMBER
+       mode |= RTLD_MEMBER;
+#endif
 
        for (idx = 0; filesLoaded[idx].filename && idx < lastfile; idx++)
                if (strcmp(filesLoaded[idx].filename, filename) == 0)
                        /* already loaded */
                        return MAL_SUCCEED;
-@-
-Use the search path provided in the configuration file
-@c
-       s = strrchr(filename, DIR_SEP);
-       snprintf(nme, MAXPATHLEN, "_%s", s ? s + 1 : filename);
-       fullname = MSP_locate_file(nme);
 
-       if (fullname == NULL) {
-               if( flag)
-                       throw(LOADER, "loadLibrary", RUNTIME_FILE_NOT_FOUND 
":%s", filename);
+       /* ignore any path given */
+       if ((s = strrchr(filename, DIR_SEP)) == NULL)
+               s = filename;
+
+       if (mod_path != NULL) {
+               while (*mod_path == PATH_SEP)
+                       mod_path++;
+               if (*mod_path == 0)
+                       mod_path = NULL;
+       }
+       if (mod_path == NULL) {
+               if (flag)
+                       throw(LOADER, "loadLibrary", RUNTIME_FILE_NOT_FOUND 
":%s", s);
                return MAL_SUCCEED;
        }
 
-/* AIX requires RTLD_MEMBER to load a module that is a member of an archive.  
*/
-#ifdef RTLD_MEMBER
-       mode |= RTLD_MEMBER;
+       while (*mod_path) {
+               char *p;
+
+               if ((p = strchr(mod_path, PATH_SEP)) != NULL)
+                       *p = '\0';
+               /* try hardcoded SO_EXT if that is the same for modules */
+#ifdef _AIX
+               snprintf(nme, MAXPATHLEN, "%s%c%s_%s%s(%s_%s.0)",
+                               mod_path, DIR_SEP, SO_PREFIX, s, SO_EXT, 
SO_PREFIX, s);
+#else
+               snprintf(nme, MAXPATHLEN, "%s%c%s_%s%s",
+                               mod_path, DIR_SEP, SO_PREFIX, s, SO_EXT);
 #endif
+               handle = dlopen(nme, mode);
+               /* try .so */
+               if (handle == NULL && strcmp(SO_EXT, ".so") != 0) {
+                       snprintf(nme, MAXPATHLEN, "%s%c%s_%s.so",
+                                       mod_path, DIR_SEP, SO_PREFIX, s);
+                       handle = dlopen(nme, mode);
+               }
+#ifdef __APPLE__
+               /* try .bundle */
+               if (handle == NULL && strcmp(SO_EXT, ".bundle") != 0) {
+                       snprintf(nme, MAXPATHLEN, "%s%c%s_%s.bundle",
+                                       mod_path, DIR_SEP, SO_PREFIX, s);
+                       handle = dlopen(nme, mode);
+               }
+#endif
+               if (handle != NULL) {
+                       if (p != NULL)
+                               *p = PATH_SEP;
+                       break;
+               }
 
-       handle = dlopen(fullname, mode);
+               if (p == NULL)
+                       break;
+               *p = PATH_SEP;
+               mod_path = p + 1;
+       }
+
        if (handle == NULL) {
                errmsg = dlerror();
                if (!errmsg) 
-                       errmsg = "(no error from dlerror())";
-               GDKfree(fullname);
-               throw(LOADER, "loadLibrary", RUNTIME_LOAD_ERROR " '%s' from 
within file '%s'", errmsg, filename);
+                       errmsg = "could not locate or open library";
+               if (flag)
+                       throw(LOADER, "loadLibrary", RUNTIME_LOAD_ERROR " '%s' 
from within file '%s'", errmsg, filename);
        }
 
        mal_set_lock(mal_contextLock, "loadModule");
@@ -261,7 +305,7 @@
                showException(MAL,"loadModule", "internal error, too many 
modules loaded");
        } else {
                filesLoaded[lastfile].filename = GDKstrdup(filename);
-               filesLoaded[lastfile].fullname = fullname;
+               filesLoaded[lastfile].fullname = GDKstrdup(nme);
                filesLoaded[lastfile].handle = handle;
                lastfile ++;
        }
@@ -467,24 +511,4 @@
        /* no directory semantics (yet) */
        return locate_file(filename, SQL_EXT, recurse);
 }
-
-char *
-MSP_locate_file(const char *filename)
-{
-       char *lib_name = GDKmalloc(strlen(filename) + strlen(SO_PREFIX) + 1);
-       char *fullname;
-
-       strcpy(lib_name, SO_PREFIX);
-       strcpy(lib_name + strlen(SO_PREFIX), filename);
-
-       fullname = locate_file(lib_name, SO_EXT, 0);
-#ifdef _AIX
-       fullname = GDKrealloc(fullname, strlen(fullname) + strlen(lib_name) + 
5);
-       strcat(fullname, "(");
-       strcat(fullname, lib_name);
-       strcat(fullname, ".0)");
-#endif
-       GDKfree(lib_name);
-       return fullname;
-}
 @}
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -477,10 +477,6 @@
 address dump_trace
 comment "dump the trace statistics";
 
-pattern dump_slave() :bat[:str,:bat]
-address dump_slave
-comment "Dump the status of the slave synchronization";
-
 pattern storage():bat[:str,:bat]
 address sql_storage
 comment "return a table with storage information ";
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to