Changeset: 38ffb6c1f195 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=38ffb6c1f195
Modified Files:
        monetdb5/mal/mal_linker.c
        monetdb5/mal/mal_profiler.c
        sql/backends/monet5/UDF/pyapi3/pyapi3.c
        testing/Mtest.py.in
Branch: default
Log Message:

Merge with Oct2020 branch.


diffs (truncated from 380 to 300 lines):

diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -502,20 +502,25 @@ malLibraryEnabled(str name)
        return true;
 }
 
-#define HOW_TO_ENABLE_ERROR(LANGUAGE, OPTION) \
-       if (malLibraryEnabled(name)) \
-               return "Embedded " LANGUAGE " has not been installed. Please 
install it first, then start server with --set " OPTION; \
-       return "Embedded " LANGUAGE " has not been enabled. Start server with 
--set " OPTION;
+#define HOW_TO_ENABLE_ERROR(LANGUAGE, OPTION)                                  
        \
+       do {                                                                    
                                                \
+               if (malLibraryEnabled(name))                                    
                        \
+                       return "Embedded " LANGUAGE " has not been installed. " 
\
+                               "Please install it first, then start server 
with "      \
+                               "--set " OPTION;                                
                                        \
+               return "Embedded " LANGUAGE " has not been enabled. "           
\
+                       "Start server with --set " OPTION;                      
                        \
+       } while (0)
 
 char *
 malLibraryHowToEnable(str name)
 {
        if (strcmp(name, "pyapi3") == 0 || strcmp(name, "pyapi3map") == 0) {
-               HOW_TO_ENABLE_ERROR("Python 3", "embedded_py=3")
+               HOW_TO_ENABLE_ERROR("Python 3", "embedded_py=3");
        } else if (strcmp(name, "rapi") == 0) {
-               HOW_TO_ENABLE_ERROR("R", "embedded_r=true")
+               HOW_TO_ENABLE_ERROR("R", "embedded_r=true");
        } else if (strcmp(name, "capi") == 0) {
-               HOW_TO_ENABLE_ERROR("C/C++", "embedded_c=true")
+               HOW_TO_ENABLE_ERROR("C/C++", "embedded_c=true");
        }
        return "";
 }
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -322,69 +322,73 @@ This information can be used to determin
  * We should use an OS define to react to the maximal cores
  */
 
+#define MAXCPU         256
+#define LASTCPU                (MAXCPU - 1)
 static struct{
        lng user, nice, system, idle, iowait;
        double load;
-} corestat[256];
+} corestat[MAXCPU];
 
 static int
 getCPULoad(char cpuload[BUFSIZ]){
     int cpu, len = 0, i;
        lng user, nice, system, idle, iowait;
        size_t n;
-    char buf[BUFSIZ+1], *s;
+    char buf[512], *s;
        static FILE *proc= NULL;
        lng newload;
 
-       if (proc == NULL || ferror(proc))
-               proc = fopen("/proc/stat","r");
-       else rewind(proc);
        if (proc == NULL) {
-               /* unexpected */
-               return -1;
-       }
-       /* read complete file to avoid concurrent write issues */
-       if ((n = fread(buf, 1, BUFSIZ,proc)) == 0)
-               return -1;
-       buf[n] = 0;
-       for (s= buf; *s; s++) {
-               if (strncmp(s,"cpu",3)== 0){
-                       s +=3;
+               proc = fopen("/proc/stat", "r");
+               if (proc == NULL) {
+                       /* unexpected */
+                       return -1;
+               }
+       } else
+               rewind(proc);
+
+       while (fgets(buf, (int) sizeof(buf), proc) != NULL) {
+               n = strlen(buf);
+               if (strncmp(buf, "cpu", 3) == 0) {
+                       s = buf + 3;
                        if (*s == ' ') {
-                               s++;
-                               cpu = 255; // the cpu totals stored here
+                               cpu = LASTCPU; // the cpu totals stored here
                        }  else {
                                cpu = atoi(s);
-                               if (cpu < 0 || cpu > 255)
-                                       cpu = 255;
+                               if (cpu < 0 || cpu > LASTCPU)
+                                       cpu = LASTCPU;
                        }
-                       s= strchr(s,' ');
+                       s = strchr(s,' ');
                        if (s == NULL)          /* unexpected format of file */
                                break;
+                       while (*s && isspace((unsigned char)*s))
+                               s++;
+                       i= sscanf(s, LLSCN" "LLSCN" "LLSCN" "LLSCN" "LLSCN,  
&user, &nice, &system, &idle, &iowait);
+                       if (i == 5) {
+                               newload = (user - corestat[cpu].user + nice - 
corestat[cpu].nice + system - corestat[cpu].system);
+                               if (newload)
+                                       corestat[cpu].load = (double) newload / 
(newload + idle - corestat[cpu].idle + iowait - corestat[cpu].iowait);
+                               corestat[cpu].user = user;
+                               corestat[cpu].nice = nice;
+                               corestat[cpu].system = system;
+                               corestat[cpu].idle = idle;
+                               corestat[cpu].iowait = iowait;
+                       }
+               }
 
-                       while( *s && isspace((unsigned char)*s)) s++;
-                       i= sscanf(s,LLSCN" "LLSCN" "LLSCN" "LLSCN" "LLSCN,  
&user, &nice, &system, &idle, &iowait);
-                       if ( i != 5 )
-                               goto skip;
-                       newload = (user - corestat[cpu].user + nice - 
corestat[cpu].nice + system - corestat[cpu].system);
-                       if ( newload)
-                               corestat[cpu].load = (double) newload / 
(newload + idle - corestat[cpu].idle + iowait - corestat[cpu].iowait);
-                       corestat[cpu].user = user;
-                       corestat[cpu].nice = nice;
-                       corestat[cpu].system = system;
-                       corestat[cpu].idle = idle;
-                       corestat[cpu].iowait = iowait;
+               while (buf[n - 1] != '\n') {
+                       if (fgets(buf, (int) sizeof(buf), proc) == NULL)
+                               goto exitloop;
+                       n = strlen(buf);
                }
-         skip:
-               while (*s && *s != '\n')
-                       s++;
        }
+  exitloop:
 
-       if(cpuload == 0)
+       if (cpuload == NULL)
                return 0;
        // identify core processing
        len += snprintf(cpuload, BUFSIZ, "[");
-       for (cpu = 0; cpuload && cpu < 255 && corestat[cpu].user; cpu++) {
+       for (cpu = 0; cpuload && cpu < LASTCPU && corestat[cpu].user; cpu++) {
                len +=snprintf(cpuload + len, BUFSIZ - len, "%s%.2f", 
(cpu?",":""), corestat[cpu].load);
        }
        (void) snprintf(cpuload + len, BUFSIZ - len, "]");
@@ -792,12 +796,12 @@ getDiskSpace(void)
 
 void profilerGetCPUStat(lng *user, lng *nice, lng *sys, lng *idle, lng *iowait)
 {
-       (void) getCPULoad(0);
-       *user = corestat[255].user;
-       *nice = corestat[255].nice;
-       *sys = corestat[255].system;
-       *idle = corestat[255].idle;
-       *iowait = corestat[255].iowait;
+       (void) getCPULoad(NULL);
+       *user = corestat[LASTCPU].user;
+       *nice = corestat[LASTCPU].nice;
+       *sys = corestat[LASTCPU].system;
+       *idle = corestat[LASTCPU].idle;
+       *iowait = corestat[LASTCPU].iowait;
 }
 
 /* the heartbeat process produces a ping event once every X milliseconds */
diff --git a/sql/backends/monet5/UDF/pyapi3/pyapi.h 
b/sql/backends/monet5/UDF/pyapi3/pyapi.h
--- a/sql/backends/monet5/UDF/pyapi3/pyapi.h
+++ b/sql/backends/monet5/UDF/pyapi3/pyapi.h
@@ -16,18 +16,6 @@
 
 #include "pyheader.h"
 
-/* not using PYFUNCNAME macro here to help the malcheck test perform
- * its work (it's a bit of a shame that we need to do this, but it's a
- * valuable test) */
-pyapi_export str PYAPI2PyAPIevalStd(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
-pyapi_export str PYAPI2PyAPIevalAggr(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
-pyapi_export str PYAPI2PyAPIevalStdMap(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
-pyapi_export str PYAPI2PyAPIevalAggrMap(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
-pyapi_export str PYAPI2PyAPIevalLoader(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
-
-pyapi_export str PYAPI2PyAPIprelude(void *ret);
-
-
 pyapi_export str PYAPI3PyAPIevalStd(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 pyapi_export str PYAPI3PyAPIevalAggr(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
 pyapi_export str PYAPI3PyAPIevalStdMap(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
@@ -36,7 +24,7 @@ pyapi_export str PYAPI3PyAPIevalLoader(C
 
 pyapi_export str PYAPI3PyAPIprelude(void *ret);
 
-bool PYFUNCNAME(PyAPIInitialized)(void);
+bool PYAPI3PyAPIInitialized(void);
 
 str _loader_init(void);
 
diff --git a/sql/backends/monet5/UDF/pyapi3/pyapi3.c 
b/sql/backends/monet5/UDF/pyapi3/pyapi3.c
--- a/sql/backends/monet5/UDF/pyapi3/pyapi3.c
+++ b/sql/backends/monet5/UDF/pyapi3/pyapi3.c
@@ -70,7 +70,7 @@ static const char *FunctionBasePath(void
 static MT_Lock pyapiLock = MT_LOCK_INITIALIZER(pyapiLock);
 static bool pyapiInitialized = false;
 
-bool PYFUNCNAME(PyAPIInitialized)(void) {
+bool PYAPI3PyAPIInitialized(void) {
        return pyapiInitialized;
 }
 
@@ -90,22 +90,22 @@ static str
 PyAPIeval(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, bool 
grouped, bool mapped);
 
 str
-PYFUNCNAME(PyAPIevalStd)(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci) {
+PYAPI3PyAPIevalStd(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
        return PyAPIeval(cntxt, mb, stk, pci, false, false);
 }
 
 str
-PYFUNCNAME(PyAPIevalStdMap)(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci) {
+PYAPI3PyAPIevalStdMap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) 
{
        return PyAPIeval(cntxt, mb, stk, pci, false, true);
 }
 
 str
-PYFUNCNAME(PyAPIevalAggr)(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci) {
+PYAPI3PyAPIevalAggr(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) {
        return PyAPIeval(cntxt, mb, stk, pci, true, false);
 }
 
 str
-PYFUNCNAME(PyAPIevalAggrMap)(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci) {
+PYAPI3PyAPIevalAggrMap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci) {
        return PyAPIeval(cntxt, mb, stk, pci, true, true);
 }
 
@@ -1320,7 +1320,7 @@ wrapup:
 }
 
 str
-PYFUNCNAME(PyAPIprelude)(void *ret) {
+PYAPI3PyAPIprelude(void *ret) {
        (void) ret;
        MT_lock_set(&pyapiLock);
        if (!pyapiInitialized) {
diff --git a/sql/backends/monet5/UDF/pyapi3/pyheader.h 
b/sql/backends/monet5/UDF/pyapi3/pyheader.h
--- a/sql/backends/monet5/UDF/pyapi3/pyheader.h
+++ b/sql/backends/monet5/UDF/pyapi3/pyheader.h
@@ -75,7 +75,6 @@
 #define PyInt_FromLong PyLong_FromLong
 #define PyInt_Check PyLong_Check
 #define PythonUnicodeType Py_UNICODE
-#define PYFUNCNAME(name) PYAPI3##name
 
 #define utf8string_minlength 256
 
diff --git a/sql/backends/monet5/UDF/pyapi3/pyloader3.c 
b/sql/backends/monet5/UDF/pyapi3/pyloader3.c
--- a/sql/backends/monet5/UDF/pyapi3/pyloader3.c
+++ b/sql/backends/monet5/UDF/pyapi3/pyloader3.c
@@ -44,7 +44,7 @@ pyapi_list_length(list *l)
 }
 
 str
-PYFUNCNAME(PyAPIevalLoader)(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci) {
+PYAPI3PyAPIevalLoader(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) 
{
     sql_func * sqlfun;
     sql_subfunc * sqlmorefun;
     str exprStr;
@@ -68,7 +68,7 @@ PYFUNCNAME(PyAPIevalLoader)(Client cntxt
 
        char *loader_additional_args[] = {"_emit", "_conn"};
 
-    if (!PYFUNCNAME(PyAPIInitialized())) {
+    if (!PYAPI3PyAPIInitialized()) {
         throw(MAL, "pyapi3.eval",
               SQLSTATE(PY000) "Embedded Python is enabled but an error was 
thrown during initialization.");
     }
diff --git a/sql/test/subquery/Tests/subquery6.sql 
b/sql/test/subquery/Tests/subquery6.sql
--- a/sql/test/subquery/Tests/subquery6.sql
+++ b/sql/test/subquery/Tests/subquery6.sql
@@ -249,6 +249,66 @@ select min(i) as myx from integers group
 select ntile(i) over (), count(*) from integers;
        --error, column "i" must appear in the GROUP BY clause or be used in an 
aggregate function
 
+select (select i2.i in (select sum(i1.i + i2.i)) from integers i2) from 
integers i1;
+       --error, column "i2.i" must appear in the GROUP BY clause or be used in 
an aggregate function
+
+select (select i2.i in (select sum(i1.i + i2.i)) from integers i2) from 
integers i1 group by i1.i;
+       --error, column "i2.i" must appear in the GROUP BY clause or be used in 
an aggregate function
+
+select (select i2.i in (select sum(i1.i + i2.i)) from integers i2 group by 
i2.i) from integers i1;
+       --error, more than one row returned by a subquery used as an expression
+
+select (select i2.i in (select sum(i1.i + i2.i)) from integers i2 group by 
i2.i) from integers i1 group by i1.i;
+       --error, more than one row returned by a subquery used as an expression
+
+select (select sum(i2.i) in (select sum(i1.i + i2.i)) from integers i2 group 
by i2.i) from integers i1 group by i1.i;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to