summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2021-05-05 00:31:21 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2021-05-05 00:31:21 +0200
commit5ae67c6d6387fa6e5c207fd9aea6741fb78073a5 (patch)
tree19eb0904944a35e6869030d004e6aa85e5313f6d
parent3b5dabeb96167c35df66475c5cb9be083065e941 (diff)
downloadmariadb-git-5ae67c6d6387fa6e5c207fd9aea6741fb78073a5.tar.gz
- All this concern Json or Mongo tables based on MongoDB collections.
- Limit decimals of doubles printed from MongoDB Done in function Mini for Mongo C Driver and Java Driver Done in function SerializeValue for Java tables using the J Driver modified: storage/connect/cmgoconn.cpp modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/tabjmg.cpp - Fix crash when using BSON_TYPE_DECIMAL128 modified: storage/connect/cmgoconn.cpp - Collection name default to table name Fix it when creating tables via discovery modified: storage/connect/ha_connect.cc modified: storage/connect/tabbson.cpp modified: storage/connect/tabjson.cpp
-rw-r--r--storage/connect/cmgoconn.cpp58
-rw-r--r--storage/connect/ha_connect.cc7
-rw-r--r--storage/connect/json.cpp5
-rw-r--r--storage/connect/json.h4
-rw-r--r--storage/connect/tabbson.cpp3
-rw-r--r--storage/connect/tabjmg.cpp1
-rw-r--r--storage/connect/tabjson.cpp3
7 files changed, 53 insertions, 28 deletions
diff --git a/storage/connect/cmgoconn.cpp b/storage/connect/cmgoconn.cpp
index cd2a8b63cdb..91952ab0706 100644
--- a/storage/connect/cmgoconn.cpp
+++ b/storage/connect/cmgoconn.cpp
@@ -26,6 +26,7 @@ bool CMgoConn::IsInit = false;
bool IsArray(PSZ s);
bool MakeSelector(PGLOBAL g, PFIL fp, PSTRG s);
+int GetDefaultPrec(void);
/* --------------------------- Class INCOL --------------------------- */
@@ -563,7 +564,7 @@ void CMgoConn::ShowDocument(bson_iter_t *iter, const bson_t *doc, const char *k)
htrc("%s.%s=%s\n", k, key, str);
} break;
case BSON_TYPE_DECIMAL128: {
- char* str = NULL;
+ char str[BSON_DECIMAL128_STRING];
bson_decimal128_t dec;
bson_iter_decimal128(iter, &dec);
@@ -805,23 +806,51 @@ void CMgoConn::Close(void)
/***********************************************************************/
char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
{
- char *s, *str = NULL;
- char *Mbuf = (char*)PlugSubAlloc(g, NULL, (size_t)colp->GetLength() + 1);
- int i, k = 0;
- bool ok = true;
+ char *s, *str = NULL;
+ char *Mbuf = (char*)PlugSubAlloc(g, NULL, (size_t)colp->GetLength() + 1);
+ int i, j = 0, k = 0, n = 0, m = GetDefaultPrec();
+ bool ok = true, dbl = false;
+ double d;
+ size_t len;
if (b)
- s = str = bson_array_as_json(bson, NULL);
+ s = str = bson_array_as_json(bson, &len);
else
- s = str = bson_as_json(bson, NULL);
+ s = str = bson_as_json(bson, &len);
+
+ if (len > (size_t)colp->GetLength()) {
+ sprintf(g->Message, "Value too long for column %s", colp->GetName());
+ bson_free(str);
+ throw (int)TYPE_AM_MGO;
+ } // endif len
for (i = 0; i < colp->GetLength() && s[i]; i++) {
switch (s[i]) {
case ' ':
if (ok) continue;
+ break;
case '"':
ok = !ok;
+ break;
+ case '.':
+ if (j) dbl = true;
+ break;
default:
+ if (ok) {
+ if (isdigit(s[i])) {
+ if (!j) j = k;
+ if (dbl) n++;
+ } else if (dbl && n > m) {
+ Mbuf[k] = 0;
+ d = atof(Mbuf + j);
+ n = sprintf(Mbuf + j, "%.*f", m, d);
+ k = j + n;
+ j = n = 0;
+ } else if (j)
+ j = n = 0;
+
+ } // endif ok
+
break;
} // endswitch s[i]
@@ -830,11 +859,6 @@ char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
bson_free(str);
- if (i >= colp->GetLength()) {
- sprintf(g->Message, "Value too long for column %s", colp->GetName());
- throw (int)TYPE_AM_MGO;
- } // endif i
-
Mbuf[k] = 0;
return Mbuf;
} // end of Mini
@@ -926,13 +950,13 @@ void CMgoConn::GetColumnValue(PGLOBAL g, PCOL colp)
value->SetNull(true);
break;
case BSON_TYPE_DECIMAL128: {
- char* str = NULL;
+ char str[BSON_DECIMAL128_STRING];
bson_decimal128_t dec;
bson_iter_decimal128(&Desc, &dec);
bson_decimal128_to_string(&dec, str);
value->SetValue_psz(str);
- bson_free(str);
+// bson_free(str);
} break;
default:
value->Reset();
@@ -956,10 +980,10 @@ bool CMgoConn::AddValue(PGLOBAL g, PCOL colp, bson_t *doc, char *key, bool upd)
PVAL value = colp->GetValue();
if (value->IsNull()) {
- if (upd)
+// if (upd)
rc = BSON_APPEND_NULL(doc, key);
- else
- return false;
+// else
+// return false;
} else switch (colp->GetResultType()) {
case TYPE_STRING:
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc
index 583e4f94e91..5f210f649f5 100644
--- a/storage/connect/ha_connect.cc
+++ b/storage/connect/ha_connect.cc
@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
- char version[]= "Version 1.07.0003 April 02, 2021";
+ char version[]= "Version 1.07.0003 May 02, 2021";
#if defined(__WIN__)
char compver[]= "Version 1.07.0003 " __DATE__ " " __TIME__;
char slash= '\\';
@@ -5940,9 +5940,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
if (!fn && !zfn && !mul && !dsn)
sprintf(g->Message, "Missing %s file name", topt->type);
- else
- ok= true;
+ else if (dsn && !topt->tabname)
+ topt->tabname= tab;
+ ok= true;
break;
#if defined(JAVA_SUPPORT)
case TAB_MONGO:
diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp
index b1f9f10957b..b376a8c5c27 100644
--- a/storage/connect/json.cpp
+++ b/storage/connect/json.cpp
@@ -245,6 +245,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char* fn, int pretty) {
try {
jdp = new(g) JDOC; // MUST BE ALLOCATED BEFORE jp !!!!!
+ jdp->dfp = GetDefaultPrec();
if (!jsp) {
strcpy(g->Message, "Null json tree");
@@ -1005,8 +1006,8 @@ bool JDOC::SerializeValue(PJVAL jvp)
case TYPE_BINT:
sprintf(buf, "%lld", jvp->LLn);
return js->WriteStr(buf);
- case TYPE_DBL:
- sprintf(buf, "%.*lf", jvp->Nd, jvp->F);
+ case TYPE_DBL: // dfp to limit to the default number of decimals
+ sprintf(buf, "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F);
return js->WriteStr(buf);
case TYPE_NULL:
return js->WriteStr("null");
diff --git a/storage/connect/json.h b/storage/connect/json.h
index 26b73faef12..566cb64cc23 100644
--- a/storage/connect/json.h
+++ b/storage/connect/json.h
@@ -75,7 +75,7 @@ class JDOC: public BLOCK {
friend PJSON ParseJson(PGLOBAL, char*, size_t, int*, bool*);
friend PSZ Serialize(PGLOBAL, PJSON, char*, int);
public:
- JDOC(void) : js(NULL), s(NULL), len(0), pty(NULL) {}
+ JDOC(void) : js(NULL), s(NULL), len(0), dfp(0), pty(NULL) {}
void SetJp(JOUT* jp) { js = jp; }
@@ -94,7 +94,7 @@ public:
private:
JOUT* js;
char *s;
- int len;
+ int len, dfp;
bool *pty;
}; // end of class JDOC
diff --git a/storage/connect/tabbson.cpp b/storage/connect/tabbson.cpp
index aae9a11b28c..d36b9718cd6 100644
--- a/storage/connect/tabbson.cpp
+++ b/storage/connect/tabbson.cpp
@@ -218,8 +218,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
if (tdp->Uri) {
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
- tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
- tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
+ tdp->Collname = GetStringTableOption(g, topt, "Tabname", NULL);
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
diff --git a/storage/connect/tabjmg.cpp b/storage/connect/tabjmg.cpp
index 300091f78ad..b02bf6a7f36 100644
--- a/storage/connect/tabjmg.cpp
+++ b/storage/connect/tabjmg.cpp
@@ -505,6 +505,7 @@ char *JMGCOL::Mini(PGLOBAL g, const bson_t *bson, bool b)
switch (s[i]) {
case ' ':
if (ok) continue;
+ break;
case '"':
ok = !ok;
default:
diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp
index dfcf3ee2d4f..4a8031113d2 100644
--- a/storage/connect/tabjson.cpp
+++ b/storage/connect/tabjson.cpp
@@ -222,8 +222,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
if (tdp->Uri) {
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
- tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
- tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
+ tdp->Collname = GetStringTableOption(g, topt, "Tabname", NULL);
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);