summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2020-11-19 19:05:04 +0100
committerOlivier Bertrand <bertrandop@gmail.com>2020-11-19 19:05:04 +0100
commit000268d46fea93655c8e8652f73a97210bc539da (patch)
tree16ee3b69498b065beef778f4a223cb3107833549
parentda10bf2d5694759cf435190150cf82f597902057 (diff)
downloadmariadb-git-000268d46fea93655c8e8652f73a97210bc539da.tar.gz
Fix some json discovery problems. Modified tabjson.cpp tabjson.h
-rw-r--r--storage/connect/tabjson.cpp32
-rw-r--r--storage/connect/tabjson.h2
2 files changed, 27 insertions, 7 deletions
diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp
index b0866ba1b18..d5aa1be892d 100644
--- a/storage/connect/tabjson.cpp
+++ b/storage/connect/tabjson.cpp
@@ -159,7 +159,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg)
jsp = NULL;
row = NULL;
sep = NULL;
- i = n = bf = ncol = lvl = sz = 0;
+ i = n = bf = ncol = lvl = sz = limit = 0;
all = strfy = false;
} // end of JSONDISC constructor
@@ -172,7 +172,8 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
lvl = GetIntegerTableOption(g, topt, "Depth", lvl);
sep = GetStringTableOption(g, topt, "Separator", ".");
sz = GetIntegerTableOption(g, topt, "Jsize", 1024);
- strfy = GetBooleanTableOption(g, topt, "Stringify", false);
+ limit = GetIntegerTableOption(g, topt, "Limit", 10);
+ strfy = GetBooleanTableOption(g, topt, "Stringify", false);
/*********************************************************************/
/* Open the input file. */
@@ -458,7 +459,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
jar = (PJAR)jsp;
if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key)))
- ars = jar->GetSize(false);
+ ars = MY_MIN(jar->GetSize(false), limit);
else
ars = MY_MIN(jar->GetSize(false), 1);
@@ -527,10 +528,29 @@ void JSONDISC::AddColumn(PGLOBAL g)
if (jcp) {
if (jcp->Type != jcol.Type) {
- if (jcp->Type == TYPE_UNKNOWN)
+ if (jcp->Type == TYPE_UNKNOWN || jcol.Type == TYPE_VOID)
jcp->Type = jcol.Type;
- else if (jcol.Type != TYPE_UNKNOWN && jcol.Type != TYPE_VOID)
- jcp->Type = TYPE_STRING;
+// else if (jcol.Type != TYPE_UNKNOWN && jcol.Type != TYPE_VOID)
+// jcp->Type = TYPE_STRING;
+ else if (jcp->Type != TYPE_STRING)
+ switch (jcol.Type) {
+ case TYPE_STRING:
+ case TYPE_DOUBLE:
+ jcp->Type = jcol.Type;
+ break;
+ case TYPE_BIGINT:
+ if (jcp->Type == TYPE_INT || jcp->Type == TYPE_TINY)
+ jcp->Type = jcol.Type;
+
+ break;
+ case TYPE_INT:
+ if (jcp->Type == TYPE_TINY)
+ jcp->Type = jcol.Type;
+
+ break;
+ default:
+ break;
+ } // endswith Type
} // endif Type
diff --git a/storage/connect/tabjson.h b/storage/connect/tabjson.h
index de5115a4e09..9994c9106ca 100644
--- a/storage/connect/tabjson.h
+++ b/storage/connect/tabjson.h
@@ -68,7 +68,7 @@ public:
PCSZ sep;
char colname[65], fmt[129], buf[16];
uint *length;
- int i, n, bf, ncol, lvl, sz;
+ int i, n, bf, ncol, lvl, sz, limit;
bool all, strfy;
}; // end of JSONDISC