Commit 871532c3 authored by Olivier Bertrand's avatar Olivier Bertrand

- Continue BSON implementation

  modified:   storage/connect/bson.cpp
  modified:   storage/connect/bson.h
  modified:   storage/connect/bsonudf.cpp
  modified:   storage/connect/cmgfam.cpp
  modified:   storage/connect/cmgfam.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jmgfam.cpp
  modified:   storage/connect/jmgfam.h
  modified:   storage/connect/jmgoconn.cpp
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/tabbson.cpp
  modified:   storage/connect/tabjson.cpp
parent c05b1288
...@@ -108,7 +108,8 @@ BDOC::BDOC(PGLOBAL G) : BJSON(G, NULL) ...@@ -108,7 +108,8 @@ BDOC::BDOC(PGLOBAL G) : BJSON(G, NULL)
/* Parse a json string. */ /* Parse a json string. */
/* Note: when pretty is not known, the caller set pretty to 3. */ /* Note: when pretty is not known, the caller set pretty to 3. */
/***********************************************************************/ /***********************************************************************/
PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) { PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
{
int i, pretty = (ptyp) ? *ptyp : 3; int i, pretty = (ptyp) ? *ptyp : 3;
bool b = false; bool b = false;
...@@ -233,7 +234,8 @@ OFFSET BDOC::ParseAsArray(int& i, int pretty, int* ptyp) { ...@@ -233,7 +234,8 @@ OFFSET BDOC::ParseAsArray(int& i, int pretty, int* ptyp) {
/***********************************************************************/ /***********************************************************************/
/* Parse a JSON Array. */ /* Parse a JSON Array. */
/***********************************************************************/ /***********************************************************************/
OFFSET BDOC::ParseArray(int& i) { OFFSET BDOC::ParseArray(int& i)
{
int level = 0; int level = 0;
bool b = (!i); bool b = (!i);
PBVAL vlp, firstvlp, lastvlp; PBVAL vlp, firstvlp, lastvlp;
...@@ -290,7 +292,8 @@ OFFSET BDOC::ParseArray(int& i) { ...@@ -290,7 +292,8 @@ OFFSET BDOC::ParseArray(int& i) {
/***********************************************************************/ /***********************************************************************/
/* Parse a JSON Object. */ /* Parse a JSON Object. */
/***********************************************************************/ /***********************************************************************/
OFFSET BDOC::ParseObject(int& i) { OFFSET BDOC::ParseObject(int& i)
{
OFFSET key; OFFSET key;
int level = 0; int level = 0;
PBPR bpp, firstbpp, lastbpp; PBPR bpp, firstbpp, lastbpp;
...@@ -439,7 +442,8 @@ PBVAL BDOC::ParseValue(int& i) ...@@ -439,7 +442,8 @@ PBVAL BDOC::ParseValue(int& i)
/***********************************************************************/ /***********************************************************************/
/* Unescape and parse a JSON string. */ /* Unescape and parse a JSON string. */
/***********************************************************************/ /***********************************************************************/
OFFSET BDOC::ParseString(int& i) { OFFSET BDOC::ParseString(int& i)
{
uchar* p; uchar* p;
int n = 0; int n = 0;
...@@ -448,13 +452,13 @@ OFFSET BDOC::ParseString(int& i) { ...@@ -448,13 +452,13 @@ OFFSET BDOC::ParseString(int& i) {
throw("ParseString: Out of memory"); throw("ParseString: Out of memory");
// The size to allocate is not known yet // The size to allocate is not known yet
p = (uchar*)PlugSubAlloc(G, NULL, 0); p = (uchar*)BsonSubAlloc(0);
for (; i < len; i++) for (; i < len; i++)
switch (s[i]) { switch (s[i]) {
case '"': case '"':
p[n++] = 0; p[n++] = 0;
PlugSubAlloc(G, NULL, n); BsonSubAlloc(n);
return MOF(p); return MOF(p);
case '\\': case '\\':
if (++i < len) { if (++i < len) {
...@@ -525,7 +529,8 @@ throw("Unexpected EOF in String"); ...@@ -525,7 +529,8 @@ throw("Unexpected EOF in String");
/***********************************************************************/ /***********************************************************************/
/* Parse a JSON numeric value. */ /* Parse a JSON numeric value. */
/***********************************************************************/ /***********************************************************************/
void BDOC::ParseNumeric(int& i, PBVAL vlp) { void BDOC::ParseNumeric(int& i, PBVAL vlp)
{
char buf[50]; char buf[50];
int n = 0; int n = 0;
short nd = 0; short nd = 0;
...@@ -580,7 +585,7 @@ void BDOC::ParseNumeric(int& i, PBVAL vlp) { ...@@ -580,7 +585,7 @@ void BDOC::ParseNumeric(int& i, PBVAL vlp) {
if (has_dot || has_e) { if (has_dot || has_e) {
double dv = strtod(buf, NULL); double dv = strtod(buf, NULL);
if (nd > 6) { if (nd > 5 || dv > FLT_MAX || dv < FLT_MIN) {
double* dvp = (double*)PlugSubAlloc(G, NULL, sizeof(double)); double* dvp = (double*)PlugSubAlloc(G, NULL, sizeof(double));
*dvp = dv; *dvp = dv;
...@@ -620,7 +625,8 @@ void BDOC::ParseNumeric(int& i, PBVAL vlp) { ...@@ -620,7 +625,8 @@ void BDOC::ParseNumeric(int& i, PBVAL vlp) {
/***********************************************************************/ /***********************************************************************/
/* Serialize a BJSON document tree: */ /* Serialize a BJSON document tree: */
/***********************************************************************/ /***********************************************************************/
PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty) { PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty)
{
PSZ str = NULL; PSZ str = NULL;
bool b = false, err = true; bool b = false, err = true;
FILE* fs = NULL; FILE* fs = NULL;
...@@ -697,7 +703,8 @@ PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty) { ...@@ -697,7 +703,8 @@ PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty) {
/***********************************************************************/ /***********************************************************************/
/* Serialize a JSON Array. */ /* Serialize a JSON Array. */
/***********************************************************************/ /***********************************************************************/
bool BDOC::SerializeArray(OFFSET arp, bool b) { bool BDOC::SerializeArray(OFFSET arp, bool b)
{
bool first = true; bool first = true;
PBVAL vp = MVP(arp); PBVAL vp = MVP(arp);
...@@ -740,7 +747,8 @@ bool BDOC::SerializeArray(OFFSET arp, bool b) { ...@@ -740,7 +747,8 @@ bool BDOC::SerializeArray(OFFSET arp, bool b) {
/***********************************************************************/ /***********************************************************************/
/* Serialize a JSON Object. */ /* Serialize a JSON Object. */
/***********************************************************************/ /***********************************************************************/
bool BDOC::SerializeObject(OFFSET obp) { bool BDOC::SerializeObject(OFFSET obp)
{
bool first = true; bool first = true;
PBPR prp = MPP(obp); PBPR prp = MPP(obp);
...@@ -768,7 +776,8 @@ bool BDOC::SerializeObject(OFFSET obp) { ...@@ -768,7 +776,8 @@ bool BDOC::SerializeObject(OFFSET obp) {
/***********************************************************************/ /***********************************************************************/
/* Serialize a JSON Value. */ /* Serialize a JSON Value. */
/***********************************************************************/ /***********************************************************************/
bool BDOC::SerializeValue(PBVAL jvp) { bool BDOC::SerializeValue(PBVAL jvp)
{
char buf[64]; char buf[64];
if (jvp) switch (jvp->Type) { if (jvp) switch (jvp->Type) {
...@@ -833,7 +842,22 @@ void* BJSON::BsonSubAlloc(size_t size) ...@@ -833,7 +842,22 @@ void* BJSON::BsonSubAlloc(size_t size)
xtrc(16, "Done memp=%p used=%zd free=%zd\n", xtrc(16, "Done memp=%p used=%zd free=%zd\n",
memp, pph->To_Free, pph->FreeBlk); memp, pph->To_Free, pph->FreeBlk);
return memp; return memp;
} /* end of BsonSubAlloc */ } // end of BsonSubAlloc
/*********************************************************************************/
/* Program for SubSet re-initialization of the memory pool. */
/*********************************************************************************/
OFFSET BJSON::DupStr(PSZ str)
{
if (str) {
PSZ sm = (PSZ)BsonSubAlloc(strlen(str) + 1);
strcpy(sm, str);
return MOF(sm);
} else
return NULL;
} // end of DupStr
/*********************************************************************************/ /*********************************************************************************/
/* Program for SubSet re-initialization of the memory pool. */ /* Program for SubSet re-initialization of the memory pool. */
...@@ -888,7 +912,7 @@ void BJSON::AddPair(PBVAL bop, PSZ key, OFFSET val) ...@@ -888,7 +912,7 @@ void BJSON::AddPair(PBVAL bop, PSZ key, OFFSET val)
{ {
CheckType(bop, TYPE_JOB); CheckType(bop, TYPE_JOB);
PBPR brp; PBPR brp;
OFFSET nrp = MOF(SubAllocPair(key, val)); OFFSET nrp = NewPair(key, val);
if (bop->To_Val) { if (bop->To_Val) {
for (brp = GetObject(bop); brp->Next; brp = GetNext(brp)); for (brp = GetObject(bop); brp->Next; brp = GetNext(brp));
...@@ -948,8 +972,9 @@ PBVAL BJSON::GetKeyValue(PBVAL bop, PSZ key) ...@@ -948,8 +972,9 @@ PBVAL BJSON::GetKeyValue(PBVAL bop, PSZ key)
PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text) PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
{ {
CheckType(bop, TYPE_JOB); CheckType(bop, TYPE_JOB);
PBPR brp = GetObject(bop);
if (bop->To_Val) { if (brp) {
bool b; bool b;
if (!text) { if (!text) {
...@@ -962,12 +987,11 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text) ...@@ -962,12 +987,11 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
b = false; b = false;
} // endif text } // endif text
#if 0 if (b && !brp->Next && !strcmp(MZP(brp->Key), "$date")) {
if (b && !bop->Next && !strcmp(MZP(bop->Key), "$date")) {
int i; int i;
PSZ s; PSZ s;
First->Val->GetText(g, text); GetValueText(g, MVP(brp->Vlp), text);
s = text->GetStr(); s = text->GetStr();
i = (s[1] == '-' ? 2 : 1); i = (s[1] == '-' ? 2 : 1);
...@@ -983,10 +1007,7 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text) ...@@ -983,10 +1007,7 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
} // endif text } // endif text
} else } else for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) {
#endif // 0
for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) {
GetValueText(g, GetVal(brp), text); GetValueText(g, GetVal(brp), text);
if (brp->Next) if (brp->Next)
...@@ -1021,10 +1042,10 @@ void BJSON::SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key) ...@@ -1021,10 +1042,10 @@ void BJSON::SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key)
prp = brp; prp = brp;
if (!brp) if (!brp)
prp->Next = MOF(SubAllocPair(key, bvp)); prp->Next = NewPair(key, bvp);
} else } else
bop->To_Val = MOF(SubAllocPair(key, bvp)); bop->To_Val = NewPair(key, bvp);
bop->Nd++; bop->Nd++;
} // end of SetKeyValue } // end of SetKeyValue
...@@ -1301,7 +1322,7 @@ PBVAL BJSON::SubAllocStr(OFFSET toval, short nd) ...@@ -1301,7 +1322,7 @@ PBVAL BJSON::SubAllocStr(OFFSET toval, short nd)
bvp->To_Val = toval; bvp->To_Val = toval;
bvp->Nd = nd; bvp->Nd = nd;
return bvp; return bvp;
} // end of SubAllocVal } // end of SubAllocStr
/***********************************************************************/ /***********************************************************************/
/* Allocate a BVALUE with a given string or numeric value. */ /* Allocate a BVALUE with a given string or numeric value. */
......
...@@ -81,8 +81,8 @@ class BJSON : public BLOCK { ...@@ -81,8 +81,8 @@ class BJSON : public BLOCK {
// SubAlloc functions // SubAlloc functions
void* BsonSubAlloc(size_t size); void* BsonSubAlloc(size_t size);
PBPR SubAllocPair(OFFSET key, OFFSET val = 0); PBPR SubAllocPair(OFFSET key, OFFSET val = 0);
PBPR SubAllocPair(PSZ key, OFFSET val = 0) OFFSET NewPair(PSZ key, OFFSET val = 0)
{return SubAllocPair(MOF(key), val);} {return MOF(SubAllocPair(DupStr(key), val));}
PBVAL NewVal(int type = TYPE_NULL); PBVAL NewVal(int type = TYPE_NULL);
PBVAL NewVal(PVAL valp); PBVAL NewVal(PVAL valp);
PBVAL SubAllocVal(OFFSET toval, int type = TYPE_NULL, short nd = 0); PBVAL SubAllocVal(OFFSET toval, int type = TYPE_NULL, short nd = 0);
...@@ -90,8 +90,9 @@ class BJSON : public BLOCK { ...@@ -90,8 +90,9 @@ class BJSON : public BLOCK {
{return SubAllocVal(MOF(toval), type, nd);} {return SubAllocVal(MOF(toval), type, nd);}
PBVAL SubAllocStr(OFFSET str, short nd = 0); PBVAL SubAllocStr(OFFSET str, short nd = 0);
PBVAL SubAllocStr(PSZ str, short nd = 0) PBVAL SubAllocStr(PSZ str, short nd = 0)
{return SubAllocStr(MOF(str), nd);} {return SubAllocStr(DupStr(str), nd);}
PBVAL DupVal(PBVAL bvp); PBVAL DupVal(PBVAL bvp);
OFFSET DupStr(PSZ str);
// Array functions // Array functions
inline PBVAL GetArray(PBVAL vlp) {return MVP(vlp->To_Val);} inline PBVAL GetArray(PBVAL vlp) {return MVP(vlp->To_Val);}
......
...@@ -693,11 +693,6 @@ PBVAL BJNX::GetRow(PGLOBAL g) ...@@ -693,11 +693,6 @@ PBVAL BJNX::GetRow(PGLOBAL g)
for (i++; row && i < Nod; i++) { for (i++; row && i < Nod; i++) {
if (Nodes[i].Op == OP_XX) if (Nodes[i].Op == OP_XX)
break; break;
// else if (!Nodes[i].Key)
// Construct intermediate array
// nwr = SubAllocVal(g);
// else
// nwr = SubAllocPair(g);
// Construct new row // Construct new row
nwr = NewVal(); nwr = NewVal();
......
/************** CMGFAM C++ Program Source Code File (.CPP) *************/ /************** CMGFAM C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: cmgfam.cpp */ /* PROGRAM NAME: cmgfam.cpp */
/* ------------- */ /* ------------- */
/* Version 1.4 */ /* Version 1.5 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 20017 */ /* (C) Copyright to the author Olivier BERTRAND 20017 - 2020 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
...@@ -29,7 +29,11 @@ ...@@ -29,7 +29,11 @@
#include "reldef.h" #include "reldef.h"
#include "filamtxt.h" #include "filamtxt.h"
#include "tabdos.h" #include "tabdos.h"
#if defined(BSON_SUPPORT)
#include "tabbson.h"
#else
#include "tabjson.h" #include "tabjson.h"
#endif // BSON_SUPPORT
#include "cmgfam.h" #include "cmgfam.h"
#if defined(UNIX) || defined(UNIV_LINUX) #if defined(UNIX) || defined(UNIV_LINUX)
...@@ -53,6 +57,7 @@ CMGFAM::CMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL) ...@@ -53,6 +57,7 @@ CMGFAM::CMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL)
Pcg.Options = tdp->Options; Pcg.Options = tdp->Options;
Pcg.Filter = tdp->Filter; Pcg.Filter = tdp->Filter;
Pcg.Pipe = tdp->Pipe && tdp->Options != NULL; Pcg.Pipe = tdp->Pipe && tdp->Options != NULL;
Lrecl = tdp->Lrecl + tdp->Ending;
} else { } else {
Pcg.Uristr = NULL; Pcg.Uristr = NULL;
Pcg.Db_name = NULL; Pcg.Db_name = NULL;
...@@ -60,21 +65,55 @@ CMGFAM::CMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL) ...@@ -60,21 +65,55 @@ CMGFAM::CMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL)
Pcg.Options = NULL; Pcg.Options = NULL;
Pcg.Filter = NULL; Pcg.Filter = NULL;
Pcg.Pipe = false; Pcg.Pipe = false;
Lrecl = 0;
} // endif tdp } // endif tdp
To_Fbt = NULL; To_Fbt = NULL;
Mode = MODE_ANY; Mode = MODE_ANY;
Done = false; Done = false;
} // end of CMGFAM standard constructor
#if defined(BSON_SUPPORT)
/***********************************************************************/
/* Constructors. */
/***********************************************************************/
CMGFAM::CMGFAM(PBDEF tdp) : DOSFAM((PDOSDEF)NULL)
{
Cmgp = NULL;
Pcg.Tdbp = NULL;
if (tdp) {
Pcg.Uristr = tdp->Uri;
Pcg.Db_name = tdp->Schema;
Pcg.Coll_name = tdp->Collname;
Pcg.Options = tdp->Options;
Pcg.Filter = tdp->Filter;
Pcg.Pipe = tdp->Pipe && tdp->Options != NULL;
Lrecl = tdp->Lrecl + tdp->Ending; Lrecl = tdp->Lrecl + tdp->Ending;
} else {
Pcg.Uristr = NULL;
Pcg.Db_name = NULL;
Pcg.Coll_name = NULL;
Pcg.Options = NULL;
Pcg.Filter = NULL;
Pcg.Pipe = false;
Lrecl = 0;
} // endif tdp
To_Fbt = NULL;
Mode = MODE_ANY;
Done = false;
} // end of CMGFAM standard constructor } // end of CMGFAM standard constructor
#endif // BSON_SUPPORT
CMGFAM::CMGFAM(PCMGFAM tdfp) : DOSFAM(tdfp) CMGFAM::CMGFAM(PCMGFAM tdfp) : DOSFAM(tdfp)
{ {
Cmgp = tdfp->Cmgp;
Pcg = tdfp->Pcg; Pcg = tdfp->Pcg;
To_Fbt = tdfp->To_Fbt; To_Fbt = tdfp->To_Fbt;
Mode = tdfp->Mode; Mode = tdfp->Mode;
Done = tdfp->Done; Done = tdfp->Done;
} // end of CMGFAM copy constructor } // end of CMGFAM copy constructor
/***********************************************************************/ /***********************************************************************/
/* Reset: reset position values at the beginning of file. */ /* Reset: reset position values at the beginning of file. */
......
/*************** CMGFam H Declares Source Code File (.H) ***************/ /*************** CMGFam H Declares Source Code File (.H) ***************/
/* Name: cmgfam.h Version 1.5 */ /* Name: cmgfam.h Version 1.6 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2017 - 2020 */
/* */ /* */
/* This file contains the MongoDB access method classes declares. */ /* This file contains the MongoDB access method classes declares. */
/***********************************************************************/ /***********************************************************************/
...@@ -20,6 +20,9 @@ class DllExport CMGFAM : public DOSFAM { ...@@ -20,6 +20,9 @@ class DllExport CMGFAM : public DOSFAM {
public: public:
// Constructor // Constructor
CMGFAM(PJDEF tdp); CMGFAM(PJDEF tdp);
#if defined(BSON_SUPPORT)
CMGFAM(PBDEF tdp);
#endif // BSON_SUPPORT
CMGFAM(PCMGFAM txfp); CMGFAM(PCMGFAM txfp);
// Implementation // Implementation
......
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size #define JSONMAX 10 // JSON Default max grp size
extern "C" { extern "C" {
char version[]= "Version 1.07.0002 December 02, 2020"; char version[]= "Version 1.07.0002 December 07, 2020";
#if defined(__WIN__) #if defined(__WIN__)
char compver[]= "Version 1.07.0002 " __DATE__ " " __TIME__; char compver[]= "Version 1.07.0002 " __DATE__ " " __TIME__;
char slash= '\\'; char slash= '\\';
...@@ -230,9 +230,9 @@ char *GetUserVariable(PGLOBAL g, const uchar *varname) ...@@ -230,9 +230,9 @@ char *GetUserVariable(PGLOBAL g, const uchar *varname)
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, bool info); PQRYRES VirColumns(PGLOBAL g, bool info);
PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info); PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info);
#ifdef DEVELOPMENT #ifdef BSON_SUPPORT
PQRYRES BSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info); PQRYRES BSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info);
#endif // DEVEOPMENT #endif // BSON_SUPPORT
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info); PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
#if defined(REST_SUPPORT) #if defined(REST_SUPPORT)
PQRYRES RESTColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); PQRYRES RESTColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
...@@ -259,6 +259,9 @@ bool JsonAllPath(void); ...@@ -259,6 +259,9 @@ bool JsonAllPath(void);
char *GetJsonNull(void); char *GetJsonNull(void);
uint GetJsonGrpSize(void); uint GetJsonGrpSize(void);
char *GetJavaWrapper(void); char *GetJavaWrapper(void);
#if defined(BSON_SUPPORT)
bool Force_Bson(void);
#endif // BSON_SUPPORT
size_t GetWorkSize(void); size_t GetWorkSize(void);
void SetWorkSize(size_t); void SetWorkSize(size_t);
extern "C" const char *msglang(void); extern "C" const char *msglang(void);
...@@ -444,6 +447,13 @@ static MYSQL_THDVAR_BOOL(enable_mongo, PLUGIN_VAR_RQCMDARG, ...@@ -444,6 +447,13 @@ static MYSQL_THDVAR_BOOL(enable_mongo, PLUGIN_VAR_RQCMDARG,
#endif // !version 2,3 #endif // !version 2,3
#endif // JAVA_SUPPORT || CMGO_SUPPORT #endif // JAVA_SUPPORT || CMGO_SUPPORT
#if defined(BSON_SUPPORT)
// Force using BSON for JSON tables
static MYSQL_THDVAR_BOOL(force_bson, PLUGIN_VAR_RQCMDARG,
"Force using BSON for JSON tables",
NULL, NULL, 0); // NO by default
#endif // BSON_SUPPORT
#if defined(XMSG) || defined(NEWMSG) #if defined(XMSG) || defined(NEWMSG)
const char *language_names[]= const char *language_names[]=
{ {
...@@ -506,6 +516,8 @@ char *GetJavaWrapper(void) ...@@ -506,6 +516,8 @@ char *GetJavaWrapper(void)
bool MongoEnabled(void) {return THDVAR(current_thd, enable_mongo);} bool MongoEnabled(void) {return THDVAR(current_thd, enable_mongo);}
#endif // JAVA_SUPPORT || CMGO_SUPPORT #endif // JAVA_SUPPORT || CMGO_SUPPORT
bool Force_Bson(void) {return THDVAR(current_thd, force_bson);}
#if defined(XMSG) || defined(NEWMSG) #if defined(XMSG) || defined(NEWMSG)
extern "C" const char *msglang(void) extern "C" const char *msglang(void)
{return language_names[THDVAR(current_thd, msg_lang)];} {return language_names[THDVAR(current_thd, msg_lang)];}
...@@ -4516,9 +4528,9 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick) ...@@ -4516,9 +4528,9 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick)
case TAB_VEC: case TAB_VEC:
case TAB_REST: case TAB_REST:
case TAB_JSON: case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // DEVELOPMENT #endif // BSON_SUPPORT
if (options->filename && *options->filename) { if (options->filename && *options->filename) {
if (!quick) { if (!quick) {
char path[FN_REFLEN], dbpath[FN_REFLEN]; char path[FN_REFLEN], dbpath[FN_REFLEN];
...@@ -5444,6 +5456,9 @@ static bool add_field(String* sql, TABTYPE ttp, const char* field_name, int typ, ...@@ -5444,6 +5456,9 @@ static bool add_field(String* sql, TABTYPE ttp, const char* field_name, int typ,
if (fmt && *fmt) { if (fmt && *fmt) {
switch (ttp) { switch (ttp) {
case TAB_JSON: error |= sql->append(" JPATH='"); break; case TAB_JSON: error |= sql->append(" JPATH='"); break;
#if defined(BSON_SUPPORT)
case TAB_BSON: error |= sql->append(" JPATH='"); break;
#endif // BSON_SUPPORT
case TAB_XML: error |= sql->append(" XPATH='"); break; case TAB_XML: error |= sql->append(" XPATH='"); break;
default: error |= sql->append(" FIELD_FORMAT='"); default: error |= sql->append(" FIELD_FORMAT='");
} // endswitch ttp } // endswitch ttp
...@@ -5686,9 +5701,9 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5686,9 +5701,9 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
} else if (topt->http) { } else if (topt->http) {
switch (ttp) { switch (ttp) {
case TAB_JSON: case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // DEVELOPMENT #endif // BSON_SUPPORT
case TAB_XML: case TAB_XML:
case TAB_CSV: case TAB_CSV:
ttp = TAB_REST; ttp = TAB_REST;
...@@ -5873,9 +5888,9 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5873,9 +5888,9 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case TAB_XML: case TAB_XML:
#endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT #endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT
case TAB_JSON: case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // DEVELOPMENT #endif // BSON_SUPPORT
dsn= strz(g, create_info->connect_string); dsn= strz(g, create_info->connect_string);
if (!fn && !zfn && !mul && !dsn) if (!fn && !zfn && !mul && !dsn)
...@@ -6040,13 +6055,15 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -6040,13 +6055,15 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
qrp= VirColumns(g, fnc == FNC_COL); qrp= VirColumns(g, fnc == FNC_COL);
break; break;
case TAB_JSON: case TAB_JSON:
#if !defined(FORCE_BSON)
qrp= JSONColumns(g, db, dsn, topt, fnc == FNC_COL); qrp= JSONColumns(g, db, dsn, topt, fnc == FNC_COL);
break; break;
#if defined(DEVELOPMENT) #endif // !FORCE_BSON
#if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
qrp= BSONColumns(g, db, dsn, topt, fnc == FNC_COL); qrp= BSONColumns(g, db, dsn, topt, fnc == FNC_COL);
break; break;
#endif // DEVELOPMENT #endif // BSON_SUPPORT
#if defined(JAVA_SUPPORT) #if defined(JAVA_SUPPORT)
case TAB_MONGO: case TAB_MONGO:
url= strz(g, create_info->connect_string); url= strz(g, create_info->connect_string);
...@@ -7426,6 +7443,9 @@ static struct st_mysql_sys_var* connect_system_variables[]= { ...@@ -7426,6 +7443,9 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR(enable_mongo), MYSQL_SYSVAR(enable_mongo),
#endif // JAVA_SUPPORT || CMGO_SUPPORT #endif // JAVA_SUPPORT || CMGO_SUPPORT
MYSQL_SYSVAR(cond_push), MYSQL_SYSVAR(cond_push),
#if defined(BSON_SUPPORT)
MYSQL_SYSVAR(force_bson),
#endif // BSON_SUPPORT
NULL NULL
}; };
......
/************ JMONGO FAM C++ Program Source Code File (.CPP) ***********/ /************ JMONGO FAM C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: jmgfam.cpp */ /* PROGRAM NAME: jmgfam.cpp */
/* ------------- */ /* ------------- */
/* Version 1.0 */ /* Version 1.1 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 20017 */ /* (C) Copyright to the author Olivier BERTRAND 20017 - 2020 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
...@@ -49,7 +49,11 @@ ...@@ -49,7 +49,11 @@
#include "reldef.h" #include "reldef.h"
#include "filamtxt.h" #include "filamtxt.h"
#include "tabdos.h" #include "tabdos.h"
#if defined(BSON_SUPPORT)
#include "tabbson.h"
#else
#include "tabjson.h" #include "tabjson.h"
#endif // BSON_SUPPORT
#include "jmgfam.h" #include "jmgfam.h"
#if defined(UNIX) || defined(UNIV_LINUX) #if defined(UNIX) || defined(UNIV_LINUX)
...@@ -92,10 +96,38 @@ JMGFAM::JMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL) ...@@ -92,10 +96,38 @@ JMGFAM::JMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL)
Version = tdp->Version; Version = tdp->Version;
Lrecl = tdp->Lrecl + tdp->Ending; Lrecl = tdp->Lrecl + tdp->Ending;
Curpos = 0; Curpos = 0;
} // end of JMGFAM standard constructor } // end of JMGFAM Json standard constructor
#if defined(BSON_SUPPORT)
JMGFAM::JMGFAM(PBDEF tdp) : DOSFAM((PDOSDEF)NULL)
{
Jcp = NULL;
Ops.Driver = tdp->Schema;
Ops.Url = tdp->Uri;
Ops.User = NULL;
Ops.Pwd = NULL;
Ops.Scrollable = false;
Ops.Fsize = 0;
Ops.Version = tdp->Version;
To_Fbt = NULL;
Mode = MODE_ANY;
Uristr = tdp->Uri;
Db_name = tdp->Schema;
Coll_name = tdp->Collname;
Options = tdp->Options;
Filter = tdp->Filter;
Wrapname = tdp->Wrapname;
Done = false;
Pipe = tdp->Pipe;
Version = tdp->Version;
Lrecl = tdp->Lrecl + tdp->Ending;
Curpos = 0;
} // end of JMGFAM Bson standard constructor
#endif // BSON_SUPPORT
JMGFAM::JMGFAM(PJMGFAM tdfp) : DOSFAM(tdfp) JMGFAM::JMGFAM(PJMGFAM tdfp) : DOSFAM(tdfp)
{ {
Jcp = tdfp->Jcp;
//Client = tdfp->Client; //Client = tdfp->Client;
//Database = NULL; //Database = NULL;
//Collection = tdfp->Collection; //Collection = tdfp->Collection;
...@@ -114,6 +146,7 @@ JMGFAM::JMGFAM(PJMGFAM tdfp) : DOSFAM(tdfp) ...@@ -114,6 +146,7 @@ JMGFAM::JMGFAM(PJMGFAM tdfp) : DOSFAM(tdfp)
Done = tdfp->Done; Done = tdfp->Done;
Pipe = tdfp->Pipe; Pipe = tdfp->Pipe;
Version = tdfp->Version; Version = tdfp->Version;
Curpos = tdfp->Curpos;
} // end of JMGFAM copy constructor } // end of JMGFAM copy constructor
/***********************************************************************/ /***********************************************************************/
......
/************** MongoFam H Declares Source Code File (.H) **************/ /************** MongoFam H Declares Source Code File (.H) **************/
/* Name: jmgfam.h Version 1.0 */ /* Name: jmgfam.h Version 1.1 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2017 - 2020 */
/* */ /* */
/* This file contains the JAVA MongoDB access method classes declares */ /* This file contains the JAVA MongoDB access method classes declares */
/***********************************************************************/ /***********************************************************************/
...@@ -25,6 +25,9 @@ class DllExport JMGFAM : public DOSFAM { ...@@ -25,6 +25,9 @@ class DllExport JMGFAM : public DOSFAM {
public: public:
// Constructor // Constructor
JMGFAM(PJDEF tdp); JMGFAM(PJDEF tdp);
#if defined(BSON_SUPPORT)
JMGFAM(PBDEF tdp);
#endif // BSON_SUPPORT
JMGFAM(PJMGFAM txfp); JMGFAM(PJMGFAM txfp);
// Implementation // Implementation
......
...@@ -121,7 +121,7 @@ JMgoConn::JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper) ...@@ -121,7 +121,7 @@ JMgoConn::JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper)
/***********************************************************************/ /***********************************************************************/
void JMgoConn::AddJars(PSTRG jpop, char sep) void JMgoConn::AddJars(PSTRG jpop, char sep)
{ {
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
if (m_Version == 2) { if (m_Version == 2) {
jpop->Append(sep); jpop->Append(sep);
// jpop->Append("C:/Eclipse/workspace/MongoWrap2/bin"); // jpop->Append("C:/Eclipse/workspace/MongoWrap2/bin");
...@@ -134,7 +134,7 @@ void JMgoConn::AddJars(PSTRG jpop, char sep) ...@@ -134,7 +134,7 @@ void JMgoConn::AddJars(PSTRG jpop, char sep)
jpop->Append(sep); jpop->Append(sep);
jpop->Append("C:/mongo-java-driver/mongo-java-driver-3.4.2.jar"); jpop->Append("C:/mongo-java-driver/mongo-java-driver-3.4.2.jar");
} // endif m_Version } // endif m_Version
#endif // DEVELOPMENT #endif // BSON_SUPPORT
} // end of AddJars } // end of AddJars
/***********************************************************************/ /***********************************************************************/
......
...@@ -82,11 +82,11 @@ ...@@ -82,11 +82,11 @@
#endif // JAVA_SUPPORT #endif // JAVA_SUPPORT
#include "tabpivot.h" #include "tabpivot.h"
#include "tabvir.h" #include "tabvir.h"
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
#include "tabbson.h" #include "tabbson.h"
#else #else
#include "tabjson.h" #include "tabjson.h"
#endif // DEVELOPMENT #endif // BSON_SUPPORT
#include "ha_connect.h" #include "ha_connect.h"
#if defined(XML_SUPPORT) #if defined(XML_SUPPORT)
#include "tabxml.h" #include "tabxml.h"
...@@ -111,6 +111,9 @@ extern "C" HINSTANCE s_hModule; // Saved module handle ...@@ -111,6 +111,9 @@ extern "C" HINSTANCE s_hModule; // Saved module handle
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
bool MongoEnabled(void); bool MongoEnabled(void);
#endif // JAVA_SUPPORT || CMGO_SUPPORT #endif // JAVA_SUPPORT || CMGO_SUPPORT
#if defined(BSON_SUPPORT)
bool Force_Bson(void);
#endif // BSON_SUPPORT
/***********************************************************************/ /***********************************************************************/
/* Get the plugin directory. */ /* Get the plugin directory. */
...@@ -134,25 +137,25 @@ TABTYPE GetTypeID(const char *type) ...@@ -134,25 +137,25 @@ TABTYPE GetTypeID(const char *type)
: (!stricmp(type, "DBF")) ? TAB_DBF : (!stricmp(type, "DBF")) ? TAB_DBF
#if defined(XML_SUPPORT) #if defined(XML_SUPPORT)
: (!stricmp(type, "XML")) ? TAB_XML : (!stricmp(type, "XML")) ? TAB_XML
#endif #endif // XML_SUPPORT
: (!stricmp(type, "INI")) ? TAB_INI : (!stricmp(type, "INI")) ? TAB_INI
: (!stricmp(type, "VEC")) ? TAB_VEC : (!stricmp(type, "VEC")) ? TAB_VEC
#if defined(ODBC_SUPPORT) #if defined(ODBC_SUPPORT)
: (!stricmp(type, "ODBC")) ? TAB_ODBC : (!stricmp(type, "ODBC")) ? TAB_ODBC
#endif #endif // ODBC_SUPPORT
#if defined(JAVA_SUPPORT) #if defined(JAVA_SUPPORT)
: (!stricmp(type, "JDBC")) ? TAB_JDBC : (!stricmp(type, "JDBC")) ? TAB_JDBC
#endif #endif // JAVA_SUPPORT
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
: (!stricmp(type, "MONGO") && MongoEnabled()) ? TAB_MONGO : (!stricmp(type, "MONGO") && MongoEnabled()) ? TAB_MONGO
#endif #endif // JAVA_SUPPORT || CMGO_SUPPORT
: (!stricmp(type, "MYSQL")) ? TAB_MYSQL : (!stricmp(type, "MYSQL")) ? TAB_MYSQL
: (!stricmp(type, "MYPRX")) ? TAB_MYSQL : (!stricmp(type, "MYPRX")) ? TAB_MYSQL
: (!stricmp(type, "DIR")) ? TAB_DIR : (!stricmp(type, "DIR")) ? TAB_DIR
#if defined(__WIN__) #if defined(__WIN__)
: (!stricmp(type, "MAC")) ? TAB_MAC : (!stricmp(type, "MAC")) ? TAB_MAC
: (!stricmp(type, "WMI")) ? TAB_WMI : (!stricmp(type, "WMI")) ? TAB_WMI
#endif #endif // __WIN__
: (!stricmp(type, "TBL")) ? TAB_TBL : (!stricmp(type, "TBL")) ? TAB_TBL
: (!stricmp(type, "XCOL")) ? TAB_XCL : (!stricmp(type, "XCOL")) ? TAB_XCL
: (!stricmp(type, "OCCUR")) ? TAB_OCCUR : (!stricmp(type, "OCCUR")) ? TAB_OCCUR
...@@ -161,12 +164,12 @@ TABTYPE GetTypeID(const char *type) ...@@ -161,12 +164,12 @@ TABTYPE GetTypeID(const char *type)
: (!stricmp(type, "PIVOT")) ? TAB_PIVOT : (!stricmp(type, "PIVOT")) ? TAB_PIVOT
: (!stricmp(type, "VIR")) ? TAB_VIR : (!stricmp(type, "VIR")) ? TAB_VIR
: (!stricmp(type, "JSON")) ? TAB_JSON : (!stricmp(type, "JSON")) ? TAB_JSON
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
: (!stricmp(type, "BSON")) ? TAB_BSON : (!stricmp(type, "BSON")) ? TAB_BSON
#endif #endif // BSON_SUPPORT
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
: (!stricmp(type, "ZIP")) ? TAB_ZIP : (!stricmp(type, "ZIP")) ? TAB_ZIP
#endif #endif // ZIP_SUPPORT
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY; : (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID } // end of GetTypeID
...@@ -188,9 +191,9 @@ bool IsFileType(TABTYPE type) ...@@ -188,9 +191,9 @@ bool IsFileType(TABTYPE type)
case TAB_INI: case TAB_INI:
case TAB_VEC: case TAB_VEC:
case TAB_JSON: case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // DEVELOPMENT #endif // BSON_SUPPORT
case TAB_REST: case TAB_REST:
// case TAB_ZIP: // case TAB_ZIP:
isfile= true; isfile= true;
...@@ -286,9 +289,9 @@ bool IsTypeIndexable(TABTYPE type) ...@@ -286,9 +289,9 @@ bool IsTypeIndexable(TABTYPE type)
case TAB_VEC: case TAB_VEC:
case TAB_DBF: case TAB_DBF:
case TAB_JSON: case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // DEVELOPMENT #endif // BSON_SUPPORT
idx= true; idx= true;
break; break;
default: default:
...@@ -315,9 +318,9 @@ int GetIndexType(TABTYPE type) ...@@ -315,9 +318,9 @@ int GetIndexType(TABTYPE type)
case TAB_VEC: case TAB_VEC:
case TAB_DBF: case TAB_DBF:
case TAB_JSON: case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // DEVELOPMENT #endif // BSON_SUPPORT
xtyp= 1; xtyp= 1;
break; break;
case TAB_MYSQL: case TAB_MYSQL:
...@@ -481,10 +484,18 @@ PTABDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) ...@@ -481,10 +484,18 @@ PTABDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
case TAB_MYSQL: tdp= new(g) MYSQLDEF; break; case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
case TAB_PIVOT: tdp= new(g) PIVOTDEF; break; case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
case TAB_VIR: tdp= new(g) VIRDEF; break; case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break; case TAB_JSON:
#if defined(DEVELOPMENT) #if defined(BSON_SUPPORT)
if (Force_Bson())
tdp= new(g) BSONDEF;
else
#endif // BSON_SUPPORT
tdp= new(g) JSONDEF;
break;
#if defined(BSON_SUPPORT)
case TAB_BSON: tdp= new(g) BSONDEF; break; case TAB_BSON: tdp= new(g) BSONDEF; break;
#endif // DEVELOPMENT #endif // BSON_SUPPORT
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp= new(g) ZIPDEF; break; case TAB_ZIP: tdp= new(g) ZIPDEF; break;
#endif // ZIP_SUPPORT #endif // ZIP_SUPPORT
......
#
# Testing doc samples
#
CREATE TABLE t1
(
ISBN CHAR(15),
LANG CHAR(2),
SUBJECT CHAR(32),
AUTHOR CHAR(64),
TITLE CHAR(32),
TRANSLATION CHAR(32),
TRANSLATOR CHAR(80),
PUBLISHER CHAR(32),
DATEPUB int(4)
) ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
ISBN LANG SUBJECT AUTHOR TITLE TRANSLATION TRANSLATOR PUBLISHER DATEPUB
9782212090819 fr applications Jean-Christophe Bernadac, Franois Knab Construire une application XML NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
DROP TABLE t1;
#
# Testing Jpath. Get the number of authors
#
CREATE TABLE t1
(
ISBN CHAR(15),
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
Authors INT(2) JPATH='$.AUTHOR[#]',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATION',
Translator CHAR(80) JPATH='$.TRANSLATOR',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB'
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
ISBN Language Subject Authors Title Translation Translator Publisher Location Year
9782212090819 fr applications 2 Construire une application XML NULL NULL Eyrolles Paris 1999
9782840825685 fr applications 1 XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
DROP TABLE t1;
#
# Concatenates the authors
#
CREATE TABLE t1
(
ISBN CHAR(15),
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
AuthorFN CHAR(128) JPATH='$.AUTHOR[" and "].FIRSTNAME',
AuthorLN CHAR(128) JPATH='$.AUTHOR[" and "].LASTNAME',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATION',
Translator CHAR(80) JPATH='$.TRANSLATOR',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB'
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher Location Year
9782212090819 fr applications Jean-Christophe and Franois Bernadac and Knab Construire une application XML NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
DROP TABLE t1;
#
# Testing expanding authors
#
CREATE TABLE t1
(
ISBN CHAR(15),
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
AuthorFN CHAR(128) JPATH='$.AUTHOR[*].FIRSTNAME',
AuthorLN CHAR(128) JPATH='$.AUTHOR[*].LASTNAME',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATION',
Translator CHAR(80) JPATH='$.TRANSLATOR',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB'
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher Location Year
9782212090819 fr applications Jean-Christophe Bernadac Construire une application XML NULL NULL Eyrolles Paris 1999
9782212090819 fr applications Franois Knab Construire une application XML NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
UPDATE t1 SET AuthorFN = 'Philippe' WHERE AuthorLN = 'Knab';
SELECT * FROM t1 WHERE ISBN = '9782212090819';
ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher Location Year
9782212090819 fr applications Jean-Christophe Bernadac Construire une application XML NULL NULL Eyrolles Paris 1999
9782212090819 fr applications Philippe Knab Construire une application XML NULL NULL Eyrolles Paris 1999
#
# To add an author a new table must be created
#
CREATE TABLE t2 (
FIRSTNAME CHAR(32),
LASTNAME CHAR(32))
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json' OPTION_LIST='Object=$[1].AUTHOR';
SELECT * FROM t2;
FIRSTNAME LASTNAME
William J. Pardi
INSERT INTO t2 VALUES('Charles','Dickens');
SELECT * FROM t1;
ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher Location Year
9782212090819 fr applications Jean-Christophe Bernadac Construire une application XML NULL NULL Eyrolles Paris 1999
9782212090819 fr applications Philippe Knab Construire une application XML NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
9782840825685 fr applications Charles Dickens XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
DROP TABLE t1;
DROP TABLE t2;
#
# Check the biblio file has the good format
#
CREATE TABLE t1
(
line char(255)
)
ENGINE=CONNECT TABLE_TYPE=DOS FILE_NAME='biblio.json';
SELECT * FROM t1;
line
[
{
"ISBN": "9782212090819",
"LANG": "fr",
"SUBJECT": "applications",
"AUTHOR": [
{
"FIRSTNAME": "Jean-Christophe",
"LASTNAME": "Bernadac"
},
{
"FIRSTNAME": "Philippe",
"LASTNAME": "Knab"
}
],
"TITLE": "Construire une application XML",
"PUBLISHER": {
"NAME": "Eyrolles",
"PLACE": "Paris"
},
"DATEPUB": 1999
},
{
"ISBN": "9782840825685",
"LANG": "fr",
"SUBJECT": "applications",
"AUTHOR": [
{
"FIRSTNAME": "William J.",
"LASTNAME": "Pardi"
},
{
"FIRSTNAME": "Charles",
"LASTNAME": "Dickens"
}
],
"TITLE": "XML en Action",
"TRANSLATION": "adapt de l'anglais par",
"TRANSLATOR": {
"FIRSTNAME": "James",
"LASTNAME": "Guerin"
},
"PUBLISHER": {
"NAME": "Microsoft Press",
"PLACE": "Paris"
},
"DATEPUB": 1999
}
]
DROP TABLE t1;
#
# Testing a pretty=0 file
#
CREATE TABLE t1
(
ISBN CHAR(15) NOT NULL,
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
AuthorFN CHAR(128) JPATH='$.AUTHOR[*].FIRSTNAME',
AuthorLN CHAR(128) JPATH='$.AUTHOR[*].LASTNAME',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATED.PREFIX',
TranslatorFN CHAR(80) JPATH='$.TRANSLATED.TRANSLATOR.FIRSTNAME',
TranslatorLN CHAR(80) JPATH='$.TRANSLATED.TRANSLATOR.LASTNAME',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB',
INDEX IX(ISBN)
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='bib0.json' LRECL=320 OPTION_LIST='Pretty=0';
SHOW INDEX FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 IX 1 ISBN A NULL NULL NULL XINDEX
SELECT * FROM t1;
ISBN Language Subject AuthorFN AuthorLN Title Translation TranslatorFN TranslatorLN Publisher Location Year
9782212090819 fr applications Jean-Michel Bernadac Construire une application XML NULL NULL NULL Eyrolles Paris 1999
9782212090819 fr applications Franois Knab Construire une application XML NULL NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 2001
DESCRIBE SELECT * FROM t1 WHERE ISBN = '9782212090819';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref IX IX 15 const 1 Using where
UPDATE t1 SET AuthorFN = 'Philippe' WHERE ISBN = '9782212090819';
ERROR HY000: Got error 122 'Cannot write expanded column when Pretty is not 2' from CONNECT
DROP TABLE t1;
#
# A file with 2 arrays
#
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[*].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[].EXPENSE["+"].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[].EXPENSE[+].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t1;
WHO WEEK WHAT AMOUNT
Joe 3 Beer+Food+Food+Car 69.00
Joe 4 Beer+Beer+Food+Food+Beer 83.00
Joe 5 Beer+Food 26.00
Beth 3 Beer 16.00
Beth 4 Food+Beer 32.00
Beth 5 Food+Beer 32.00
Janet 3 Car+Food+Beer 55.00
Janet 4 Car 17.00
Janet 5 Beer+Car+Beer+Food 57.00
DROP TABLE t1;
#
# Now it can be fully expanded
#
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[*].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[*].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[*].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t1;
WHO WEEK WHAT AMOUNT
Joe 3 Beer 18.00
Joe 3 Food 12.00
Joe 3 Food 19.00
Joe 3 Car 20.00
Joe 4 Beer 19.00
Joe 4 Beer 16.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 4 Beer 14.00
Joe 5 Beer 14.00
Joe 5 Food 12.00
Beth 3 Beer 16.00
Beth 4 Food 17.00
Beth 4 Beer 15.00
Beth 5 Food 12.00
Beth 5 Beer 20.00
Janet 3 Car 19.00
Janet 3 Food 18.00
Janet 3 Beer 18.00
Janet 4 Car 17.00
Janet 5 Beer 14.00
Janet 5 Car 12.00
Janet 5 Beer 19.00
Janet 5 Food 12.00
DROP TABLE t1;
#
# A table showing many calculated results
#
CREATE TABLE t1 (
WHO CHAR(12) NOT NULL,
WEEKS CHAR(12) NOT NULL JPATH='$.WEEK[", "].NUMBER',
SUMS CHAR(64) NOT NULL JPATH='$.WEEK["+"].EXPENSE[+].AMOUNT',
SUM DOUBLE(8,2) NOT NULL JPATH='$.WEEK[+].EXPENSE[+].AMOUNT',
AVGS CHAR(64) NOT NULL JPATH='$.WEEK["+"].EXPENSE[!].AMOUNT',
SUMAVG DOUBLE(8,2) NOT NULL JPATH='$.WEEK[+].EXPENSE[!].AMOUNT',
AVGSUM DOUBLE(8,2) NOT NULL JPATH='$.WEEK[!].EXPENSE[+].AMOUNT',
AVGAVG DOUBLE(8,2) NOT NULL JPATH='$.WEEK[!].EXPENSE[!].AMOUNT',
AVERAGE DOUBLE(8,2) NOT NULL JPATH='$.WEEK[!].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t1;
WHO WEEKS SUMS SUM AVGS SUMAVG AVGSUM AVGAVG AVERAGE
Joe 3, 4, 5 69.00+83.00+26.00 178.00 17.25+16.60+13.00 46.85 59.33 15.62 16.18
Beth 3, 4, 5 16.00+32.00+32.00 80.00 16.00+16.00+16.00 48.00 26.67 16.00 16.00
Janet 3, 4, 5 55.00+17.00+57.00 129.00 18.33+17.00+14.25 49.58 43.00 16.53 16.12
DROP TABLE t1;
#
# Expand expense in 3 one week tables
#
CREATE TABLE t2 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[0].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[0].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[0].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t2;
WHO WEEK WHAT AMOUNT
Joe 3 Beer 18.00
Joe 3 Food 12.00
Joe 3 Food 19.00
Joe 3 Car 20.00
Beth 3 Beer 16.00
Janet 3 Car 19.00
Janet 3 Food 18.00
Janet 3 Beer 18.00
CREATE TABLE t3 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[1].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[1].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[1].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t3;
WHO WEEK WHAT AMOUNT
Joe 4 Beer 19.00
Joe 4 Beer 16.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 4 Beer 14.00
Beth 4 Food 17.00
Beth 4 Beer 15.00
Janet 4 Car 17.00
CREATE TABLE t4 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[2].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[2].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[2].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t4;
WHO WEEK WHAT AMOUNT
Joe 5 Beer 14.00
Joe 5 Food 12.00
Beth 5 Food 12.00
Beth 5 Beer 20.00
Janet 5 Beer 14.00
Janet 5 Car 12.00
Janet 5 Beer 19.00
Janet 5 Food 12.00
#
# The expanded table is made as a TBL table
#
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32),
AMOUNT DOUBLE(8,2))
ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t2,t3,t4';
SELECT * FROM t1;
WHO WEEK WHAT AMOUNT
Joe 3 Beer 18.00
Joe 3 Food 12.00
Joe 3 Food 19.00
Joe 3 Car 20.00
Beth 3 Beer 16.00
Janet 3 Car 19.00
Janet 3 Food 18.00
Janet 3 Beer 18.00
Joe 4 Beer 19.00
Joe 4 Beer 16.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 4 Beer 14.00
Beth 4 Food 17.00
Beth 4 Beer 15.00
Janet 4 Car 17.00
Joe 5 Beer 14.00
Joe 5 Food 12.00
Beth 5 Food 12.00
Beth 5 Beer 20.00
Janet 5 Beer 14.00
Janet 5 Car 12.00
Janet 5 Beer 19.00
Janet 5 Food 12.00
DROP TABLE t1, t2, t3, t4;
#
# Three partial JSON tables
#
CREATE TABLE t2 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp3.json';
SELECT * FROM t2;
WHO WEEK WHAT AMOUNT
Joe 3 Beer 18.00
Joe 3 Food 12.00
Joe 3 Food 19.00
Joe 3 Car 20.00
Beth 3 Beer 16.00
Janet 3 Car 19.00
Janet 3 Food 18.00
Janet 3 Beer 18.00
CREATE TABLE t3 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp4.json';
SELECT * FROM t3;
WHO WEEK WHAT AMOUNT
Joe 4 Beer 19.00
Joe 4 Beer 16.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 4 Beer 14.00
Beth 4 Food 17.00
Beth 4 Beer 15.00
Janet 4 Car 17.00
CREATE TABLE t4 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp5.json';
SELECT * FROM t4;
WHO WEEK WHAT AMOUNT
Joe 5 Beer 14.00
Joe 5 Food 12.00
Beth 5 Food 12.00
Beth 5 Beer 20.00
Janet 5 Beer 14.00
Janet 5 Car 12.00
Janet 5 Beer 19.00
Janet 5 Food 12.00
#
# The complete table can be a multiple JSON table
#
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp*.json' MULTIPLE=1;
SELECT * FROM t1 ORDER BY WHO, WEEK, WHAT, AMOUNT;
WHO WEEK WHAT AMOUNT
Beth 3 Beer 16.00
Beth 4 Beer 15.00
Beth 4 Food 17.00
Beth 5 Beer 20.00
Beth 5 Food 12.00
Janet 3 Beer 18.00
Janet 3 Car 19.00
Janet 3 Food 18.00
Janet 4 Car 17.00
Janet 5 Beer 14.00
Janet 5 Beer 19.00
Janet 5 Car 12.00
Janet 5 Food 12.00
Joe 3 Beer 18.00
Joe 3 Car 20.00
Joe 3 Food 12.00
Joe 3 Food 19.00
Joe 4 Beer 14.00
Joe 4 Beer 16.00
Joe 4 Beer 19.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 5 Beer 14.00
Joe 5 Food 12.00
DROP TABLE t1;
#
# Or also a partition JSON table
#
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp%s.json';
ALTER TABLE t1
PARTITION BY LIST COLUMNS(WEEK) (
PARTITION `3` VALUES IN(3),
PARTITION `4` VALUES IN(4),
PARTITION `5` VALUES IN(5));
Warnings:
Warning 1105 Data repartition in 3 is unchecked
Warning 1105 Data repartition in 4 is unchecked
Warning 1105 Data repartition in 5 is unchecked
SHOW WARNINGS;
Level Code Message
Warning 1105 Data repartition in 3 is unchecked
Warning 1105 Data repartition in 4 is unchecked
Warning 1105 Data repartition in 5 is unchecked
SELECT * FROM t1;
WHO WEEK WHAT AMOUNT
Joe 3 Beer 18.00
Joe 3 Food 12.00
Joe 3 Food 19.00
Joe 3 Car 20.00
Beth 3 Beer 16.00
Janet 3 Car 19.00
Janet 3 Food 18.00
Janet 3 Beer 18.00
Joe 4 Beer 19.00
Joe 4 Beer 16.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 4 Beer 14.00
Beth 4 Food 17.00
Beth 4 Beer 15.00
Janet 4 Car 17.00
Joe 5 Beer 14.00
Joe 5 Food 12.00
Beth 5 Food 12.00
Beth 5 Beer 20.00
Janet 5 Beer 14.00
Janet 5 Car 12.00
Janet 5 Beer 19.00
Janet 5 Food 12.00
SELECT * FROM t1 WHERE WEEK = 4;
WHO WEEK WHAT AMOUNT
Joe 4 Beer 19.00
Joe 4 Beer 16.00
Joe 4 Food 17.00
Joe 4 Food 17.00
Joe 4 Beer 14.00
Beth 4 Food 17.00
Beth 4 Beer 15.00
Janet 4 Car 17.00
DROP TABLE t1, t2, t3, t4;
--source include/not_embedded.inc
--source include/have_partition.inc
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MTR_SUITE_DIR/std_data/biblio.json $MYSQLD_DATADIR/test/biblio.json
--copy_file $MTR_SUITE_DIR/std_data/bib0.json $MYSQLD_DATADIR/test/bib0.json
--copy_file $MTR_SUITE_DIR/std_data/expense.json $MYSQLD_DATADIR/test/expense.json
--copy_file $MTR_SUITE_DIR/std_data/mulexp3.json $MYSQLD_DATADIR/test/mulexp3.json
--copy_file $MTR_SUITE_DIR/std_data/mulexp4.json $MYSQLD_DATADIR/test/mulexp4.json
--copy_file $MTR_SUITE_DIR/std_data/mulexp5.json $MYSQLD_DATADIR/test/mulexp5.json
--echo #
--echo # Testing doc samples
--echo #
CREATE TABLE t1
(
ISBN CHAR(15),
LANG CHAR(2),
SUBJECT CHAR(32),
AUTHOR CHAR(64),
TITLE CHAR(32),
TRANSLATION CHAR(32),
TRANSLATOR CHAR(80),
PUBLISHER CHAR(32),
DATEPUB int(4)
) ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Testing Jpath. Get the number of authors
--echo #
CREATE TABLE t1
(
ISBN CHAR(15),
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
Authors INT(2) JPATH='$.AUTHOR[#]',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATION',
Translator CHAR(80) JPATH='$.TRANSLATOR',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB'
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Concatenates the authors
--echo #
CREATE TABLE t1
(
ISBN CHAR(15),
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
AuthorFN CHAR(128) JPATH='$.AUTHOR[" and "].FIRSTNAME',
AuthorLN CHAR(128) JPATH='$.AUTHOR[" and "].LASTNAME',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATION',
Translator CHAR(80) JPATH='$.TRANSLATOR',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB'
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Testing expanding authors
--echo #
CREATE TABLE t1
(
ISBN CHAR(15),
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
AuthorFN CHAR(128) JPATH='$.AUTHOR[*].FIRSTNAME',
AuthorLN CHAR(128) JPATH='$.AUTHOR[*].LASTNAME',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATION',
Translator CHAR(80) JPATH='$.TRANSLATOR',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB'
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT * FROM t1;
UPDATE t1 SET AuthorFN = 'Philippe' WHERE AuthorLN = 'Knab';
SELECT * FROM t1 WHERE ISBN = '9782212090819';
--echo #
--echo # To add an author a new table must be created
--echo #
CREATE TABLE t2 (
FIRSTNAME CHAR(32),
LASTNAME CHAR(32))
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json' OPTION_LIST='Object=$[1].AUTHOR';
SELECT * FROM t2;
INSERT INTO t2 VALUES('Charles','Dickens');
SELECT * FROM t1;
DROP TABLE t1;
DROP TABLE t2;
--echo #
--echo # Check the biblio file has the good format
--echo #
CREATE TABLE t1
(
line char(255)
)
ENGINE=CONNECT TABLE_TYPE=DOS FILE_NAME='biblio.json';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Testing a pretty=0 file
--echo #
CREATE TABLE t1
(
ISBN CHAR(15) NOT NULL,
Language CHAR(2) JPATH='$.LANG',
Subject CHAR(32) JPATH='$.SUBJECT',
AuthorFN CHAR(128) JPATH='$.AUTHOR[*].FIRSTNAME',
AuthorLN CHAR(128) JPATH='$.AUTHOR[*].LASTNAME',
Title CHAR(32) JPATH='$.TITLE',
Translation CHAR(32) JPATH='$.TRANSLATED.PREFIX',
TranslatorFN CHAR(80) JPATH='$.TRANSLATED.TRANSLATOR.FIRSTNAME',
TranslatorLN CHAR(80) JPATH='$.TRANSLATED.TRANSLATOR.LASTNAME',
Publisher CHAR(20) JPATH='$.PUBLISHER.NAME',
Location CHAR(16) JPATH='$.PUBLISHER.PLACE',
Year int(4) JPATH='$.DATEPUB',
INDEX IX(ISBN)
)
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='bib0.json' LRECL=320 OPTION_LIST='Pretty=0';
SHOW INDEX FROM t1;
SELECT * FROM t1;
DESCRIBE SELECT * FROM t1 WHERE ISBN = '9782212090819';
--error ER_GET_ERRMSG
UPDATE t1 SET AuthorFN = 'Philippe' WHERE ISBN = '9782212090819';
DROP TABLE t1;
--echo #
--echo # A file with 2 arrays
--echo #
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[*].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[].EXPENSE["+"].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[].EXPENSE[+].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Now it can be fully expanded
--echo #
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[*].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[*].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[*].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
#--error ER_GET_ERRMSG
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # A table showing many calculated results
--echo #
CREATE TABLE t1 (
WHO CHAR(12) NOT NULL,
WEEKS CHAR(12) NOT NULL JPATH='$.WEEK[", "].NUMBER',
SUMS CHAR(64) NOT NULL JPATH='$.WEEK["+"].EXPENSE[+].AMOUNT',
SUM DOUBLE(8,2) NOT NULL JPATH='$.WEEK[+].EXPENSE[+].AMOUNT',
AVGS CHAR(64) NOT NULL JPATH='$.WEEK["+"].EXPENSE[!].AMOUNT',
SUMAVG DOUBLE(8,2) NOT NULL JPATH='$.WEEK[+].EXPENSE[!].AMOUNT',
AVGSUM DOUBLE(8,2) NOT NULL JPATH='$.WEEK[!].EXPENSE[+].AMOUNT',
AVGAVG DOUBLE(8,2) NOT NULL JPATH='$.WEEK[!].EXPENSE[!].AMOUNT',
AVERAGE DOUBLE(8,2) NOT NULL JPATH='$.WEEK[!].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Expand expense in 3 one week tables
--echo #
CREATE TABLE t2 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[0].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[0].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[0].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t2;
CREATE TABLE t3 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[1].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[1].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[1].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t3;
CREATE TABLE t4 (
WHO CHAR(12),
WEEK INT(2) JPATH='$.WEEK[2].NUMBER',
WHAT CHAR(32) JPATH='$.WEEK[2].EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.WEEK[2].EXPENSE[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='expense.json';
SELECT * FROM t4;
--echo #
--echo # The expanded table is made as a TBL table
--echo #
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32),
AMOUNT DOUBLE(8,2))
ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t2,t3,t4';
SELECT * FROM t1;
DROP TABLE t1, t2, t3, t4;
--echo #
--echo # Three partial JSON tables
--echo #
CREATE TABLE t2 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp3.json';
SELECT * FROM t2;
CREATE TABLE t3 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp4.json';
SELECT * FROM t3;
CREATE TABLE t4 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp5.json';
SELECT * FROM t4;
--echo #
--echo # The complete table can be a multiple JSON table
--echo #
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp*.json' MULTIPLE=1;
SELECT * FROM t1 ORDER BY WHO, WEEK, WHAT, AMOUNT;
DROP TABLE t1;
--echo #
--echo # Or also a partition JSON table
--echo #
CREATE TABLE t1 (
WHO CHAR(12),
WEEK INT(2),
WHAT CHAR(32) JPATH='$.EXPENSE[*].WHAT',
AMOUNT DOUBLE(8,2) JPATH='$.EXPENSE.[*].AMOUNT')
ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='mulexp%s.json';
ALTER TABLE t1
PARTITION BY LIST COLUMNS(WEEK) (
PARTITION `3` VALUES IN(3),
PARTITION `4` VALUES IN(4),
PARTITION `5` VALUES IN(5));
SHOW WARNINGS;
SELECT * FROM t1;
SELECT * FROM t1 WHERE WEEK = 4;
DROP TABLE t1, t2, t3, t4;
#
# Clean up
#
--remove_file $MYSQLD_DATADIR/test/biblio.json
--remove_file $MYSQLD_DATADIR/test/bib0.dnx
--remove_file $MYSQLD_DATADIR/test/bib0.json
--remove_file $MYSQLD_DATADIR/test/expense.json
--remove_file $MYSQLD_DATADIR/test/mulexp3.json
--remove_file $MYSQLD_DATADIR/test/mulexp4.json
--remove_file $MYSQLD_DATADIR/test/mulexp5.json
/************* tabbson C++ Program Source Code File (.CPP) *************/ /************* tabbson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.0 */ /* PROGRAM NAME: tabbson Version 1.0 */
/* (C) Copyright to the author Olivier BERTRAND 2020 */ /* (C) Copyright to the author Olivier BERTRAND 2020 */
/* This program are the BSON class DB execution routines. */ /* This program are the BSON class DB execution routines. */
/***********************************************************************/ /***********************************************************************/
...@@ -29,14 +29,12 @@ ...@@ -29,14 +29,12 @@
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
#include "filamzip.h" #include "filamzip.h"
#endif // ZIP_SUPPORT #endif // ZIP_SUPPORT
#if 0
#if defined(JAVA_SUPPORT) #if defined(JAVA_SUPPORT)
#include "jmgfam.h" #include "jmgfam.h"
#endif // JAVA_SUPPORT #endif // JAVA_SUPPORT
#if defined(CMGO_SUPPORT) #if defined(CMGO_SUPPORT)
#include "cmgfam.h" #include "cmgfam.h"
#endif // CMGO_SUPPORT #endif // CMGO_SUPPORT
#endif // 0
#include "tabmul.h" #include "tabmul.h"
#include "checklvl.h" #include "checklvl.h"
#include "resource.h" #include "resource.h"
...@@ -266,38 +264,36 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) ...@@ -266,38 +264,36 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
if (tdp->Zipped) { if (tdp->Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
tjnp = new(g)TDBBSN(tdp->G, tdp, new(g) UNZFAM(tdp)); tjnp = new(g)TDBBSN(g, tdp, new(g) UNZFAM(tdp));
#else // !ZIP_SUPPORT #else // !ZIP_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
return NULL; return NULL;
#endif // !ZIP_SUPPORT #endif // !ZIP_SUPPORT
#if 0
} else if (tdp->Uri) { } else if (tdp->Uri) {
if (tdp->Driver && toupper(*tdp->Driver) == 'C') { if (tdp->Driver && toupper(*tdp->Driver) == 'C') {
#if defined(CMGO_SUPPORT) #if defined(CMGO_SUPPORT)
tjnp = new(g) TDBBSN(G, tdp, new(g) CMGFAM(tdp)); tjnp = new(g) TDBBSN(g, tdp, new(g) CMGFAM(tdp));
#else #else
sprintf(g->Message, "Mongo %s Driver not available", "C"); sprintf(g->Message, "Mongo %s Driver not available", "C");
return 0; return 0;
#endif #endif
} else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') {
#if defined(JAVA_SUPPORT) #if defined(JAVA_SUPPORT)
tjnp = new(g) TDBBSN(G, tdp, new(g) JMGFAM(tdp)); tjnp = new(g) TDBBSN(g, tdp, new(g) JMGFAM(tdp));
#else #else
sprintf(g->Message, "Mongo %s Driver not available", "Java"); sprintf(g->Message, "Mongo %s Driver not available", "Java");
return 0; return 0;
#endif #endif
} else { // Driver not specified } else { // Driver not specified
#if defined(CMGO_SUPPORT) #if defined(CMGO_SUPPORT)
tjnp = new(g) TDBBSN(G, tdp, new(g) CMGFAM(tdp)); tjnp = new(g) TDBBSN(g, tdp, new(g) CMGFAM(tdp));
#elif defined(JAVA_SUPPORT) #elif defined(JAVA_SUPPORT)
tjnp = new(g) TDBBSN(G, tdp, new(g) JMGFAM(tdp)); tjnp = new(g) TDBBSN(g, tdp, new(g) JMGFAM(tdp));
#else #else
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return 0; return 0;
#endif #endif
} // endif Driver } // endif Driver
#endif // 0
} else if (tdp->Pretty >= 0) } else if (tdp->Pretty >= 0)
tjnp = new(g) TDBBSN(g, tdp, new(g) DOSFAM(tdp)); tjnp = new(g) TDBBSN(g, tdp, new(g) DOSFAM(tdp));
...@@ -394,7 +390,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j) ...@@ -394,7 +390,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
char *p, *pc = colname + strlen(colname), buf[32]; char *p, *pc = colname + strlen(colname), buf[32];
int ars; int ars;
size_t n; size_t n;
PBPR job; PBVAL job;
PBVAL jar; PBVAL jar;
if (jvp && !bp->IsJson(jvp)) { if (jvp && !bp->IsJson(jvp)) {
...@@ -436,9 +432,9 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j) ...@@ -436,9 +432,9 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
switch (jsp->Type) { switch (jsp->Type) {
case TYPE_JOB: case TYPE_JOB:
job = bp->GetObject(jsp); job = jsp;
for (PBPR jrp = job; jrp; jrp = bp->GetNext(jrp)) { for (PBPR jrp = bp->GetObject(job); jrp; jrp = bp->GetNext(jrp)) {
PCSZ k = bp->GetKey(jrp); PCSZ k = bp->GetKey(jrp);
if (*k != '$') { if (*k != '$') {
...@@ -456,7 +452,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j) ...@@ -456,7 +452,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
return false; return false;
case TYPE_JAR: case TYPE_JAR:
jar = bp->GetArray(jsp); jar = jsp;
if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key))) if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key)))
ars = MY_MIN(bp->GetArraySize(jar), limit); ars = MY_MIN(bp->GetArraySize(jar), limit);
...@@ -722,9 +718,11 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp) ...@@ -722,9 +718,11 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
case TYPE_BINT: case TYPE_BINT:
case TYPE_DBL: case TYPE_DBL:
case TYPE_DTM: case TYPE_DTM:
case TYPE_FLOAT:
switch (vp->GetType()) { switch (vp->GetType()) {
case TYPE_STRING: case TYPE_STRING:
case TYPE_DATE: case TYPE_DATE:
case TYPE_DECIM:
vp->SetValue_psz(GetString(jvp)); vp->SetValue_psz(GetString(jvp));
break; break;
case TYPE_INT: case TYPE_INT:
...@@ -738,7 +736,7 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp) ...@@ -738,7 +736,7 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
case TYPE_DOUBLE: case TYPE_DOUBLE:
vp->SetValue(GetDouble(jvp)); vp->SetValue(GetDouble(jvp));
if (jvp->Type == TYPE_DBL) if (jvp->Type == TYPE_DBL || jvp->Type == TYPE_FLOAT)
vp->SetPrec(jvp->Nd); vp->SetPrec(jvp->Nd);
break; break;
...@@ -1175,7 +1173,6 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -1175,7 +1173,6 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m)
return NULL; return NULL;
} // endif Lrecl } // endif Lrecl
#if 0
if (Uri) { if (Uri) {
if (Driver && toupper(*Driver) == 'C') { if (Driver && toupper(*Driver) == 'C') {
#if defined(CMGO_SUPPORT) #if defined(CMGO_SUPPORT)
...@@ -1203,8 +1200,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -1203,8 +1200,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m)
} // endif Driver } // endif Driver
} else if (Zipped) { } else if (Zipped) {
#endif // 0 // if (Zipped) {
if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) { if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2020 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2020 */
/* This program are the JSON class DB execution routines. */ /* This program are the JSON class DB execution routines. */
/***********************************************************************/ /***********************************************************************/
#undef BSON_SUPPORT
/***********************************************************************/ /***********************************************************************/
/* Include relevant sections of the MariaDB header file. */ /* Include relevant sections of the MariaDB header file. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment