[Commits] Rev 4618: Merge in lp:~maria-captains/maria/10.0

Sergei Golubchik serg at mariadb.org
Tue Feb 24 15:17:05 EET 2015


At lp:~maria-captains/maria/10.0

------------------------------------------------------------
revno: 4618 [merge]
revision-id: sergii at pisem.net-20150224131700-aivkhzqi5rbvpo3l
parent: jplindst at mariadb.org-20150224083349-78kx1llk7b0lk96u
parent: bertrandop at gmail.com-20150222165302-evsx01py0hsyh4f1
committer: Sergei Golubchik <sergii at pisem.net>
branch nick: 10.0
timestamp: Tue 2015-02-24 14:17:00 +0100
message:
  Merge
modified:
  storage/connect/global.h       global.h-20130118152109-mmnrlp4ll8csqtqq-17
  storage/connect/ha_connect.cc  ha_connect.cc-20130118152127-2616haw0q36d4dmb-2
  storage/connect/json.cpp       json.cpp-20150115143630-dawznhps8fdj3qme-1
  storage/connect/jsonudf.cpp    jsonudf.cpp-20150211203816-gtd88lms33bcgfg4-1
  storage/connect/plgdbutl.cpp   plgdbutl.cpp-20130118152118-8rznf4ulkgxm3gnq-16
  storage/connect/plugutil.c     plugutil.c-20130118152132-uyiyr9tgvg0qtd52-4
  storage/connect/tabjson.cpp    tabjson.cpp-20150115143639-v2h2q40gysdrmpk6-1
  storage/connect/tabodbc.cpp    tabodbc.cpp-20130118152118-8rznf4ulkgxm3gnq-27
=== modified file 'storage/connect/global.h'
--- a/storage/connect/global.h	2014-11-15 17:28:24 +0000
+++ b/storage/connect/global.h	2015-02-22 16:53:02 +0000
@@ -235,7 +235,7 @@ typedef struct _global {            /* G
   void     *Xchk;                   /* indexes in create/alter         */
   short     Alchecked;              /* Checked for ALTER               */
   short     Mrr;                    /* True when doing mrr             */
-  short     Trace;
+  int       N;                      /* Utility                         */
   int       jump_level;
   jmp_buf   jumper[MAX_JUMP + 2];
   } GLOBAL;

=== modified file 'storage/connect/ha_connect.cc'
--- a/storage/connect/ha_connect.cc	2015-02-11 20:39:41 +0000
+++ b/storage/connect/ha_connect.cc	2015-02-22 16:53:02 +0000
@@ -165,9 +165,10 @@
 /***********************************************************************/
 /*  Initialize the ha_connect static members.                          */
 /***********************************************************************/
-#define SZCONV 8192
-#define SZWORK 67108864            // Default work area size 64M
-#define SZWMIN 4194304             // Minimum work area size  4M
+#define SZCONV     8192
+#define SZWORK 67108864             // Default work area size 64M
+#define SZWMIN  4194304             // Minimum work area size  4M
+#define JSONMAX      10             // JSON Default max grp size
 
 extern "C" {
        char  version[]= "Version 1.03.0006 February 06, 2015";
@@ -217,6 +218,7 @@ bool    ExactInfo(void);
 USETEMP UseTemp(void);
 int     GetConvSize(void);
 TYPCONV GetTypeConv(void);
+uint    GetJsonGrpSize(void);
 uint    GetWorkSize(void);
 void    SetWorkSize(uint);
 extern "C" const char *msglang(void);
@@ -323,6 +325,12 @@ static MYSQL_THDVAR_ENUM(
   0,                               // def (no)
   &xconv_typelib);                 // typelib
 
+// Estimate max number of rows for JSON aggregate functions
+static MYSQL_THDVAR_UINT(json_grp_size,
+       PLUGIN_VAR_RQCMDARG,             // opt
+       "max number of rows for JSON aggregate functions.",
+       NULL, NULL, JSONMAX, 1, INT_MAX, 1);
+
 #if defined(XMSG) || defined(NEWMSG)
 const char *language_names[]=
 {
@@ -353,6 +361,7 @@ bool ExactInfo(void) {return THDVAR(curr
 USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);}
 int GetConvSize(void) {return THDVAR(current_thd, conv_size);}
 TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
+uint GetJsonGrpSize(void) {return THDVAR(current_thd, json_grp_size);}
 uint GetWorkSize(void) {return THDVAR(current_thd, work_size);}
 void SetWorkSize(uint n) 
 {
@@ -6516,6 +6525,7 @@ static struct st_mysql_sys_var* connect_
 #if defined(XMSG)
   MYSQL_SYSVAR(errmsg_dir_path),
 #endif   // XMSG
+  MYSQL_SYSVAR(json_grp_size),
   NULL
 };
 

=== modified file 'storage/connect/json.cpp'
--- a/storage/connect/json.cpp	2015-02-18 23:59:02 +0000
+++ b/storage/connect/json.cpp	2015-02-22 16:53:02 +0000
@@ -74,6 +74,7 @@ PJSON ParseJson(PGLOBAL g, char *s, int
           goto err;
         } else if (!(jsp = ParseObject(g, ++i, src)))
           goto err;
+
         break;
       case ' ':
       case '\t':
@@ -90,6 +91,11 @@ PJSON ParseJson(PGLOBAL g, char *s, int
 
         sprintf(g->Message, "Unexpected ',' (pretty=%d)", pretty);
         goto err;
+      case '"':
+        if (!(jsp = ParseValue(g, i, src)))
+          goto err;
+
+        break;
       case '(':
         b = true;
         break;

=== modified file 'storage/connect/jsonudf.cpp'
--- a/storage/connect/jsonudf.cpp	2015-02-19 00:25:31 +0000
+++ b/storage/connect/jsonudf.cpp	2015-02-22 16:53:02 +0000
@@ -8,12 +8,18 @@
 /*  Include relevant sections of the MariaDB header file.              */
 /***********************************************************************/
 #include <my_global.h>
+#include <mysqld.h>
 #include <mysql.h>
+#include <sql_error.h>
 
 #include "global.h"
 #include "plgdbsem.h"
 #include "json.h"
 
+#define MEMFIX  512
+
+uint GetJsonGrpSize(void);
+
 extern "C" {
 DllExport my_bool Json_Value_init(UDF_INIT*, UDF_ARGS*, char*);
 DllExport char *Json_Value(UDF_INIT*, UDF_ARGS*, char*,
@@ -23,6 +29,10 @@ DllExport my_bool Json_Array_init(UDF_IN
 DllExport char *Json_Array(UDF_INIT*, UDF_ARGS*, char*,
                          unsigned long*, char *, char *);
 DllExport void Json_Array_deinit(UDF_INIT*);
+DllExport my_bool Json_Array_Add_init(UDF_INIT*, UDF_ARGS*, char*);
+DllExport char *Json_Array_Add(UDF_INIT*, UDF_ARGS*, char*,
+                         unsigned long*, char *, char *);
+DllExport void Json_Array_Add_deinit(UDF_INIT*);
 DllExport my_bool Json_Object_init(UDF_INIT*, UDF_ARGS*, char*);
 DllExport char *Json_Object(UDF_INIT*, UDF_ARGS*, char*,
                          unsigned long*, char *, char *);
@@ -44,8 +54,8 @@ DllExport void Json_Object_Grp_deinit(UD
 /***********************************************************************/
 /*  Allocate and initialise the memory area.                           */
 /***********************************************************************/
-static my_bool JsonInit(UDF_INIT *initid, char *message, unsigned long reslen,
-                                                  unsigned long memlen)
+static my_bool JsonInit(UDF_INIT *initid, char *message, 
+                        unsigned long reslen, unsigned long memlen)
 {
   PGLOBAL g = PlugInit(NULL, memlen);
 
@@ -119,7 +129,7 @@ static my_bool CalcLen(UDF_ARGS *args, m
     } // endfor i
 
   // Calculate the amount of memory needed
-  memlen = 1024 + sizeof(JOUTSTR) + reslen;
+  memlen = MEMFIX + sizeof(JOUTSTR) + reslen;
 
   for (i = 0; i < args->arg_count; i++) {
     memlen += (args->lengths[i] + sizeof(JVALUE));
@@ -219,14 +229,23 @@ static PSZ MakeKey(PGLOBAL g, UDF_ARGS *
 static PJVAL MakeValue(PGLOBAL g, UDF_ARGS *args, int i)
 {
   char *sap = args->args[i];
+  PJSON jsp;
   PJVAL jvp = new(g) JVALUE;
 
   if (sap) switch (args->arg_type[i]) {
     case STRING_RESULT:
       if (args->lengths[i]) {
-        if (IsJson(args, i))
-          jvp->SetValue(ParseJson(g, sap, args->lengths[i], 0));
-        else
+        if (IsJson(args, i)) {
+          if (!(jsp = ParseJson(g, sap, args->lengths[i], 0)))
+            push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, 
+                         g->Message);
+
+          if (jsp && jsp->GetType() == TYPE_JVAL)
+            jvp = (PJVAL)jsp;
+          else
+            jvp->SetValue(jsp);
+
+        } else
           jvp->SetString(g, MakePSZ(g, args, i));
 
         } // endif str
@@ -329,6 +348,59 @@ void Json_Array_deinit(UDF_INIT* initid)
 } // end of Json_Array_deinit
 
 /***********************************************************************/
+/*  Add values to a Json array.                                        */
+/***********************************************************************/
+my_bool Json_Array_Add_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+  unsigned long reslen, memlen;
+
+  if (args->arg_count < 2) {
+    strcpy(message, "Json_Value_Add must have at least 2 arguments");
+    return true;
+  } else if (!IsJson(args, 0)) {
+    strcpy(message, "Json_Value_Add first argument must be a json array");
+    return true;
+  } else
+    CalcLen(args, false, reslen, memlen);
+
+  return JsonInit(initid, message, reslen, memlen);
+} // end of Json_Array_Add_init
+
+char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, 
+                unsigned long *res_length, char *is_null, char *error)
+{
+  char   *str;
+  PJVAL   jvp;
+  PJAR    arp;
+  PGLOBAL g = (PGLOBAL)initid->ptr;
+
+  PlugSubSet(g, g->Sarea, g->Sarea_Size);
+  jvp = MakeValue(g, args, 0);
+
+  if (jvp->GetValType() != TYPE_JAR) {
+    arp = new(g) JARRAY;
+    arp->AddValue(g, jvp);
+  } else
+    arp = jvp->GetArray();
+
+  for (uint i = 1; i < args->arg_count; i++)
+    arp->AddValue(g, MakeValue(g, args, i));
+
+  arp->InitArray(g);
+
+  if (!(str = Serialize(g, arp, NULL, 0)))
+    str = strcpy(result, g->Message);
+
+  *res_length = strlen(str);
+  return str;
+} // end of Json_Array_Add
+
+void Json_Array_Add_deinit(UDF_INIT* initid)
+{
+  PlugExit((PGLOBAL)initid->ptr);
+} // end of Json_Array_Add_deinit
+
+/***********************************************************************/
 /*  Make a Json Oject containing all the parameters.                   */
 /***********************************************************************/
 my_bool Json_Object_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
@@ -370,7 +442,7 @@ void Json_Object_deinit(UDF_INIT* initid
 /***********************************************************************/
 my_bool Json_Array_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
 {
-  unsigned long reslen, memlen, n = 10;
+  unsigned long reslen, memlen, n = GetJsonGrpSize();
 
   if (args->arg_count != 1) {
     strcpy(message, "Json_Array_Grp can only accept 1 argument");
@@ -379,7 +451,7 @@ my_bool Json_Array_Grp_init(UDF_INIT *in
     CalcLen(args, false, reslen, memlen);
   
   reslen *= n;
-  memlen *= n;
+  memlen += ((memlen - MEMFIX) * (n - 1));
 
   if (JsonInit(initid, message, reslen, memlen))
     return true;
@@ -388,6 +460,7 @@ my_bool Json_Array_Grp_init(UDF_INIT *in
 
   PlugSubSet(g, g->Sarea, g->Sarea_Size);
   g->Activityp = (PACTIVITY)new(g) JARRAY;
+  g->N = (int)n;
   return false;
 } // end of Json_Array_Grp_init
 
@@ -397,7 +470,9 @@ void Json_Array_Grp_add(UDF_INIT *initid
   PGLOBAL g = (PGLOBAL)initid->ptr;
   PJAR    arp = (PJAR)g->Activityp;
 
-  arp->AddValue(g, MakeValue(g, args, 0));
+  if (g->N-- > 0)
+    arp->AddValue(g, MakeValue(g, args, 0));
+
 } // end of Json_Array_Grp_add
 
 char *Json_Array_Grp(UDF_INIT *initid, UDF_ARGS *args, char *result, 
@@ -407,6 +482,10 @@ char *Json_Array_Grp(UDF_INIT *initid, U
   PGLOBAL g = (PGLOBAL)initid->ptr;
   PJAR    arp = (PJAR)g->Activityp;
 
+  if (g->N < 0)
+    push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, 
+                 "Result truncated to json_grp_size values");
+
   arp->InitArray(g);
 
   if (!(str = Serialize(g, arp, NULL, 0)))
@@ -422,6 +501,7 @@ void Json_Array_Grp_clear(UDF_INIT *init
 
   PlugSubSet(g, g->Sarea, g->Sarea_Size);
   g->Activityp = (PACTIVITY)new(g) JARRAY;
+  g->N = GetJsonGrpSize();
 } // end of Json_Array_Grp_clear
 
 void Json_Array_Grp_deinit(UDF_INIT* initid)
@@ -434,7 +514,7 @@ void Json_Array_Grp_deinit(UDF_INIT* ini
 /***********************************************************************/
 my_bool Json_Object_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
 {
-  unsigned long reslen, memlen, n = 10;
+  unsigned long reslen, memlen, n = GetJsonGrpSize();
 
   if (args->arg_count != 2) {
     strcpy(message, "Json_Array_Grp can only accept 2 argument");
@@ -443,7 +523,7 @@ my_bool Json_Object_Grp_init(UDF_INIT *i
     CalcLen(args, true, reslen, memlen);
   
   reslen *= n;
-  memlen *= n;
+  memlen += ((memlen - MEMFIX) * (n - 1));
 
   if (JsonInit(initid, message, reslen, memlen))
     return true;
@@ -452,6 +532,7 @@ my_bool Json_Object_Grp_init(UDF_INIT *i
 
   PlugSubSet(g, g->Sarea, g->Sarea_Size);
   g->Activityp = (PACTIVITY)new(g) JOBJECT;
+  g->N = (int)n;
   return false;
 } // end of Json_Object_Grp_init
 
@@ -461,7 +542,9 @@ void Json_Object_Grp_add(UDF_INIT *initi
   PGLOBAL g = (PGLOBAL)initid->ptr;
   PJOB    objp = (PJOB)g->Activityp;
 
-  objp->SetValue(g, MakeValue(g, args, 0), MakePSZ(g, args, 1)); 
+  if (g->N-- > 0)
+    objp->SetValue(g, MakeValue(g, args, 0), MakePSZ(g, args, 1));
+
 } // end of Json_Object_Grp_add
 
 char *Json_Object_Grp(UDF_INIT *initid, UDF_ARGS *args, char *result, 
@@ -471,6 +554,10 @@ char *Json_Object_Grp(UDF_INIT *initid,
   PGLOBAL g = (PGLOBAL)initid->ptr;
   PJOB    objp = (PJOB)g->Activityp;
 
+  if (g->N < 0)
+    push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, 
+                 "Result truncated to json_grp_size values");
+
   if (!(str = Serialize(g, objp, NULL, 0)))
     str = strcpy(result, g->Message);
 
@@ -484,6 +571,7 @@ void Json_Object_Grp_clear(UDF_INIT *ini
 
   PlugSubSet(g, g->Sarea, g->Sarea_Size);
   g->Activityp = (PACTIVITY)new(g) JOBJECT;
+  g->N = GetJsonGrpSize();
 } // end of Json_Object_Grp_clear
 
 void Json_Object_Grp_deinit(UDF_INIT* initid)

=== modified file 'storage/connect/plgdbutl.cpp'
--- a/storage/connect/plgdbutl.cpp	2014-11-16 00:16:51 +0000
+++ b/storage/connect/plgdbutl.cpp	2015-02-22 16:53:02 +0000
@@ -311,7 +311,7 @@ PQRYRES PlgAllocResult(PGLOBAL g, int nc
     else
       crp->Kdata = NULL;
 
-    if (g->Trace)
+    if (trace)
       htrc("Column(%d) %s type=%d len=%d value=%p\n",
               crp->Ncol, crp->Name, crp->Type, crp->Length, crp->Kdata);
 

=== modified file 'storage/connect/plugutil.c'
--- a/storage/connect/plugutil.c	2014-11-15 17:28:24 +0000
+++ b/storage/connect/plugutil.c	2015-02-22 16:53:02 +0000
@@ -144,12 +144,12 @@ PGLOBAL PlugInit(LPCSTR Language, uint w
     return NULL;
   } else {
     g->Sarea_Size = worksize;
-    g->Trace = 0;
     g->Createas = 0;
     g->Alchecked = 0;
     g->Mrr = 0;
     g->Activityp = g->ActivityStart = NULL;
     g->Xchk = NULL;
+    g->N = 0;
     strcpy(g->Message, "");
 
     /*******************************************************************/

=== modified file 'storage/connect/tabjson.cpp'
--- a/storage/connect/tabjson.cpp	2015-02-18 23:59:02 +0000
+++ b/storage/connect/tabjson.cpp	2015-02-22 16:53:02 +0000
@@ -931,7 +931,11 @@ void JSONCOL::WriteColumn(PGLOBAL g)
     case TYPE_STRING:
       if (Nodes[Nod-1].Op == OP_XX) {
         s = Value->GetCharValue();
-        jsp = ParseJson(g, s, (int)strlen(s), 0);
+
+        if (!(jsp = ParseJson(g, s, (int)strlen(s), 0))) {
+          strcpy(g->Message, s);
+          longjmp(g->jumper[g->jump_level], 666);
+          } // endif jsp
 
         if (arp) {
           if (Nod > 1 && Nodes[Nod-2].Rank)

=== modified file 'storage/connect/tabodbc.cpp'
--- a/storage/connect/tabodbc.cpp	2015-02-08 17:17:29 +0000
+++ b/storage/connect/tabodbc.cpp	2015-02-22 16:53:02 +0000
@@ -787,7 +787,7 @@ bool TDBODBC::OpenDB(PGLOBAL g)
   {
   bool rc = true;
 
-  if (g->Trace)
+  if (trace)
     htrc("ODBC OpenDB: tdbp=%p tdb=R%d use=%dmode=%d\n",
             this, Tdb_No, Use, Mode);
 
@@ -1185,12 +1185,12 @@ void ODBCCOL::ReadColumn(PGLOBAL g)
 
   } // endif Buf_Type
 
-  if (g->Trace) {
+  if (trace) {
     char buf[64];
 
     htrc("ODBC Column %s: rows=%d buf=%p type=%d value=%s\n",
       Name, tdbp->Rows, Bufp, Buf_Type, Value->GetCharString(buf));
-    } // endif Trace
+    } // endif trace
 
  put:
   if (tdbp->Memory != 2)
@@ -1424,7 +1424,7 @@ bool TDBXDBC::OpenDB(PGLOBAL g)
   {
   bool rc = false;
 
-  if (g->Trace)
+  if (trace)
     htrc("ODBC OpenDB: tdbp=%p tdb=R%d use=%dmode=%d\n",
             this, Tdb_No, Use, Mode);
 



More information about the commits mailing list